-
Notifications
You must be signed in to change notification settings - Fork 143
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
use Cstring when passing strings to C #550
Conversation
LGTM: Could you add a test? |
Sure. I will add unit tests. This is just a prototype to show my approach to fix the problem. |
would also be great to see where else in the library this change can be made |
Another fix would be to normalize string types to |
I don't think that is what we should do (i.e. normalization). The approach here, by fixing it in the low level functions is the most correct way to go about this. |
Agreed. Anyway, we should use |
The two has no difference in GC safety. |
Oh, I don't understand Julia's GC rooting then. I thought that because julia> f(x) = ccall(:getenv, Cstring, (Cstring,), x)
f (generic function with 1 method)
julia> code_llvm(f, (String,))
; @ REPL[1]:1 within `f'
define i64 @julia_f_12244(%jl_value_t addrspace(10)* nonnull) {
top:
%1 = alloca %jl_value_t addrspace(10)*, i32 2
%gcframe = alloca %jl_value_t addrspace(10)*, i32 3
%2 = bitcast %jl_value_t addrspace(10)** %gcframe to i8*
call void @llvm.memset.p0i8.i32(i8* %2, i8 0, i32 24, i32 0, i1 false)
%thread_ptr = call i8* asm "movq %fs:0, $0", "=r"()
%ptls_i8 = getelementptr i8, i8* %thread_ptr, i64 -15552
...
julia> f(x) = ccall(:getenv, Cstring, (Ptr{UInt8},), x)
f (generic function with 1 method)
julia> code_llvm(f, (String,))
; @ REPL[3]:1 within `f'
define i64 @julia_f_12252(%jl_value_t addrspace(10)* nonnull) {
top:
; ┌ @ pointer.jl:59 within `unsafe_convert'
; │┌ @ pointer.jl:143 within `pointer_from_objref'
%1 = addrspacecast %jl_value_t addrspace(10)* %0 to %jl_value_t addrspace(11)*
%2 = addrspacecast %jl_value_t addrspace(11)* %1 to %jl_value_t*
; │└
; │┌ @ pointer.jl:155 within `+'
%3 = bitcast %jl_value_t* %2 to i8*
%4 = getelementptr i8, i8* %3, i64 8
%5 = ptrtoint i8* %4 to i64
; └└
%6 = call i64 inttoptr (i64 140308921968352 to i64 (i64)*)(i64 %5)
ret i64 %6
} |
Never use any of the Just look at |
Okay. |
@bicycle1885 Tests would be great, |
bump |
this is strictly better than what we have so merging. Hopefully we can address the improvements brought up in this PR discussion in a separate PR. |
HDF5.jl currently uses
Ptr{UInt8}
instead ofCstring
when it passes strings to HDF5 functions. This causes problems if we try to handle substrings such as:This fix is a minimal patch to fix the problem demonstrated above. I think we need a more thorough investigation of the wrapper functions to completely fix that. If you like this idea, I will add more patches here.