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: doesn't properly recognize a typedef'd C array type when it's a const C function argument #7270
Comments
Comment 2 by krzysiek@dajerade.pl: Another important thing is that at the moment it's impossible to bypass this by casting to *[12]C.uchar and have the program compile both on Linux and Mac OS. After changing the problematic line to: C.fooconst((*[12]C.uchar)(&bar)) the program compiles and runs fine on Linux, but Mac OS go fails: src/kg/constbug/main.go:12: cannot use (*[12]_Ctype_unsignedchar)(&bar) (type *[12]_Ctype_unsignedchar) as type *_Ctype_Bar in function argument |
Comment 3 by krzysiek@dajerade.pl: It seems that this is a GCC bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60524 |
Similarly:
And some Go:
Results in some stuff like:
(since it thinks it's of type something) I didn't spend much time into digging into the root cause, but it looks similar enough. If this is another bug, let me know and I'll file this as a new issue. Workaround is to define a new function in the C block -
And invoke it as
|
The reason for this is that package main
/*
typedef unsigned char Bar[12];
void foo(Bar* f){} // this works
void foo2(const Bar* f){} // this confuses cgo
*/
import "C"
func main() {
var v C.Bar
C.foo(&v) // this works
C.foo2(&v) // error, pasted below
} The behaviour experienced by @paultag doesn't work with either Clang or GCC. It seems like a separate issue to me. |
Thanks for the small test case. I believe the underlying cause is a bug in GCC. I filed https://gcc.gnu.org/PR81001. |
The crypto_aead functions with precomputation take a pointer to a `crypto_aead_aes256gcm_state` object as argument, not a char array. The compiler is changed to clang because the code with the correct pointer does not compile with GCC, see golang/go#7270.
The crypto_aead functions with precomputation take a pointer to a `crypto_aead_aes256gcm_state` object as argument, not a char array. The compiler is changed to clang because the code with the correct pointer does not compile with GCC, see golang/go#7270.
The crypto_aead functions with precomputation take a pointer to a `crypto_aead_aes256gcm_state` object as argument, not a char array. The compiler is changed to clang because the code with the correct pointer does not compile with GCC, see golang/go#7270.
by krzysiek@dajerade.pl:
Attachments:
The text was updated successfully, but these errors were encountered: