From 18736f2cba86c21fb77202eb595eb7bafa111fcd Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Sat, 5 Nov 2005 15:45:57 +0000 Subject: [PATCH] add missing INCREF git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7814 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pycontainer.swg | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg index d5699373e..e1e64598a 100644 --- a/Lib/python/pycontainer.swg +++ b/Lib/python/pycontainer.swg @@ -38,12 +38,16 @@ namespace swig { class PyItem { PyObject *_obj; public: + PyItem() :_obj(0) + { + } + PyItem(const PyItem& item) : _obj(item._obj) { Py_XINCREF(_obj); } - PyItem(PyObject *obj = 0) :_obj(obj) + PyItem(PyObject *obj) :_obj(obj) { Py_XINCREF(_obj); } @@ -62,7 +66,7 @@ namespace swig { ~PyItem() { - Py_XDECREF(_obj); + if (_obj) Py_DECREF(_obj); } operator PyObject *() const @@ -91,7 +95,9 @@ namespace swig { template <> struct traits_from { typedef PyItem value_type; static PyObject *from(const value_type& val) { - return static_cast(val); + PyObject *obj = static_cast(val); + Py_XINCREF(obj); + return obj; } }; @@ -158,6 +164,7 @@ namespace swig { template <> struct traits_from { typedef PyObject * value_type; static PyObject *from(const value_type& val) { + Py_XINCREF(val); return val; } };