From a77bf68f69758e933a9719b83ce3076d10fc1790 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Sat, 17 Jul 2004 17:52:29 +0000 Subject: [PATCH] prevent a reference leak when OOR objects are created git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28281 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/contrib/ogl/_oglbasic.i | 3 +- wxPython/src/_evthandler.i | 3 +- wxPython/src/_grid_rename.i | 10 ++++++ wxPython/src/_sizers.i | 3 +- wxPython/src/grid.i | 62 ++++++++++++++++++-------------- 5 files changed, 51 insertions(+), 30 deletions(-) diff --git a/wxPython/contrib/ogl/_oglbasic.i b/wxPython/contrib/ogl/_oglbasic.i index 7ceb86fac6..70c18ca92f 100644 --- a/wxPython/contrib/ogl/_oglbasic.i +++ b/wxPython/contrib/ogl/_oglbasic.i @@ -89,7 +89,8 @@ public: void _setCallbackInfo(PyObject* self, PyObject* _class); %extend { void _setOORInfo(PyObject* _self) { - self->SetClientObject(new wxPyOORClientData(_self)); + if (!self->GetClientObject()) + self->SetClientObject(new wxPyOORClientData(_self)); } } %pythoncode { diff --git a/wxPython/src/_evthandler.i b/wxPython/src/_evthandler.i index 915d659f4d..164eb60d41 100644 --- a/wxPython/src/_evthandler.i +++ b/wxPython/src/_evthandler.i @@ -69,7 +69,8 @@ public: %extend { void _setOORInfo(PyObject* _self) { if (_self && _self != Py_None) { - self->SetClientObject(new wxPyOORClientData(_self)); + if (!self->GetClientObject()) + self->SetClientObject(new wxPyOORClientData(_self)); } else { wxPyOORClientData* data = (wxPyOORClientData*)self->GetClientObject(); diff --git a/wxPython/src/_grid_rename.i b/wxPython/src/_grid_rename.i index b6e4bb35c2..befc12a39d 100644 --- a/wxPython/src/_grid_rename.i +++ b/wxPython/src/_grid_rename.i @@ -14,6 +14,16 @@ %rename(GRID_VALUE_DATETIME) wxGRID_VALUE_DATETIME; %rename(GridNoCellCoords) wxGridNoCellCoords; %rename(GridNoCellRect) wxGridNoCellRect; +%rename(GRID_DEFAULT_NUMBER_ROWS) wxGRID_DEFAULT_NUMBER_ROWS; +%rename(GRID_DEFAULT_NUMBER_COLS) wxGRID_DEFAULT_NUMBER_COLS; +%rename(GRID_DEFAULT_ROW_HEIGHT) wxGRID_DEFAULT_ROW_HEIGHT; +%rename(GRID_DEFAULT_COL_WIDTH) wxGRID_DEFAULT_COL_WIDTH; +%rename(GRID_DEFAULT_COL_LABEL_HEIGHT) wxGRID_DEFAULT_COL_LABEL_HEIGHT; +%rename(GRID_DEFAULT_ROW_LABEL_WIDTH) wxGRID_DEFAULT_ROW_LABEL_WIDTH; +%rename(GRID_LABEL_EDGE_ZONE) wxGRID_LABEL_EDGE_ZONE; +%rename(GRID_MIN_ROW_HEIGHT) wxGRID_MIN_ROW_HEIGHT; +%rename(GRID_MIN_COL_WIDTH) wxGRID_MIN_COL_WIDTH; +%rename(GRID_DEFAULT_SCROLLBAR_WIDTH) wxGRID_DEFAULT_SCROLLBAR_WIDTH; %rename(GridCellRenderer) wxGridCellRenderer; %rename(PyGridCellRenderer) wxPyGridCellRenderer; %rename(GridCellStringRenderer) wxGridCellStringRenderer; diff --git a/wxPython/src/_sizers.i b/wxPython/src/_sizers.i index 6fe840b6ba..f015df3233 100644 --- a/wxPython/src/_sizers.i +++ b/wxPython/src/_sizers.i @@ -372,7 +372,8 @@ public: %extend { void _setOORInfo(PyObject* _self) { - self->SetClientObject(new wxPyOORClientData(_self)); + if (!self->GetClientObject()) + self->SetClientObject(new wxPyOORClientData(_self)); } DocAStr(Add, diff --git a/wxPython/src/grid.i b/wxPython/src/grid.i index 42544af69c..771190095b 100644 --- a/wxPython/src/grid.i +++ b/wxPython/src/grid.i @@ -63,7 +63,8 @@ PyObject* wxPyMake_##TYPE(TYPE* source, bool setThisOwn) { \ wxPyOORClientData* data = (wxPyOORClientData*)source->GetClientObject(); \ if (data) { \ target = data->m_obj; \ - Py_INCREF(target); \ + if (target) \ + Py_INCREF(target); \ } \ /* Otherwise make a new wrapper for it the old fashioned way and \ give it the OOR treatment */ \ @@ -521,28 +522,30 @@ const wxRect wxGridNoCellRect; %mutable; -%rename(GRID_DEFAULT_NUMBER_ROWS) WXGRID_DEFAULT_NUMBER_ROWS; -%rename(GRID_DEFAULT_NUMBER_COLS) WXGRID_DEFAULT_NUMBER_COLS; -%rename(GRID_DEFAULT_ROW_HEIGHT) WXGRID_DEFAULT_ROW_HEIGHT; -%rename(GRID_DEFAULT_COL_WIDTH) WXGRID_DEFAULT_COL_WIDTH; -%rename(GRID_DEFAULT_COL_LABEL_HEIGHT) WXGRID_DEFAULT_COL_LABEL_HEIGHT; -%rename(GRID_DEFAULT_ROW_LABEL_WIDTH) WXGRID_DEFAULT_ROW_LABEL_WIDTH; -%rename(GRID_LABEL_EDGE_ZONE) WXGRID_LABEL_EDGE_ZONE; -%rename(GRID_MIN_ROW_HEIGHT) WXGRID_MIN_ROW_HEIGHT; -%rename(GRID_MIN_COL_WIDTH) WXGRID_MIN_COL_WIDTH; -%rename(GRID_DEFAULT_SCROLLBAR_WIDTH) WXGRID_DEFAULT_SCROLLBAR_WIDTH; +%{ +#define wxGRID_DEFAULT_NUMBER_ROWS WXGRID_DEFAULT_NUMBER_ROWS +#define wxGRID_DEFAULT_NUMBER_COLS WXGRID_DEFAULT_NUMBER_COLS +#define wxGRID_DEFAULT_ROW_HEIGHT WXGRID_DEFAULT_ROW_HEIGHT +#define wxGRID_DEFAULT_COL_WIDTH WXGRID_DEFAULT_COL_WIDTH +#define wxGRID_DEFAULT_COL_LABEL_HEIGHT WXGRID_DEFAULT_COL_LABEL_HEIGHT +#define wxGRID_DEFAULT_ROW_LABEL_WIDTH WXGRID_DEFAULT_ROW_LABEL_WIDTH +#define wxGRID_LABEL_EDGE_ZONE WXGRID_LABEL_EDGE_ZONE +#define wxGRID_MIN_ROW_HEIGHT WXGRID_MIN_ROW_HEIGHT +#define wxGRID_MIN_COL_WIDTH WXGRID_MIN_COL_WIDTH +#define wxGRID_DEFAULT_SCROLLBAR_WIDTH WXGRID_DEFAULT_SCROLLBAR_WIDTH +%} enum { - WXGRID_DEFAULT_NUMBER_ROWS, - WXGRID_DEFAULT_NUMBER_COLS, - WXGRID_DEFAULT_ROW_HEIGHT, - WXGRID_DEFAULT_COL_WIDTH, - WXGRID_DEFAULT_COL_LABEL_HEIGHT, - WXGRID_DEFAULT_ROW_LABEL_WIDTH, - WXGRID_LABEL_EDGE_ZONE, - WXGRID_MIN_ROW_HEIGHT, - WXGRID_MIN_COL_WIDTH, - WXGRID_DEFAULT_SCROLLBAR_WIDTH + wxGRID_DEFAULT_NUMBER_ROWS, + wxGRID_DEFAULT_NUMBER_COLS, + wxGRID_DEFAULT_ROW_HEIGHT, + wxGRID_DEFAULT_COL_WIDTH, + wxGRID_DEFAULT_COL_LABEL_HEIGHT, + wxGRID_DEFAULT_ROW_LABEL_WIDTH, + wxGRID_LABEL_EDGE_ZONE, + wxGRID_MIN_ROW_HEIGHT, + wxGRID_MIN_COL_WIDTH, + wxGRID_DEFAULT_SCROLLBAR_WIDTH }; @@ -556,7 +559,8 @@ class wxGridCellRenderer public: %extend { void _setOORInfo(PyObject* _self) { - self->SetClientObject(new wxPyOORClientData(_self)); + if (!self->GetClientObject()) + self->SetClientObject(new wxPyOORClientData(_self)); } } @@ -762,7 +766,8 @@ class wxGridCellEditor public: %extend { void _setOORInfo(PyObject* _self) { - self->SetClientObject(new wxPyOORClientData(_self)); + if (!self->GetClientObject()) + self->SetClientObject(new wxPyOORClientData(_self)); } } @@ -1030,14 +1035,15 @@ public: %extend { void _setOORInfo(PyObject* _self) { - self->SetClientObject(new wxPyOORClientData(_self)); + if (!self->GetClientObject()) + self->SetClientObject(new wxPyOORClientData(_self)); } } %pythonAppend wxGridCellAttr "self._setOORInfo(self)" wxGridCellAttr(wxGridCellAttr *attrDefault = NULL); - + wxGridCellAttr *Clone() const; void MergeWith(wxGridCellAttr *mergefrom); void IncRef(); @@ -1095,7 +1101,8 @@ public: %extend { void _setOORInfo(PyObject* _self) { - self->SetClientObject(new wxPyOORClientData(_self)); + if (!self->GetClientObject()) + self->SetClientObject(new wxPyOORClientData(_self)); } } @@ -1156,7 +1163,8 @@ public: %extend { void _setOORInfo(PyObject* _self) { - self->SetClientObject(new wxPyOORClientData(_self)); + if (!self->GetClientObject()) + self->SetClientObject(new wxPyOORClientData(_self)); } } -- 2.45.2