Skip to content

Commit

Permalink
Attribute of SWIG wrapped classes instances were overwritten on __ini…
Browse files Browse the repository at this point in the history
…t__()

When a SWIG classes instances is initialized, its internal dictionary was
reset to NULL, which result in the loss of any attribute that might have
been set for the instance.

Only initialize the internal dictionary on actual PyObject creation.

class Test(MySwigWrappedClass):
        def __init__(self):
                self.val = "Random Value"
                MySwigWrappedClass.__init__(self)

p = Test()
print hasattr(p, "val") # Should return True, but used to return False
  • Loading branch information
amaeldoe committed Feb 6, 2015
1 parent ff3645d commit 49732e6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Lib/python/pyrun.swg
Expand Up @@ -1437,18 +1437,21 @@ SWIG_Python_NewPointerObj(PyObject *self, void *ptr, swig_type_info *type, int f
newobj = (SwigPyObject *) newobj->next;
newobj->next = next_self;
newobj = (SwigPyObject *)next_self;
#ifdef SWIGPYTHON_BUILTIN
newobj->dict = 0;
#endif
}
} else {
newobj = PyObject_New(SwigPyObject, clientdata->pytype);
#ifdef SWIGPYTHON_BUILTIN
newobj->dict = 0;
#endif
}
if (newobj) {
newobj->ptr = ptr;
newobj->ty = type;
newobj->own = own;
newobj->next = 0;
#ifdef SWIGPYTHON_BUILTIN
newobj->dict = 0;
#endif
return (PyObject*) newobj;
}
return SWIG_Py_Void();
Expand Down

0 comments on commit 49732e6

Please sign in to comment.