OLD | NEW |
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 30 matching lines...) Expand all Loading... |
41 | 41 |
42 // Write second Go output: definitions of _C_xxx. | 42 // Write second Go output: definitions of _C_xxx. |
43 // In a separate file so that the import of "unsafe" does not | 43 // In a separate file so that the import of "unsafe" does not |
44 // pollute the original file. | 44 // pollute the original file. |
45 fmt.Fprintf(fgo2, "// Created by cgo - DO NOT EDIT\n\n") | 45 fmt.Fprintf(fgo2, "// Created by cgo - DO NOT EDIT\n\n") |
46 fmt.Fprintf(fgo2, "package %s\n\n", p.PackageName) | 46 fmt.Fprintf(fgo2, "package %s\n\n", p.PackageName) |
47 fmt.Fprintf(fgo2, "import \"unsafe\"\n\n") | 47 fmt.Fprintf(fgo2, "import \"unsafe\"\n\n") |
48 fmt.Fprintf(fgo2, "import \"os\"\n\n") | 48 fmt.Fprintf(fgo2, "import \"os\"\n\n") |
49 fmt.Fprintf(fgo2, "import _ \"runtime/cgo\"\n\n") | 49 fmt.Fprintf(fgo2, "import _ \"runtime/cgo\"\n\n") |
50 fmt.Fprintf(fgo2, "type _ unsafe.Pointer\n\n") | 50 fmt.Fprintf(fgo2, "type _ unsafe.Pointer\n\n") |
51 » fmt.Fprintf(fgo2, "func _Cerrno(dst *os.Error, x int) { *dst = os.Errno(
x) }\n") | 51 » fmt.Fprintf(fgo2, "func _Cerrno(dst *error, x int) { *dst = os.Errno(x)
}\n") |
52 | 52 |
53 for name, def := range typedef { | 53 for name, def := range typedef { |
54 fmt.Fprintf(fgo2, "type %s ", name) | 54 fmt.Fprintf(fgo2, "type %s ", name) |
55 printer.Fprint(fgo2, fset, def) | 55 printer.Fprint(fgo2, fset, def) |
56 fmt.Fprintf(fgo2, "\n") | 56 fmt.Fprintf(fgo2, "\n") |
57 } | 57 } |
58 fmt.Fprintf(fgo2, "type _Ctype_void [0]byte\n") | 58 fmt.Fprintf(fgo2, "type _Ctype_void [0]byte\n") |
59 | 59 |
60 fmt.Fprintf(fc, cProlog) | 60 fmt.Fprintf(fc, cProlog) |
61 | 61 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } | 196 } |
197 fmt.Fprintf(&buf, "\t\t%s%s r;\n", qual, t.C) | 197 fmt.Fprintf(&buf, "\t\t%s%s r;\n", qual, t.C) |
198 off += t.Size | 198 off += t.Size |
199 } | 199 } |
200 if off%p.PtrSize != 0 { | 200 if off%p.PtrSize != 0 { |
201 pad := p.PtrSize - off%p.PtrSize | 201 pad := p.PtrSize - off%p.PtrSize |
202 fmt.Fprintf(&buf, "\t\tchar __pad%d[%d];\n", off, pad) | 202 fmt.Fprintf(&buf, "\t\tchar __pad%d[%d];\n", off, pad) |
203 off += pad | 203 off += pad |
204 } | 204 } |
205 if n.AddError { | 205 if n.AddError { |
206 » » fmt.Fprint(&buf, "\t\tvoid *e[2]; /* os.Error */\n") | 206 » » fmt.Fprint(&buf, "\t\tvoid *e[2]; /* error */\n") |
207 off += 2 * p.PtrSize | 207 off += 2 * p.PtrSize |
208 } | 208 } |
209 if off == 0 { | 209 if off == 0 { |
210 fmt.Fprintf(&buf, "\t\tchar unused;\n") // avoid empty struct | 210 fmt.Fprintf(&buf, "\t\tchar unused;\n") // avoid empty struct |
211 } | 211 } |
212 fmt.Fprintf(&buf, "\t}") | 212 fmt.Fprintf(&buf, "\t}") |
213 return buf.String(), off | 213 return buf.String(), off |
214 } | 214 } |
215 | 215 |
216 func (p *Package) writeDefsFunc(fc, fgo2 *os.File, n *Name) { | 216 func (p *Package) writeDefsFunc(fc, fgo2 *os.File, n *Name) { |
217 name := n.Go | 217 name := n.Go |
218 gtype := n.FuncType.Go | 218 gtype := n.FuncType.Go |
219 if n.AddError { | 219 if n.AddError { |
220 » » // Add "os.Error" to return type list. | 220 » » // Add "error" to return type list. |
221 // Type list is known to be 0 or 1 element - it's a C function. | 221 // Type list is known to be 0 or 1 element - it's a C function. |
222 » » err := &ast.Field{Type: ast.NewIdent("os.Error")} | 222 » » err := &ast.Field{Type: ast.NewIdent("error")} |
223 l := gtype.Results.List | 223 l := gtype.Results.List |
224 if len(l) == 0 { | 224 if len(l) == 0 { |
225 l = []*ast.Field{err} | 225 l = []*ast.Field{err} |
226 } else { | 226 } else { |
227 l = []*ast.Field{l[0], err} | 227 l = []*ast.Field{l[0], err} |
228 } | 228 } |
229 t := new(ast.FuncType) | 229 t := new(ast.FuncType) |
230 *t = *gtype | 230 *t = *gtype |
231 t.Results = &ast.FieldList{List: l} | 231 t.Results = &ast.FieldList{List: l} |
232 gtype = t | 232 gtype = t |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 typedef unsigned short ushort; | 736 typedef unsigned short ushort; |
737 typedef long long int64; | 737 typedef long long int64; |
738 typedef unsigned long long uint64; | 738 typedef unsigned long long uint64; |
739 typedef __SIZE_TYPE__ uintptr; | 739 typedef __SIZE_TYPE__ uintptr; |
740 | 740 |
741 typedef struct { char *p; int n; } GoString; | 741 typedef struct { char *p; int n; } GoString; |
742 typedef void *GoMap; | 742 typedef void *GoMap; |
743 typedef void *GoChan; | 743 typedef void *GoChan; |
744 typedef struct { void *t; void *v; } GoInterface; | 744 typedef struct { void *t; void *v; } GoInterface; |
745 ` | 745 ` |
OLD | NEW |