Skip to content

Commit b11191d

Browse files
authored
Allow passing a Vector of strings to jlcxx::ArrayRef (#482)
Fixes issue JuliaInterop/libcxxwrap-julia#188
1 parent cd56bf0 commit b11191d

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CxxWrap"
22
uuid = "1f15a43c-97ca-5a2a-ae31-89f07a497df4"
33
authors = ["Bart Janssens <bart@bartjanssens.org>"]
4-
version = "0.17.0"
4+
version = "0.17.1"
55

66
[deps]
77
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,9 @@ Often, new releases of `CxxWrap` also require a new release of the C++ component
10701070
There was no change in the API, but because of a change in the way the mapping between C++ and Julia types is implemented the C++ modules need to be recompiled against `libcxxwrap-julia` 0.13.
10711071
The reason for this change is that the old method caused crahses on macOS with Apple CPUs (M1, ...).
10721072
1073+
## Breaking changes in v0.17
1074+
1075+
* The binary parts of dependent packages need to be rebuilt against `libcxxwrap-julia` 0.14, which has a better way of adding STL functionality
10731076
10741077
## References
10751078
* [JuliaCon 2020 Talk: Julia and C++: a technical overview of CxxWrap.jl](https://www.youtube.com/watch?v=u7IaXwKSUU0)

src/CxxWrap.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ map_julia_arg_type(t::Type{CxxPtr{T}}, ::Type{IsCxxType}) where {T} = Union{CxxP
590590
map_julia_arg_type(t::Type{CxxPtr{CxxChar}}) = Union{PtrTypes{Cchar}, String}
591591
map_julia_arg_type(t::Type{<:Array{T}}) where {T <: CxxNumber} = Union{t, Array{julia_int_type(T)}}
592592
map_julia_arg_type(t::Type{<:Array{Ptr{T}}}) where {T <: CxxNumber} = Union{t, Array{Ptr{julia_int_type(T)}}}
593+
map_julia_arg_type(t::Type{Vector{Ptr{CxxChar}}}) = Union{t, Vector{Ptr{julia_int_type(CxxChar)}}, Vector{String}}
593594
map_julia_arg_type(t::Type{ConstCxxPtr{CxxChar}}) = Union{ConstPtrTypes{Cchar}, String}
594595
map_julia_arg_type(::Type{T}) where {T<:Tuple} = Tuple{map_julia_arg_type.(T.parameters)...}
595596

@@ -616,8 +617,10 @@ Base.unsafe_convert(to_type::Type{<:CxxBaseRef{T}}, v::CxxBaseRef) where {T} = t
616617
Base.unsafe_convert(to_type::Type{<:CxxBaseRef}, v::Base.RefValue) = to_type(pointer_from_objref(v))
617618

618619
Base.cconvert(::Type{CxxPtr{CxxPtr{CxxChar}}}, v::Vector{String}) = Base.cconvert(Ptr{Ptr{Cchar}}, v)
620+
Base.cconvert(::Type{Vector{Ptr{CxxChar}}}, v::Vector{String}) = Base.cconvert(Ptr{Ptr{Cchar}}, v)
619621
Base.unsafe_convert(to_type::Type{CxxPtr{CxxPtr{CxxChar}}}, a::Base.RefArray{Ptr{Cchar}, Vector{Ptr{Cchar}}, Any}) = to_type(Base.unsafe_convert(Ptr{Ptr{Cchar}}, a))
620622
Base.unsafe_convert(to_type::Type{CxxPtr{CxxPtr{CxxChar}}}, a::Base.RefArray{Ptr{Cchar}, Vector{Ptr{Cchar}}, Vector{Any}}) = to_type(Base.unsafe_convert(Ptr{Ptr{Cchar}}, a))
623+
Base.unsafe_convert(::Type{Vector{Ptr{CxxChar}}}, a::Union{Base.RefArray{Ptr{Cchar}, Vector{Ptr{Cchar}}, Any}, Base.RefArray{Ptr{Cchar}, Vector{Ptr{Cchar}}, Vector{Any}}}) = a.x[1:end-1]
621624

622625
cxxconvert(to_type::Type{<:CxxBaseRef{T}}, x, ::Type{IsNormalType}) where {T} = Ref{T}(convert(T,x))
623626
cxxconvert(to_type::Type{<:CxxBaseRef{T}}, x::Base.RefValue, ::Type{IsNormalType}) where {T} = x

test/containers.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,9 @@ end
7171

7272
@test Containers.make_tuple_vector() == [(1.0,2.0), (3.0,4.0)]
7373

74+
# Defined only in libcxxwrap-julia main.
75+
if isdefined(Containers, :catstrings)
76+
@test Containers.catstrings(["aaa", "bb"]) == "aaabb"
77+
end
78+
7479
end

0 commit comments

Comments
 (0)