Fixing setting this in Python when using __slots__
Don't attempt to use the class's __dict__ for setting 'this' when
a user has extended a class with:
__slots__ = ['this'].
Was segfaulting. Now we fall back to a simple PyObject_SetAttr if the
usual approach to setting 'this' in __dict__ does not work.
Closes #1673 Closes #1674
This commit is contained in:
parent
a9731251a4
commit
a01e8474f6
4 changed files with 46 additions and 15 deletions
|
|
@ -1248,22 +1248,19 @@ SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this)
|
|||
SWIGRUNTIME void
|
||||
SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this)
|
||||
{
|
||||
PyObject *dict;
|
||||
#if !defined(SWIG_PYTHON_SLOW_GETSET_THIS)
|
||||
PyObject **dictptr = _PyObject_GetDictPtr(inst);
|
||||
if (dictptr != NULL) {
|
||||
dict = *dictptr;
|
||||
if (dict == NULL) {
|
||||
dict = PyDict_New();
|
||||
*dictptr = dict;
|
||||
}
|
||||
PyDict_SetItem(dict, SWIG_This(), swig_this);
|
||||
return;
|
||||
}
|
||||
PyObject **dictptr = _PyObject_GetDictPtr(inst);
|
||||
if (dictptr != NULL) {
|
||||
PyObject *dict = *dictptr;
|
||||
if (dict == NULL) {
|
||||
dict = PyDict_New();
|
||||
*dictptr = dict;
|
||||
}
|
||||
PyDict_SetItem(dict, SWIG_This(), swig_this);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
dict = PyObject_GetAttrString(inst, "__dict__");
|
||||
PyDict_SetItem(dict, SWIG_This(), swig_this);
|
||||
Py_DECREF(dict);
|
||||
PyObject_SetAttr(inst, SWIG_This(), swig_this);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue