Allow the OOR reference to be saved without doing an INCREF. This

solves the circular reference problem with wx.Timer.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31095 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2004-12-20 22:50:29 +00:00
parent 56a52e9094
commit 94fd5e4dc1
6 changed files with 65 additions and 28 deletions

View File

@@ -866,17 +866,6 @@ bool wxPyCheckForApp() {
//---------------------------------------------------------------------------
void wxPyClientData_dtor(wxPyClientData* self) {
if (! wxPyDoingCleanup) { // Don't do it during cleanup as Python
// may have already garbage collected the object...
bool blocked = wxPyBeginBlockThreads();
Py_DECREF(self->m_obj);
self->m_obj = NULL;
wxPyEndBlockThreads(blocked);
}
}
void wxPyUserData_dtor(wxPyUserData* self) {
if (! wxPyDoingCleanup) {
bool blocked = wxPyBeginBlockThreads();
@@ -887,6 +876,20 @@ void wxPyUserData_dtor(wxPyUserData* self) {
}
void wxPyClientData_dtor(wxPyClientData* self) {
if (! wxPyDoingCleanup) { // Don't do it during cleanup as Python
// may have already garbage collected the object...
if (self->m_incRef) {
bool blocked = wxPyBeginBlockThreads();
Py_DECREF(self->m_obj);
wxPyEndBlockThreads(blocked);
}
self->m_obj = NULL;
}
}
// This is called when an OOR controled object is being destroyed. Although
// the C++ object is going away there is no way to force the Python object
// (and all references to it) to die too. This causes problems (crashes) in
@@ -909,8 +912,9 @@ void wxPyOORClientData_dtor(wxPyOORClientData* self) {
}
// Only if there is more than one reference to the object
if ( !wxPyDoingCleanup && self->m_obj->ob_refcnt > 1 ) {
// Only if there is more than one reference to the object and we are
// holding the OOR reference:
if ( !wxPyDoingCleanup && self->m_obj->ob_refcnt > 1 && self->m_incRef) {
// bool isInstance = wxPyInstance_Check(self->m_obj);
// TODO same here
//wxASSERT_MSG(isInstance, wxT("m_obj not an instance!?!?!"));