diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2020-02-06 07:27:08 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2020-02-06 07:27:08 +0000 |
commit | 94b4c7dc214d84dfbb695cb59f225e7120268d61 (patch) | |
tree | 55e3f2d6d32d079ba824c8ca9df826afdd74e0e8 /Lib | |
parent | a01e8474f605c5127a512c4ede2b094206db0570 (diff) | |
download | swig-94b4c7dc214d84dfbb695cb59f225e7120268d61.tar.gz |
Better error checking when setting 'this' in Python
If python_append.i is modified to use:
__slots__ = []
instead of
__slots__ = ["this"]
then this additional error checking prevents a crash and shows a stack trace and error:
AttributeError: 'ForSlots' object has no attribute 'this'
Related to issue #1674
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/python/pyrun.swg | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 66fa67055..63ff82ff8 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1245,7 +1245,7 @@ SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this) return inst; } -SWIGRUNTIME void +SWIGRUNTIME int SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this) { #if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) @@ -1256,11 +1256,10 @@ SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this) dict = PyDict_New(); *dictptr = dict; } - PyDict_SetItem(dict, SWIG_This(), swig_this); - return; + return PyDict_SetItem(dict, SWIG_This(), swig_this); } #endif - PyObject_SetAttr(inst, SWIG_This(), swig_this); + return PyObject_SetAttr(inst, SWIG_This(), swig_this); } @@ -1274,7 +1273,8 @@ SWIG_Python_InitShadowInstance(PyObject *args) { if (sthis) { SwigPyObject_append((PyObject*) sthis, obj[1]); } else { - SWIG_Python_SetSwigThis(obj[0], obj[1]); + if (SWIG_Python_SetSwigThis(obj[0], obj[1]) != 0) + return NULL; } return SWIG_Py_Void(); } |