From a66212dcdf3f4b2d4e2b1d1dc45f2ff35bd51bfd Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Sat, 15 Jun 2002 05:51:11 +0000 Subject: [PATCH] Fixed a bunch of embarassing reference leaks git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15848 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/CHANGES.txt | 10 ++ wxPython/src/clip_dnd.i | 12 +- wxPython/src/controls2.i | 12 +- wxPython/src/grid.i | 222 ++++++++++++++++++--------------- wxPython/src/helpers.h | 104 +++++++++------ wxPython/src/html.i | 4 +- wxPython/src/misc2.i | 31 +++-- wxPython/src/msw/clip_dnd.cpp | 12 +- wxPython/src/msw/controls2.cpp | 12 +- wxPython/src/msw/grid.cpp | 200 ++++++++++++++++------------- wxPython/src/msw/html.cpp | 4 +- wxPython/src/msw/misc2.cpp | 31 +++-- wxPython/src/msw/wx.cpp | 6 - 13 files changed, 372 insertions(+), 288 deletions(-) diff --git a/wxPython/CHANGES.txt b/wxPython/CHANGES.txt index 6e94c00e6a..235dbaef83 100644 --- a/wxPython/CHANGES.txt +++ b/wxPython/CHANGES.txt @@ -121,6 +121,16 @@ supported are: Changed wxGenButton to derive from wxPyControl and overload DoGetBestSize and AcceptsFocus. +Added wxArtProvider. + +Added wxCallAfter which is a helper function that registers a function +(or any callable Python object) to be called one time the next time +there are no pending events. This is useful for when you need to do +something but it can't be done during the current event handler. The +implementation is very simple, see wxPython/wx.py. + +Fixed a boatload of reference leaks. + diff --git a/wxPython/src/clip_dnd.i b/wxPython/src/clip_dnd.i index 1c0b7b3dc5..d1be82ee3e 100644 --- a/wxPython/src/clip_dnd.i +++ b/wxPython/src/clip_dnd.i @@ -288,8 +288,9 @@ wxBitmap wxPyBitmapDataObject::GetBitmap() { void wxPyBitmapDataObject::SetBitmap(const wxBitmap& bitmap) { wxPyBeginBlockThreads(); if (m_myInst.findCallback("SetBitmap")) { - m_myInst.callCallback(Py_BuildValue("(O)", - wxPyConstructObject((void*)&bitmap, "wxBitmap"))); + PyObject* bo = wxPyConstructObject((void*)&bitmap, "wxBitmap"); + m_myInst.callCallback(Py_BuildValue("(O)", bo)); + Py_DECREF(bo); } wxPyEndBlockThreads(); } @@ -625,10 +626,11 @@ bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) { bool rval = FALSE; wxPyBeginBlockThreads(); - PyObject* list = wxArrayString2PyList_helper(filenames); - if (m_myInst.findCallback("OnDropFiles")) + if (m_myInst.findCallback("OnDropFiles")) { + PyObject* list = wxArrayString2PyList_helper(filenames); rval = m_myInst.callCallback(Py_BuildValue("(iiO)",x,y,list)); - Py_DECREF(list); + Py_DECREF(list); + } wxPyEndBlockThreads(); return rval; } diff --git a/wxPython/src/controls2.i b/wxPython/src/controls2.i index aa63f8a257..31acadfa5e 100644 --- a/wxPython/src/controls2.i +++ b/wxPython/src/controls2.i @@ -1075,11 +1075,13 @@ public: int rval = 0; bool found; wxPyBeginBlockThreads(); - if ((found = m_myInst.findCallback("OnCompareItems"))) - rval = m_myInst.callCallback(Py_BuildValue( - "(OO)", - wxPyConstructObject((void*)&item1, "wxTreeItemId"), - wxPyConstructObject((void*)&item2, "wxTreeItemId"))); + if ((found = m_myInst.findCallback("OnCompareItems"))) { + PyObject *o1 = wxPyConstructObject((void*)&item1, "wxTreeItemId"); + PyObject *o2 = wxPyConstructObject((void*)&item2, "wxTreeItemId"); + rval = m_myInst.callCallback(Py_BuildValue("(OO)",o1,o2)); + Py_DECREF(o1); + Py_DECREF(o2); + } wxPyEndBlockThreads(); if (! found) rval = wxTreeCtrl::OnCompareItems(item1, item2); diff --git a/wxPython/src/grid.i b/wxPython/src/grid.i index 09db772abf..c833668cef 100644 --- a/wxPython/src/grid.i +++ b/wxPython/src/grid.i @@ -45,6 +45,50 @@ %} //--------------------------------------------------------------------------- +// OOR related typemaps and helper functions + +%typemap(python, out) wxGridCellRenderer* { $target = wxPyMake_wxGridCellRenderer($source); } +%typemap(python, out) wxGridCellEditor* { $target = wxPyMake_wxGridCellEditor($source); } +%typemap(python, out) wxGridCellAttr* { $target = wxPyMake_wxGridCellAttr($source); } +%typemap(python, out) wxGridCellAttrProvider* { $target = wxPyMake_wxGridCellAttrProvider($source); } +%typemap(python, out) wxGridTableBase* { $target = wxPyMake_wxGridTableBase($source); } + + +%{ + +#define wxPyMake_TEMPLATE(TYPE) \ +PyObject* wxPyMake_##TYPE(TYPE* source) { \ + PyObject* target = NULL; \ + if (source) { \ + /* Check if there is already a pointer to a Python object in the \ + OOR data that we can use. */ \ + wxPyOORClientData* data = (wxPyOORClientData*)source->GetClientObject(); \ + if (data) { \ + target = data->m_obj; \ + Py_INCREF(target); \ + } \ + /* Otherwise make a new wrapper for it the old fashioned way and \ + give it the OOR treatment */ \ + if (! target) { \ + target = wxPyConstructObject(source, #TYPE, FALSE); \ + if (target) \ + source->SetClientObject(new wxPyOORClientData(target)); \ + } \ + } else { /* source was NULL so return None. */ \ + Py_INCREF(Py_None); target = Py_None; \ + } \ + return target; \ +} \ + + +wxPyMake_TEMPLATE(wxGridCellRenderer) +wxPyMake_TEMPLATE(wxGridCellEditor) +wxPyMake_TEMPLATE(wxGridCellAttr) +wxPyMake_TEMPLATE(wxGridCellAttrProvider) +wxPyMake_TEMPLATE(wxGridTableBase) + +%} + //--------------------------------------------------------------------------- // Macros, similar to what's in helpers.h, to aid in the creation of // virtual methods that are able to make callbacks to Python. Many of these @@ -81,14 +125,14 @@ #define PYCALLBACK__GCAINTINT(PCLASS, CBNAME) \ void CBNAME(wxGridCellAttr *attr, int a, int b) { \ - wxPyBeginBlockThreads(); \ + wxPyBeginBlockThreads(); \ bool found; \ if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \ - PyObject* obj = wxPyConstructObject((void*)attr, "wxGridCellAttr", 0);\ - wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oii)", obj, a, b)); \ + PyObject* obj = wxPyMake_wxGridCellAttr(attr); \ + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oii)", obj, a, b)); \ Py_DECREF(obj); \ } \ - wxPyEndBlockThreads(); \ + wxPyEndBlockThreads(); \ if (! found) \ PCLASS::CBNAME(attr, a, b); \ } \ @@ -100,10 +144,10 @@ #define PYCALLBACK__GCAINT(PCLASS, CBNAME) \ void CBNAME(wxGridCellAttr *attr, int val) { \ - wxPyBeginBlockThreads(); \ + wxPyBeginBlockThreads(); \ bool found; \ if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \ - PyObject* obj = wxPyConstructObject((void*)attr, "wxGridCellAttr", 0);\ + PyObject* obj = wxPyMake_wxGridCellAttr(attr); \ wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, val)); \ Py_DECREF(obj); \ } \ @@ -160,8 +204,11 @@ #define PYCALLBACK__INTINTSTRING_pure(CBNAME) \ void CBNAME(int a, int b, const wxString& c) { \ wxPyBeginBlockThreads(); \ - if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \ - wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,wx2PyString(c)));\ + if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \ + PyObject* s = wx2PyString(c); \ + rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,s));\ + Py_DECREF(s); \ + } \ wxPyEndBlockThreads(); \ } @@ -194,8 +241,11 @@ bool rval = 0; \ bool found; \ wxPyBeginBlockThreads(); \ - if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \ - rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", a,b,wx2PyString(c)));\ + if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \ + PyObject* s = wx2PyString(c); \ + rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,s));\ + Py_DECREF(s); \ + } \ wxPyEndBlockThreads(); \ if (! found) \ rval = PCLASS::CBNAME(a,b,c); \ @@ -258,7 +308,7 @@ Py_DECREF(ro); Py_DECREF(str); \ } \ } \ - wxPyEndBlockThreads(); \ + wxPyEndBlockThreads(); \ if (! found) \ rval = PCLASS::CBNAME(a, b); \ return rval; \ @@ -272,10 +322,10 @@ #define PYCALLBACK__(PCLASS, CBNAME) \ void CBNAME() { \ bool found; \ - wxPyBeginBlockThreads(); \ + wxPyBeginBlockThreads(); \ if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \ wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \ - wxPyEndBlockThreads(); \ + wxPyEndBlockThreads(); \ if (! found) \ PCLASS::CBNAME(); \ } \ @@ -290,10 +340,10 @@ bool CBNAME(size_t a, size_t b) { \ bool rval = 0; \ bool found; \ - wxPyBeginBlockThreads(); \ + wxPyBeginBlockThreads(); \ if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \ rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \ - wxPyEndBlockThreads(); \ + wxPyEndBlockThreads(); \ if (! found) \ rval = PCLASS::CBNAME(a,b); \ return rval; \ @@ -308,10 +358,10 @@ bool CBNAME(size_t a) { \ bool rval = 0; \ bool found; \ - wxPyBeginBlockThreads(); \ + wxPyBeginBlockThreads(); \ if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \ rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)", a)); \ - wxPyEndBlockThreads(); \ + wxPyEndBlockThreads(); \ if (! found) \ rval = PCLASS::CBNAME(a); \ return rval; \ @@ -348,8 +398,11 @@ void CBNAME(int a, const wxString& c) { \ bool found; \ wxPyBeginBlockThreads(); \ - if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \ - wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", a, wx2PyString(c))); \ + if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \ + PyObject* s = wx2PyString(c); \ + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)",a,s)); \ + Py_DECREF(s); \ + } \ wxPyEndBlockThreads(); \ if (! found) \ PCLASS::CBNAME(a,c); \ @@ -446,50 +499,6 @@ -%} - -//--------------------------------------------------------------------------- -// OOR related typemaps and helper functions - -%typemap(python, out) wxGridCellRenderer* { $target = wxPyMake_wxGridCellRenderer($source); } -%typemap(python, out) wxGridCellEditor* { $target = wxPyMake_wxGridCellEditor($source); } -%typemap(python, out) wxGridCellAttr* { $target = wxPyMake_wxGridCellAttr($source); } -%typemap(python, out) wxGridCellAttrProvider* { $target = wxPyMake_wxGridCellAttrProvider($source); } -%typemap(python, out) wxGridTableBase* { $target = wxPyMake_wxGridTableBase($source); } - -%{ - - -#define wxPyMake_TEMPLATE(TYPE) \ -PyObject* wxPyMake_##TYPE(TYPE* source) { \ - PyObject* target = NULL; \ - if (source) { \ - /* Check if there is already a pointer to a Python object in the \ - OOR data that we can use. */ \ - wxPyOORClientData* data = (wxPyOORClientData*)source->GetClientObject(); \ - if (data) { \ - target = data->m_obj; \ - Py_INCREF(target); \ - } \ - /* Otherwise make a new wrapper for it the old fashioned way and \ - give it the OOR treatment */ \ - if (! target) { \ - target = wxPyConstructObject(source, #TYPE, FALSE); \ - if (target) \ - source->SetClientObject(new wxPyOORClientData(target)); \ - } \ - } else { /* source was NULL so return None. */ \ - Py_INCREF(Py_None); target = Py_None; \ - } \ - return target; \ -} \ - -wxPyMake_TEMPLATE(wxGridCellRenderer) -wxPyMake_TEMPLATE(wxGridCellEditor) -wxPyMake_TEMPLATE(wxGridCellAttr) -wxPyMake_TEMPLATE(wxGridCellAttrProvider) -wxPyMake_TEMPLATE(wxGridTableBase) - %} //--------------------------------------------------------------------------- @@ -559,13 +568,17 @@ public: int row, int col, bool isSelected) { wxPyBeginBlockThreads(); if (wxPyCBH_findCallback(m_myInst, "Draw")) { - wxPyCBH_callCallback(m_myInst, - Py_BuildValue("(OOOOiii)", - wxPyConstructObject((void*)&grid, "wxGrid", 0), - wxPyConstructObject((void*)&attr, "wxGridCellAttr", 0), - wxPyConstructObject((void*)&dc, "wxDC", 0), - wxPyConstructObject((void*)&rect, "wxRect", 0), - row, col, isSelected)); + PyObject* go = wxPyMake_wxObject(&grid); + PyObject* dco = wxPyMake_wxObject(&dc); + PyObject* ao = wxPyMake_wxGridCellAttr(&attr); + PyObject* ro = wxPyConstructObject((void*)&rect, "wxRect", 0); + + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOOOiii)", go, ao, dco, ro, + row, col, isSelected)); + Py_DECREF(go); + Py_DECREF(ao); + Py_DECREF(dco); + Py_DECREF(ro); } wxPyEndBlockThreads(); } @@ -577,12 +590,17 @@ public: if (wxPyCBH_findCallback(m_myInst, "GetBestSize")) { PyObject* ro; wxSize* ptr; - ro = wxPyCBH_callCallbackObj(m_myInst, - Py_BuildValue("(OOOii)", - wxPyConstructObject((void*)&grid, "wxGrid", 0), - wxPyConstructObject((void*)&attr, "wxGridCellAttr", 0), - wxPyConstructObject((void*)&dc, "wxDC", 0), - row, col)); + PyObject* go = wxPyMake_wxObject(&grid); + PyObject* dco = wxPyMake_wxObject(&dc); + PyObject* ao = wxPyMake_wxGridCellAttr(&attr); + + ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OOOii)", + go, ao, dco, + row, col)); + Py_DECREF(go); + Py_DECREF(ao); + Py_DECREF(dco); + if (ro) { const char* errmsg = "GetBestSize should return a 2-tuple of integers or a wxSize object."; if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p")) { @@ -763,11 +781,12 @@ public: void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) { wxPyBeginBlockThreads(); if (wxPyCBH_findCallback(m_myInst, "Create")) { - wxPyCBH_callCallback(m_myInst, - Py_BuildValue("(OiO)", - wxPyConstructObject((void*)parent, "wxWindow", 0), - id, - wxPyConstructObject((void*)evtHandler, "wxEvtHandler", 0))); + PyObject* po = wxPyMake_wxObject(parent); + PyObject* eo = wxPyMake_wxObject(evtHandler); + + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OiO)", po, id, eo)); + Py_DECREF(po); + Py_DECREF(eo); } wxPyEndBlockThreads(); } @@ -776,9 +795,9 @@ public: void BeginEdit(int row, int col, wxGrid* grid) { wxPyBeginBlockThreads(); if (wxPyCBH_findCallback(m_myInst, "BeginEdit")) { - wxPyCBH_callCallback(m_myInst, - Py_BuildValue("(iiO)", row, col, - wxPyConstructObject((void*)grid, "wxGrid", 0))); + PyObject* go = wxPyMake_wxObject(grid); + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", row, col, go)); + Py_DECREF(go); } wxPyEndBlockThreads(); } @@ -788,9 +807,9 @@ public: bool rv = FALSE; wxPyBeginBlockThreads(); if (wxPyCBH_findCallback(m_myInst, "EndEdit")) { - rv = wxPyCBH_callCallback(m_myInst, - Py_BuildValue("(iiO)", row, col, - wxPyConstructObject((void*)grid, "wxGrid", 0))); + PyObject* go = wxPyMake_wxObject(grid); + rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", row, col, go)); + Py_DECREF(go); } wxPyEndBlockThreads(); return rv; @@ -818,10 +837,11 @@ public: void Show(bool show, wxGridCellAttr *attr) { bool found; wxPyBeginBlockThreads(); - if ((found = wxPyCBH_findCallback(m_myInst, "Show"))) - wxPyCBH_callCallback(m_myInst, - Py_BuildValue("(iO)", show, - wxPyConstructObject((void*)attr, "wxGridCellAttr", 0))); + if ((found = wxPyCBH_findCallback(m_myInst, "Show"))) { + PyObject* ao = wxPyMake_wxGridCellAttr(attr); + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", show, ao)); + Py_DECREF(ao); + } wxPyEndBlockThreads(); if (! found) wxGridCellEditor::Show(show, attr); @@ -832,13 +852,17 @@ public: void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) { - bool found; \ + bool found; wxPyBeginBlockThreads(); - if ((found = wxPyCBH_findCallback(m_myInst, "PaintBackground)"))) - wxPyCBH_callCallback(m_myInst, - Py_BuildValue("(OO)", - wxPyConstructObject((void*)&rectCell, "wxRect", 0), - wxPyConstructObject((void*)attr, "wxGridCellAttr", 0))); + if ((found = wxPyCBH_findCallback(m_myInst, "PaintBackground)"))) { + PyObject* ao = wxPyMake_wxGridCellAttr(attr); + PyObject* ro = wxPyConstructObject((void*)&rectCell, "wxRect", 0); + + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", ro, ao)); + + Py_DECREF(ro); + Py_DECREF(ao); + } wxPyEndBlockThreads(); if (! found) wxGridCellEditor::PaintBackground(rectCell, attr); @@ -1189,7 +1213,9 @@ public: void SetValue(int row, int col, const wxString& val) { wxPyBeginBlockThreads(); if (wxPyCBH_findCallback(m_myInst, "SetValue")) { - wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",row,col,wx2PyString(val))); + PyObject* s = wx2PyString(val); + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",row,col,s)); + Py_DECREF(s); } wxPyEndBlockThreads(); } diff --git a/wxPython/src/helpers.h b/wxPython/src/helpers.h index 7831008324..fc20239de3 100644 --- a/wxPython/src/helpers.h +++ b/wxPython/src/helpers.h @@ -950,10 +950,10 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh); #define IMP_PYCALLBACK__BOOL2DBLINT(CLASS, PCLASS, CBNAME) \ void CLASS::CBNAME(bool a, double b, double c, int d) { \ bool found; \ - wxPyBeginBlockThreads(); \ + wxPyBeginBlockThreads(); \ if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \ wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iddi)", (int)a,b,c,d));\ - wxPyEndBlockThreads(); \ + wxPyEndBlockThreads(); \ if (! found) \ PCLASS::CBNAME(a, b, c, d); \ } \ @@ -971,10 +971,13 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh); #define IMP_PYCALLBACK__STRING(CLASS, PCLASS, CBNAME) \ void CLASS::CBNAME(const wxString& a) { \ bool found; \ - wxPyBeginBlockThreads(); \ - if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \ - wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", wx2PyString(a))); \ - wxPyEndBlockThreads(); \ + wxPyBeginBlockThreads(); \ + if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \ + PyObject* s = wx2PyString(a); \ + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", s)); \ + Py_DECREF(s); \ + } \ + wxPyEndBlockThreads(); \ if (! found) \ PCLASS::CBNAME(a); \ } \ @@ -992,10 +995,13 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh); bool CLASS::CBNAME(const wxString& a) { \ bool rval=FALSE; \ bool found; \ - wxPyBeginBlockThreads(); \ - if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \ - rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", wx2PyString(a)));\ - wxPyEndBlockThreads(); \ + wxPyBeginBlockThreads(); \ + if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \ + PyObject* s = wx2PyString(a); \ + rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", s)); \ + Py_DECREF(s); \ + } \ + wxPyEndBlockThreads(); \ if (! found) \ rval = PCLASS::CBNAME(a); \ return rval; \ @@ -1009,15 +1015,18 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh); #define DEC_PYCALLBACK_BOOL_STRING_pure(CBNAME) \ bool CBNAME(const wxString& a); -#define IMP_PYCALLBACK_BOOL_STRING_pure(CLASS, PCLASS, CBNAME) \ - bool CLASS::CBNAME(const wxString& a) { \ - bool rval=FALSE; \ - wxPyBeginBlockThreads(); \ - if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \ - rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", wx2PyString(a))); \ - wxPyEndBlockThreads(); \ - return rval; \ - } \ +#define IMP_PYCALLBACK_BOOL_STRING_pure(CLASS, PCLASS, CBNAME) \ + bool CLASS::CBNAME(const wxString& a) { \ + bool rval=FALSE; \ + wxPyBeginBlockThreads(); \ + if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \ + PyObject* s = wx2PyString(a); \ + rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", s)); \ + Py_DECREF(s); \ + } \ + wxPyEndBlockThreads(); \ + return rval; \ + } \ //--------------------------------------------------------------------------- @@ -1030,7 +1039,9 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh); wxPyBeginBlockThreads(); \ if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \ PyObject* ro; \ - ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(O)", wx2PyString(a)));\ + PyObject* s = wx2PyString(a); \ + ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(O)", s)); \ + Py_DECREF(s); \ if (ro) { \ rval = Py2wxString(ro); \ Py_DECREF(ro); \ @@ -1048,10 +1059,12 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh); #define IMP_PYCALLBACK_STRING_STRINGINT_pure(CLASS, PCLASS, CBNAME) \ wxString CLASS::CBNAME(const wxString& a,int b) { \ wxString rval; \ - wxPyBeginBlockThreads(); \ + wxPyBeginBlockThreads(); \ if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \ PyObject* ro; \ - ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(Oi)", wx2PyString(a),b)); \ + PyObject* s = wx2PyString(a); \ + ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(Oi)",s,b)); \ + Py_DECREF(s); \ if (ro) { \ rval = Py2wxString(ro); \ Py_DECREF(ro); \ @@ -1071,10 +1084,14 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh); bool CLASS::CBNAME(const wxString& a, const wxString& b) { \ bool rval=FALSE; \ bool found; \ - wxPyBeginBlockThreads(); \ - if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \ - rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", \ - wx2PyString(a), wx2PyString(b))); \ + wxPyBeginBlockThreads(); \ + if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \ + PyObject* s1 = wx2PyString(a); \ + PyObject* s2 = wx2PyString(b); \ + rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)",s1,s2)); \ + Py_DECREF(s1); \ + Py_DECREF(s2); \ + } \ wxPyEndBlockThreads(); \ if (! found) \ rval = PCLASS::CBNAME(a, b); \ @@ -1142,13 +1159,13 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh); #define IMP_PYCALLBACK_BOOL_TAG_pure(CLASS, PCLASS, CBNAME) \ bool CLASS::CBNAME(const wxHtmlTag& a) { \ bool rval=FALSE; \ - wxPyBeginBlockThreads(); \ + wxPyBeginBlockThreads(); \ if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \ PyObject* obj = wxPyConstructObject((void*)&a, "wxHtmlTag", 0); \ rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \ Py_DECREF(obj); \ } \ - wxPyEndBlockThreads(); \ + wxPyEndBlockThreads(); \ return rval; \ } @@ -1161,13 +1178,13 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh); #define IMP_PYCALLBACK__CELLINTINT(CLASS, PCLASS, CBNAME) \ void CLASS::CBNAME(wxHtmlCell *cell, wxCoord x, wxCoord y) { \ bool found; \ - wxPyBeginBlockThreads(); \ + wxPyBeginBlockThreads(); \ if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \ PyObject* obj = wxPyConstructObject((void*)cell, "wxHtmlCell", 0); \ wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(Oii)",obj,x,y)); \ Py_DECREF(obj); \ } \ - wxPyEndBlockThreads(); \ + wxPyEndBlockThreads(); \ if (! found) \ PCLASS::CBNAME(cell, x, y); \ } \ @@ -1185,7 +1202,7 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh); #define IMP_PYCALLBACK__CELLINTINTME(CLASS, PCLASS, CBNAME) \ void CLASS::CBNAME(wxHtmlCell *cell, wxCoord x, wxCoord y, const wxMouseEvent& e) { \ bool found; \ - wxPyBeginBlockThreads(); \ + wxPyBeginBlockThreads(); \ if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \ PyObject* obj = wxPyConstructObject((void*)cell, "wxHtmlCell", 0); \ PyObject* o2 = wxPyConstructObject((void*)&e, "wxMouseEvent", 0); \ @@ -1193,12 +1210,12 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh); Py_DECREF(obj); \ Py_DECREF(o2); \ } \ - wxPyEndBlockThreads(); \ + wxPyEndBlockThreads(); \ if (! found) \ - PCLASS::CBNAME(cell, x, y, e); \ + PCLASS::CBNAME(cell, x, y, e); \ } \ void CLASS::base_##CBNAME(wxHtmlCell *cell, wxCoord x, wxCoord y, const wxMouseEvent& e) { \ - PCLASS::CBNAME(cell, x, y, e); \ + PCLASS::CBNAME(cell, x, y, e); \ } @@ -1211,10 +1228,10 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh); #define IMP_PYCALLBACK___pure(CLASS, PCLASS, CBNAME) \ void CLASS::CBNAME() { \ - wxPyBeginBlockThreads(); \ + wxPyBeginBlockThreads(); \ if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \ wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \ - wxPyEndBlockThreads(); \ + wxPyEndBlockThreads(); \ } //--------------------------------------------------------------------------- @@ -1266,13 +1283,13 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh); bool CLASS::CBNAME(wxWindow* a) { \ bool rval=FALSE; \ bool found; \ - wxPyBeginBlockThreads(); \ + wxPyBeginBlockThreads(); \ if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \ PyObject* obj = wxPyMake_wxObject(a); \ rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \ Py_DECREF(obj); \ } \ - wxPyEndBlockThreads(); \ + wxPyEndBlockThreads(); \ if (! found) \ rval = PCLASS::CBNAME(a); \ return rval; \ @@ -1362,13 +1379,15 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh); if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \ PyObject* ro; \ PyObject* obj = wxPyMake_wxObject(&a); \ + PyObject* s = wx2PyString(b); \ ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OO)",\ - obj, wx2PyString(b))); \ + obj, s)); \ if (ro) { \ SWIG_GetPtrObj(ro, (void **)&rval, "_wxFSFILE_p"); \ Py_DECREF(ro); \ } \ Py_DECREF(obj); \ + Py_DECREF(s); \ } \ wxPyEndBlockThreads(); \ return rval; \ @@ -1422,8 +1441,11 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh); bool CLASS::CBNAME(int a, int b, const wxString& c) { \ bool rval=FALSE; \ wxPyBeginBlockThreads(); \ - if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \ - rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b, wx2PyString(c)));\ + if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \ + PyObject* s = wx2PyString(c); \ + rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,s));\ + Py_DECREF(s); \ + } \ wxPyEndBlockThreads(); \ return rval; \ } \ diff --git a/wxPython/src/html.i b/wxPython/src/html.i index bb978a43d9..9d757ed813 100644 --- a/wxPython/src/html.i +++ b/wxPython/src/html.i @@ -514,7 +514,9 @@ wxHtmlOpeningStatus wxPyHtmlWindow::OnOpeningURL(wxHtmlURLType type, wxPyBeginBlockThreads(); if ((found = wxPyCBH_findCallback(m_myInst, "OnOpeningURL"))) { PyObject* ro; - ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iO)", type, wx2PyString(url))); + PyObject* s = wx2PyString(url); + ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iO)", type, s)); + Py_DECREF(s); if (PyString_Check(ro) #if PYTHON_API_VERSION >= 1009 || PyUnicode_Check(ro) diff --git a/wxPython/src/misc2.i b/wxPython/src/misc2.i index eaba07bcce..ef93904448 100644 --- a/wxPython/src/misc2.i +++ b/wxPython/src/misc2.i @@ -696,9 +696,11 @@ public: virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) { bool found; wxPyBeginBlockThreads(); - if ((found = wxPyCBH_findCallback(m_myInst, "DoLog"))) - wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level, - wx2PyString(szString), t)); + if ((found = wxPyCBH_findCallback(m_myInst, "DoLog"))) { + PyObject* s = wx2PyString(szString); + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level, s, t)); + Py_DECREF(s); + } wxPyEndBlockThreads(); if (! found) wxLog::DoLog(level, szString, t); @@ -707,9 +709,11 @@ public: virtual void DoLogString(const wxChar *szString, time_t t) { bool found; wxPyBeginBlockThreads(); - if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString"))) - wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", - wx2PyString(szString), t)); + if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString"))) { + PyObject* s = wx2PyString(szString); + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", s, t)); + Py_DECREF(s); + } wxPyEndBlockThreads(); if (! found) wxLog::DoLogString(szString, t); @@ -1412,20 +1416,13 @@ public: PyObject* so = wxPyConstructObject((void*)&size, "wxSize", 0); PyObject* ro; wxBitmap* ptr; -#if 0 - ro = wxPyCBH_callCallbackObj( - m_myInst, Py_BuildValue("(OOO)", - wx2PyString(id), - wx2PyString(client), - so)); -#else // testing... - PyObject *args, *s1, *s2; + PyObject* s1, *s2; s1 = wx2PyString(id); s2 = wx2PyString(client); - args = Py_BuildValue("(OOO)", s1, s2, so); - ro = wxPyCBH_callCallbackObj(m_myInst, args); -#endif + ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OOO)", s1, s2, so)); Py_DECREF(so); + Py_DECREF(s1); + Py_DECREF(s2); if (ro) { if (!SWIG_GetPtrObj(ro, (void**)&ptr, "_wxBitmap_p")) rval = *ptr; diff --git a/wxPython/src/msw/clip_dnd.cpp b/wxPython/src/msw/clip_dnd.cpp index e9a9f19cc1..321a322c0f 100644 --- a/wxPython/src/msw/clip_dnd.cpp +++ b/wxPython/src/msw/clip_dnd.cpp @@ -191,8 +191,9 @@ wxBitmap wxPyBitmapDataObject::GetBitmap() { void wxPyBitmapDataObject::SetBitmap(const wxBitmap& bitmap) { wxPyBeginBlockThreads(); if (m_myInst.findCallback("SetBitmap")) { - m_myInst.callCallback(Py_BuildValue("(O)", - wxPyConstructObject((void*)&bitmap, "wxBitmap"))); + PyObject* bo = wxPyConstructObject((void*)&bitmap, "wxBitmap"); + m_myInst.callCallback(Py_BuildValue("(O)", bo)); + Py_DECREF(bo); } wxPyEndBlockThreads(); } @@ -293,10 +294,11 @@ bool wxPyFileDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) { bool rval = FALSE; wxPyBeginBlockThreads(); - PyObject* list = wxArrayString2PyList_helper(filenames); - if (m_myInst.findCallback("OnDropFiles")) + if (m_myInst.findCallback("OnDropFiles")) { + PyObject* list = wxArrayString2PyList_helper(filenames); rval = m_myInst.callCallback(Py_BuildValue("(iiO)",x,y,list)); - Py_DECREF(list); + Py_DECREF(list); + } wxPyEndBlockThreads(); return rval; } diff --git a/wxPython/src/msw/controls2.cpp b/wxPython/src/msw/controls2.cpp index c4dbd0eb17..9a88d7de7e 100644 --- a/wxPython/src/msw/controls2.cpp +++ b/wxPython/src/msw/controls2.cpp @@ -213,11 +213,13 @@ public: int rval = 0; bool found; wxPyBeginBlockThreads(); - if ((found = m_myInst.findCallback("OnCompareItems"))) - rval = m_myInst.callCallback(Py_BuildValue( - "(OO)", - wxPyConstructObject((void*)&item1, "wxTreeItemId"), - wxPyConstructObject((void*)&item2, "wxTreeItemId"))); + if ((found = m_myInst.findCallback("OnCompareItems"))) { + PyObject *o1 = wxPyConstructObject((void*)&item1, "wxTreeItemId"); + PyObject *o2 = wxPyConstructObject((void*)&item2, "wxTreeItemId"); + rval = m_myInst.callCallback(Py_BuildValue("(OO)",o1,o2)); + Py_DECREF(o1); + Py_DECREF(o2); + } wxPyEndBlockThreads(); if (! found) rval = wxTreeCtrl::OnCompareItems(item1, item2); diff --git a/wxPython/src/msw/grid.cpp b/wxPython/src/msw/grid.cpp index 4b890d14cf..de3859039a 100644 --- a/wxPython/src/msw/grid.cpp +++ b/wxPython/src/msw/grid.cpp @@ -91,6 +91,39 @@ static PyObject* t_output_helper(PyObject* target, PyObject* o) { DECLARE_DEF_STRING2(DateTimeFormatStr, wxT("%c")); static const wxString wxPyEmptyString(wxT("")); + +#define wxPyMake_TEMPLATE(TYPE) \ +PyObject* wxPyMake_##TYPE(TYPE* source) { \ + PyObject* target = NULL; \ + if (source) { \ + /* Check if there is already a pointer to a Python object in the \ + OOR data that we can use. */ \ + wxPyOORClientData* data = (wxPyOORClientData*)source->GetClientObject(); \ + if (data) { \ + target = data->m_obj; \ + Py_INCREF(target); \ + } \ + /* Otherwise make a new wrapper for it the old fashioned way and \ + give it the OOR treatment */ \ + if (! target) { \ + target = wxPyConstructObject(source, #TYPE, FALSE); \ + if (target) \ + source->SetClientObject(new wxPyOORClientData(target)); \ + } \ + } else { /* source was NULL so return None. */ \ + Py_INCREF(Py_None); target = Py_None; \ + } \ + return target; \ +} \ + + +wxPyMake_TEMPLATE(wxGridCellRenderer) +wxPyMake_TEMPLATE(wxGridCellEditor) +wxPyMake_TEMPLATE(wxGridCellAttr) +wxPyMake_TEMPLATE(wxGridCellAttrProvider) +wxPyMake_TEMPLATE(wxGridTableBase) + + #define PYCALLBACK_GCA_INTINTKIND(PCLASS, CBNAME) \ wxGridCellAttr* CBNAME(int a, int b, wxGridCellAttr::wxAttrKind c) { \ wxGridCellAttr* rval = NULL; \ @@ -119,14 +152,14 @@ static PyObject* t_output_helper(PyObject* target, PyObject* o) { #define PYCALLBACK__GCAINTINT(PCLASS, CBNAME) \ void CBNAME(wxGridCellAttr *attr, int a, int b) { \ - wxPyBeginBlockThreads(); \ + wxPyBeginBlockThreads(); \ bool found; \ if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \ - PyObject* obj = wxPyConstructObject((void*)attr, "wxGridCellAttr", 0);\ - wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oii)", obj, a, b)); \ + PyObject* obj = wxPyMake_wxGridCellAttr(attr); \ + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oii)", obj, a, b)); \ Py_DECREF(obj); \ } \ - wxPyEndBlockThreads(); \ + wxPyEndBlockThreads(); \ if (! found) \ PCLASS::CBNAME(attr, a, b); \ } \ @@ -138,10 +171,10 @@ static PyObject* t_output_helper(PyObject* target, PyObject* o) { #define PYCALLBACK__GCAINT(PCLASS, CBNAME) \ void CBNAME(wxGridCellAttr *attr, int val) { \ - wxPyBeginBlockThreads(); \ + wxPyBeginBlockThreads(); \ bool found; \ if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \ - PyObject* obj = wxPyConstructObject((void*)attr, "wxGridCellAttr", 0);\ + PyObject* obj = wxPyMake_wxGridCellAttr(attr); \ wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", obj, val)); \ Py_DECREF(obj); \ } \ @@ -198,8 +231,11 @@ static PyObject* t_output_helper(PyObject* target, PyObject* o) { #define PYCALLBACK__INTINTSTRING_pure(CBNAME) \ void CBNAME(int a, int b, const wxString& c) { \ wxPyBeginBlockThreads(); \ - if (wxPyCBH_findCallback(m_myInst, #CBNAME)) \ - wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,wx2PyString(c)));\ + if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \ + PyObject* s = wx2PyString(c); \ + rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,s));\ + Py_DECREF(s); \ + } \ wxPyEndBlockThreads(); \ } @@ -232,8 +268,11 @@ static PyObject* t_output_helper(PyObject* target, PyObject* o) { bool rval = 0; \ bool found; \ wxPyBeginBlockThreads(); \ - if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \ - rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", a,b,wx2PyString(c)));\ + if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \ + PyObject* s = wx2PyString(c); \ + rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",a,b,s));\ + Py_DECREF(s); \ + } \ wxPyEndBlockThreads(); \ if (! found) \ rval = PCLASS::CBNAME(a,b,c); \ @@ -296,7 +335,7 @@ static PyObject* t_output_helper(PyObject* target, PyObject* o) { Py_DECREF(ro); Py_DECREF(str); \ } \ } \ - wxPyEndBlockThreads(); \ + wxPyEndBlockThreads(); \ if (! found) \ rval = PCLASS::CBNAME(a, b); \ return rval; \ @@ -310,10 +349,10 @@ static PyObject* t_output_helper(PyObject* target, PyObject* o) { #define PYCALLBACK__(PCLASS, CBNAME) \ void CBNAME() { \ bool found; \ - wxPyBeginBlockThreads(); \ + wxPyBeginBlockThreads(); \ if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \ wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \ - wxPyEndBlockThreads(); \ + wxPyEndBlockThreads(); \ if (! found) \ PCLASS::CBNAME(); \ } \ @@ -328,10 +367,10 @@ static PyObject* t_output_helper(PyObject* target, PyObject* o) { bool CBNAME(size_t a, size_t b) { \ bool rval = 0; \ bool found; \ - wxPyBeginBlockThreads(); \ + wxPyBeginBlockThreads(); \ if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \ rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)", a,b)); \ - wxPyEndBlockThreads(); \ + wxPyEndBlockThreads(); \ if (! found) \ rval = PCLASS::CBNAME(a,b); \ return rval; \ @@ -346,10 +385,10 @@ static PyObject* t_output_helper(PyObject* target, PyObject* o) { bool CBNAME(size_t a) { \ bool rval = 0; \ bool found; \ - wxPyBeginBlockThreads(); \ + wxPyBeginBlockThreads(); \ if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \ rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)", a)); \ - wxPyEndBlockThreads(); \ + wxPyEndBlockThreads(); \ if (! found) \ rval = PCLASS::CBNAME(a); \ return rval; \ @@ -386,8 +425,11 @@ static PyObject* t_output_helper(PyObject* target, PyObject* o) { void CBNAME(int a, const wxString& c) { \ bool found; \ wxPyBeginBlockThreads(); \ - if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \ - wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", a, wx2PyString(c))); \ + if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \ + PyObject* s = wx2PyString(c); \ + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)",a,s)); \ + Py_DECREF(s); \ + } \ wxPyEndBlockThreads(); \ if (! found) \ PCLASS::CBNAME(a,c); \ @@ -485,39 +527,6 @@ static PyObject* t_output_helper(PyObject* target, PyObject* o) { - - -#define wxPyMake_TEMPLATE(TYPE) \ -PyObject* wxPyMake_##TYPE(TYPE* source) { \ - PyObject* target = NULL; \ - if (source) { \ - /* Check if there is already a pointer to a Python object in the \ - OOR data that we can use. */ \ - wxPyOORClientData* data = (wxPyOORClientData*)source->GetClientObject(); \ - if (data) { \ - target = data->m_obj; \ - Py_INCREF(target); \ - } \ - /* Otherwise make a new wrapper for it the old fashioned way and \ - give it the OOR treatment */ \ - if (! target) { \ - target = wxPyConstructObject(source, #TYPE, FALSE); \ - if (target) \ - source->SetClientObject(new wxPyOORClientData(target)); \ - } \ - } else { /* source was NULL so return None. */ \ - Py_INCREF(Py_None); target = Py_None; \ - } \ - return target; \ -} \ - -wxPyMake_TEMPLATE(wxGridCellRenderer) -wxPyMake_TEMPLATE(wxGridCellEditor) -wxPyMake_TEMPLATE(wxGridCellAttr) -wxPyMake_TEMPLATE(wxGridCellAttrProvider) -wxPyMake_TEMPLATE(wxGridTableBase) - - class wxPyGridCellRenderer : public wxGridCellRenderer { public: @@ -529,13 +538,17 @@ public: int row, int col, bool isSelected) { wxPyBeginBlockThreads(); if (wxPyCBH_findCallback(m_myInst, "Draw")) { - wxPyCBH_callCallback(m_myInst, - Py_BuildValue("(OOOOiii)", - wxPyConstructObject((void*)&grid, "wxGrid", 0), - wxPyConstructObject((void*)&attr, "wxGridCellAttr", 0), - wxPyConstructObject((void*)&dc, "wxDC", 0), - wxPyConstructObject((void*)&rect, "wxRect", 0), - row, col, isSelected)); + PyObject* go = wxPyMake_wxObject(&grid); + PyObject* dco = wxPyMake_wxObject(&dc); + PyObject* ao = wxPyMake_wxGridCellAttr(&attr); + PyObject* ro = wxPyConstructObject((void*)&rect, "wxRect", 0); + + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOOOiii)", go, ao, dco, ro, + row, col, isSelected)); + Py_DECREF(go); + Py_DECREF(ao); + Py_DECREF(dco); + Py_DECREF(ro); } wxPyEndBlockThreads(); } @@ -547,12 +560,17 @@ public: if (wxPyCBH_findCallback(m_myInst, "GetBestSize")) { PyObject* ro; wxSize* ptr; - ro = wxPyCBH_callCallbackObj(m_myInst, - Py_BuildValue("(OOOii)", - wxPyConstructObject((void*)&grid, "wxGrid", 0), - wxPyConstructObject((void*)&attr, "wxGridCellAttr", 0), - wxPyConstructObject((void*)&dc, "wxDC", 0), - row, col)); + PyObject* go = wxPyMake_wxObject(&grid); + PyObject* dco = wxPyMake_wxObject(&dc); + PyObject* ao = wxPyMake_wxGridCellAttr(&attr); + + ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OOOii)", + go, ao, dco, + row, col)); + Py_DECREF(go); + Py_DECREF(ao); + Py_DECREF(dco); + if (ro) { const char* errmsg = "GetBestSize should return a 2-tuple of integers or a wxSize object."; if (!SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p")) { @@ -612,11 +630,12 @@ public: void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) { wxPyBeginBlockThreads(); if (wxPyCBH_findCallback(m_myInst, "Create")) { - wxPyCBH_callCallback(m_myInst, - Py_BuildValue("(OiO)", - wxPyConstructObject((void*)parent, "wxWindow", 0), - id, - wxPyConstructObject((void*)evtHandler, "wxEvtHandler", 0))); + PyObject* po = wxPyMake_wxObject(parent); + PyObject* eo = wxPyMake_wxObject(evtHandler); + + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OiO)", po, id, eo)); + Py_DECREF(po); + Py_DECREF(eo); } wxPyEndBlockThreads(); } @@ -625,9 +644,9 @@ public: void BeginEdit(int row, int col, wxGrid* grid) { wxPyBeginBlockThreads(); if (wxPyCBH_findCallback(m_myInst, "BeginEdit")) { - wxPyCBH_callCallback(m_myInst, - Py_BuildValue("(iiO)", row, col, - wxPyConstructObject((void*)grid, "wxGrid", 0))); + PyObject* go = wxPyMake_wxObject(grid); + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", row, col, go)); + Py_DECREF(go); } wxPyEndBlockThreads(); } @@ -637,9 +656,9 @@ public: bool rv = FALSE; wxPyBeginBlockThreads(); if (wxPyCBH_findCallback(m_myInst, "EndEdit")) { - rv = wxPyCBH_callCallback(m_myInst, - Py_BuildValue("(iiO)", row, col, - wxPyConstructObject((void*)grid, "wxGrid", 0))); + PyObject* go = wxPyMake_wxObject(grid); + rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)", row, col, go)); + Py_DECREF(go); } wxPyEndBlockThreads(); return rv; @@ -667,10 +686,11 @@ public: void Show(bool show, wxGridCellAttr *attr) { bool found; wxPyBeginBlockThreads(); - if ((found = wxPyCBH_findCallback(m_myInst, "Show"))) - wxPyCBH_callCallback(m_myInst, - Py_BuildValue("(iO)", show, - wxPyConstructObject((void*)attr, "wxGridCellAttr", 0))); + if ((found = wxPyCBH_findCallback(m_myInst, "Show"))) { + PyObject* ao = wxPyMake_wxGridCellAttr(attr); + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", show, ao)); + Py_DECREF(ao); + } wxPyEndBlockThreads(); if (! found) wxGridCellEditor::Show(show, attr); @@ -681,13 +701,17 @@ public: void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr) { - bool found; \ + bool found; wxPyBeginBlockThreads(); - if ((found = wxPyCBH_findCallback(m_myInst, "PaintBackground)"))) - wxPyCBH_callCallback(m_myInst, - Py_BuildValue("(OO)", - wxPyConstructObject((void*)&rectCell, "wxRect", 0), - wxPyConstructObject((void*)attr, "wxGridCellAttr", 0))); + if ((found = wxPyCBH_findCallback(m_myInst, "PaintBackground)"))) { + PyObject* ao = wxPyMake_wxGridCellAttr(attr); + PyObject* ro = wxPyConstructObject((void*)&rectCell, "wxRect", 0); + + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)", ro, ao)); + + Py_DECREF(ro); + Py_DECREF(ao); + } wxPyEndBlockThreads(); if (! found) wxGridCellEditor::PaintBackground(rectCell, attr); @@ -780,7 +804,9 @@ public: void SetValue(int row, int col, const wxString& val) { wxPyBeginBlockThreads(); if (wxPyCBH_findCallback(m_myInst, "SetValue")) { - wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",row,col,wx2PyString(val))); + PyObject* s = wx2PyString(val); + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiO)",row,col,s)); + Py_DECREF(s); } wxPyEndBlockThreads(); } diff --git a/wxPython/src/msw/html.cpp b/wxPython/src/msw/html.cpp index 82788159f1..0d8c6925db 100644 --- a/wxPython/src/msw/html.cpp +++ b/wxPython/src/msw/html.cpp @@ -264,7 +264,9 @@ wxHtmlOpeningStatus wxPyHtmlWindow::OnOpeningURL(wxHtmlURLType type, wxPyBeginBlockThreads(); if ((found = wxPyCBH_findCallback(m_myInst, "OnOpeningURL"))) { PyObject* ro; - ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iO)", type, wx2PyString(url))); + PyObject* s = wx2PyString(url); + ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(iO)", type, s)); + Py_DECREF(s); if (PyString_Check(ro) #if PYTHON_API_VERSION >= 1009 || PyUnicode_Check(ro) diff --git a/wxPython/src/msw/misc2.cpp b/wxPython/src/msw/misc2.cpp index 1ae38fbb59..0f2e7c818c 100644 --- a/wxPython/src/msw/misc2.cpp +++ b/wxPython/src/msw/misc2.cpp @@ -145,9 +145,11 @@ public: virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) { bool found; wxPyBeginBlockThreads(); - if ((found = wxPyCBH_findCallback(m_myInst, "DoLog"))) - wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level, - wx2PyString(szString), t)); + if ((found = wxPyCBH_findCallback(m_myInst, "DoLog"))) { + PyObject* s = wx2PyString(szString); + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level, s, t)); + Py_DECREF(s); + } wxPyEndBlockThreads(); if (! found) wxLog::DoLog(level, szString, t); @@ -156,9 +158,11 @@ public: virtual void DoLogString(const wxChar *szString, time_t t) { bool found; wxPyBeginBlockThreads(); - if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString"))) - wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", - wx2PyString(szString), t)); + if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString"))) { + PyObject* s = wx2PyString(szString); + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", s, t)); + Py_DECREF(s); + } wxPyEndBlockThreads(); if (! found) wxLog::DoLogString(szString, t); @@ -289,20 +293,13 @@ public: PyObject* so = wxPyConstructObject((void*)&size, "wxSize", 0); PyObject* ro; wxBitmap* ptr; -#if 0 - ro = wxPyCBH_callCallbackObj( - m_myInst, Py_BuildValue("(OOO)", - wx2PyString(id), - wx2PyString(client), - so)); -#else // testing... - PyObject *args, *s1, *s2; + PyObject* s1, *s2; s1 = wx2PyString(id); s2 = wx2PyString(client); - args = Py_BuildValue("(OOO)", s1, s2, so); - ro = wxPyCBH_callCallbackObj(m_myInst, args); -#endif + ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OOO)", s1, s2, so)); Py_DECREF(so); + Py_DECREF(s1); + Py_DECREF(s2); if (ro) { if (!SWIG_GetPtrObj(ro, (void**)&ptr, "_wxBitmap_p")) rval = *ptr; diff --git a/wxPython/src/msw/wx.cpp b/wxPython/src/msw/wx.cpp index ebdaad6aa2..a67fca1c02 100644 --- a/wxPython/src/msw/wx.cpp +++ b/wxPython/src/msw/wx.cpp @@ -1788,8 +1788,6 @@ static struct { char *n1; char *n2; void *(*pcnv)(void *); } _swig_mapping[] = { { "_uint","_int",0}, { "_uint","_wxWindowID",0}, { "_wxChar","_char",0}, - { "_wxString","_wxArtID",0}, - { "_wxString","_wxArtClient",0}, { "_char","_wxChar",0}, { "_struct_wxNativeFontInfo","_wxNativeFontInfo",0}, { "_EBool","_wxCoord",0}, @@ -1863,11 +1861,7 @@ static struct { char *n1; char *n2; void *(*pcnv)(void *); } _swig_mapping[] = { { "_wxCoord","_size_t",0}, { "_wxCoord","_time_t",0}, { "_wxCoord","_wxPrintQuality",0}, - { "_wxArtClient","_wxArtID",0}, - { "_wxArtClient","_wxString",0}, { "_wxEvtHandler","_wxPyApp",SwigwxPyAppTowxEvtHandler}, - { "_wxArtID","_wxString",0}, - { "_wxArtID","_wxArtClient",0}, {0,0,0}}; static PyObject *SWIG_globals; -- 2.45.2