How can I tell a module compiled without -builtin
that an %import
ed module is compiled with -builtin
? Doing this naively gives me segfaults when the non-builtin module assumes that objects from the first module have wrappers.
(I never get segfaults if everything is compiled with -builtin
turned off, or when using the second module alone with -builtin
turned on; it's just when using them together with different compilation options.)
Details
I have several separate modules that I use SWIG for. Let's say one of them is named A
, and contains fundamental objects (quaternions). Because it contains basic objects that are involved in many computations, I prefer to use SWIG's -builtin
option for it. I have tested it, and this does make a pretty significant difference in timing.
Now, I also have another module named B
which needs to use objects from A
. But B
contains big fat composite objects that I don't act on very many times, so I don't expect that there's much advantage in using -builtin
here. Moreover, I really like to extend the classes in B
, and do various things that are not possible with -builtin
.
The problem is that I have to %import A.i
inside of B.i
. But then the code that's generated for B
assumes that A
objects have the extra wrappers, rather than using -builtin
. So when I use B
, I get segfaults.
(At least, I assume the segfaults result because B
assumes the extra wrappers. I looked through my B_wrap.cpp
file enough to see that it was assuming the presence of those wrappers, though I can't really say that I did any test to ensure that's where the problem was coming from. But the segfaults did coincide only with uses of A
from B
. On its own, A
has never given me any trouble. Also, if I compile A
and B
without -builtin
, I never get segfaults.)
In principle, I could use MONK's approach and just subclass any class that I need to add methods to, while compiling everything with -builtin
. But this would break the nice correspondence between names in my C++ code and names in my python code, as well as requiring one or other set of users to change the names they use, as well as being a general pain in the butt.
I apologize for not having a MWE, but I think it would be an unreasonably large MWE.