]> Cypherpunks repositories - gostls13.git/commitdiff
cgo: support export for built-in types
authorMaxim Pimenov <mpimenov@google.com>
Tue, 20 Dec 2011 17:28:45 +0000 (09:28 -0800)
committerIan Lance Taylor <iant@golang.org>
Tue, 20 Dec 2011 17:28:45 +0000 (09:28 -0800)
This change doesn't pay attention to structs
so they still cannot be exported, see Issue 2552.

Fixes #2462.

R=dvyukov, rsc, iant
CC=golang-dev
https://golang.org/cl/5487058

misc/cgo/test/Makefile
misc/cgo/test/basic.go
misc/cgo/test/issue2462.go [new file with mode: 0644]
src/cmd/cgo/out.go

index 5617e78c3726f23007a89b152ccbd5f715b50ebf..c05482e4a22a9a348b369988c15eee7109c1dda0 100644 (file)
@@ -16,6 +16,7 @@ CGOFILES=\
        issue1222.go\
        issue1328.go\
        issue1560.go\
+       issue2462.go\
        duplicate_symbol.go\
 
 CGO_OFILES=\
index 5fb2d07d5c20f05bc58714682ce5a95b93609512..bdcee5ca0a60b49e063676cf52fe91b38a58961b 100644 (file)
@@ -128,9 +128,9 @@ func testMultipleAssign(t *testing.T) {
 }
 
 var (
-       uint  = (C.uint)(0)
-       ulong C.ulong
-       char  C.char
+       cuint  = (C.uint)(0)
+       culong C.ulong
+       cchar  C.char
 )
 
 type Context struct {
diff --git a/misc/cgo/test/issue2462.go b/misc/cgo/test/issue2462.go
new file mode 100644 (file)
index 0000000..12cd91d
--- /dev/null
@@ -0,0 +1,102 @@
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package cgotest
+
+import "C"
+
+//export exportbyte
+func exportbyte() byte {
+       return 0
+}
+
+//export exportbool
+func exportbool() bool {
+       return false
+}
+
+//export exportrune
+func exportrune() rune {
+       return 0
+}
+
+//export exporterror
+func exporterror() error {
+       return nil
+}
+
+//export exportint
+func exportint() int {
+       return 0
+}
+
+//export exportuint
+func exportuint() uint {
+       return 0
+}
+
+//export exportuintptr
+func exportuintptr() uintptr {
+       return (uintptr)(0)
+}
+
+//export exportint8
+func exportint8() int8 {
+       return 0
+}
+
+//export exportuint8
+func exportuint8() uint8 {
+       return 0
+}
+
+//export exportint16
+func exportint16() int16 {
+       return 0
+}
+
+//export exportuint16
+func exportuint16() uint16 {
+       return 0
+}
+
+//export exportint32
+func exportint32() int32 {
+       return 0
+}
+
+//export exportuint32
+func exportuint32() uint32 {
+       return 0
+}
+
+//export exportint64
+func exportint64() int64 {
+       return 0
+}
+
+//export exportuint64
+func exportuint64() uint64 {
+       return 0
+}
+
+//export exportfloat32
+func exportfloat32() float32 {
+       return 0
+}
+
+//export exportfloat64
+func exportfloat64() float64 {
+       return 0
+}
+
+//export exportcomplex64
+func exportcomplex64() complex64 {
+       return 0
+}
+
+//export exportcomplex128
+func exportcomplex128() complex128 {
+       return 0
+}
index 5d7ec3974aca8caf8e180ce4e43576860f0a805b..9f266164919849683def99c13460d70cdded90b6 100644 (file)
@@ -599,8 +599,11 @@ func c(repr string, args ...interface{}) *TypeRepr {
 
 // Map predeclared Go types to Type.
 var goTypes = map[string]*Type{
+       "bool":       {Size: 1, Align: 1, C: c("uchar")},
+       "byte":       {Size: 1, Align: 1, C: c("uchar")},
        "int":        {Size: 4, Align: 4, C: c("int")},
        "uint":       {Size: 4, Align: 4, C: c("uint")},
+       "rune":       {Size: 4, Align: 4, C: c("int")},
        "int8":       {Size: 1, Align: 1, C: c("schar")},
        "uint8":      {Size: 1, Align: 1, C: c("uchar")},
        "int16":      {Size: 2, Align: 2, C: c("short")},
@@ -632,7 +635,7 @@ func (p *Package) cgoType(e ast.Expr) *Type {
        case *ast.FuncType:
                return &Type{Size: p.PtrSize, Align: p.PtrSize, C: c("void*")}
        case *ast.InterfaceType:
-               return &Type{Size: 3 * p.PtrSize, Align: p.PtrSize, C: c("GoInterface")}
+               return &Type{Size: 2 * p.PtrSize, Align: p.PtrSize, C: c("GoInterface")}
        case *ast.MapType:
                return &Type{Size: p.PtrSize, Align: p.PtrSize, C: c("GoMap")}
        case *ast.ChanType:
@@ -666,6 +669,9 @@ func (p *Package) cgoType(e ast.Expr) *Type {
                if t.Name == "string" {
                        return &Type{Size: p.PtrSize + 4, Align: p.PtrSize, C: c("GoString")}
                }
+               if t.Name == "error" {
+                       return &Type{Size: 2 * p.PtrSize, Align: p.PtrSize, C: c("GoInterface")}
+               }
                if r, ok := goTypes[t.Name]; ok {
                        if r.Align > p.PtrSize {
                                r.Align = p.PtrSize