diff options
Diffstat (limited to 'src/cmd/cgo/out.go')
| -rw-r--r-- | src/cmd/cgo/out.go | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index 6802dd1cf..9c962b8ff 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -236,7 +236,7 @@ func (p *Package) writeDefsFunc(fc, fgo2 *os.File, n *Name) { printer.Fprint(fgo2, fset, d) fmt.Fprintf(fgo2, "\n") - if name == "CString" || name == "GoString" || name == "GoStringN" { + if name == "CString" || name == "GoString" || name == "GoStringN" || name == "GoBytes" { // The builtins are already defined in the C prolog. return } @@ -316,7 +316,7 @@ func (p *Package) writeOutput(f *File, srcfile string) { func (p *Package) writeOutputFunc(fgcc *os.File, n *Name) { name := n.Mangle - if name == "_Cfunc_CString" || name == "_Cfunc_GoString" || name == "_Cfunc_GoStringN" || p.Written[name] { + if name == "_Cfunc_CString" || name == "_Cfunc_GoString" || name == "_Cfunc_GoStringN" || name == "_Cfunc_GoBytes" || p.Written[name] { // The builtins are already defined in the C prolog, and we don't // want to duplicate function definitions we've already done. return @@ -412,7 +412,7 @@ func (p *Package) writeExports(fgo2, fc, fm *os.File) { t := p.cgoType(atype) if off%t.Align != 0 { pad := t.Align - off%t.Align - ctype += fmt.Sprintf("\t\tchar __pad%d[%d]\n", npad, pad) + ctype += fmt.Sprintf("\t\tchar __pad%d[%d];\n", npad, pad) off += pad npad++ } @@ -646,6 +646,8 @@ func (p *Package) cgoType(e ast.Expr) *Type { } return r } + error(e.Pos(), "unrecognized Go type %s", t.Name) + return &Type{Size: 4, Align: 4, C: c("int")} case *ast.SelectorExpr: id, ok := t.X.(*ast.Ident) if ok && id.Name == "unsafe" && t.Sel.Name == "Pointer" { @@ -679,8 +681,10 @@ __cgo_size_assert(double, 8) const builtinProlog = ` typedef struct { char *p; int n; } _GoString_; +typedef struct { char *p; int n; int c; } _GoBytes_; _GoString_ GoString(char *p); _GoString_ GoStringN(char *p, int l); +_GoBytes_ GoBytes(void *p, int n); char *CString(_GoString_); ` @@ -705,10 +709,17 @@ void } void +·_Cfunc_GoBytes(int8 *p, int32 l, Slice s) +{ + s = runtime·gobytes((byte*)p, l); + FLUSH(&s); +} + +void ·_Cfunc_CString(String s, int8 *p) { p = runtime·cmalloc(s.len+1); - runtime·mcpy((byte*)p, s.str, s.len); + runtime·memmove((byte*)p, s.str, s.len); p[s.len] = 0; FLUSH(&p); } |
