#670 Multiple inheritance broken between 1.3.27 and and 1.3.28

closed-wont-fix
szager
python (259)
5
2011-04-12
2006-04-26
No

I've finally pinned down my numpy problems to a swig bug. There was
a numpy bug too, to make the analysis harder.

I'm using a python class (Image) that inherits from a python class
(baseImage) and a C struct (myImage). I then play swig games to
make a C function that returns a (myImage *) return an Image, using
tricks that I learnt on the swig list. The stand-alone .i file is attached
to this bug report.

With 1.3.27 (and -python) Image.__init__() is called when the typemap
is uses to convert a myImage* to an Image; with 1.3.28 it isn't:

Swig 1.3.27

>>> from inheritBug import *; print "Image:",; i = Image(); print
"newImage:",; j = newImage()
Image: __init__ for Image
newImage: __init__ for Image
>>> print "Type equality:", type(i) == type(j), "\ni:", i.msg, "\nj:", j.msg
Type equality: True
i: Hello World
j: Hello World
>>>

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Swig 1.3.28 (or 1.3.29 or cvs):

>>> from inheritBug import *; print "Image:",; i = Image(); print
"newImage:",; j = newImage()
Reading symbols for shared libraries + done
Image: __init__ for Image
newImage:
>>> print "Type equality:", type(i) == type(j), "\ni:", i.msg, "\nj:", j.msg
Type equality: True
i: Hello World
------------------------------------------------------------
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "inheritBug.py", line 61, in <lambda>
__getattr__ = lambda self, name: _swig_getattr(self, myImage, name)
File "inheritBug.py", line 28, in _swig_getattr
raise AttributeError,name
AttributeError: msg
j:>>>

Discussion

  • Robert Lupton the Good

    Swig .i file to illustrate problem

     
  • szager

    szager - 2011-04-12

    That magic is pitch black; it doesn't make any sense to try and support it. Here's a simpler and more supportable implementation which has the added benefit of working with the latest versions of SWIG:

    // -*- C -*-
    %module inherit_mixed

    %{

    #include <Python.h>

    typedef struct {
    int i;
    } myImage;

    %}

    typedef struct {
    int i;
    } myImage;

    %pythoncode %{

    newImage = lambda *args : Image(*args)

    class baseImage(object):
    def __init__(self, msgString):
    self.msg = msgString

    class Image(baseImage, myImage):
    def __init__(self, *args):
    print "__init__ for Image"
    baseImage.__init__(self, "Hello World")
    myImage.__init__(self)

    %}

    Marking wontfix.

    Stefan

     
  • szager

    szager - 2011-04-12
    • assigned_to: marcelomatus --> szager
    • status: open --> closed-wont-fix
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks