Merge branch 'amaeldoe-master'
* amaeldoe-master: Add python runtime test for dynamically added attributes Attribute of SWIG wrapped classes instances were overwritten on __init__() Fix SwigPyObject->dict memory leak Make __dict__ accessible for Python builtin classes
This commit is contained in:
commit
b886a54fce
4 changed files with 56 additions and 3 deletions
|
|
@ -7,3 +7,24 @@ if b.a.x != 3: raise RuntimeError
|
||||||
|
|
||||||
b.b.x = 3
|
b.b.x = 3
|
||||||
if b.b.x != 3: raise RuntimeError
|
if b.b.x != 3: raise RuntimeError
|
||||||
|
|
||||||
|
|
||||||
|
# Test dynamically added attributes - Github pull request #320
|
||||||
|
b.added = 123
|
||||||
|
|
||||||
|
if b.added != 123:
|
||||||
|
raise RuntimeError("Wrong attribute value")
|
||||||
|
|
||||||
|
if not b.__dict__.has_key("added"):
|
||||||
|
raise RuntimeError("Missing added attribute in __dict__")
|
||||||
|
|
||||||
|
class PyBar(struct_value.Bar):
|
||||||
|
def __init__(self):
|
||||||
|
self.extra = "hi"
|
||||||
|
struct_value.Bar.__init__(self)
|
||||||
|
|
||||||
|
pybar = PyBar()
|
||||||
|
if not pybar.__dict__.has_key("extra"):
|
||||||
|
raise RuntimeError("Missing extra attribute in __dict__")
|
||||||
|
if pybar.extra != "hi":
|
||||||
|
raise RuntimeError("Incorrect attribute value for extra")
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ SWIGINTERN void \
|
||||||
wrapper##_closure(PyObject *a) { \
|
wrapper##_closure(PyObject *a) { \
|
||||||
SwigPyObject *sobj; \
|
SwigPyObject *sobj; \
|
||||||
sobj = (SwigPyObject *)a; \
|
sobj = (SwigPyObject *)a; \
|
||||||
|
Py_XDECREF(sobj->dict); \
|
||||||
if (sobj->own) { \
|
if (sobj->own) { \
|
||||||
PyObject *o = wrapper(a, NULL); \
|
PyObject *o = wrapper(a, NULL); \
|
||||||
Py_XDECREF(o); \
|
Py_XDECREF(o); \
|
||||||
|
|
|
||||||
|
|
@ -381,6 +381,23 @@ typedef struct {
|
||||||
#endif
|
#endif
|
||||||
} SwigPyObject;
|
} SwigPyObject;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef SWIGPYTHON_BUILTIN
|
||||||
|
|
||||||
|
SWIGRUNTIME PyObject *
|
||||||
|
SwigPyObject_get___dict__(PyObject *v, PyObject *SWIGUNUSEDPARM(args))
|
||||||
|
{
|
||||||
|
SwigPyObject *sobj = (SwigPyObject *)v;
|
||||||
|
|
||||||
|
if (!sobj->dict)
|
||||||
|
sobj->dict = PyDict_New();
|
||||||
|
|
||||||
|
Py_INCREF(sobj->dict);
|
||||||
|
return sobj->dict;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
SWIGRUNTIME PyObject *
|
SWIGRUNTIME PyObject *
|
||||||
SwigPyObject_long(SwigPyObject *v)
|
SwigPyObject_long(SwigPyObject *v)
|
||||||
{
|
{
|
||||||
|
|
@ -1420,18 +1437,21 @@ SWIG_Python_NewPointerObj(PyObject *self, void *ptr, swig_type_info *type, int f
|
||||||
newobj = (SwigPyObject *) newobj->next;
|
newobj = (SwigPyObject *) newobj->next;
|
||||||
newobj->next = next_self;
|
newobj->next = next_self;
|
||||||
newobj = (SwigPyObject *)next_self;
|
newobj = (SwigPyObject *)next_self;
|
||||||
|
#ifdef SWIGPYTHON_BUILTIN
|
||||||
|
newobj->dict = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
newobj = PyObject_New(SwigPyObject, clientdata->pytype);
|
newobj = PyObject_New(SwigPyObject, clientdata->pytype);
|
||||||
|
#ifdef SWIGPYTHON_BUILTIN
|
||||||
|
newobj->dict = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (newobj) {
|
if (newobj) {
|
||||||
newobj->ptr = ptr;
|
newobj->ptr = ptr;
|
||||||
newobj->ty = type;
|
newobj->ty = type;
|
||||||
newobj->own = own;
|
newobj->own = own;
|
||||||
newobj->next = 0;
|
newobj->next = 0;
|
||||||
#ifdef SWIGPYTHON_BUILTIN
|
|
||||||
newobj->dict = 0;
|
|
||||||
#endif
|
|
||||||
return (PyObject*) newobj;
|
return (PyObject*) newobj;
|
||||||
}
|
}
|
||||||
return SWIG_Py_Void();
|
return SWIG_Py_Void();
|
||||||
|
|
|
||||||
|
|
@ -3058,6 +3058,17 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If this is a builtin type, create a PyGetSetDef entry for this member variable. */
|
/* If this is a builtin type, create a PyGetSetDef entry for this member variable. */
|
||||||
|
if (builtin) {
|
||||||
|
const char *memname = "__dict__";
|
||||||
|
Hash *h = Getattr(builtin_getset, memname);
|
||||||
|
if (!h) {
|
||||||
|
h = NewHash();
|
||||||
|
Setattr(builtin_getset, memname, h);
|
||||||
|
Delete(h);
|
||||||
|
}
|
||||||
|
Setattr(h, "getter", "SwigPyObject_get___dict__");
|
||||||
|
}
|
||||||
|
|
||||||
if (builtin_getter) {
|
if (builtin_getter) {
|
||||||
String *memname = Getattr(n, "membervariableHandler:sym:name");
|
String *memname = Getattr(n, "membervariableHandler:sym:name");
|
||||||
if (!memname)
|
if (!memname)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue