-
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: Treat typedef
s of primitives as identical types in the same compilation unit.
#21809
Comments
The quickest way to get this working now would be to add a wrapper function. Something like...
|
Yep!
https://golang.org/doc/contribute.html has instructions for setting up. The cgo implementation is in |
I think I did this right? https://go-review.googlesource.com/62670 One oddity of my change that I'm not sure if it's ok:
This (imo) seems like a good thing as it reduces the amount of boilerlate for writing C interop, but it did change some of the error messages produced in the incorrect case (see the test I had to modify). |
Change https://golang.org/cl/62670 mentions this issue: |
Change https://golang.org/cl/63276 mentions this issue: |
Change https://golang.org/cl/63277 mentions this issue: |
This is a spinoff from #13467
Here's a "minimal" reproduction, I'll include my concrete usecase below.
Consider two vendors which provide equivalent implementations of ~*~something~*~ -- in this toy example, they are providing a function called
My_foo
vendora/include/foo.h
vendora/src/foo.c
vendorb/include/foo.h
vendorb/src/foo.c
differences
So you don't have to play "spot the differences", both vendors provide a
typedef
forMy_ssize_t
as an alias tolong
. The two vendors define equivalent functions, but one vendor chose to uselong
in the function definition and the other chose to use the typedefMy_ssize_t
.compiling the c bits to shared libraries:
main.go
Running (compiling) against vendora
Running (compiling) against vendorb
Here I expect the same output as running (compiling) against vendora
My description of the problem
Despite
My_ssize_t
andlong
being identical C types in the same module, they are treated as different go types.My concrete problem
My concrete problem actually has to do with interfacing with CPython / pypy, you can read more about it in the other issue: #13467 (comment)
My thoughts
I'm not a seasoned go developer, but my initial inclination that would at least solve my problem would be to make
typedef primitive x
intotype
aliases in cgo -- is this reasonable? where do I start hacking 😄The text was updated successfully, but these errors were encountered: