From 94b4c7dc214d84dfbb695cb59f225e7120268d61 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 6 Feb 2020 07:27:08 +0000 Subject: [PATCH] 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 --- Lib/python/pyrun.swg | 10 +++++----- 1 file 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(); }