summaryrefslogtreecommitdiff
path: root/src/run.bash
diff options
context:
space:
mode:
authorKevin Klues <klueska@gmail.com>2013-07-24 17:27:42 -0700
committerKevin Klues <klueska@gmail.com>2013-07-24 17:27:42 -0700
commit8531c71615899b8eb3f711d968951992df045bb2 (patch)
tree2f83d4babc8445dea03df50b91179a4459e0a371 /src/run.bash
parent69ba3668853c80e73172a485973e137ef07df989 (diff)
downloadgo-8531c71615899b8eb3f711d968951992df045bb2.tar.gz
cmd/cgo: Fix issue with cgo cdefs
The problem is that the cdecl() function in cmd/cgo/godefs.go isn't properly translating the Go array type to a C array type when an asterisk follows the [] in the array type declaration (it is perfectly legal to put the asterisk on either side of the [] in go syntax, depending on how you set up your pointers). That said, the cdefs tool is only designed to translate from Go types generated using the cgo *godefs* tool -- where the godefs tool is designed to translate gcc-style C types into Go types. In essence, the cdefs tool translates from gcc-style C types to Go types (via the godefs tool), then back to kenc-style C types. Because of this, cdefs does not need to know how to translate arbitraty Go types into C, just the ones produced by godefs. The problem is that during this translation process, the logic is slightly wrong when going from (e.g.): char *array[10]; to: array [10]*int8; back to: int8 *array[10]; In the current implementation of cdecl(), the translation from the Go type declaration back to the kenc-style declaration looks for Go types of the form: name *[]type; rather than the actual generated Go type declaration of: name []*type; Both are valid Go syntax, with slightly different semantics, but the latter is the only one that can ever be generated by the godefs tools. (The semantics of the former are not directly expressible in a single C statement -- you would have to have to first typedef the array type, then declare a pointer to that typedef'd type in a separate statement). This commit changes the logic of cdecl() to look properly for, and translate, Go type declarations of the form: name []*type; Additionally, the original implementation only allowed for a single asterisk and a single sized aray (i.e. only a single level of pointer indirection, and only one set of []) on the type, whereas the patched version allows for an arbitrary number of both. Tests are included in misc/cgo/testcdefs and the all.bash script has been updated to account for these. R=golang-dev, bradfitz, dave, iant CC=golang-dev https://codereview.appspot.com/11377043 Committer: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/run.bash')
-rwxr-xr-xsrc/run.bash5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/run.bash b/src/run.bash
index 032463496..4d8d04bfb 100755
--- a/src/run.bash
+++ b/src/run.bash
@@ -125,6 +125,11 @@ esac
) || exit $?
[ "$CGO_ENABLED" != 1 ] ||
+(xcd ../misc/cgo/testcdefs
+./test.bash || exit 1
+) || exit $?
+
+[ "$CGO_ENABLED" != 1 ] ||
[ "$GOHOSTOS" == windows ] ||
(xcd ../misc/cgo/testso
./test.bash || exit 1