From: Marcelo M. <mar...@us...> - 2005-11-02 12:52:11
|
Update of /cvsroot/swig/SWIG/Lib/python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22487/Lib/python Modified Files: pyrun.swg Log Message: safer direct creation of a new instance avoiding the __init__ method Index: pyrun.swg =================================================================== RCS file: /cvsroot/swig/SWIG/Lib/python/pyrun.swg,v retrieving revision 1.77 retrieving revision 1.78 diff -C2 -d -r1.77 -r1.78 *** pyrun.swg 31 Oct 2005 09:57:29 -0000 1.77 --- pyrun.swg 2 Nov 2005 12:52:01 -0000 1.78 *************** *** 48,52 **** /* Flags for new pointer objects */ ! #define SWIG_POINTER_NEW SWIG_POINTER_OWN << 1 --- 48,53 ---- /* Flags for new pointer objects */ ! #define SWIG_POINTER_NOSHADOW SWIG_POINTER_OWN << 1 ! #define SWIG_POINTER_NEW SWIG_POINTER_NOSHADOW | SWIG_POINTER_OWN *************** *** 474,478 **** return &pyswigpacked_type; } - SWIGRUNTIME PyObject * PySwigPacked_New(void *ptr, size_t size, swig_type_info *ty) --- 475,478 ---- *************** *** 511,514 **** --- 511,522 ---- * ----------------------------------------------------------------------------- */ + SWIGRUNTIME + PyObject * + SWIG_This() + { + static PyObject *_this = SWIG_STATIC_POINTER(_this) PyString_FromString("this"); + return _this; + } + /* Convert a pointer value */ *************** *** 521,529 **** void *vptr = 0; PySwigObject *sobj = 0; - static PyObject *SWIG_this = - #if !defined(__cplusplus) - 0; if (!SWIG_this) SWIG_this = - #endif - PyString_FromString("this"); if (!obj) return SWIG_ERROR; --- 529,532 ---- *************** *** 535,539 **** if (!(PySwigObject_Check(obj))) { pyobj = obj; ! obj = PyObject_GetAttr(obj,SWIG_this); if (!obj) goto type_error; if (!PySwigObject_Check(obj)) { --- 538,542 ---- if (!(PySwigObject_Check(obj))) { pyobj = obj; ! obj = PyObject_GetAttr(obj, SWIG_This()); if (!obj) goto type_error; if (!PySwigObject_Check(obj)) { *************** *** 607,614 **** * ----------------------------------------------------------------------------- */ SWIGRUNTIME PyObject * SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) { PyObject *robj = 0; ! int own = (flags & SWIG_POINTER_OWN) || (flags & SWIG_POINTER_NEW); if (!type) { if (!PyErr_Occurred()) { --- 610,653 ---- * ----------------------------------------------------------------------------- */ + SWIGRUNTIMEINLINE void * + SWIG_NewClientData(PyObject* obj) + { + if (PyClass_Check(obj)) { + Py_INCREF(obj); + return obj; + } else { + PyObject *args = PyTuple_New(1); + PyTuple_SetItem(args, 0, obj); + return args; + } + } + + /* Create a new instance object whitout calling __init__ */ + + SWIGRUNTIME PyObject* + SWIG_NewInstance(PyObject * obj) + { + PyObject *inst = 0; + if (PyTuple_Check(obj)) { + static PyObject* fnew = SWIG_STATIC_POINTER(fnew) PyObject_GetAttrString((PyObject*)&PyBaseObject_Type, "__new__"); + inst = PyObject_Call(fnew, obj, NULL); + } else if (PyClass_Check(obj)) { + inst = PyInstance_NewRaw(obj, NULL); + } else { + PyObject* args = PyTuple_New(1); + PyTuple_SetItem(args,0,obj); + inst = SWIG_NewInstance(args); + Py_DECREF(args); + } + + return inst; + } + + SWIGRUNTIME PyObject * SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) { PyObject *robj = 0; ! int own = (flags & SWIG_POINTER_OWN); ! int shadow = !(flags & SWIG_POINTER_NOSHADOW); if (!type) { if (!PyErr_Occurred()) { *************** *** 623,635 **** robj = PySwigObject_New((void *) ptr, type, own); if (!robj || (robj == Py_None)) return robj; ! /* direct new call doesn't create a shadow */ ! if (!(flags & SWIG_POINTER_NEW) && type->clientdata) { ! PyObject *inst; ! PyObject *args = PyDict_New(); ! PyDict_SetItemString(args, "_swig_this", robj); ! Py_DECREF(robj); ! inst = PyEval_CallObjectWithKeywords((PyObject *) type->clientdata, NULL, args); ! Py_DECREF(args); if (inst) { robj = inst; } --- 662,670 ---- robj = PySwigObject_New((void *) ptr, type, own); if (!robj || (robj == Py_None)) return robj; ! if (shadow && type->clientdata) { ! PyObject *inst = SWIG_NewInstance((PyObject *)type->clientdata); if (inst) { + PyObject_SetAttr(inst, SWIG_This(), robj); + Py_DECREF(robj); robj = inst; } |