diff --git a/SWIG/Lib/python/pyrun.swg b/SWIG/Lib/python/pyrun.swg index 33b635501..3efe171bc 100644 --- a/SWIG/Lib/python/pyrun.swg +++ b/SWIG/Lib/python/pyrun.swg @@ -161,7 +161,7 @@ typedef struct { PyObject *newraw; PyObject *newargs; PyObject *destroy; - PyObject *delargs; + int delargs; } PySwigClientData; SWIGRUNTIME PySwigClientData * @@ -184,6 +184,7 @@ PySwigClientData_New(PyObject* obj) Py_INCREF(data->newraw); data->newargs = PyTuple_New(1); PyTuple_SetItem(data->newargs, 0, obj); + Py_INCREF(data->newargs); } /* the destroy method, aka as the C++ delete method */ data->destroy = PyObject_GetAttrString(data->klass, "__swig_destroy__"); @@ -194,7 +195,7 @@ PySwigClientData_New(PyObject* obj) if (data->destroy) { Py_INCREF(data->destroy); int flags = PyCFunction_GET_FLAGS(data->destroy); - data->delargs = (flags & (METH_VARARGS)) ? PyTuple_New(1) : 0; + data->delargs = (flags & (METH_VARARGS)); } else { data->delargs = 0; } @@ -209,7 +210,6 @@ PySwigClientData_Del(PySwigClientData* data) Py_XDECREF(data->newraw); Py_XDECREF(data->newargs); Py_XDECREF(data->destroy); - Py_XDECREF(data->delargs); free(data); } @@ -334,13 +334,13 @@ PySwigObject_dealloc(PyObject *v) PyObject *res; PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); PyObject *mself = PyCFunction_GET_SELF(destroy); - PyObject *args = data->delargs; - if (args) { + if (data->delargs) { /* we need to create a temporal object to carry the destroy operation */ PyObject *tmp = PySwigObject_New(sobj->ptr, ty, 0); + PyObject *args = PyTuple_New(1); PyTuple_SetItem(args,0,tmp); res = ((*meth)(mself, args)); - PyTuple_SetItem(args,0,SWIG_Py_Void()); + Py_DECREF(args); } else { res = ((*meth)(mself, v)); } diff --git a/SWIG/Lib/typemaps/ptrtypes.swg b/SWIG/Lib/typemaps/ptrtypes.swg index 8d16e941f..d6361dba8 100644 --- a/SWIG/Lib/typemaps/ptrtypes.swg +++ b/SWIG/Lib/typemaps/ptrtypes.swg @@ -138,10 +138,10 @@ %define %ptr_typecheck_typemap(check,asptr_meth,frag,Type...) %typemap(typecheck,precedence=check,fragment=frag) Type * - "$1 = asptr_meth($input, (Type**)(0));"; + "$1 = asptr_meth($input, (Type**)(0)) != 0;"; %typemap(typecheck,precedence=check,fragment=frag) Type, const Type& - "Type *ptr; $1 = asptr_meth($input, &ptr) && ptr;"; + "$1 = asptr_meth($input, (Type**)(0)) != 0;"; %enddef diff --git a/SWIG/Source/Modules/python.cxx b/SWIG/Source/Modules/python.cxx index 962720698..bf1798f26 100644 --- a/SWIG/Source/Modules/python.cxx +++ b/SWIG/Source/Modules/python.cxx @@ -2216,7 +2216,6 @@ public: } Printf(f_directors_h,"\n\n"); - Printf(f_directors_h,"public:\n"); Printf(f_directors_h,"#if defined(SWIG_DIRECTOR_VTABLE)\n"); Printf(f_directors_h,"/* VTable implementation */\n"); Printf(f_directors_h," PyObject *swig_get_method(size_t method_index, const char *method_name) const {\n"); @@ -2229,7 +2228,6 @@ public: Printf(f_directors_h," msg += method_name;\n"); Printf(f_directors_h," Swig::DirectorMethodException::raise(msg.c_str());\n"); Printf(f_directors_h," }\n"); - Printf(f_directors_h," Py_DECREF(swig_get_self());\n"); Printf(f_directors_h," vtable[method_index] = method;\n"); Printf(f_directors_h," };\n"); Printf(f_directors_h," return method;\n");