--- /dev/null
+// Copyright 2013 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 "testing"
+
+/*
+extern int issue5548_in_c(void);
+*/
+import "C"
+
+//export issue5548FromC
+func issue5548FromC(s string, i int) int {
+ if len(s) == 4 && s == "test" && i == 42 {
+ return 1
+ }
+ return 0
+}
+
+func test5548(t *testing.T) {
+ if C.issue5548_in_c() == 0 {
+ t.Fail()
+ }
+}
return &Type{Size: p.PtrSize, Align: p.PtrSize, C: c("%s*", x.C)}
case *ast.ArrayType:
if t.Len == nil {
- return &Type{Size: p.PtrSize + 8, Align: p.PtrSize, C: c("GoSlice")}
+ // Slice: pointer, len, cap.
+ return &Type{Size: p.PtrSize * 3, Align: p.PtrSize, C: c("GoSlice")}
}
case *ast.StructType:
// TODO
return &Type{Size: p.PtrSize, Align: p.PtrSize, C: c("GoUintptr")}
}
if t.Name == "string" {
- // The string data is 1 pointer + 1 int, but this always
- // rounds to 2 pointers due to alignment.
+ // The string data is 1 pointer + 1 (pointer-sized) int.
return &Type{Size: 2 * p.PtrSize, Align: p.PtrSize, C: c("GoString")}
}
if t.Name == "error" {
`
const builtinProlog = `
-typedef struct { char *p; int n; } _GoString_;
-typedef struct { char *p; int n; int c; } _GoBytes_;
+/* Define intgo when compiling with GCC. */
+#ifdef __PTRDIFF_TYPE__
+typedef __PTRDIFF_TYPE__ intgo;
+#elif defined(_LP64)
+typedef long long intgo;
+#else
+typedef int intgo;
+#endif
+
+typedef struct { char *p; intgo n; } _GoString_;
+typedef struct { char *p; intgo n; intgo c; } _GoBytes_;
_GoString_ GoString(char *p);
-_GoString_ GoStringN(char *p, int l);
-_GoBytes_ GoBytes(void *p, int n);
+_GoString_ GoStringN(char *p, intgo l);
+_GoBytes_ GoBytes(void *p, intgo n);
char *CString(_GoString_);
`
}
void
-·_Cfunc_GoStringN(int8 *p, int32 l, String s)
+·_Cfunc_GoStringN(int8 *p, intgo l, String s)
{
s = runtime·gostringn((byte*)p, l);
FLUSH(&s);
}
void
-·_Cfunc_GoBytes(int8 *p, int32 l, Slice s)
+·_Cfunc_GoBytes(int8 *p, intgo l, Slice s)
{
s = runtime·gobytes((byte*)p, l);
FLUSH(&s);
typedef __complex float GoComplex64;
typedef __complex double GoComplex128;
-typedef struct { char *p; int n; } GoString;
+typedef struct { char *p; GoInt n; } GoString;
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;
-typedef struct { void *data; int len; int cap; } GoSlice;
+typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
`