-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/cgo: problem with forward-declared enum #1293
Labels
Comments
This is not enough information to reproduce the problem. None of the files you've supplied are complete. The real problem is the unrecognized Go type prints from cgo. Could you please change src/cmd/cgo/out.go:605 from error(e.Pos(), "unrecognized Go type %v", e) to error(e.Pos(), "unrecognized Go type %T", e) (%v -> %T) and then reinstall cgo and let us know what the output says? Status changed to WaitingForReply. |
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I updaten to the last release 1. I change in the file "src/cmd/cgo/out.go" the line "559" to "error(e.Pos(), "unrecognized Go type %T", e)" 2. I create a header file with the following text entry MQ_EXTERN enum MqErrorE MQ_DECL MqDummy ( struct MqS * const ctx, MQ_SIZE const id, struct MqS ** const filter ) __attribute__((nonnull(1))); 3. I create a "Go" file with the following text entry func (this *MqS) Dummy(i int32) *MqS { var ret *_Ctype_struct_MqS this.iErrorMqToGoWithCheck(C.MqDummy((*_Ctype_struct_MqS)(this), C.MQ_SIZE(i), &ret)) return (*MqS)(ret) } 4. I get the following results CGOPKGPATH= cgo -- -I . -I /home/dev1usr/Project/NHI1/theLink/libmsgque - -DMQ_IGNORE_EXTERN MqS.go MqSException.go MqBufferS.go MqBinary.go send.go read.go link.go config.go service.go slave.go unrecognized Go type *ast.StructType unrecognized Go type *ast.StructType unrecognized Go type *ast.StructType unrecognized Go type *ast.StructType unrecognized Go type *ast.StructType unrecognized Go type *ast.StructType unrecognized Go type *ast.StructType unrecognized Go type *ast.StructType unrecognized Go type *ast.StructType unrecognized Go type *ast.StructType unrecognized Go type *ast.StructType unrecognized Go type *ast.StructType unrecognized Go type *ast.StructType unrecognized Go type *ast.StructType unrecognized Go type *ast.StructType unrecognized Go type *ast.StructType unrecognized Go type *ast.StructType unrecognized Go type *ast.StructType unrecognized Go type *ast.StructType unrecognized Go type *ast.StructType 6g -o _go_.6 MqS.cgo1.go MqSException.cgo1.go MqBufferS.cgo1.go MqBinary.cgo1.go send.cgo1.go read.cgo1.go link.cgo1.go config.cgo1.go service.cgo1.go slave.cgo1.go _cgo_gotypes.go 6c -FVw -I"/home/dev1usr/src/go/src/pkg/runtime" _cgo_defun.c rm -f _obj/gomsgque.a gopack grc _obj/gomsgque.a _go_.6 _cgo_defun.6 cp _obj/gomsgque.a "/home/dev1usr/src/go/pkg/linux_amd64/gomsgque.a" gcc -m64 -fPIC -O2 -o MqS.cgo2.o -c -I . -I /home/dev1usr/Project/NHI1/theLink/libmsgque -DMQ_IGNORE_EXTERN MqS.cgo2.c gcc -m64 -fPIC -O2 -o MqSException.cgo2.o -c -I . -I /home/dev1usr/Project/NHI1/theLink/libmsgque -DMQ_IGNORE_EXTERN MqSException.cgo2.c gcc -m64 -fPIC -O2 -o MqBufferS.cgo2.o -c -I . -I /home/dev1usr/Project/NHI1/theLink/libmsgque -DMQ_IGNORE_EXTERN MqBufferS.cgo2.c gcc -m64 -fPIC -O2 -o MqBinary.cgo2.o -c -I . -I /home/dev1usr/Project/NHI1/theLink/libmsgque -DMQ_IGNORE_EXTERN MqBinary.cgo2.c gcc -m64 -fPIC -O2 -o send.cgo2.o -c -I . -I /home/dev1usr/Project/NHI1/theLink/libmsgque -DMQ_IGNORE_EXTERN send.cgo2.c gcc -m64 -fPIC -O2 -o read.cgo2.o -c -I . -I /home/dev1usr/Project/NHI1/theLink/libmsgque -DMQ_IGNORE_EXTERN read.cgo2.c gcc -m64 -fPIC -O2 -o link.cgo2.o -c -I . -I /home/dev1usr/Project/NHI1/theLink/libmsgque -DMQ_IGNORE_EXTERN link.cgo2.c gcc -m64 -fPIC -O2 -o config.cgo2.o -c -I . -I /home/dev1usr/Project/NHI1/theLink/libmsgque -DMQ_IGNORE_EXTERN config.cgo2.c config.cgo2.c: In function '_cgo_Cfunc_MqDummy': config.cgo2.c:287:3: error: expected specifier-qualifier-list before '*' token config.cgo2.c:292:3: error: 'struct <anonymous>' has no member named 'r' config.cgo2.c:292:32: error: 'struct <anonymous>' has no member named 'p2' 5. the "unrecognized Go type ..." is not the problem. every "callback" create such a line of code and this is !not! related to the compile-error at the end of the file 6. the problem is the compile error, the following code can not be compiled void _cgo_Cfunc_MqDummy(void *v) { struct { struct MqS* p0; MQ_SIZE p1; char __pad12[4]; * p2; enum MqErrorE r; char __pad28[4]; } *a = v; a->r = MqDummy(a->p0, a->p1, a->p2); } mfg, andreas otto -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJNBkBjAAoJEGTcPijNG3/AiDgH/iki8GzJVx9cBv8cZZy7Wj84 VFh8fbqlCeLbAxTiavRX8tSoZXY+YmFRoS3fi+LCxhLvxT9XrKJE138HTGwTZgEk 0+vumdMdzPFbbUIsiT4AX5+sJr/wSZ7c3KWoCybG0coYm/YXeYH0F4AsuSOTzeKZ qsbX+j/lp22bmHHlCVL8p8vkUvWADJNt5/GuCbRPboHtORN52ahpEVHnftzRueIT dlN9rMh+HKEXsz0TxVB/Ycb1RvOwxjGWVFNfXHBGA1oM2AfnK7vZgiN3Yl2ufvnR sd86AXYp/oFgbJ1NrY8YzjPnOLn+zDxuXtqHI3AFR0uIwFLRYZWBxx3SEWIMN5M= =NAtb -----END PGP SIGNATURE----- |
I believe you about #5. This is still not enough information to reproduce the problem. None of the files you've supplied are complete. You've only shown fragments. Please include a recipe with complete files so that I can run cgo myself on the files and see it generate the problematic output. |
Hi, sorry for my wrong answer. I prepare an example ... this example create a core during compile ... it's not exactly the same problem but we get closer Attachments:
|
Owner changed to r...@golang.org. Status changed to Accepted. |
Owner changed to builder@golang.org. |
Standalone test: package p /* typedef signed int MQ_INT; enum ErrorE { OK = 1, WAR = 2, ERR =3, }; struct DummyS { MQ_INT a; float b; }; enum MqErrorE MqDummy ( struct DummyS *ctx, MQ_INT const id, struct DummyS ** const filter ); */ import "C" type DummyS _Ctype_struct_DummyS func (this *DummyS) Dummy(i int32) *DummyS { var ret *_Ctype_struct_DummyS C.MqDummy((*_Ctype_struct_DummyS)(this),C.MQ_INT(i),&ret) return (*DummyS)(ret) } On Linux, go build: # test panic: runtime error: invalid memory address or nil pointer dereference [signal 0xb code=0x1 addr=0x18 pc=0x40c5c6] goroutine 2 [running]: main.(*Package).rewriteRef(0xf84007a000, 0xf84004eaf0, 0xf840071a20, 0x200000002) /home/rsc/go/src/cmd/cgo/gcc.go:658 +0xa7f main.(*Package).Translate(0xf84007a000, 0xf84004eaf0, 0x29, 0x588d24) /home/rsc/go/src/cmd/cgo/gcc.go:271 +0x129 main.main() /home/rsc/go/src/cmd/cgo/main.go:225 +0x905 created by _rt0_amd64 /home/rsc/go/src/pkg/runtime/asm_amd64.s:69 +0xd1 goroutine 1 [syscall]: On Mac, go build: # test test.go:30:3: unexpected: 0-byte enum type - enum MqErrorE {} Leaving for after Go 1. Labels changed: added priority-later, removed priority-go1. Status changed to HelpWanted. |
Today on Linux: % go build z.go # command-line-arguments z.go: In function ‘_cgo_f33557c6eda4_Cfunc_MqDummy’: z.go:53:8: error: variable or field ‘r’ declared void z.go:55:2: error: invalid use of undefined type ‘enum MqErrorE’ It doesn't crash any more. On the Mac, it's unchanged. Where does 'r' come from? Delaying to Go 1.3. Labels changed: added go1.3maybe, removed go1.2maybe. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by aotto1968zwei:
The text was updated successfully, but these errors were encountered: