When doing some multiple inheritance with Python classes generated by SWIG, a bug occurs when more than 2 classes are used: the underlying SWIG object (accessible through self.this
) will only be able to track at most two classes, the first and last initialized.
I've tracked down the issue to the SwigPyObject_append
method in the generated CPP code. This function doesn't check if the first argument (sobj
) already has a next
element.
Attachments:
+ swig.patch
contains the patch we currently use to circumvent the issue;
Could you please put this patch on github https://github.com/swig/swig and include a runtime testcase.
Doesn't look like a PR was ever submitted, and the code in
Lib/python/pyrun.swg
is still missing the line shown by the patch against the generated code here.Applying the change to the appropriate file is trivial, but creating a testcase from scratch may be tricky. It seems you need to multiply inherit from at least 3 classes, but the submitter didn't say what actually goes wrong if you do that...
Aha, https://github.com/swig/swig/issues/422 might be caused by this. I'll test if the fix here solves that in which case (a) we have a testcase and (b) we can solve that ticket too.
It does fix the reproducers in the newer bug. I've noted that there will merge the patch shortly.
Closing this in favour of the newer ticket.
I've now merged your fix to master (https://github.com/swig/swig/commit/e23d912b49a91704131bf43915e82f25bbbe942c) - should be in SWIG 4.1.0.