From: Ian Lance Taylor Date: Wed, 13 Jun 2012 20:23:38 +0000 (-0400) Subject: [release-branch.go1] cgo: rename C names for Go types to avoid conflicting with package X-Git-Tag: go1.0.2~103 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c08ef1339e2d1b3f9764fd298a7c9fe688d55141;p=gostls13.git [release-branch.go1] cgo: rename C names for Go types to avoid conflicting with package ««« backport d063a7844d48 cgo: rename C names for Go types to avoid conflicting with package Fixes #3371. R=rsc, bsiegert, r, mtj, iant CC=golang-dev https://golang.org/cl/6131060 »»» --- diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index 814250c2ec..acd1e0b438 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -736,25 +736,23 @@ 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")}, - "uint16": {Size: 2, Align: 2, C: c("ushort")}, - "int32": {Size: 4, Align: 4, C: c("int")}, - "uint32": {Size: 4, Align: 4, C: c("uint")}, - "int64": {Size: 8, Align: 8, C: c("int64")}, - "uint64": {Size: 8, Align: 8, C: c("uint64")}, - "float": {Size: 4, Align: 4, C: c("float")}, - "float32": {Size: 4, Align: 4, C: c("float")}, - "float64": {Size: 8, Align: 8, C: c("double")}, - "complex": {Size: 8, Align: 8, C: c("__complex float")}, - "complex64": {Size: 8, Align: 8, C: c("__complex float")}, - "complex128": {Size: 16, Align: 16, C: c("__complex double")}, + "bool": {Size: 1, Align: 1, C: c("GoUint8")}, + "byte": {Size: 1, Align: 1, C: c("GoUint8")}, + "int": {Size: 4, Align: 4, C: c("GoInt")}, + "uint": {Size: 4, Align: 4, C: c("GoUint")}, + "rune": {Size: 4, Align: 4, C: c("GoInt32")}, + "int8": {Size: 1, Align: 1, C: c("GoInt8")}, + "uint8": {Size: 1, Align: 1, C: c("GoUint8")}, + "int16": {Size: 2, Align: 2, C: c("GoInt16")}, + "uint16": {Size: 2, Align: 2, C: c("GoUint16")}, + "int32": {Size: 4, Align: 4, C: c("GoInt32")}, + "uint32": {Size: 4, Align: 4, C: c("GoUint32")}, + "int64": {Size: 8, Align: 8, C: c("GoInt64")}, + "uint64": {Size: 8, Align: 8, C: c("GoUint64")}, + "float32": {Size: 4, Align: 4, C: c("GoFloat32")}, + "float64": {Size: 8, Align: 8, C: c("GoFloat64")}, + "complex64": {Size: 8, Align: 8, C: c("GoComplex64")}, + "complex128": {Size: 16, Align: 16, C: c("GoComplex128")}, } // Map an ast type to a Type. @@ -799,7 +797,7 @@ func (p *Package) cgoType(e ast.Expr) *Type { return def } if t.Name == "uintptr" { - return &Type{Size: p.PtrSize, Align: p.PtrSize, C: c("uintptr")} + return &Type{Size: p.PtrSize, Align: p.PtrSize, C: c("GoUintptr")} } if t.Name == "string" { return &Type{Size: p.PtrSize + 4, Align: p.PtrSize, C: c("GoString")} @@ -930,13 +928,21 @@ Slice GoBytes(char *p, int n) { ` const gccExportHeaderProlog = ` -typedef unsigned int uint; -typedef signed char schar; -typedef unsigned char uchar; -typedef unsigned short ushort; -typedef long long int64; -typedef unsigned long long uint64; -typedef __SIZE_TYPE__ uintptr; +typedef int GoInt; +typedef unsigned int GoUint; +typedef signed char GoInt8; +typedef unsigned char GoUint8; +typedef short GoInt16; +typedef unsigned short GoUint16; +typedef int GoInt32; +typedef unsigned int GoUint32; +typedef long long GoInt64; +typedef unsigned long long GoUint64; +typedef __SIZE_TYPE__ GoUintptr; +typedef float GoFloat32; +typedef double GoFloat64; +typedef __complex float GoComplex64; +typedef __complex double GoComplex128; typedef struct { char *p; int n; } GoString; typedef void *GoMap;