Reviewers: golang-dev_googlegroups.com,
Message:
Hello
golang-dev@googlegroups.com (cc:
vova616@gmail.com),
I'd like you to review this change to
https://code.google.com/p/goDescription:
cmd/cgo: bool alignment/padding issue.
Fixes issue 4417.
Please review this at
http://codereview.appspot.com/6782097/Affected files:
M src/cmd/cgo/gcc.go
A test/fixedbugs/issue4417.go
Index: src/cmd/cgo/gcc.go
===================================================================
--- a/src/cmd/cgo/gcc.go
+++ b/src/cmd/cgo/gcc.go
@@ -771,8 +771,8 @@
"-o" + gccTmp(), // write object to tmp
"-gdwarf-2", // generate DWARF v2 debugging
symbols
"-fno-eliminate-unused-debug-types", // gets rid of e.g. untyped enum
otherwise
- "-c", // do not link
- "-xc", // input language is C
+ "-c", // do not link
+ "-xc", // input language is C
}
c = append(c, p.GccOptions...)
c = append(c, p.gccMachine()...)
@@ -1078,7 +1078,7 @@
case *dwarf.BoolType:
t.Go = c.bool
- t.Align = c.ptrSize
+ t.Align = 1
case *dwarf.CharType:
if t.Size != 1 {
Index: test/fixedbugs/issue4417.go
===================================================================
new file mode 100644
--- /dev/null
+++ b/test/fixedbugs/issue4417.go
@@ -0,0 +1,48 @@
+// run
+
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Issue 4417: cmd/cgo: bool alignment/padding issue.
+// bool alignment is wrong and causing wrong arguments when calling
functions.
+//
+
+package main
+
+/*
+#include <stdbool.h>
+
+static int c_bool(bool a, bool b, int c, bool d, bool e) {
+ return c;
+}
+*/
+import "C"
+
+func main() {
+ b := C.c_bool(true, true, 10, true, false)
+ if b != 10 {
+ print("found ", b, " excepted 10\n")
+ panic("failure.")
+ }
+ b = C.c_bool(true, true, 5, true, true)
+ if b != 5 {
+ print("found ", b, " excepted 5\n")
+ panic("failure.")
+ }
+ b = C.c_bool(true, true, 3, true, false)
+ if b != 3 {
+ print("found ", b, " excepted 3\n")
+ panic("failure.")
+ }
+ b = C.c_bool(false, false, 1, true, false)
+ if b != 1 {
+ print("found ", b, " excepted 1\n")
+ panic("failure.")
+ }
+ b = C.c_bool(false, true, 200, true, false)
+ if b != 200 {
+ print("found ", b, " excepted 200\n")
+ panic("failure.")
+ }
+}
\ No newline at end of file