Menu

#1379 SwigPyObject_append don't work for >2 elements

None
closed-duplicate
nobody
python (260)
5
2022-07-20
2014-08-11
jicks
No

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;

1 Attachments

Discussion

  • William Fulton

    William Fulton - 2014-08-12

    Could you please put this patch on github https://github.com/swig/swig and include a runtime testcase.

     
  • Olly Betts

    Olly Betts - 2022-01-23

    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...

     
  • Olly Betts

    Olly Betts - 2022-01-23

    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.

     
  • Olly Betts

    Olly Betts - 2022-01-25
    • status: open --> closed-duplicate
    • Group: -->
     
  • Olly Betts

    Olly Betts - 2022-01-25

    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.

     
  • Olly Betts

    Olly Betts - 2022-07-20

    I've now merged your fix to master (https://github.com/swig/swig/commit/e23d912b49a91704131bf43915e82f25bbbe942c) - should be in SWIG 4.1.0.

     

Log in to post a comment.