1
0
mirror of https://github.com/golang/go synced 2024-11-05 15:06:09 -07:00
go/misc
Kevin Klues f7dfeea90f 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://golang.org/cl/11377043
2013-07-24 17:27:42 -07:00
..
arm arm: add gdb support to android launcher script 2010-07-30 10:35:07 +03:00
bash misc/bash: Completion for go tool. 2012-02-28 07:41:49 +11:00
bbedit misc/{bbedit|IntelliJIDEA|kate}: add missing delete predeclared identifier 2013-06-24 13:17:56 -07:00
cgo cmd/cgo: Fix issue with cgo cdefs 2013-07-24 17:27:42 -07:00
chrome/gophertool gophertool: fix links 2012-10-22 01:05:21 +08:00
dashboard misc/dashboard: show all race builders as "race" 2013-06-26 21:20:53 +04:00
dist dist: fix postinstall script for Darwin 2013-07-15 10:52:38 +10:00
emacs misc/emacs: replace our go-goto-opening-parenthesis with backward-up-list 2013-07-24 13:48:04 -04:00
fraise misc: update type + builtin lists found in editor support files 2011-01-19 23:07:49 -05:00
git misc/git: add gofmt git pre-commit hook 2012-11-15 19:58:49 +01:00
goplay misc/goplay: use go run x.go instead of go build x.go 2013-07-12 09:41:10 +10:00
IntelliJIDEA misc/{bbedit|IntelliJIDEA|kate}: add missing delete predeclared identifier 2013-06-24 13:17:56 -07:00
kate misc/{bbedit|IntelliJIDEA|kate}: add missing delete predeclared identifier 2013-06-24 13:17:56 -07:00
notepadplus misc/notepadplus: add missing operator keyword 2013-06-24 14:19:00 +10:00
swig misc/swig: remove old broken Makefile 2013-03-20 08:06:58 -07:00
vim misc/vim: Allow multiple GOOS/GOARCH. 2013-07-02 15:24:09 +10:00
xcode misc/xcode: fix typos 2012-03-05 15:50:48 -08:00
zsh misc: update zsh completion 2013-04-07 04:11:12 +08:00
benchcmp misc/benchcmp: show byte allocation statistics 2012-12-22 14:51:16 -05:00
pprof misc/pprof: fix html5 doctype declaration 2013-06-09 22:01:03 +08:00