diff options
author | Gustavo Niemeyer <gustavo@niemeyer.net> | 2011-03-06 18:05:57 -0500 |
---|---|---|
committer | Gustavo Niemeyer <gustavo@niemeyer.net> | 2011-03-06 18:05:57 -0500 |
commit | 15c39e6695409eba389c801a9a266ecacfc3ce97 (patch) | |
tree | 1a96e7140f3ff9f73605c085a0923cd523380f9b /src/cmd/cgo/main.go | |
parent | 535e00cfbb056bc56b16f9d9a321215337cc20e7 (diff) | |
download | go-15c39e6695409eba389c801a9a266ecacfc3ce97.tar.gz |
cgo: fix dwarf type parsing
The recursive algorithm used to parse types in cgo
has a bug related to building the C type representation.
As an example, when the recursion starts at a type *T,
the C type representation won't be known until type T
itself is parsed. But then, it is possible that type T
references the type **T internally. The latter
representation is built based on the one of *T, which
started the recursion, so it won't attempt to parse it
again, and will instead use the current representation
value for *T, which is still empty at this point.
This problem was fixed by introducing a simple TypeRepr
type which builds the string representation lazily,
analogous to how the Go type information is built within
the same algorithm. This way, even if a type
representation is still unknown at some level in the
recursion, representations dependant on it can still
be created correctly.
R=rsc
CC=golang-dev
http://codereview.appspot.com/4244052
Committer: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/cmd/cgo/main.go')
-rw-r--r-- | src/cmd/cgo/main.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/cmd/cgo/main.go b/src/cmd/cgo/main.go index dbf0664dc..2dc662de5 100644 --- a/src/cmd/cgo/main.go +++ b/src/cmd/cgo/main.go @@ -82,11 +82,17 @@ type ExpFunc struct { ExpName string // name to use from C } +// A TypeRepr contains the string representation of a type. +type TypeRepr struct { + Repr string + FormatArgs []interface{} +} + // A Type collects information about a type in both the C and Go worlds. type Type struct { Size int64 Align int64 - C string + C *TypeRepr Go ast.Expr EnumValues map[string]int64 } |