mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/cgo: use intgo, not int, for string and slice structures
Fixes #5548. R=golang-dev, minux.ma CC=golang-dev https://golang.org/cl/9643044
This commit is contained in:
parent
9bdb7e1967
commit
8f7863d638
4 changed files with 71 additions and 11 deletions
|
|
@ -937,7 +937,8 @@ func (p *Package) cgoType(e ast.Expr) *Type {
|
|||
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
|
||||
|
|
@ -974,8 +975,7 @@ func (p *Package) cgoType(e ast.Expr) *Type {
|
|||
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" {
|
||||
|
|
@ -1028,11 +1028,20 @@ __cgo_size_assert(double, 8)
|
|||
`
|
||||
|
||||
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_);
|
||||
`
|
||||
|
||||
|
|
@ -1050,14 +1059,14 @@ void
|
|||
}
|
||||
|
||||
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);
|
||||
|
|
@ -1134,9 +1143,9 @@ typedef double GoFloat64;
|
|||
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;
|
||||
`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue