JuliaInterop / Cxx.jl

The Julia C++ Interface
Other
755 stars 107 forks source link

cpptype of empty array #463

Open ethomag opened 4 years ago

ethomag commented 4 years ago

I'm using Cxx to interface a fairly complicated C++ library. A test case that worked fine in July (I think I was using Julia 1.1 and Cxx 0.3.x) failed with Julia 1.3.1 and Cxx 0.4.0. I tried to understand what was happening (I can safely say that this code is way beyond my competence level), but the following patch in Cxx got it working again:

$ git diff
diff --git a/src/typetranslation.jl b/src/typetranslation.jl
index aa5e370..b82b290 100644
--- a/src/typetranslation.jl
+++ b/src/typetranslation.jl
@@ -292,7 +292,7 @@ function cpptype(C,::Type{T}) where T
         InverseMappedTypes[MappedTypes[T]] = T
         # For callable julia types, also add an operator() method to the anonymous
         # class
-        if !isempty(T.name.mt)
+        if !isempty(T.name.mt) && isa(T.name.mt.defs, Core.TypeMapEntry)
             linfo = T.name.mt.defs.func
             sig = T.name.mt.defs.sig
             nargt = length(sig.parameters)-1

What I think caused the problem was that in the testcase, one of the parameters to a C++ function was an empty array (Array{Complex{Float64}}(undef, 0, 0)) and that confused Cxx type translation. Since I hardly understand what I'm doing, I welcome someone with the proper competence to make a proper patch.

Gnimuc commented 4 years ago

Hi @keno, do you have time to take a look at this and many other recent issues?