From 49bc8fbb0803f91d391211356492fba9bc4e68dc Mon Sep 17 00:00:00 2001 From: "Jason McCampbell (Enthought, Inc)" Date: Thu, 15 Mar 2012 16:07:22 -0500 Subject: Don't clear weakrefs if Python interpreter isn't running Change-Id: I51ba2fcf5f881abb38e9b69b115fb98c536e2146 Reviewed-by: Hugo Parente Lima --- libshiboken/basewrapper.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp index 382012f..0d2d4b6 100644 --- a/libshiboken/basewrapper.cpp +++ b/libshiboken/basewrapper.cpp @@ -206,7 +206,10 @@ SbkObjectType SbkObject_Type = { { { void SbkDeallocWrapper(PyObject* pyObj) { SbkObject* sbkObj = reinterpret_cast(pyObj); - if (sbkObj->weakreflist) + + // Check that Python is still initialized as sometimes this is called by a static destructor + // after Python interpeter is shutdown. + if (sbkObj->weakreflist && Py_IsInitialized()) PyObject_ClearWeakRefs(pyObj); // If I have ownership and is valid delete C++ pointer @@ -232,7 +235,9 @@ void SbkDeallocWrapper(PyObject* pyObj) void SbkDeallocWrapperWithPrivateDtor(PyObject* self) { SbkObject* sbkObj = reinterpret_cast(self); - if (sbkObj->weakreflist) + // Check that Python is still initialized as sometimes this is called by a static destructor + // after Python interpeter is shutdown. + if (sbkObj->weakreflist && Py_IsInitialized()) PyObject_ClearWeakRefs(self); Shiboken::Object::deallocData(sbkObj, true); -- cgit v1.2.3