-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
ccall fails to pass/return struct{char, char} #14204
Comments
Does using Cchar in Struct10 make difference? Char is 4 bytes and Cchar 1 byte. |
Yes, works fine when using |
I think type Char in julia and char in C different bittypes. For equivalence, Cchar is the correct one to use in Julia. You can check the size of Struct10 with sizeof. If Char used the size is 8 bytes, else Cchar used the size is 2 bytes (equivalently i64 and i16) |
Yes, you should use |
OK thanks. I had the impression some conversions happened automatically, because of how often this actually leads to functional code. Sorry for the noise! |
Conversion happens if ccall is instructed to but you tell ccall that argument type is Struct10 and type of 'a' is Struct10 so no conversion is needed. |
Messing around with the
ccall
test suite, I came across this test failure on x86_64:test.c
(compile usingclang -g -fPIC -shared -Wall test.c -o test.so
):test.jl
:This yields:
The struct is passed incorrectly to the C function, printing
97,0
instead of97,98
. Analyzing theccall
signature, julia seems to bitcast the struct to ai64
while clang generates a coercedi16
parameter (however, having a quick look in the debugger I couldn't spot the'b'
anywhere in memory). The return value is also botched.This is on a haswell x86_64, with julia from git master built using LLVM 3.7, but it also fails on 0.4 from the Arch repositories.
The text was updated successfully, but these errors were encountered: