Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb53abfe

Browse files
authored
Merge pull request#76 from krrutkow/master
Fix bug with statically-sized arrays as function argument
2 parents6eb4875 +7fa4a84 commitb53abfe

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

‎Project.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name ="CBinding"
22
uuid ="d43a6710-96b8-4a2d-833c-c424785e5374"
33
authors = ["Keith Rutkowski <keith@analytech-solutions.com>"]
4-
version ="1.0.4"
4+
version ="1.0.5"
55

66
[deps]
77
Clang_jll ="0ee61d77-7f21-5576-8119-9fcc46b10100"

‎README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,10 @@ Therefore, attaching other methods to a bound C function is not possible.
534534
It is also sometimes necessary to use the`c"..."` mangled names directly in Julia (for instance in the REPL help mode).
535535
Until consistent, universal support for the string macro is available, the mangled names can be used directly as`var"c\"...\""`, like`help?> var"c\"struct Y\""`.
536536

537+
When a C function has a statically-sized array as an argument in its signature, the semantics of C is to treat the argument as a pointer instead.
538+
Therefore, the statically-sized array in the binding signature will be lowered to a pointer for the underlying`ccall`.
539+
A user can then pass any argument (array, pointer, etc.) that is compatible with a pointer argument type (not the anticipated statically-sized array type).
540+
537541

538542
#Some helpful tips
539543

‎src/arrays.jl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Base.size(::Type{CA}) where {T, N, CA<:Carrays{T, N}} = (N,)
2929
Base.length(::Type{CA})where {T, N, CA<:Carrays{T, N}}= N
3030
Base.eltype(::Type{CA})where {T, N, CA<:Carrays{T, N}}= T
3131
Base.convert(::Type{CA}, t::Tuple)where {CA<:Carray}=CA(t...)
32+
Base.convert(::Type{CA}, v::Vector)where {CA<:Carray}=CA(v...)
3233

3334
Base.convert(::Type{CA}, str::String)where {T<:Union{Int8, UInt8, Cconst{Int8}, Cconst{UInt8}}, CA<:Carray{T}}=CA(str...)
3435
Base.convert(::Type{String}, ca::Carray{T})where {T<:Union{Int8, UInt8, Cconst{Int8}, Cconst{UInt8}}}=String(map(t->reinterpret(UInt8,convert(unqualifiedtype(T), t)),collect(ca)))

‎src/functions.jl‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ cconvert_default(::Type{T}) where {E, T<:AbstractArray{E}} = Cptr{E}
3434
$(func<:Cptr? :(Core.Intrinsics.bitcast(Ptr{Cvoid}, func)): libisa Symbol? :(($(QuoteNode(name)),$(String(lib)))):QuoteNode(name)),
3535
$((convisa Symbol? (conv,): ())...),
3636
$(retT),
37-
($(((argT<:Cvariadic? :(Ptr{Cvoid}...): argT)for argTin argTs)...),),
37+
($(((
38+
argT<:Cvariadic? :(Ptr{Cvoid}...):
39+
argT<:Carray? Cptr{eltype(argT)}:# statically sized arrays (even when typedef-ed) are passed by pointer
40+
argT
41+
)for argTin argTs)...),),
3842
$((:(args[$(i)])for iineachindex(args))...)
3943
))
4044
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp