Improve error handling calling PyObject_SetAttr

Less obscure error when setting 'this' on the SWIG proxy object
attempting to override __setattr__ in C++ (swig-user mailing list
query 19 Aug 2019).
This commit is contained in:
William S Fulton 2019-09-13 07:37:03 +01:00
commit 719eea090d
2 changed files with 11 additions and 6 deletions

View file

@ -69,8 +69,7 @@ namespace swig {
static bool back_reference(PyObject* child, PyObject* owner) {
SwigPyObject* swigThis = SWIG_Python_GetSwigThis(child);
if (swigThis && (swigThis->own & SWIG_POINTER_OWN) != SWIG_POINTER_OWN) {
PyObject_SetAttr(child, container_owner_attribute(), owner);
return true;
return PyObject_SetAttr(child, container_owner_attribute(), owner) != -1;
}
return false;
}