Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(787)

Delta Between Two Patch Sets: src/cmd/cgo/out.go

Issue 9895043: code review 9895043: cmd/cgo: use gcc_struct attribute for packed structs to... (Closed)
Left Patch Set: Created 10 years, 10 months ago
Right Patch Set: diff -r 5a3640ad42c3 https://code.google.com/p/go/ Created 10 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/cmd/cgo/doc.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package main 5 package main
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "debug/elf" 9 "debug/elf"
10 "debug/macho" 10 "debug/macho"
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 fmt.Fprintf(fgcc, "_cgo%s%s(void *v)\n", cPrefix, n.Mangle) 478 fmt.Fprintf(fgcc, "_cgo%s%s(void *v)\n", cPrefix, n.Mangle)
479 fmt.Fprintf(fgcc, "{\n") 479 fmt.Fprintf(fgcc, "{\n")
480 if n.AddError { 480 if n.AddError {
481 fmt.Fprintf(fgcc, "\tint e;\n") // assuming 32 bit (see comment above structType) 481 fmt.Fprintf(fgcc, "\tint e;\n") // assuming 32 bit (see comment above structType)
482 fmt.Fprintf(fgcc, "\terrno = 0;\n") 482 fmt.Fprintf(fgcc, "\terrno = 0;\n")
483 } 483 }
484 // We're trying to write a gcc struct that matches 6c/8c/5c's layout. 484 // We're trying to write a gcc struct that matches 6c/8c/5c's layout.
485 // Use packed attribute to force no padding in this struct in case 485 // Use packed attribute to force no padding in this struct in case
486 // gcc has different packing requirements. For example, 486 // gcc has different packing requirements. For example,
487 // on 386 Windows, gcc wants to 8-align int64s, but 8c does not. 487 // on 386 Windows, gcc wants to 8-align int64s, but 8c does not.
488 » fmt.Fprintf(fgcc, "\t%s __attribute__((__packed__)) *a = v;\n", ctype) 488 » // Use __gcc_struct__ to work around http://gcc.gnu.org/PR52991 on x86,
489 » // and http://golang.org/issue/5603.
490 » extraAttr := ""
491 » if goarch == "amd64" || goarch == "386" {
492 » » extraAttr = ", __gcc_struct__"
493 » }
494 » fmt.Fprintf(fgcc, "\t%s __attribute__((__packed__%v)) *a = v;\n", ctype, extraAttr)
489 fmt.Fprintf(fgcc, "\t") 495 fmt.Fprintf(fgcc, "\t")
490 if t := n.FuncType.Result; t != nil { 496 if t := n.FuncType.Result; t != nil {
491 fmt.Fprintf(fgcc, "a->r = ") 497 fmt.Fprintf(fgcc, "a->r = ")
492 if c := t.C.String(); c[len(c)-1] == '*' { 498 if c := t.C.String(); c[len(c)-1] == '*' {
493 fmt.Fprint(fgcc, "(__typeof__(a->r)) ") 499 fmt.Fprint(fgcc, "(__typeof__(a->r)) ")
494 } 500 }
495 } 501 }
496 fmt.Fprintf(fgcc, "%s(", n.C) 502 fmt.Fprintf(fgcc, "%s(", n.C)
497 for i, t := range n.FuncType.Params { 503 for i, t := range n.FuncType.Params {
498 if i > 0 { 504 if i > 0 {
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 typedef double GoFloat64; 1148 typedef double GoFloat64;
1143 typedef __complex float GoComplex64; 1149 typedef __complex float GoComplex64;
1144 typedef __complex double GoComplex128; 1150 typedef __complex double GoComplex128;
1145 1151
1146 typedef struct { char *p; GoInt n; } GoString; 1152 typedef struct { char *p; GoInt n; } GoString;
1147 typedef void *GoMap; 1153 typedef void *GoMap;
1148 typedef void *GoChan; 1154 typedef void *GoChan;
1149 typedef struct { void *t; void *v; } GoInterface; 1155 typedef struct { void *t; void *v; } GoInterface;
1150 typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; 1156 typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
1151 ` 1157 `
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b