From 3d444101d114ca5e462558277b0fc7f3f7eb651b Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Tue, 29 Mar 2011 06:57:02 +0000 Subject: [PATCH] A slew of changes based on William Fulton's code review. - Fixed naming conventions; SwigPyBuiltin is used a lot - Removed use of std::vector - builtin.swg isn't included if -builtin isn't specified - Changed many feature names to use a "python:" prefix - Eliminated static vars in std_pair.i - Eliminated C++-style comments (//) - Enabled autodoc and docstring with -builtin - Fixed non-ansi generated C code - Detect and complain if two incompatible swig modules are loaded - Removed argcargvtest_runme3.py, and fixed argcargvtest_runme.py so that 2to3 handles it better - Removed anonymous namespaces - Eliminated builtin_init typemaps; consolidated functionality into SWIG_Python_NewPointerObj - Eliminate printf warnings from %U conversion character by switching to %S, which works just as well - Fixed li_std_set_runme.py for python3, which returns set members in a different order from python2 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12562 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 4 + .../test-suite/python/argcargvtest_runme.py | 10 +- .../test-suite/python/argcargvtest_runme3.py | 27 - .../python/default_constructor_runme.py | 4 +- .../test-suite/python/li_std_set_runme.py | 2 +- Lib/python/boost_shared_ptr.i | 16 +- Lib/python/builtin.swg | 106 ++-- Lib/python/carrays.i | 4 +- Lib/python/director.swg | 6 +- Lib/python/pycontainer.swg | 18 +- Lib/python/pyinit.swg | 31 +- Lib/python/pyiterators.swg | 6 +- Lib/python/pyopers.swg | 16 +- Lib/python/pyrun.swg | 215 +++++--- Lib/python/pyruntime.swg | 3 + Lib/python/pystdcommon.swg | 2 +- Lib/python/pystrings.swg | 2 +- Lib/python/pytypemaps.swg | 12 +- Lib/python/pywstrings.swg | 2 +- Lib/python/std_map.i | 12 +- Lib/python/std_multimap.i | 2 +- Lib/python/std_pair.i | 48 +- Source/Modules/python.cxx | 511 ++++++++++-------- 23 files changed, 550 insertions(+), 509 deletions(-) delete mode 100644 Examples/test-suite/python/argcargvtest_runme3.py diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 995b584b7..5423542f7 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -526,6 +526,8 @@ wallkw.cpptest: SWIGOPT += -Wallkw preproc_include.ctest: SWIGOPT += -includeall +NOT_BROKEN_C_TEST_CASES = $(C_TEST_CASES:=.ctest) + NOT_BROKEN_TEST_CASES = $(CPP_TEST_CASES:=.cpptest) \ $(C_TEST_CASES:=.ctest) \ $(MULTI_CPP_TEST_CASES:=.multicpptest) \ @@ -547,6 +549,8 @@ all: $(BROKEN_TEST_CASES) $(NOT_BROKEN_TEST_CASES) check: $(NOT_BROKEN_TEST_CASES) +check-c : $(NOT_BROKEN_C_TEST_CASES) + # partialcheck target runs SWIG only, ie no compilation or running of tests (for a subset of languages) partialcheck: $(MAKE) check CC=true CXX=true LDSHARED=true CXXSHARED=true RUNTOOL=true COMPILETOOL=true diff --git a/Examples/test-suite/python/argcargvtest_runme.py b/Examples/test-suite/python/argcargvtest_runme.py index 584a19f6e..047ea9551 100644 --- a/Examples/test-suite/python/argcargvtest_runme.py +++ b/Examples/test-suite/python/argcargvtest_runme.py @@ -2,16 +2,16 @@ from argcargvtest import * largs=['hi','hola','hello'] if mainc(largs) != 3: - raise RuntimeError, "bad main typemap" + raise RuntimeError("bad main typemap") targs=('hi','hola') if mainv(targs,1) != 'hola': - print mainv(targs,1) - raise RuntimeError, "bad main typemap" + print(mainv(targs,1)) + raise RuntimeError("bad main typemap") targs=('hi', 'hola') if mainv(targs,1) != 'hola': - raise RuntimeError, "bad main typemap" + raise RuntimeError("bad main typemap") try: error = 0 @@ -20,7 +20,7 @@ try: except TypeError: pass if error: - raise RuntimeError, "bad main typemap" + raise RuntimeError("bad main typemap") diff --git a/Examples/test-suite/python/argcargvtest_runme3.py b/Examples/test-suite/python/argcargvtest_runme3.py deleted file mode 100644 index 047ea9551..000000000 --- a/Examples/test-suite/python/argcargvtest_runme3.py +++ /dev/null @@ -1,27 +0,0 @@ -from argcargvtest import * - -largs=['hi','hola','hello'] -if mainc(largs) != 3: - raise RuntimeError("bad main typemap") - -targs=('hi','hola') -if mainv(targs,1) != 'hola': - print(mainv(targs,1)) - raise RuntimeError("bad main typemap") - -targs=('hi', 'hola') -if mainv(targs,1) != 'hola': - raise RuntimeError("bad main typemap") - -try: - error = 0 - mainv('hello',1) - error = 1 -except TypeError: - pass -if error: - raise RuntimeError("bad main typemap") - - - -initializeApp(largs) diff --git a/Examples/test-suite/python/default_constructor_runme.py b/Examples/test-suite/python/default_constructor_runme.py index 60771c177..8d0dc5ba2 100644 --- a/Examples/test-suite/python/default_constructor_runme.py +++ b/Examples/test-suite/python/default_constructor_runme.py @@ -1,6 +1,6 @@ -import _default_constructor +import default_constructor -dc = _default_constructor +dc = default_constructor # Old static syntax not supported #a = dc.new_A() diff --git a/Examples/test-suite/python/li_std_set_runme.py b/Examples/test-suite/python/li_std_set_runme.py index 6d8963138..449333e73 100644 --- a/Examples/test-suite/python/li_std_set_runme.py +++ b/Examples/test-suite/python/li_std_set_runme.py @@ -92,5 +92,5 @@ sum = () for i in s: sum = sum + (i,) -if sum != (1, 'hello', (1, 2)): +if (len(sum) != 3 or (not 1 in sum) or (not 'hello' in sum) or (not (1, 2) in sum)) : raise RuntimeError diff --git a/Lib/python/boost_shared_ptr.i b/Lib/python/boost_shared_ptr.i index b62b2b87f..bae1576c2 100644 --- a/Lib/python/boost_shared_ptr.i +++ b/Lib/python/boost_shared_ptr.i @@ -6,6 +6,10 @@ #define SHARED_PTR_DISOWN 0 #endif +%fragment("SWIG_null_deleter_python", "header", fragment="SWIG_null_deleter") { +%#define SWIG_NO_NULL_DELETER_SWIG_BUILTIN_INIT +} + // Language specific macro implementing all the customisations for handling the smart pointer %define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...) @@ -76,7 +80,7 @@ } } -%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * { +%typemap(out, fragment="SWIG_null_deleter_python") CONST TYPE * { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0; %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), $owner | SWIG_POINTER_OWN)); } @@ -99,7 +103,7 @@ $1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype); } } -%typemap(varout, fragment="SWIG_null_deleter") CONST TYPE * { +%typemap(varout, fragment="SWIG_null_deleter_python") CONST TYPE * { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0; %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } @@ -120,7 +124,7 @@ $1 = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype); } } -%typemap(out, fragment="SWIG_null_deleter") CONST TYPE & { +%typemap(out, fragment="SWIG_null_deleter_python") CONST TYPE & { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } @@ -142,7 +146,7 @@ $1 = *%const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype); } } -%typemap(varout, fragment="SWIG_null_deleter") CONST TYPE & { +%typemap(varout, fragment="SWIG_null_deleter_python") CONST TYPE & { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(&$1 SWIG_NO_NULL_DELETER_0); %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } @@ -164,7 +168,7 @@ } $1 = &temp; } -%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST& { +%typemap(out, fragment="SWIG_null_deleter_python") TYPE *CONST& { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } @@ -316,7 +320,7 @@ #if defined(SWIGPYTHON_BUILTIN) -%typemap(builtin_init, fragment="SWIG_null_deleter") CONST TYPE * { +%typemap(builtin_init, fragment="SWIG_null_deleter_python") CONST TYPE * { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0; %set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), $owner | SWIG_POINTER_OWN)); } diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index 69402568e..aa7dbbe89 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -1,10 +1,10 @@ -#define PYSWIG_UNARYFUNC_CLOSURE(wrapper) \ +#define SWIGPY_UNARYFUNC_CLOSURE(wrapper) \ SWIGINTERN PyObject * \ wrapper##_closure(PyObject *a) { \ return wrapper(a, NULL); \ } -#define PYSWIG_DESTRUCTOR_CLOSURE(wrapper) \ +#define SWIGPY_DESTRUCTOR_CLOSURE(wrapper) \ SWIGINTERN void \ wrapper##_closure(PyObject *a) { \ SwigPyObject *sobj = (SwigPyObject *)a; \ @@ -14,7 +14,7 @@ wrapper##_closure(PyObject *a) { \ } \ } -#define PYSWIG_INQUIRY_CLOSURE(wrapper) \ +#define SWIGPY_INQUIRY_CLOSURE(wrapper) \ SWIGINTERN int \ wrapper##_closure(PyObject *a) { \ PyObject *pyresult = wrapper(a, NULL); \ @@ -23,7 +23,7 @@ wrapper##_closure(PyObject *a) { \ return result; \ } -#define PYSWIG_BINARYFUNC_CLOSURE(wrapper) \ +#define SWIGPY_BINARYFUNC_CLOSURE(wrapper) \ SWIGINTERN PyObject * \ wrapper##_closure(PyObject *a, PyObject *b) { \ PyObject *tuple = PyTuple_New(1); \ @@ -35,7 +35,7 @@ wrapper##_closure(PyObject *a, PyObject *b) { \ return result; \ } -#define PYSWIG_TERNARYFUNC_CLOSURE(wrapper) \ +#define SWIGPY_TERNARYFUNC_CLOSURE(wrapper) \ SWIGINTERN PyObject * \ wrapper##_closure(PyObject *a, PyObject *b, PyObject *c) { \ PyObject *tuple = PyTuple_New(2); \ @@ -49,7 +49,7 @@ wrapper##_closure(PyObject *a, PyObject *b, PyObject *c) { \ return result; \ } -#define PYSWIG_LENFUNC_CLOSURE(wrapper) \ +#define SWIGPY_LENFUNC_CLOSURE(wrapper) \ SWIGINTERN Py_ssize_t \ wrapper##_closure(PyObject *a) { \ PyObject *resultobj = wrapper(a, NULL); \ @@ -58,7 +58,7 @@ wrapper##_closure(PyObject *a) { \ return result; \ } -#define PYSWIG_SSIZESSIZEARGFUNC_CLOSURE(wrapper) \ +#define SWIGPY_SSIZESSIZEARGFUNC_CLOSURE(wrapper) \ SWIGINTERN PyObject * \ wrapper##_closure(PyObject *a, Py_ssize_t b, Py_ssize_t c) { \ PyObject *tuple = PyTuple_New(2); \ @@ -70,7 +70,7 @@ wrapper##_closure(PyObject *a, Py_ssize_t b, Py_ssize_t c) { \ return result; \ } -#define PYSWIG_SSIZESSIZEOBJARGPROC_CLOSURE(wrapper) \ +#define SWIGPY_SSIZESSIZEOBJARGPROC_CLOSURE(wrapper) \ SWIGINTERN int \ wrapper##_closure(PyObject *a, Py_ssize_t b, Py_ssize_t c, PyObject *d) { \ PyObject *tuple = PyTuple_New(d ? 3 : 2); \ @@ -88,7 +88,7 @@ wrapper##_closure(PyObject *a, Py_ssize_t b, Py_ssize_t c, PyObject *d) { \ return result; \ } -#define PYSWIG_SSIZEARGFUNC_CLOSURE(wrapper) \ +#define SWIGPY_SSIZEARGFUNC_CLOSURE(wrapper) \ SWIGINTERN PyObject * \ wrapper##_closure(PyObject *a, Py_ssize_t b) { \ PyObject *tuple = PyTuple_New(1); \ @@ -99,7 +99,7 @@ wrapper##_closure(PyObject *a, Py_ssize_t b) { \ return result; \ } -#define PYSWIG_FUNPACK_SSIZEARGFUNC_CLOSURE(wrapper) \ +#define SWIGPY_FUNPACK_SSIZEARGFUNC_CLOSURE(wrapper) \ SWIGINTERN PyObject * \ wrapper##_closure(PyObject *a, Py_ssize_t b) { \ PyObject *arg = _PyLong_FromSsize_t(b); \ @@ -108,7 +108,7 @@ wrapper##_closure(PyObject *a, Py_ssize_t b) { \ return result; \ } -#define PYSWIG_SSIZEOBJARGPROC_CLOSURE(wrapper) \ +#define SWIGPY_SSIZEOBJARGPROC_CLOSURE(wrapper) \ SWIGINTERN int \ wrapper##_closure(PyObject *a, Py_ssize_t b, PyObject *c) { \ PyObject *tuple = PyTuple_New(2); \ @@ -123,7 +123,7 @@ wrapper##_closure(PyObject *a, Py_ssize_t b, PyObject *c) { \ return result; \ } -#define PYSWIG_OBJOBJARGPROC_CLOSURE(wrapper) \ +#define SWIGPY_OBJOBJARGPROC_CLOSURE(wrapper) \ SWIGINTERN int \ wrapper##_closure(PyObject *a, PyObject *b, PyObject *c) { \ PyObject *tuple = PyTuple_New(c ? 2 : 1); \ @@ -141,13 +141,13 @@ wrapper##_closure(PyObject *a, PyObject *b, PyObject *c) { \ return result; \ } -#define PYSWIG_REPRFUNC_CLOSURE(wrapper) \ +#define SWIGPY_REPRFUNC_CLOSURE(wrapper) \ SWIGINTERN PyObject * \ wrapper##_closure(PyObject *a) { \ return wrapper(a, NULL); \ } -#define PYSWIG_HASHFUNC_CLOSURE(wrapper) \ +#define SWIGPY_HASHFUNC_CLOSURE(wrapper) \ SWIGINTERN long \ wrapper##_closure(PyObject *a) { \ PyObject *pyresult = wrapper(a, NULL); \ @@ -158,7 +158,7 @@ wrapper##_closure(PyObject *a) { \ return result; \ } -#define PYSWIG_ITERNEXT_CLOSURE(wrapper) \ +#define SWIGPY_ITERNEXT_CLOSURE(wrapper) \ SWIGINTERN PyObject * \ wrapper##_closure(PyObject *a) { \ PyObject *result = wrapper(a, NULL); \ @@ -170,13 +170,13 @@ wrapper##_closure(PyObject *a) { \ } SWIGINTERN int -py_builtin_bad_init(PyObject *self, PyObject *args, PyObject *kwds) { +SwigPyBuiltin_BadInit(PyObject *self, PyObject *args, PyObject *kwds) { PyErr_Format(PyExc_TypeError, "Cannot create new instances of type '%.300s'", self->ob_type->tp_name); return -1; } SWIGINTERN void -py_builtin_bad_dealloc(PyObject *pyobj) { +SwigPyBuiltin_BadDealloc(PyObject *pyobj) { SwigPyObject *sobj = (SwigPyObject *)pyobj; if (sobj->own) { PyErr_Format(PyExc_TypeError, "Swig detected a memory leak in type '%.300s': no callable destructor found.", pyobj->ob_type->tp_name); @@ -189,7 +189,7 @@ typedef struct { } SwigPyGetSet; SWIGINTERN PyObject * -pyswig_getter_closure(PyObject *obj, void *closure) { +SwigPyBuiltin_GetterClosure (PyObject *obj, void *closure) { if (!closure) return SWIG_Py_Void(); SwigPyGetSet *getset = (SwigPyGetSet *)closure; @@ -203,7 +203,7 @@ pyswig_getter_closure(PyObject *obj, void *closure) { } SWIGINTERN PyObject * -pyswig_funpack_getter_closure(PyObject *obj, void *closure) { +SwigPyBuiltin_FunpackGetterClosure (PyObject *obj, void *closure) { if (!closure) return SWIG_Py_Void(); SwigPyGetSet *getset = (SwigPyGetSet *)closure; @@ -214,7 +214,7 @@ pyswig_funpack_getter_closure(PyObject *obj, void *closure) { } SWIGINTERN int -pyswig_setter_closure(PyObject *obj, PyObject *val, void *closure) { +SwigPyBuiltin_SetterClosure (PyObject *obj, PyObject *val, void *closure) { if (!closure) { PyErr_Format(PyExc_TypeError, "Missing getset closure"); return -1; @@ -235,7 +235,7 @@ pyswig_setter_closure(PyObject *obj, PyObject *val, void *closure) { } SWIGINTERN int -pyswig_funpack_setter_closure(PyObject *obj, PyObject *val, void *closure) { +SwigPyBuiltin_FunpackSetterClosure (PyObject *obj, PyObject *val, void *closure) { if (!closure) { PyErr_Format(PyExc_TypeError, "Missing getset closure"); return -1; @@ -250,41 +250,6 @@ pyswig_funpack_setter_closure(PyObject *obj, PyObject *val, void *closure) { return result ? 0 : -1; } -SWIGINTERN PyObject * -pyswig_static_getter_closure(PyObject *obj, void *closure) { - if (!closure) - return SWIG_Py_Void(); - SwigPyGetSet *getset = (SwigPyGetSet *)closure; - if (!getset->get) - return SWIG_Py_Void(); - PyObject *tuple = PyTuple_New(0); - assert(tuple); - PyObject *result = (*getset->get)(obj, tuple); - Py_DECREF(tuple); - return result; -} - -SWIGINTERN int -pyswig_static_setter_closure(PyObject *obj, PyObject *val, void *closure) { - if (!closure) { - PyErr_Format(PyExc_TypeError, "Missing getset closure"); - return -1; - } - SwigPyGetSet *getset = (SwigPyGetSet *)closure; - if (!getset->set) { - PyErr_Format(PyExc_TypeError, "Illegal static variable assignment."); - return -1; - } - PyObject *tuple = PyTuple_New(1); - assert(tuple); - PyTuple_SET_ITEM(tuple, 0, val); - Py_XINCREF(val); - PyObject *result = (*getset->set)(obj, tuple); - Py_DECREF(tuple); - Py_XDECREF(result); - return result ? 0 : -1; -} - SWIGINTERN void SwigPyStaticVar_dealloc(PyDescrObject *descr) { _PyObject_GC_UNTRACK(descr); @@ -296,7 +261,7 @@ SwigPyStaticVar_dealloc(PyDescrObject *descr) { SWIGINTERN PyObject * SwigPyStaticVar_repr(PyGetSetDescrObject *descr) { #if PY_VERSION_HEX >= 0x03000000 - return PyUnicode_FromFormat("", descr->d_name, descr->d_type->tp_name); + return PyUnicode_FromFormat("", descr->d_name, descr->d_type->tp_name); #else return PyString_FromFormat("", PyString_AsString(descr->d_name), descr->d_type->tp_name); #endif @@ -416,19 +381,22 @@ SwigPyStaticVar_new_getset(PyTypeObject *type, PyGetSetDef *getset) { return descr; } -#ifdef __cplusplus - -#include - SWIGINTERN void -pyswig_builtin_init_bases(PyTypeObject *type, std::vector &bases) { - if (!bases.size()) - bases.push_back(SwigPyObject_type()); +SwigPyBuiltin_InitBases (PyTypeObject *type, PyTypeObject **bases) { + int base_count = 0; + PyTypeObject **b; + int i; + + if (!bases[0]) { + bases[0] = SwigPyObject_type(); + bases[1] = NULL; + } type->tp_base = bases[0]; Py_INCREF((PyObject *)bases[0]); - PyObject *tuple = PyTuple_New(bases.size()); - int i; - for (i = 0; i < bases.size(); ++i) { + for (b = bases; *b != NULL; ++b) + ++base_count; + PyObject *tuple = PyTuple_New(base_count); + for (i = 0; i < base_count; ++i) { PyTuple_SET_ITEM(tuple, i, (PyObject *)bases[i]); Py_INCREF((PyObject *)bases[i]); } @@ -436,10 +404,8 @@ pyswig_builtin_init_bases(PyTypeObject *type, std::vector &bases } SWIGINTERN PyObject * -pyswig_this_closure(PyObject *self, void *closure) { +SwigPyBuiltin_ThisClosure (PyObject *self, void *closure) { PyObject *result = (PyObject *)SWIG_Python_GetSwigThis(self); Py_XINCREF(result); return result; } - -#endif diff --git a/Lib/python/carrays.i b/Lib/python/carrays.i index 6a43637e6..8a881fd0b 100644 --- a/Lib/python/carrays.i +++ b/Lib/python/carrays.i @@ -1,7 +1,7 @@ %define %array_class(TYPE,NAME) #if defined(SWIGPYTHON_BUILTIN) - %feature("pyslot", "sq_item", functype="ssizeargfunc") NAME::__getitem__; - %feature("pyslot", "sq_ass_item", functype="ssizeobjargproc") NAME::__setitem__; + %feature("python:slot", "sq_item", functype="ssizeargfunc") NAME::__getitem__; + %feature("python:slot", "sq_ass_item", functype="ssizeobjargproc") NAME::__setitem__; %inline %{ typedef struct NAME { diff --git a/Lib/python/director.swg b/Lib/python/director.swg index 3a801dd3a..c80695ff7 100644 --- a/Lib/python/director.swg +++ b/Lib/python/director.swg @@ -460,12 +460,12 @@ namespace Swig { return own; } - template - static PyObject* pyobj_disown(PyObject *pyobj, PyObject *SWIGUNUSEDPARM(args)) + template + static PyObject* swig_pyobj_disown(PyObject *pyobj, PyObject *SWIGUNUSEDPARM(args)) { SwigPyObject *sobj = (SwigPyObject *)pyobj; sobj->own = 0; - Director *d = SWIG_DIRECTOR_CAST(reinterpret_cast<_Tp *>(sobj->ptr)); + Director *d = SWIG_DIRECTOR_CAST(reinterpret_cast(sobj->ptr)); if (d) d->swig_disown(); return PyWeakref_NewProxy(pyobj, NULL); diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg index 4878f66c7..f2e633023 100644 --- a/Lib/python/pycontainer.swg +++ b/Lib/python/pycontainer.swg @@ -587,7 +587,7 @@ namespace swig } #if defined(SWIGPYTHON_BUILTIN) - %feature("pyslot", "tp_iter", functype="getiterfunc") iterator; + %feature("python:slot", "tp_iter", functype="getiterfunc") iterator; #else %pythoncode {def __iter__(self): return self.iterator()} #endif @@ -604,8 +604,8 @@ namespace swig %newobject __getslice__; #if defined(SWIGPYTHON_BUILTIN) - %feature("pyslot", "nb_nonzero", functype="inquiry") __nonzero__; - %feature("pyslot", "sq_length", functype="lenfunc") __len__; + %feature("python:slot", "nb_nonzero", functype="inquiry") __nonzero__; + %feature("python:slot", "sq_length", functype="lenfunc") __len__; #endif // SWIGPYTHON_BUILTIN %extend { @@ -634,12 +634,12 @@ namespace swig %fragment("SwigPySequence_Base"); #if defined(SWIGPYTHON_BUILTIN) - //%feature("pyslot", "sq_item", functype="ssizeargfunc") __getitem__; - //%feature("pyslot", "sq_slice", functype="ssizessizeargfunc") __getslice__; - //%feature("pyslot", "sq_ass_item", functype="ssizeobjargproc") __setitem__; - //%feature("pyslot", "sq_ass_slice", functype="ssizessizeobjargproc") __setslice__; - %feature("pyslot", "mp_subscript", functype="binaryfunc") __getitem__; - %feature("pyslot", "mp_ass_subscript", functype="objobjargproc") __setitem__; + //%feature("python:slot", "sq_item", functype="ssizeargfunc") __getitem__; + //%feature("python:slot", "sq_slice", functype="ssizessizeargfunc") __getslice__; + //%feature("python:slot", "sq_ass_item", functype="ssizeobjargproc") __setitem__; + //%feature("python:slot", "sq_ass_slice", functype="ssizessizeobjargproc") __setslice__; + %feature("python:slot", "mp_subscript", functype="binaryfunc") __getitem__; + %feature("python:slot", "mp_ass_subscript", functype="objobjargproc") __setitem__; #endif // SWIGPYTHON_BUILTIN %extend { diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index 5f777894b..1027695f0 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -7,8 +7,6 @@ %init %{ #ifdef __cplusplus -#include - extern "C" { #endif @@ -241,7 +239,7 @@ SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { for (i = 0; constants[i].type; ++i) { switch(constants[i].type) { case SWIG_PY_POINTER: - obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0); + obj = SWIG_InternalNewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0); break; case SWIG_PY_BINARY: obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype)); @@ -340,16 +338,14 @@ SWIG_init(void) { #if defined(SWIGPYTHON_BUILTIN) PyTypeObject *builtin_pytype = 0; -#ifdef __cplusplus - std::vector builtin_bases; -#endif + int builtin_base_count = 0; swig_type_info *builtin_basetype = 0; PyObject *tuple = NULL; PyGetSetDescrObject *static_getset = NULL; int i; - // metatype is used to implement static member variables. + /* metatype is used to implement static member variables. */ PyObject *metatype_args = Py_BuildValue("(s(O){})", "SwigPyObjectType", &PyType_Type); assert(metatype_args); PyTypeObject *metatype = (PyTypeObject *) PyType_Type.tp_call((PyObject *) &PyType_Type, metatype_args, NULL); @@ -381,22 +377,29 @@ SWIG_init(void) { SwigPyClientData *cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; if (!cd) { SwigPyObject_stype->clientdata = &SwigPyObject_clientdata; - SwigPyObject_clientdata.pytype = _PySwigObject_type(); + SwigPyObject_clientdata.pytype = SwigPyObject_TypeOnce(); + } else if (SwigPyObject_TypeOnce()->tp_basicsize != cd->pytype->tp_basicsize) { + PyErr_SetString(PyExc_RuntimeError, "Import error: attempted to load two incompatible swig-generated modules."); +# if PY_VERSION_HEX >= 0x03000000 + return NULL; +# else + return; +# endif } - // All objects have a 'this' attribute + /* All objects have a 'this' attribute */ static PyGetSetDef this_getset_def = { - const_cast("this"), pyswig_this_closure, NULL, NULL, NULL + (char*) "this", SwigPyBuiltin_ThisClosure, NULL, NULL, NULL }; PyObject *this_descr = PyDescr_NewGetSet(SwigPyObject_type(), &this_getset_def); - // All objects have a 'thisown' attribute + /* All objects have a 'thisown' attribute */ static SwigPyGetSet thisown_getset_closure = { (PyCFunction) SwigPyObject_own, (PyCFunction) SwigPyObject_own }; static PyGetSetDef thisown_getset_def = { - const_cast("thisown"), pyswig_getter_closure, pyswig_setter_closure, NULL, &thisown_getset_closure + const_cast("thisown"), SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure }; PyObject *thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def); @@ -405,9 +408,9 @@ SWIG_init(void) { PyDict_SetItemString(md, "__all__", public_interface); Py_DECREF(public_interface); for (i = 0; SwigMethods[i].ml_name != NULL; ++i) - pyswig_add_public_symbol(public_interface, SwigMethods[i].ml_name); + SwigPyBuiltin_AddPublicSymbol(public_interface, SwigMethods[i].ml_name); for (i = 0; swig_const_table[i].name != 0; ++i) - pyswig_add_public_symbol(public_interface, swig_const_table[i].name); + SwigPyBuiltin_AddPublicSymbol(public_interface, swig_const_table[i].name); #endif SWIG_InstallConstants(d,swig_const_table); diff --git a/Lib/python/pyiterators.swg b/Lib/python/pyiterators.swg index 6ff2ef3ee..5521027a7 100644 --- a/Lib/python/pyiterators.swg +++ b/Lib/python/pyiterators.swg @@ -318,7 +318,7 @@ namespace swig { if (!seq) return SWIG_Py_Void(); SwigPyIterator *iter = make_output_iterator(seq->begin(), seq->begin(), seq->end(), pyself); - return SWIG_NewPointerObj(iter, SWIGTYPE_p_swig__SwigPyIterator, SWIG_POINTER_OWN); + return SWIG_InternalNewPointerObj(iter, SWIGTYPE_p_swig__SwigPyIterator, SWIG_POINTER_OWN); } } @@ -350,8 +350,8 @@ namespace swig %nodirector SwigPyIterator; #if defined(SWIGPYTHON_BUILTIN) - %feature("tp_iter") SwigPyIterator "&swig::make_output_iterator_builtin"; - %feature("pyslot", "tp_iternext", functype="iternextfunc") SwigPyIterator::__next__; + %feature("python:tp_iter") SwigPyIterator "&swig::make_output_iterator_builtin"; + %feature("python:slot", "tp_iternext", functype="iternextfunc") SwigPyIterator::__next__; #else %extend SwigPyIterator { %pythoncode {def __iter__(self): return self} diff --git a/Lib/python/pyopers.swg b/Lib/python/pyopers.swg index a51d87549..2dbaba41e 100644 --- a/Lib/python/pyopers.swg +++ b/Lib/python/pyopers.swg @@ -6,10 +6,10 @@ #ifdef __cplusplus #if defined(SWIGPYTHON_BUILTIN) -#define %pybinoperator(pyname,oper,functp,slot) %rename(pyname) oper; %pythonmaybecall oper; %feature("pyslot", #slot, functype=#functp) oper; %feature("pyslot", #slot, functype=#functp) pyname; -#define %pycompare(pyname,oper,comptype) %rename(pyname) oper; %pythonmaybecall oper; %feature("pycompare", #comptype) oper; %feature("pycompare", #comptype) pyname; +#define %pybinoperator(pyname,oper,functp,slt) %rename(pyname) oper; %pythonmaybecall oper; %feature("python:slot", #slt, functype=#functp) oper; %feature("python:slot", #slt, functype=#functp) pyname; +#define %pycompare(pyname,oper,comptype) %rename(pyname) oper; %pythonmaybecall oper; %feature("python:compare", #comptype) oper; %feature("python:compare", #comptype) pyname; #else -#define %pybinoperator(pyname,oper,functp,slot) %rename(pyname) oper; %pythonmaybecall oper +#define %pybinoperator(pyname,oper,functp,slt) %rename(pyname) oper; %pythonmaybecall oper #define %pycompare(pyname,oper,comptype) %pybinoperator(pyname,oper,,comptype) #endif @@ -34,13 +34,13 @@ %pycompare(__eq__, *::operator==, Py_EQ); %pycompare(__ne__, *::operator!=, Py_NE); -%feature("pyslot", "nb_truediv", functype="binaryfunc") *::operator/; +%feature("python:slot", "nb_truediv", functype="binaryfunc") *::operator/; /* Special cases */ %rename(__invert__) *::operator~; -%feature("pyslot", "nb_invert", functype="unaryfunc") *::operator~; +%feature("python:slot", "nb_invert", functype="unaryfunc") *::operator~; %rename(__call__) *::operator(); -%feature("pyslot", "tp_call", functype="ternaryfunc") *::operator(); +%feature("python:slot", "tp_call", functype="ternaryfunc") *::operator(); #if defined(SWIGPYTHON_BUILTIN) %pybinoperator(__nonzero__, *::operator bool, inquiry, nb_nonzero); @@ -103,9 +103,9 @@ __bool__ = __nonzero__ */ #if defined(SWIGPYTHON_BUILTIN) -#define %pyinplaceoper(SwigPyOper, Oper, functp, slot) %delobject Oper; %newobject Oper; %feature("pyslot", #slot, functype=#functp) Oper; %rename(SwigPyOper) Oper +#define %pyinplaceoper(SwigPyOper, Oper, functp, slt) %delobject Oper; %newobject Oper; %feature("python:slot", #slt, functype=#functp) Oper; %rename(SwigPyOper) Oper #else -#define %pyinplaceoper(SwigPyOper, Oper, functp, slot) %delobject Oper; %newobject Oper; %rename(SwigPyOper) Oper +#define %pyinplaceoper(SwigPyOper, Oper, functp, slt) %delobject Oper; %newobject Oper; %rename(SwigPyOper) Oper #endif %pyinplaceoper(__iadd__ , *::operator +=, binaryfunc, nb_inplace_add); diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 393bc6ddd..84b552a72 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -13,7 +13,15 @@ #define SWIG_Python_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, 0) #define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtr(obj, pptr, type, flags) #define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, own) -#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(ptr, type, flags) + +#ifdef SWIGPYTHON_BUILTIN +#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(self, ptr, type, flags) +#else +#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(NULL, ptr, type, flags) +#endif + +#define SWIG_InternalNewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(NULL, ptr, type, flags) + #define SWIG_CheckImplicit(ty) SWIG_Python_CheckImplicit(ty) #define SWIG_AcquirePtr(ptr, src) SWIG_Python_AcquirePtr(ptr, src) #define swig_owntype int @@ -28,7 +36,7 @@ /* for C or C++ function pointers */ #define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_Python_ConvertFunctionPtr(obj, pptr, type) -#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Python_NewPointerObj(ptr, type, 0) +#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Python_NewPointerObj(NULL, ptr, type, 0) /* for C++ member pointers, ie, member methods */ #define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) @@ -74,7 +82,7 @@ SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) { #if defined(SWIGPYTHON_BUILTIN) SWIGINTERN void -pyswig_add_public_symbol(PyObject *seq, const char *key) { +SwigPyBuiltin_AddPublicSymbol(PyObject *seq, const char *key) { PyObject *s = PyString_InternFromString(key); PyList_Append(seq, s); Py_DECREF(s); @@ -85,7 +93,7 @@ SWIG_Python_SetConstant(PyObject *d, PyObject *public_interface, const char *nam PyDict_SetItemString(d, (char *)name, obj); Py_DECREF(obj); if (public_interface) - pyswig_add_public_symbol(public_interface, name); + SwigPyBuiltin_AddPublicSymbol(public_interface, name); } #else @@ -210,6 +218,9 @@ SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssi #define SWIG_POINTER_IMPLICIT_CONV (SWIG_POINTER_DISOWN << 1) +#define SWIG_BUILTIN_TP_INIT (SWIG_POINTER_OWN << 2) +#define SWIG_BUILTIN_INIT (SWIG_BUILTIN_TP_INIT | SWIG_POINTER_OWN) + #ifdef __cplusplus extern "C" { #if 0 @@ -478,7 +489,7 @@ SwigPyObject_richcompare(SwigPyObject *v, SwigPyObject *w, int op) } -SWIGRUNTIME PyTypeObject* _PySwigObject_type(void); +SWIGRUNTIME PyTypeObject* SwigPyObject_TypeOnce(void); #ifdef SWIGPYTHON_BUILTIN static swig_type_info *SwigPyObject_stype = 0; @@ -493,7 +504,7 @@ SwigPyObject_type(void) { #else SWIGRUNTIME PyTypeObject* SwigPyObject_type(void) { - static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigObject_type(); + static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyObject_TypeOnce(); return type; } #endif @@ -675,7 +686,7 @@ SwigPyObject_getattr(SwigPyObject *sobj,char *name) #endif SWIGRUNTIME PyTypeObject* -_PySwigObject_type(void) { +SwigPyObject_TypeOnce(void) { static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer"; static PyNumberMethods SwigPyObject_as_number = { @@ -876,17 +887,17 @@ SwigPyPacked_compare(SwigPyPacked *v, SwigPyPacked *w) return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size); } -SWIGRUNTIME PyTypeObject* _PySwigPacked_type(void); +SWIGRUNTIME PyTypeObject* SwigPyPacked_TypeOnce(void); SWIGRUNTIME PyTypeObject* SwigPyPacked_type(void) { - static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigPacked_type(); + static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyPacked_TypeOnce(); return type; } SWIGRUNTIMEINLINE int SwigPyPacked_Check(PyObject *op) { - return ((op)->ob_type == _PySwigPacked_type()) + return ((op)->ob_type == SwigPyPacked_TypeOnce()) || (strcmp((op)->ob_type->tp_name,"SwigPyPacked") == 0); } @@ -901,7 +912,7 @@ SwigPyPacked_dealloc(PyObject *v) } SWIGRUNTIME PyTypeObject* -_PySwigPacked_type(void) { +SwigPyPacked_TypeOnce(void) { static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer"; static PyTypeObject swigpypacked_type; static int type_init = 0; @@ -1044,6 +1055,8 @@ SWIG_This(void) SWIGRUNTIME SwigPyObject * SWIG_Python_GetSwigThis(PyObject *pyobj) { + PyObject *obj; + if (SwigPyObject_Check(pyobj)) return (SwigPyObject *) pyobj; @@ -1058,7 +1071,7 @@ SWIG_Python_GetSwigThis(PyObject *pyobj) return NULL; #endif - PyObject *obj = 0; + obj = 0; #if (!defined(SWIG_PYTHON_SLOW_GETSET_THIS) && (PY_VERSION_HEX >= 0x02030000)) if (PyInstance_Check(pyobj)) { @@ -1120,92 +1133,95 @@ SWIG_Python_AcquirePtr(PyObject *obj, int own) { SWIGRUNTIME int SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) { - if (!obj) return SWIG_ERROR; - if (obj == Py_None) { + int res; + SwigPyObject *sobj; + + if (!obj) return SWIG_ERROR; + if (obj == Py_None) { if (ptr) *ptr = 0; return SWIG_OK; - } + } - int res = SWIG_ERROR; + res = SWIG_ERROR; - SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj); - if (own) - *own = 0; - while (sobj) { - void *vptr = sobj->ptr; - if (ty) { - swig_type_info *to = sobj->ty; - if (to == ty) { - /* no type cast needed */ - if (ptr) *ptr = vptr; - break; - } else { - swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); - if (!tc) { - sobj = (SwigPyObject *)sobj->next; - } else { - if (ptr) { - int newmemory = 0; - *ptr = SWIG_TypeCast(tc,vptr,&newmemory); - if (newmemory == SWIG_CAST_NEW_MEMORY) { - assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */ - if (own) - *own = *own | SWIG_CAST_NEW_MEMORY; - } - } - break; - } - } - } else { + sobj = SWIG_Python_GetSwigThis(obj); + if (own) + *own = 0; + while (sobj) { + void *vptr = sobj->ptr; + if (ty) { + swig_type_info *to = sobj->ty; + if (to == ty) { + /* no type cast needed */ if (ptr) *ptr = vptr; break; - } - } - if (sobj) { - if (own) - *own = *own | sobj->own; - if (flags & SWIG_POINTER_DISOWN) { - sobj->own = 0; - } - res = SWIG_OK; - } else { - if (flags & SWIG_POINTER_IMPLICIT_CONV) { - SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0; - if (data && !data->implicitconv) { - PyObject *klass = data->klass; - if (klass) { - PyObject *impconv; - data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/ - impconv = SWIG_Python_CallFunctor(klass, obj); - data->implicitconv = 0; - if (PyErr_Occurred()) { - PyErr_Clear(); - impconv = 0; + } else { + swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); + if (!tc) { + sobj = (SwigPyObject *)sobj->next; + } else { + if (ptr) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc,vptr,&newmemory); + if (newmemory == SWIG_CAST_NEW_MEMORY) { + assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */ + if (own) + *own = *own | SWIG_CAST_NEW_MEMORY; } - if (impconv) { - SwigPyObject *iobj = SWIG_Python_GetSwigThis(impconv); - if (iobj) { - void *vptr; - res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0); - if (SWIG_IsOK(res)) { - if (ptr) { - *ptr = vptr; - /* transfer the ownership to 'ptr' */ - iobj->own = 0; - res = SWIG_AddCast(res); - res = SWIG_AddNewMask(res); - } else { - res = SWIG_AddCast(res); - } + } + break; + } + } + } else { + if (ptr) *ptr = vptr; + break; + } + } + if (sobj) { + if (own) + *own = *own | sobj->own; + if (flags & SWIG_POINTER_DISOWN) { + sobj->own = 0; + } + res = SWIG_OK; + } else { + if (flags & SWIG_POINTER_IMPLICIT_CONV) { + SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0; + if (data && !data->implicitconv) { + PyObject *klass = data->klass; + if (klass) { + PyObject *impconv; + data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/ + impconv = SWIG_Python_CallFunctor(klass, obj); + data->implicitconv = 0; + if (PyErr_Occurred()) { + PyErr_Clear(); + impconv = 0; + } + if (impconv) { + SwigPyObject *iobj = SWIG_Python_GetSwigThis(impconv); + if (iobj) { + void *vptr; + res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0); + if (SWIG_IsOK(res)) { + if (ptr) { + *ptr = vptr; + /* transfer the ownership to 'ptr' */ + iobj->own = 0; + res = SWIG_AddCast(res); + res = SWIG_AddNewMask(res); + } else { + res = SWIG_AddCast(res); } } - Py_DECREF(impconv); } + Py_DECREF(impconv); } } } } - return res; + } + return res; } /* Convert a function ptr value */ @@ -1375,14 +1391,30 @@ SWIG_Python_InitShadowInstance(PyObject *args) { /* Create a new pointer object */ SWIGRUNTIME PyObject * -SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) { +SWIG_Python_NewPointerObj(PyObject *self, void *ptr, swig_type_info *type, int flags) { + SwigPyClientData *clientdata; + PyObject * robj; + int own; + if (!ptr) return SWIG_Py_Void(); - SwigPyClientData *clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0; - int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; + clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0; + own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; if (clientdata && clientdata->pytype) { - SwigPyObject *newobj = PyObject_New(SwigPyObject, clientdata->pytype); + SwigPyObject *newobj; + if (flags & SWIG_BUILTIN_TP_INIT) { + newobj = (SwigPyObject*) self; + if (newobj->ptr) { + PyObject *next_self = clientdata->pytype->tp_alloc(clientdata->pytype, 0); + while (newobj->next) + newobj = (SwigPyObject *) newobj->next; + newobj->next = next_self; + newobj = (SwigPyObject *)next_self; + } + } else { + newobj = PyObject_New(SwigPyObject, clientdata->pytype); + } if (newobj) { newobj->ptr = ptr; newobj->ty = type; @@ -1396,7 +1428,9 @@ SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) { return SWIG_Py_Void(); } - PyObject *robj = SwigPyObject_New(ptr, type, own); + assert(!(flags & SWIG_BUILTIN_TP_INIT)); + + robj = SwigPyObject_New(ptr, type, own); if (clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); if (inst) { @@ -1414,6 +1448,7 @@ SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { return ptr ? SwigPyPacked_New((void *) ptr, sz, type) : SWIG_Py_Void(); } +/* SWIGRUNTIME int SWIG_Python_NewBuiltinObj(PyObject *self, void *ptr, swig_type_info *type, int flags) { assert(self); @@ -1437,6 +1472,7 @@ SWIG_Python_NewBuiltinObj(PyObject *self, void *ptr, swig_type_info *type, int f #endif return 0; } +*/ /* -----------------------------------------------------------------------------* * Get type list @@ -1671,7 +1707,6 @@ SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) return result; } -// Cribbed from Objects/object.c in the python source code and modified SWIGRUNTIME int SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { PyTypeObject *tp = obj->ob_type; diff --git a/Lib/python/pyruntime.swg b/Lib/python/pyruntime.swg index c20ed964f..dd22a1fdf 100644 --- a/Lib/python/pyruntime.swg +++ b/Lib/python/pyruntime.swg @@ -10,4 +10,7 @@ %insert(runtime) "pythreads.swg"; /* Python thread code */ %insert(runtime) "pyapi.swg"; /* Python API */ %insert(runtime) "pyrun.swg"; /* Python run-time code */ + +#if defined(SWIGPYTHON_BUILTIN) %insert(runtime) "builtin.swg"; /* Specialization for classes with single inheritance */ +#endif \ No newline at end of file diff --git a/Lib/python/pystdcommon.swg b/Lib/python/pystdcommon.swg index 7e9720cc0..2f223a839 100644 --- a/Lib/python/pystdcommon.swg +++ b/Lib/python/pystdcommon.swg @@ -6,7 +6,7 @@ namespace swig { */ template struct traits_from_ptr { static PyObject *from(Type *val, int owner = 0) { - return SWIG_NewPointerObj(val, type_info(), owner); + return SWIG_InternalNewPointerObj(val, type_info(), owner); } }; diff --git a/Lib/python/pystrings.swg b/Lib/python/pystrings.swg index 1983037a5..f6a4eba8a 100644 --- a/Lib/python/pystrings.swg +++ b/Lib/python/pystrings.swg @@ -86,7 +86,7 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size) if (size > INT_MAX) { swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); return pchar_descriptor ? - SWIG_NewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : SWIG_Py_Void(); + SWIG_InternalNewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : SWIG_Py_Void(); } else { %#if PY_VERSION_HEX >= 0x03000000 return PyUnicode_FromStringAndSize(carray, %numeric_cast(size,int)); diff --git a/Lib/python/pytypemaps.swg b/Lib/python/pytypemaps.swg index aad9bacd7..c47a2ee93 100644 --- a/Lib/python/pytypemaps.swg +++ b/Lib/python/pytypemaps.swg @@ -88,9 +88,11 @@ $result = SWIG_NewPointerObj(%new_copy(*$1, $*ltype), $descriptor, SWIG_POINTER_OWN | %newpointer_flags); } +/* %typemap(builtin_init,noblock=1) const SWIGTYPE & SMARTPOINTER { $result = SWIG_NewBuiltinObj(self, %new_copy(*$1, $*ltype), $descriptor, SWIG_POINTER_OWN | %newpointer_flags); } +*/ %typemap(ret,noblock=1) const SWIGTYPE & SMARTPOINTER, SWIGTYPE SMARTPOINTER { if ($result) { @@ -108,15 +110,19 @@ * ------------------------------------------------------------ */ /* Pointers, references */ +/* %typemap(builtin_init,noblock=1) SWIGTYPE *, SWIGTYPE &, SWIGTYPE[] { %set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr($1), $descriptor, $owner | %newpointer_flags)); } - +*/ +/* %typemap(builtin_init, noblock=1) SWIGTYPE *const& { %set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr(*$1), $*descriptor, $owner | %newpointer_flags)); } - +*/ /* Return by value */ +/* %typemap(builtin_init, noblock=1) SWIGTYPE { - %set_output(SWIG_Python_NewBuiltinObj(self, %new_copy($1, $ltype), $&descriptor, SWIG_POINTER_OWN | %newpointer_flags)); + %set_output(SWIG_Python_NewBuiltinObj(self, %new_copy($1, $ltype), $&descriptor, $owner | %newpointer_flags)); } +*/ diff --git a/Lib/python/pywstrings.swg b/Lib/python/pywstrings.swg index 7c36f248d..91f96d9e4 100644 --- a/Lib/python/pywstrings.swg +++ b/Lib/python/pywstrings.swg @@ -50,7 +50,7 @@ SWIG_FromWCharPtrAndSize(const wchar_t * carray, size_t size) if (size > INT_MAX) { swig_type_info* pwchar_descriptor = SWIG_pwchar_descriptor(); return pwchar_descriptor ? - SWIG_NewPointerObj(%const_cast(carray,wchar_t *), pwchar_descriptor, 0) : SWIG_Py_Void(); + SWIG_InternalNewPointerObj(%const_cast(carray,wchar_t *), pwchar_descriptor, 0) : SWIG_Py_Void(); } else { return PyUnicode_FromWideChar(carray, %numeric_cast(size,int)); } diff --git a/Lib/python/std_map.i b/Lib/python/std_map.i index 2b3a90747..0c6681e3c 100644 --- a/Lib/python/std_map.i +++ b/Lib/python/std_map.i @@ -47,7 +47,7 @@ static PyObject *from(const map_type& map) { swig_type_info *desc = swig::type_info(); if (desc && desc->clientdata) { - return SWIG_NewPointerObj(new map_type(map), desc, SWIG_POINTER_OWN); + return SWIG_InternalNewPointerObj(new map_type(map), desc, SWIG_POINTER_OWN); } else { SWIG_PYTHON_THREAD_BEGIN_BLOCK; size_type size = map.size(); @@ -127,7 +127,7 @@ if (!seq) return SWIG_Py_Void(); SwigPyIterator *iter = make_output_key_iterator(seq->begin(), seq->begin(), seq->end(), pyself); - return SWIG_NewPointerObj(iter, SWIGTYPE_p_swig__SwigPyIterator, SWIG_POINTER_OWN); + return SWIG_InternalNewPointerObj(iter, SWIGTYPE_p_swig__SwigPyIterator, SWIG_POINTER_OWN); } template(); if (desc && desc->clientdata) { - return SWIG_NewPointerObj(new multimap_type(multimap), desc, SWIG_POINTER_OWN); + return SWIG_InternalNewPointerObj(new multimap_type(multimap), desc, SWIG_POINTER_OWN); } else { size_type size = multimap.size(); int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1; diff --git a/Lib/python/std_pair.i b/Lib/python/std_pair.i index 49f381afb..386fbdab7 100644 --- a/Lib/python/std_pair.i +++ b/Lib/python/std_pair.i @@ -127,12 +127,10 @@ SwigPython_std_pair_len (PyObject *a) SWIGINTERN PyObject* SwigPython_std_pair_repr (PyObject *o) { - static PyObject *first = PyString_FromString("first"); - static PyObject *second = PyString_FromString("second"); PyObject *tuple = PyTuple_New(2); assert(tuple); - PyTuple_SET_ITEM(tuple, 0, PyObject_GetAttr(o, first)); - PyTuple_SET_ITEM(tuple, 1, PyObject_GetAttr(o, second)); + PyTuple_SET_ITEM(tuple, 0, PyObject_GetAttrString(o, "first")); + PyTuple_SET_ITEM(tuple, 1, PyObject_GetAttrString(o, "second")); PyObject *result = PyObject_Repr(tuple); Py_DECREF(tuple); return result; @@ -141,45 +139,39 @@ SwigPython_std_pair_repr (PyObject *o) SWIGINTERN PyObject* SwigPython_std_pair_getitem (PyObject *a, Py_ssize_t b) { - static PyObject *first = PyString_FromString("first"); - static PyObject *second = PyString_FromString("second"); - PyObject *attr_name = b % 2 ? second : first; - PyObject *result = PyObject_GetAttr(a, attr_name); + PyObject *result = PyObject_GetAttrString(a, b % 2 ? "second" : "first"); return result; } SWIGINTERN int SwigPython_std_pair_setitem (PyObject *a, Py_ssize_t b, PyObject *c) { - static PyObject *first = PyString_FromString("first"); - static PyObject *second = PyString_FromString("second"); - PyObject *attr_name = b % 2 ? second : first; - int result = PyObject_SetAttr(a, attr_name, c); + int result = PyObject_SetAttrString(a, b % 2 ? "second" : "first", c); return result; } #endif } -%feature("sq_length") std::pair "SwigPython_std_pair_len"; -%feature("sq_length") std::pair "SwigPython_std_pair_len"; -%feature("sq_length") std::pair "SwigPython_std_pair_len"; -%feature("sq_length") std::pair "SwigPython_std_pair_len"; +%feature("python:sq_length") std::pair "SwigPython_std_pair_len"; +%feature("python:sq_length") std::pair "SwigPython_std_pair_len"; +%feature("python:sq_length") std::pair "SwigPython_std_pair_len"; +%feature("python:sq_length") std::pair "SwigPython_std_pair_len"; -%feature("tp_repr") std::pair "SwigPython_std_pair_repr"; -%feature("tp_repr") std::pair "SwigPython_std_pair_repr"; -%feature("tp_repr") std::pair "SwigPython_std_pair_repr"; -%feature("tp_repr") std::pair "SwigPython_std_pair_repr"; +%feature("python:tp_repr") std::pair "SwigPython_std_pair_repr"; +%feature("python:tp_repr") std::pair "SwigPython_std_pair_repr"; +%feature("python:tp_repr") std::pair "SwigPython_std_pair_repr"; +%feature("python:tp_repr") std::pair "SwigPython_std_pair_repr"; -%feature("sq_item") std::pair "SwigPython_std_pair_getitem"; -%feature("sq_item") std::pair "SwigPython_std_pair_getitem"; -%feature("sq_item") std::pair "SwigPython_std_pair_getitem"; -%feature("sq_item") std::pair "SwigPython_std_pair_getitem"; +%feature("python:sq_item") std::pair "SwigPython_std_pair_getitem"; +%feature("python:sq_item") std::pair "SwigPython_std_pair_getitem"; +%feature("python:sq_item") std::pair "SwigPython_std_pair_getitem"; +%feature("python:sq_item") std::pair "SwigPython_std_pair_getitem"; -%feature("sq_ass_item") std::pair "SwigPython_std_pair_setitem"; -%feature("sq_ass_item") std::pair "SwigPython_std_pair_setitem"; -%feature("sq_ass_item") std::pair "SwigPython_std_pair_setitem"; -%feature("sq_ass_item") std::pair "SwigPython_std_pair_setitem"; +%feature("python:sq_ass_item") std::pair "SwigPython_std_pair_setitem"; +%feature("python:sq_ass_item") std::pair "SwigPython_std_pair_setitem"; +%feature("python:sq_ass_item") std::pair "SwigPython_std_pair_setitem"; +%feature("python:sq_ass_item") std::pair "SwigPython_std_pair_setitem"; %define %swig_pair_methods(pair...) #if !defined(SWIGPYTHON_BUILTIN) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index b07d4534a..2c89dab10 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -62,6 +62,7 @@ static int classic = 0; static int modern = 0; static int new_repr = 1; static int no_header_file = 0; +static int max_bases = 0; static int py3 = 0; @@ -163,47 +164,57 @@ static const char *usage3 = (char *) "\ Function annotation \n\ \n"; -static String *getSlot(Node *n, const char *key) { +static String *getSlot(Node *n = NULL, const char *key = NULL) { static String *slot_default = NewString("0"); - String *val = Getattr(n, key); + String *val = key && *key ? Getattr(n, key) : NULL; return val ? val : slot_default; } +static void printSlot (File *f, DOH const *slotval, DOH const *slotname, DOH const *functype = NULL, bool comma=true) { + if (functype) + slotval = NewStringf("(%s) %s", functype, slotval); + int len = Len(slotval); + int fieldwidth = len > 40 ? 0 : 40 - len; + Printf(f, " %s%s%*s/* %s */\n", slotval, comma ? "," : "", fieldwidth, "", slotname); + if (functype) + Delete((DOH*) slotval); +} + static String *getClosure(String *functype, String *wrapper, int funpack = 0) { static const char *functypes[] = { - "unaryfunc", "PYSWIG_UNARYFUNC_CLOSURE", - "destructor", "PYSWIG_DESTRUCTOR_CLOSURE", - "inquiry", "PYSWIG_INQUIRY_CLOSURE", - "getiterfunc", "PYSWIG_UNARYFUNC_CLOSURE", - "binaryfunc", "PYSWIG_BINARYFUNC_CLOSURE", - "ternaryfunc", "PYSWIG_TERNARYFUNC_CLOSURE", - "lenfunc", "PYSWIG_LENFUNC_CLOSURE", - "ssizeargfunc", "PYSWIG_SSIZEARGFUNC_CLOSURE", - "ssizessizeargfunc", "PYSWIG_SSIZESSIZEARGFUNC_CLOSURE", - "ssizeobjargproc", "PYSWIG_SSIZEOBJARGPROC_CLOSURE", - "ssizessizeobjargproc", "PYSWIG_SSIZESSIZEOBJARGPROC_CLOSURE", - "objobjargproc", "PYSWIG_OBJOBJARGPROC_CLOSURE", - "reprfunc", "PYSWIG_REPRFUNC_CLOSURE", - "hashfunc", "PYSWIG_HASHFUNC_CLOSURE", - "iternextfunc", "PYSWIG_ITERNEXT_CLOSURE", + "unaryfunc", "SWIGPY_UNARYFUNC_CLOSURE", + "destructor", "SWIGPY_DESTRUCTOR_CLOSURE", + "inquiry", "SWIGPY_INQUIRY_CLOSURE", + "getiterfunc", "SWIGPY_UNARYFUNC_CLOSURE", + "binaryfunc", "SWIGPY_BINARYFUNC_CLOSURE", + "ternaryfunc", "SWIGPY_TERNARYFUNC_CLOSURE", + "lenfunc", "SWIGPY_LENFUNC_CLOSURE", + "ssizeargfunc", "SWIGPY_SSIZEARGFUNC_CLOSURE", + "ssizessizeargfunc", "SWIGPY_SSIZESSIZEARGFUNC_CLOSURE", + "ssizeobjargproc", "SWIGPY_SSIZEOBJARGPROC_CLOSURE", + "ssizessizeobjargproc", "SWIGPY_SSIZESSIZEOBJARGPROC_CLOSURE", + "objobjargproc", "SWIGPY_OBJOBJARGPROC_CLOSURE", + "reprfunc", "SWIGPY_REPRFUNC_CLOSURE", + "hashfunc", "SWIGPY_HASHFUNC_CLOSURE", + "iternextfunc", "SWIGPY_ITERNEXT_CLOSURE", NULL }; static const char *funpack_functypes[] = { - "unaryfunc", "PYSWIG_UNARYFUNC_CLOSURE", - "destructor", "PYSWIG_DESTRUCTOR_CLOSURE", - "inquiry", "PYSWIG_INQUIRY_CLOSURE", - "getiterfunc", "PYSWIG_UNARYFUNC_CLOSURE", - "ternaryfunc", "PYSWIG_TERNARYFUNC_CLOSURE", - "lenfunc", "PYSWIG_LENFUNC_CLOSURE", - "ssizeargfunc", "PYSWIG_FUNPACK_SSIZEARGFUNC_CLOSURE", - "ssizessizeargfunc", "PYSWIG_SSIZESSIZEARGFUNC_CLOSURE", - "ssizeobjargproc", "PYSWIG_SSIZEOBJARGPROC_CLOSURE", - "ssizessizeobjargproc", "PYSWIG_SSIZESSIZEOBJARGPROC_CLOSURE", - "objobjargproc", "PYSWIG_OBJOBJARGPROC_CLOSURE", - "reprfunc", "PYSWIG_REPRFUNC_CLOSURE", - "hashfunc", "PYSWIG_HASHFUNC_CLOSURE", - "iternextfunc", "PYSWIG_ITERNEXT_CLOSURE", + "unaryfunc", "SWIGPY_UNARYFUNC_CLOSURE", + "destructor", "SWIGPY_DESTRUCTOR_CLOSURE", + "inquiry", "SWIGPY_INQUIRY_CLOSURE", + "getiterfunc", "SWIGPY_UNARYFUNC_CLOSURE", + "ternaryfunc", "SWIGPY_TERNARYFUNC_CLOSURE", + "lenfunc", "SWIGPY_LENFUNC_CLOSURE", + "ssizeargfunc", "SWIGPY_FUNPACK_SSIZEARGFUNC_CLOSURE", + "ssizessizeargfunc", "SWIGPY_SSIZESSIZEARGFUNC_CLOSURE", + "ssizeobjargproc", "SWIGPY_SSIZEOBJARGPROC_CLOSURE", + "ssizessizeobjargproc", "SWIGPY_SSIZESSIZEOBJARGPROC_CLOSURE", + "objobjargproc", "SWIGPY_OBJOBJARGPROC_CLOSURE", + "reprfunc", "SWIGPY_REPRFUNC_CLOSURE", + "hashfunc", "SWIGPY_HASHFUNC_CLOSURE", + "iternextfunc", "SWIGPY_ITERNEXT_CLOSURE", NULL }; @@ -614,7 +625,6 @@ public: if (builtin) { f_builtins = NewString(""); - Printf(f_builtins, "#ifdef __cplusplus\nnamespace {\n#endif\n\n"); } if (directorsEnabled()) { @@ -949,8 +959,11 @@ public: Append(methods, "};\n"); Printf(f_wrappers, "%s\n", methods); + Printf(f_wrappers, "#ifdef __cplusplus\n"); + Printf(f_wrappers, "} /* extern \"C\" */\n"); + Printf(f_wrappers, "#endif\n"); + if (builtin) { - Printv(f_builtins, "#ifdef __cplusplus\n} // namespace {\n#endif\n\n", NIL); Dump(f_builtins, f_wrappers); } @@ -967,10 +980,6 @@ public: Printf(f_init, "#endif\n"); Printf(f_init, "}\n"); - Printf(f_wrappers, "#ifdef __cplusplus\n"); - Printf(f_wrappers, "}\n"); - Printf(f_wrappers, "#endif\n"); - if (shadow) { if (builtin) { Printv(f_shadow_import_stmts, "}\n", NIL); @@ -997,6 +1006,8 @@ public: } Dump(f_wrappers, f_begin); + if (builtin) + Printf(f_begin, "static PyTypeObject *builtin_bases[%d];\n\n", max_bases + 2); Wrapper_pretty_print(f_init, f_begin); Delete(f_header); @@ -1261,6 +1272,21 @@ public: Setattr(n, "python:docstring", doc); Setattr(n, "python:autodoc", autodoc); return doc; + } + + /* ------------------------------------------------------------ + * cdocstring() + * Get the docstring text as it would appear in C-language + * source code. + * ------------------------------------------------------------ */ + + String *cdocstring(Node *n, autodoc_t ad_type) + { + String *ds = docstring(n, ad_type, "", false); + Replaceall(ds, "\\", "\\\\"); + Replaceall(ds, "\"", "\\\""); + Replaceall(ds, "\n", "\\n\"\n\t\t\""); + return ds; } /* ----------------------------------------------------------------------------- @@ -1830,20 +1856,16 @@ public: Append(methods, "NULL"); } else if (Getattr(n, "feature:callback")) { if (have_docstring(n)) { - String *ds = docstring(n, AUTODOC_FUNC, "", false); - Replaceall(ds, "\\", "\\\\"); - Replaceall(ds, "\"", "\\\""); - Replaceall(ds, "\n", "\\n\"\n\t\t\""); + String *ds = cdocstring(n, AUTODOC_FUNC); Printf(methods, "(char *)\"%s\\nswig_ptr: %s\"", ds, Getattr(n, "feature:callback:name")); + Delete(ds); } else { Printf(methods, "(char *)\"swig_ptr: %s\"", Getattr(n, "feature:callback:name")); } } else if (have_docstring(n)) { - String *ds = docstring(n, AUTODOC_FUNC, "", false); - Replaceall(ds, "\\", "\\\\"); - Replaceall(ds, "\"", "\\\""); - Replaceall(ds, "\n", "\\n\"\n\t\t\""); + String *ds = cdocstring(n, AUTODOC_FUNC); Printf(methods, "(char *)\"%s\"", ds); + Delete(ds); } else { Append(methods, "NULL"); } @@ -2035,7 +2057,7 @@ public: bool builtin_getter = (builtin && GetFlag(n, "memberget")); bool builtin_setter = (builtin && GetFlag(n, "memberset") && !builtin_getter); bool over_varargs = false; - char const *self_param = builtin_self ? "self" : "SWIGUNUSEDPARM(self)"; + char const *self_param = builtin ? "self" : "SWIGUNUSEDPARM(self)"; char const *wrap_return = builtin_ctor ? "int " : "PyObject *"; String *linkage = NewString("SWIGINTERN "); String *wrapper_name = Swig_name_wrapper(iname); @@ -2058,10 +2080,7 @@ public: int allow_thread = threads_enable(n); - if (builtin_ctor) - Wrapper_add_local(f, "resultobj", "int resultobj = 0"); - else - Wrapper_add_local(f, "resultobj", "PyObject *resultobj = 0"); + Wrapper_add_local(f, "resultobj", "PyObject *resultobj = 0"); // Emit all of the local variables for holding arguments. emit_parameter_variables(l, f); @@ -2112,7 +2131,7 @@ public: } if (overname) { - String *over_varargs_attr = Getattr(n, "sym:over_varargs"); + String *over_varargs_attr = Getattr(n, "python:overvarargs"); if (!over_varargs_attr) { for (Node *sibling = n; sibling; sibling = Getattr(sibling, "sym:nextSibling")) { if (emit_isvarargs(Getattr(sibling, "parms"))) { @@ -2122,7 +2141,7 @@ public: } over_varargs_attr = NewString(over_varargs ? "1" : "0"); for (Node *sibling = n; sibling; sibling = Getattr(sibling, "sym:nextSibling")) - Setattr(sibling, "sym:over_varargs", over_varargs_attr); + Setattr(sibling, "python:overvarargs", over_varargs_attr); } if (Strcmp(over_varargs_attr, "0") != 0) over_varargs = true; @@ -2133,10 +2152,9 @@ public: int onearg = funpack && (tuple_required == 1 && tuple_arguments == 1); if (builtin && funpack && !overname && !builtin_ctor) { - if (noargs) - SetFlag(n, "noargs"); - else if (onearg) - SetFlag(n, "onearg"); + String *argattr = NewStringf("%d", tuple_arguments); + Setattr(n, "python:argcount", argattr); + Delete(argattr); } /* Generate code for argument marshalling */ @@ -2446,12 +2464,7 @@ public: /* This part below still needs cleanup */ /* Return the function value */ - if (builtin_ctor) { - Printf(f->code, "%s\n", actioncode); - tm = Swig_typemap_lookup("builtin_init", n, "result", f); - } else { - tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode); - } + tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode); if (tm) { if (builtin_self) { @@ -2464,7 +2477,9 @@ public: Replaceall(tm, "$source", "result"); Replaceall(tm, "$target", "resultobj"); Replaceall(tm, "$result", "resultobj"); - if (handled_as_init) { + if (builtin_ctor) { + Replaceall(tm, "$owner", "SWIG_BUILTIN_INIT"); + } else if (handled_as_init) { Replaceall(tm, "$owner", "SWIG_POINTER_NEW"); } else { if (GetFlag(n, "feature:new")) { @@ -2548,7 +2563,10 @@ public: } } - Append(f->code, " return resultobj;\n"); + if (builtin_ctor) + Append(f->code, " return resultobj == Py_None ? 1 : 0;\n"); + else + Append(f->code, " return resultobj;\n"); /* Error handling code */ @@ -2598,7 +2616,7 @@ public: if (funpack) { Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **swig_obj) {", NIL); } else { - Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL); + Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL); } Wrapper_add_local(f, "resultobj", builtin_ctor ? "int resultobj" : "PyObject *resultobj"); Wrapper_add_local(f, "varargs", "PyObject *varargs"); @@ -2619,7 +2637,7 @@ public: Printf(f->code, "newargs = PyTuple_GetSlice(args,0,%d);\n", num_arguments); Printf(f->code, "varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args)+1);\n", num_arguments); } - Printf(f->code, "resultobj = %s__varargs__(self,newargs,varargs);\n", wname); + Printf(f->code, "resultobj = %s__varargs__(%s,newargs,varargs);\n", wname, builtin ? "self" : "NULL"); Append(f->code, "Py_XDECREF(newargs);\n"); Append(f->code, "Py_XDECREF(varargs);\n"); Append(f->code, "return resultobj;\n"); @@ -2644,9 +2662,7 @@ public: // Put this in tp_init of the PyTypeObject if (builtin_ctor) { - // Can't use checkAttribute(n, "access", "public") because - // "access" attr isn't set on %extend methods - if ((director_method || !checkAttribute(n, "access", "private")) && !Getattr(class_members, iname)) { + if ((director_method || !is_private(n)) && !Getattr(class_members, iname)) { Setattr(class_members, iname, n); if (!builtin_tp_init) builtin_tp_init = Swig_name_wrapper(iname); @@ -2677,10 +2693,11 @@ public: if (in_class && builtin) { /* Handle operator overloads overloads for builtin types */ - String *slot = Getattr(n, "feature:pyslot"); + String *slot = Getattr(n, "feature:python:slot"); if (slot) { - String *closure_decl = getClosure(Getattr(n, "feature:pyslot:functype"), wrapper_name, overname ? 0 : funpack); - String *feature_name = NewStringf("feature:%s", slot); + String *func_type = Getattr(n, "feature:python:slot:functype"); + String *closure_decl = getClosure(func_type, wrapper_name, overname ? 0 : funpack); + String *feature_name = NewStringf("feature:python:%s", slot); String *closure_name = Copy(wrapper_name); if (closure_decl) { if (!Getattr(n, "sym:overloaded") || !Getattr(n, "sym:nextSibling")) @@ -2688,15 +2705,20 @@ public: Append(closure_name, "_closure"); Delete(closure_decl); } + if (func_type) { + String *s = NewStringf("(%s) %s", func_type, closure_name); + Delete(closure_name); + closure_name = s; + } Setattr(parent, feature_name, closure_name); Delete(feature_name); Delete(closure_name); } /* Handle comparison operators for builtin types */ - String *compare = Getattr(n, "feature:pycompare"); + String *compare = Getattr(n, "feature:python:compare"); if (compare) { - Hash *richcompare = Getattr(parent, "richcompare"); + Hash *richcompare = Getattr(parent, "python:richcompare"); assert(richcompare); Setattr(richcompare, compare, wrapper_name); } @@ -2743,7 +2765,7 @@ public: if (!have_globals) { Printf(f_init, "\t PyDict_SetItemString(md,(char*)\"%s\", SWIG_globals());\n", global_name); if (builtin) - Printf(f_init, "\t pyswig_add_public_symbol(public_interface, \"%s\");\n", global_name); + Printf(f_init, "\t SwigPyBuiltin_AddPublicSymbol(public_interface, \"%s\");\n", global_name); have_globals = 1; if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) { Printf(f_shadow_stubs, "%s = %s.%s\n", global_name, module, global_name); @@ -2764,7 +2786,7 @@ public: Setattr(n, "wrap:name", varsetname); if (builtin && in_class) { String *set_wrapper = Swig_name_wrapper(setname); - Setattr(n, "builtin:setter", set_wrapper); + Setattr(n, "pybuiltin:setter", set_wrapper); Delete(set_wrapper); } Printf(setf->def, "SWIGINTERN int %s(PyObject *_val) {", varsetname); @@ -2800,12 +2822,14 @@ public: Setattr(n, "wrap:name", vargetname); if (builtin && in_class) { String *get_wrapper = Swig_name_wrapper(getname); - Setattr(n, "builtin:getter", get_wrapper); + Setattr(n, "pybuiltin:getter", get_wrapper); Delete(get_wrapper); } int addfail = 0; Printf(getf->def, "SWIGINTERN PyObject *%s(void) {", vargetname); Wrapper_add_local(getf, "pyobj", "PyObject *pyobj = 0"); + if (builtin) + Wrapper_add_local(getf, "self", "PyObject *self = 0"); if ((tm = Swig_typemap_lookup("varout", n, name, 0))) { Replaceall(tm, "$source", name); Replaceall(tm, "$target", "pyobj"); @@ -2828,7 +2852,7 @@ public: Printf(f_init, "\t SWIG_addvarlink(SWIG_globals(),(char*)\"%s\",%s, %s);\n", iname, vargetname, varsetname); if (builtin && shadow && !assignable && !in_class) { Printf(f_init, "\t PyDict_SetItemString(md, (char*)\"%s\", PyObject_GetAttrString(SWIG_globals(), \"%s\"));\n", iname, iname); - Printf(f_init, "\t pyswig_add_public_symbol(public_interface, \"%s\");\n", iname); + Printf(f_init, "\t SwigPyBuiltin_AddPublicSymbol(public_interface, \"%s\");\n", iname); } Delete(vargetname); Delete(varsetname); @@ -2874,8 +2898,8 @@ public: } if (builtin && in_class) { - Swig_require("builtin_constantWrapper", n, "*sym:name", "builtin_sym:name", NIL); - Setattr(n, "sym:name", Getattr(n, "builtin_sym:name")); + Swig_require("builtin_constantWrapper", n, "*sym:name", "pybuiltin:symname", NIL); + Setattr(n, "sym:name", Getattr(n, "pybuiltin:symname")); } if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) { @@ -3114,7 +3138,7 @@ public: if (shadow) { if (builtin) { String *rname = SwigType_namestr(real_classname); - Printf(builtin_methods, tab4 "{ \"__disown__\", (PyCFunction) Swig::Director::pyobj_disown< %s >, METH_NOARGS, \"\" },\n", rname); + Printf(builtin_methods, tab4 "{ \"__disown__\", (PyCFunction) Swig::Director::swig_pyobj_disown< %s >, METH_NOARGS, \"\" },\n", rname); Delete(rname); } else { String *symname = Getattr(n, "sym:name"); @@ -3183,7 +3207,7 @@ public: String *rname = add_explicit_scope(SwigType_namestr(name)); String *mname = SwigType_manglestr(rname); - Printf(f_init, "\n// type '%s'\n", rname); + Printf(f_init, "\n/* type '%s' */\n", rname); Printf(f_init, " builtin_pytype = (PyTypeObject *)&SwigPyBuiltin_%s_type;\n", mname); Printf(f_init, " builtin_pytype->tp_dict = d = PyDict_New();\n"); @@ -3203,44 +3227,51 @@ public: int funpack = modernargs && fastunpack; Printv(f_init, "#if PY_VERSION_HEX >= 0x03000000\n", NIL); - Printf(f_init, tab4 "builtin_pytype->ob_base.ob_base.ob_type = metatype;\n"); + Printf(f_init, " builtin_pytype->ob_base.ob_base.ob_type = metatype;\n"); Printv(f_init, "#else\n", NIL); - Printf(f_init, tab4 "builtin_pytype->ob_type = metatype;\n"); + Printf(f_init, " builtin_pytype->ob_type = metatype;\n"); Printv(f_init, "#endif\n", NIL); - Printf(f_init, tab4 "builtin_pytype->tp_new = PyType_GenericNew;\n"); + Printf(f_init, " builtin_pytype->tp_new = PyType_GenericNew;\n"); + Printv(f_init, " builtin_base_count = 0;\n", NIL); List *baselist = Getattr(n, "bases"); if (baselist) { + int base_count = 0; for (Iterator b = First(baselist); b.item; b = Next(b)) { String *bname = Getattr(b.item, "name"); if (!bname || GetFlag(b.item, "feature:ignore")) continue; + base_count++; String *base_name = Copy(bname); SwigType_add_pointer(base_name); String *base_mname = SwigType_manglestr(base_name); - Printf(f_init, " builtin_basetype = SWIG_MangledTypeQuery(\"%s\");\n", base_mname); - Printv(f_init, " if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) {\n", NIL); - Printv(f_init, " builtin_bases.push_back(((SwigPyClientData*) builtin_basetype->clientdata)->pytype);\n", NIL); - Printv(f_init, " }\n", NIL); + Printf(f_init, " builtin_basetype = SWIG_MangledTypeQuery(\"%s\");\n", base_mname); + Printv(f_init, " if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) {\n", NIL); + Printv(f_init, " builtin_bases[builtin_base_count++] = ((SwigPyClientData*) builtin_basetype->clientdata)->pytype;\n", NIL); + Printv(f_init, " }\n", NIL); Delete(base_name); Delete(base_mname); } + if (base_count > max_bases) + max_bases = base_count; } - Printv(f_init, " pyswig_builtin_init_bases(builtin_pytype, builtin_bases);\n", NIL); - Printv(f_init, " builtin_bases.clear();\n", NIL); + Printv(f_init, " builtin_bases[builtin_base_count] = NULL;\n", NIL); + Printv(f_init, " SwigPyBuiltin_InitBases(builtin_pytype, builtin_bases);\n", NIL); // Check for non-public destructor, in which case tp_dealloc will issue // a warning and allow the memory to leak. Any class that doesn't explicitly // have a private/protected destructor has an implicit public destructor. - String *tp_dealloc = Getattr(n, "feature:tp_dealloc"); + String *tp_dealloc = Getattr(n, "feature:python:tp_dealloc"); if (tp_dealloc) { - Printf(f, "PYSWIG_DESTRUCTOR_CLOSURE(%s);\n", tp_dealloc); + Printf(f, "SWIGPY_DESTRUCTOR_CLOSURE(%s);\n", tp_dealloc); tp_dealloc = NewStringf("%s_closure", tp_dealloc); } else { - tp_dealloc = NewString("py_builtin_bad_dealloc"); + tp_dealloc = NewString("SwigPyBuiltin_BadDealloc"); } + String *getset_name = NewStringf("%s_getset", templ); + String *methods_name = NewStringf("%s_methods", templ); String *getset_def = NewString(""); - Printf(getset_def, "SWIGINTERN PyGetSetDef %s_getset[] = {\n", templ); + Printf(getset_def, "SWIGINTERN PyGetSetDef %s[] = {\n", getset_name); // All objects have 'this' and 'thisown' attributes Printv(f_init, "PyDict_SetItemString(d, \"this\", this_descr);\n", NIL); @@ -3252,8 +3283,8 @@ public: Hash *mgetset = member_iter.item; String *getter = Getattr(mgetset, "getter"); String *setter = Getattr(mgetset, "setter"); - const char *getter_closure = getter ? funpack ? "pyswig_funpack_getter_closure" : "pyswig_getter_closure" : "0"; - const char *setter_closure = setter ? funpack ? "pyswig_funpack_setter_closure" : "pyswig_setter_closure" : "0"; + const char *getter_closure = getter ? funpack ? "SwigPyBuiltin_FunpackGetterClosure" : "SwigPyBuiltin_GetterClosure" : "0"; + const char *setter_closure = setter ? funpack ? "SwigPyBuiltin_FunpackSetterClosure" : "SwigPyBuiltin_SetterClosure" : "0"; String *gspair = NewStringf("%s_%s_getset", symname, memname); Printf(f, "static SwigPyGetSet %s = { %s, %s };\n", gspair, getter ? getter : "0", setter ? setter : "0"); String *entry = @@ -3270,13 +3301,14 @@ public: Delete(gspair); Delete(entry); } - Printv(f, getset_def, " {NULL} // Sentinel\n", "};\n\n", NIL); + Printv(f, getset_def, " {NULL} /* Sentinel */\n", "};\n\n", NIL); // Rich compare function - Hash *richcompare = Getattr(n, "richcompare"); + Hash *richcompare = Getattr(n, "python:richcompare"); + String *richcompare_func = NewStringf("%s_richcompare", templ); assert(richcompare); Printf(f, "SWIGINTERN PyObject *\n"); - Printf(f, "%s_richcompare(PyObject *self, PyObject *other, int op) {\n", templ); + Printf(f, "%s(PyObject *self, PyObject *other, int op) {\n", richcompare_func); Printf(f, " PyObject *result = NULL;\n"); if (!funpack) { Printf(f, " PyObject *tuple = PyTuple_New(1);\n"); @@ -3309,175 +3341,177 @@ public: // No instance dict for nondynamic objects if (GetFlag(n, "feature:python:nondynamic")) - Setattr(n, "feature:tp_setattro", "SWIG_Python_NonDynamicSetAttr"); + Setattr(n, "feature:python:tp_setattro", "SWIG_Python_NonDynamicSetAttr"); - char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : Swig_directorclass(n) ? "0" : "py_builtin_bad_init"; + String *quoted_symname = NewStringf("\"%s\"", symname); + String *quoted_rname = NewStringf("\"%s\"", rname); + char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : Swig_directorclass(n) ? "0" : "SwigPyBuiltin_BadInit"; String *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES"); String *py3_tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE"); + Printf(f, "static PyHeapTypeObject %s_type = {\n", templ); // PyTypeObject ht_type - //Printf(f, "template <> PyTypeObject %s::pytype = {\n", templ); Printf(f, " {\n"); Printv(f, "#if PY_VERSION_HEX >= 0x03000000\n", NIL); Printv(f, " PyVarObject_HEAD_INIT(&PyType_Type, 0)\n", NIL); Printv(f, "#else\n", NIL); Printf(f, " PyObject_HEAD_INIT(NULL)\n"); - Printf(f, " 0, /*ob_size*/\n"); + printSlot(f, getSlot(), "ob_size"); Printv(f, "#endif\n", NIL); - Printf(f, " \"%s\", /*tp_name*/\n", symname); - Printf(f, " sizeof(SwigPyObject), /*tp_basicsize*/\n", templ); - Printf(f, " %s, /*tp_itemsize*/\n", getSlot(n, "feature:tp_itemsize")); - Printf(f, " %s, /*tp_dealloc*/\n", tp_dealloc); - Printf(f, " %s, /*tp_print*/\n", getSlot(n, "feature:tp_print")); - Printf(f, " %s, /*tp_getattr*/\n", getSlot(n, "feature:tp_getattr")); - Printf(f, " %s, /*tp_setattr*/\n", getSlot(n, "feature:tp_setattr")); - Printf(f, " %s, /*tp_compare*/\n", getSlot(n, "feature:tp_compare")); - Printf(f, " %s, /*tp_repr*/\n", getSlot(n, "feature:tp_repr")); + printSlot(f, quoted_symname, "tp_name"); + printSlot(f, "sizeof(SwigPyObject)", "tp_basicsize"); + printSlot(f, getSlot(n, "feature:python:tp_itemsize"), "tp_itemsize"); + printSlot(f, tp_dealloc, "tp_dealloc", "destructor"); + printSlot(f, getSlot(n, "feature:python:tp_print"), "tp_print", "printfunc"); + printSlot(f, getSlot(n, "feature:python:tp_getattr"), "tp_getattr", "getattrfunc"); + printSlot(f, getSlot(n, "feature:python:tp_setattr"), "tp_setattr", "setattrfunc"); + Printv(f, "#if PY_VERSION_HEX >= 0x03000000\n", NIL); + printSlot(f, getSlot(n, "feature:python:tp_compare"), "tp_compare"); + Printv(f, "#else\n", NIL); + printSlot(f, getSlot(n, "feature:python:tp_compare"), "tp_compare", "cmpfunc"); + Printv(f, "#endif\n", NIL); + printSlot(f, getSlot(n, "feature:python:tp_repr"), "tp_repr", "reprfunc"); Printf(f, " &%s_type.as_number, /*tp_as_number*/\n", templ); Printf(f, " &%s_type.as_sequence, /*tp_as_sequence*/\n", templ); Printf(f, " &%s_type.as_mapping, /*tp_as_mapping*/\n", templ); - Printf(f, " %s, /*tp_hash */\n", getSlot(n, "feature:tp_hash")); - Printf(f, " %s, /*tp_call*/\n", getSlot(n, "feature:tp_call")); - Printf(f, " %s, /*tp_str*/\n", getSlot(n, "feature:tp_str")); - Printf(f, " %s, /*tp_getattro*/\n", getSlot(n, "feature:tp_getattro")); - Printf(f, " %s, /*tp_setattro*/\n", getSlot(n, "feature:tp_setattro")); + printSlot(f, getSlot(n, "feature:python:tp_hash"), "tp_hash", "hashfunc"); + printSlot(f, getSlot(n, "feature:python:tp_call"), "tp_call", "ternaryfunc"); + printSlot(f, getSlot(n, "feature:python:tp_str"), "tp_str", "reprfunc"); + printSlot(f, getSlot(n, "feature:python:tp_getattro"), "tp_getattro", "getattrofunc"); + printSlot(f, getSlot(n, "feature:python:tp_setattro"), "tp_setattro", "setattrofunc"); Printf(f, " &%s_type.as_buffer, /*tp_as_buffer*/\n", templ); Printv(f, "#if PY_VERSION_HEX >= 0x03000000\n", NIL); - Printf(f, " %s, /*tp_flags*/\n", py3_tp_flags); + printSlot(f, py3_tp_flags, "tp_flags"); Printv(f, "#else\n", NIL); - Printf(f, " %s, /*tp_flags*/\n", tp_flags); + printSlot(f, tp_flags, "tp_flags"); Printv(f, "#endif\n", NIL); - Printf(f, " \"%s\", /* tp_doc */\n", rname); - Printf(f, " %s, /* tp_traverse */\n", getSlot(n, "feature:tp_traverse")); - Printf(f, " %s, /* tp_clear */\n", getSlot(n, "feature:tp_clear")); - Printf(f, " %s_richcompare, /* tp_richcompare */\n", templ); - Printf(f, " %s, /* tp_weaklistoffset */\n", getSlot(n, "feature:tp_weaklistoffset")); - Printf(f, " (getiterfunc) %s, /* tp_iter */\n", getSlot(n, "feature:tp_iter")); - Printf(f, " (iternextfunc) %s, /* tp_iternext */\n", getSlot(n, "feature:tp_iternext")); - Printf(f, " %s_methods, /* tp_methods */\n", templ); - Printf(f, " %s, /* tp_members */\n", getSlot(n, "feature:tp_members")); - Printf(f, " %s_getset, /* tp_getset */\n", templ); - Printf(f, " %s, /* tp_base */\n", getSlot(n, "feature:tp_base")); - Printf(f, " %s, /* tp_dict */\n", getSlot(n, "feature:tp_dict")); - Printf(f, " %s, /* tp_descr_get */\n", getSlot(n, "feature:tp_descr_get")); - Printf(f, " %s, /* tp_descr_set */\n", getSlot(n, "feature:tp_descr_set")); + printSlot(f, quoted_rname, "tp_doc"); + printSlot(f, getSlot(n, "feature:python:tp_traverse"), "tp_traverse", "traverseproc"); + printSlot(f, getSlot(n, "feature:python:tp_clear"), "tp_clear", "inquiry"); + printSlot(f, richcompare_func, "feature:python:tp_richcompare", "richcmpfunc"); + printSlot(f, getSlot(n, "feature:python:tp_weaklistoffset"), "tp_weaklistoffset"); + printSlot(f, getSlot(n, "feature:python:tp_iter"), "tp_iter", "getiterfunc"); + printSlot(f, getSlot(n, "feature:python:tp_iternext"), "tp_iternext", "iternextfunc"); + printSlot(f, methods_name, "tp_methods"); + printSlot(f, getSlot(n, "feature:python:tp_members"), "tp_members"); + printSlot(f, getset_name, " tp_getset"); + printSlot(f, getSlot(n, "feature:python:tp_base"), "tp_base"); + printSlot(f, getSlot(n, "feature:python:tp_dict"), "tp_dict"); + printSlot(f, getSlot(n, "feature:python:tp_descr_get"), "tp_descr_get", "descrgetfunc"); + printSlot(f, getSlot(n, "feature:python:tp_descr_set"), "tp_descr_set", "descrsetfunc"); Printf(f, " (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */\n"); - Printf(f, " (initproc)%s, /* tp_init */\n", tp_init); - Printf(f, " %s, /* tp_alloc */\n", getSlot(n, "feature:tp_alloc")); - Printf(f, " 0, /* tp_new */\n"); - Printf(f, " %s /* tp_free */\n", getSlot(n, "feature:tp_free")); + printSlot(f, tp_init, "tp_init", "initproc"); + printSlot(f, getSlot(n, "feature:python:tp_alloc"), "tp_alloc", "allocfunc"); + printSlot(f, "0", "tp_new", "newfunc"); + printSlot(f, getSlot(n, "feature:python:tp_free"), "tp_free", "freefunc"); Printf(f, " },\n"); // PyNumberMethods as_number - //Printf(f, "template <> PyNumberMethods %s::number_methods = {\n", templ); Printf(f, " {\n"); - Printf(f, " (binaryfunc) %s, // nb_add;\n", getSlot(n, "feature:nb_add")); - Printf(f, " (binaryfunc) %s, // nb_subtract;\n", getSlot(n, "feature:nb_subtract")); - Printf(f, " (binaryfunc) %s, // nb_multiply;\n", getSlot(n, "feature:nb_multiply")); + printSlot(f, getSlot(n, "feature:python:nb_add"), "nb_add", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_subtract"), "nb_subtract", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_multiply"), "nb_multiply", "binaryfunc"); Printv(f, "#if PY_VERSION_HEX < 0x03000000\n", NIL); - Printf(f, " (binaryfunc) %s, // nb_divide;\n", getSlot(n, "feature:nb_divide")); + printSlot(f, getSlot(n, "feature:python:nb_divide"), "nb_divide", "binaryfunc"); Printv(f, "#endif\n", NIL); - Printf(f, " (binaryfunc) %s, // nb_remainder;\n", getSlot(n, "feature:nb_remainder")); - Printf(f, " (binaryfunc) %s, // nb_divmod;\n", getSlot(n, "feature:nb_divmod")); - Printf(f, " (ternaryfunc) %s, // nb_power;\n", getSlot(n, "feature:nb_power")); - Printf(f, " (unaryfunc) %s, // nb_negative;\n", getSlot(n, "feature:nb_negative")); - Printf(f, " (unaryfunc) %s, // nb_positive;\n", getSlot(n, "feature:nb_positive")); - Printf(f, " (unaryfunc) %s, // nb_absolute;\n", getSlot(n, "feature:nb_absolute")); - Printf(f, " (inquiry) %s, // nb_nonzero;\n", getSlot(n, "feature:nb_nonzero")); - Printf(f, " (unaryfunc) %s, // nb_invert;\n", getSlot(n, "feature:nb_invert")); - Printf(f, " (binaryfunc) %s, // nb_lshift;\n", getSlot(n, "feature:nb_lshift")); - Printf(f, " (binaryfunc) %s, // nb_rshift;\n", getSlot(n, "feature:nb_rshift")); - Printf(f, " (binaryfunc) %s, // nb_and;\n", getSlot(n, "feature:nb_and")); - Printf(f, " (binaryfunc) %s, // nb_xor;\n", getSlot(n, "feature:nb_xor")); - Printf(f, " (binaryfunc) %s, // nb_or;\n", getSlot(n, "feature:nb_or")); + printSlot(f, getSlot(n, "feature:python:nb_remainder"), "nb_remainder", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_divmod"), "nb_divmod", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_power"), "nb_power", "ternaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_negative"), "nb_negative", "unaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_positive"), "nb_positive", "unaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_absolute"), "nb_absolute", "unaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_nonzero"), "nb_nonzero", "inquiry"); + printSlot(f, getSlot(n, "feature:python:nb_invert"), "nb_invert", "unaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_lshift"), "nb_lshift", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_rshift"), "nb_rshift", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_and"), "nb_and", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_xor"), "nb_xor", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_or"), "nb_or", "binaryfunc"); Printv(f, "#if PY_VERSION_HEX < 0x03000000\n", NIL); - Printf(f, " (coercion) %s, // nb_coerce;\n", getSlot(n, "feature:nb_coerce")); + printSlot(f, getSlot(n, "feature:python:nb_coerce"), "nb_coerce", "coercion"); Printv(f, "#endif\n", NIL); - Printf(f, " (unaryfunc) %s, // nb_int;\n", getSlot(n, "feature:nb_int")); + printSlot(f, getSlot(n, "feature:python:nb_int"), "nb_int", "unaryfunc"); Printv(f, "#if PY_VERSION_HEX >= 0x03000000\n", NIL); - Printf(f, " (void*) %s, // nb_reserved;\n", getSlot(n, "feature:nb_reserved")); + printSlot(f, getSlot(n, "feature:python:nb_reserved"), "nb_reserved", "void*"); Printv(f, "#else\n", NIL); - Printf(f, " (unaryfunc) %s, // nb_long;\n", getSlot(n, "feature:nb_long")); + printSlot(f, getSlot(n, "feature:python:nb_long"), "nb_long", "unaryfunc"); Printv(f, "#endif\n", NIL); - Printf(f, " (unaryfunc) %s, // nb_float;\n", getSlot(n, "feature:nb_float")); + printSlot(f, getSlot(n, "feature:python:nb_float"), "nb_float", "unaryfunc"); Printv(f, "#if PY_VERSION_HEX < 0x03000000\n", NIL); - Printf(f, " (unaryfunc) %s, // nb_oct;\n", getSlot(n, "feature:nb_oct")); - Printf(f, " (unaryfunc) %s, // nb_hex;\n", getSlot(n, "feature:nb_hex")); + printSlot(f, getSlot(n, "feature:python:nb_oct"), "nb_oct", "unaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_hex"), "nb_hex", "unaryfunc"); Printv(f, "#endif\n", NIL); - Printf(f, " (binaryfunc) %s, // nb_inplace_add;\n", getSlot(n, "feature:nb_inplace_add")); - Printf(f, " (binaryfunc) %s, // nb_inplace_subtract;\n", getSlot(n, "feature:nb_inplace_subtract")); - Printf(f, " (binaryfunc) %s, // nb_inplace_multiply;\n", getSlot(n, "feature:nb_inplace_multiply")); + printSlot(f, getSlot(n, "feature:python:nb_inplace_add"), "nb_inplace_add", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_inplace_subtract"), "nb_inplace_subtract", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_inplace_multiply"), "nb_inplace_multiply", "binaryfunc"); Printv(f, "#if PY_VERSION_HEX < 0x03000000\n", NIL); - Printf(f, " (binaryfunc) %s, // nb_inplace_divide;\n", getSlot(n, "feature:nb_inplace_divide")); + printSlot(f, getSlot(n, "feature:python:nb_inplace_divide"), "nb_inplace_divide", "binaryfunc"); Printv(f, "#endif\n", NIL); - Printf(f, " (binaryfunc) %s, // nb_inplace_remainder;\n", getSlot(n, "feature:nb_inplace_remainder")); - Printf(f, " (ternaryfunc) %s, // nb_inplace_power;\n", getSlot(n, "feature:nb_inplace_power")); - Printf(f, " (binaryfunc) %s, // nb_inplace_lshift;\n", getSlot(n, "feature:nb_inplace_lshift")); - Printf(f, " (binaryfunc) %s, // nb_inplace_rshift;\n", getSlot(n, "feature:nb_inplace_rshift")); - Printf(f, " (binaryfunc) %s, // nb_inplace_and;\n", getSlot(n, "feature:nb_inplace_and")); - Printf(f, " (binaryfunc) %s, // nb_inplace_xor;\n", getSlot(n, "feature:nb_inplace_xor")); - Printf(f, " (binaryfunc) %s, // nb_inplace_or;\n", getSlot(n, "feature:nb_inplace_or")); - Printf(f, " (binaryfunc) %s, // nb_floor_divide;\n", getSlot(n, "feature:nb_floor_divide")); - Printf(f, " (binaryfunc) %s, // nb_true_divide;\n", getSlot(n, "feature:nb_true_divide")); - Printf(f, " (binaryfunc) %s, // nb_inplace_floor_divide;\n", getSlot(n, "feature:nb_inplace_floor_divide")); - Printf(f, " (binaryfunc) %s, // nb_inplace_true_divide;\n", getSlot(n, "feature:nb_inplace_true_divide")); - Printf(f, " (unaryfunc) %s, // nb_index;\n", getSlot(n, "feature:nb_index")); + printSlot(f, getSlot(n, "feature:python:nb_inplace_remainder"), "nb_inplace_remainder", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_inplace_power"), "nb_inplace_power", "ternaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_inplace_lshift"), "nb_inplace_lshift", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_inplace_rshift"), "nb_inplace_rshift", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_inplace_and"), "nb_inplace_and", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_inplace_xor"), "nb_inplace_xor", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_inplace_or"), "nb_inplace_or", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_floor_divide"), "nb_floor_divide", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_true_divide"), "nb_true_divide", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_inplace_floor_divide"), "nb_inplace_floor_divide", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_inplace_true_divide"), "nb_inplace_true_divide", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:nb_index"), "nb_index", "unaryfunc"); Printf(f, " },\n"); // PyMappingMethods as_mapping; - //Printf(f, "template <> PyMappingMethods %s::mapping_methods = {\n", templ); Printf(f, " {\n"); - Printf(f, " (lenfunc) %s, // mp_length;\n", getSlot(n, "feature:mp_length")); - Printf(f, " (binaryfunc) %s, // mp_subscript;\n", getSlot(n, "feature:mp_subscript")); - Printf(f, " (objobjargproc) %s, // mp_ass_subscript;\n", getSlot(n, "feature:mp_ass_subscript")); + printSlot(f, getSlot(n, "feature:python:mp_length"), "mp_length", "lenfunc"); + printSlot(f, getSlot(n, "feature:python:mp_subscript"), "mp_subscript", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:mp_ass_subscript"), " mp_ass_subscript", "objobjargproc"); Printf(f, " },\n"); // PySequenceMethods as_sequence; - //Printf(f, "template <> PySequenceMethods %s::sequence_methods = {\n", templ); Printf(f, " {\n"); - Printf(f, " (lenfunc) %s, // sq_length\n", getSlot(n, "feature:sq_length")); - Printf(f, " (binaryfunc) %s, // sq_concat\n", getSlot(n, "feature:sq_concat")); - Printf(f, " (ssizeargfunc) %s, // sq_repeat\n", getSlot(n, "feature:sq_repeat")); - Printf(f, " (ssizeargfunc) %s, // sq_item\n", getSlot(n, "feature:sq_item")); + Printf(f, " (lenfunc) %s, // sq_length\n", getSlot(n, "feature:python:sq_length")); + Printf(f, " (binaryfunc) %s, // sq_concat\n", getSlot(n, "feature:python:sq_concat")); + Printf(f, " (ssizeargfunc) %s, // sq_repeat\n", getSlot(n, "feature:python:sq_repeat")); + Printf(f, " (ssizeargfunc) %s, // sq_item\n", getSlot(n, "feature:python:sq_item")); Printv(f, "#if PY_VERSION_HEX >= 0x03000000\n", NIL); Printf(f, " (void*) %s, // was_sq_slice\n", getSlot(n, "feature:was_sq_slice")); Printv(f, "#else\n", NIL); - Printf(f, " (ssizessizeargfunc) %s, // sq_slice\n", getSlot(n, "feature:sq_slice")); + Printf(f, " (ssizessizeargfunc) %s, // sq_slice\n", getSlot(n, "feature:python:sq_slice")); Printv(f, "#endif\n", NIL); - Printf(f, " (ssizeobjargproc) %s, // sq_ass_item\n", getSlot(n, "feature:sq_ass_item")); + Printf(f, " (ssizeobjargproc) %s, // sq_ass_item\n", getSlot(n, "feature:python:sq_ass_item")); Printv(f, "#if PY_VERSION_HEX >= 0x03000000\n", NIL); Printf(f, " (void*) %s, // was_sq_ass_slice\n", getSlot(n, "feature:was_sq_ass_slice")); Printv(f, "#else\n", NIL); - Printf(f, " (ssizessizeobjargproc) %s, // sq_ass_slice\n", getSlot(n, "feature:sq_ass_slice")); + Printf(f, " (ssizessizeobjargproc) %s, // sq_ass_slice\n", getSlot(n, "feature:python:sq_ass_slice")); Printv(f, "#endif\n", NIL); - Printf(f, " (objobjproc) %s, // sq_contains\n", getSlot(n, "feature:sq_contains")); - Printf(f, " (binaryfunc) %s, // sq_inplace_concat\n", getSlot(n, "feature:sq_inplace_concat")); - Printf(f, " (ssizeargfunc) %s, // sq_inplace_repeat\n", getSlot(n, "feature:sq_inplace_repeat")); + Printf(f, " (objobjproc) %s, // sq_contains\n", getSlot(n, "feature:python:sq_contains")); + Printf(f, " (binaryfunc) %s, // sq_inplace_concat\n", getSlot(n, "feature:python:sq_inplace_concat")); + Printf(f, " (ssizeargfunc) %s, // sq_inplace_repeat\n", getSlot(n, "feature:python:sq_inplace_repeat")); Printf(f, " },\n"); // PyBufferProcs as_buffer; Printf(f, " {\n"); Printv(f, "#if PY_VERSION_HEX >= 0x03000000\n", NIL); - Printf(f, " (getbufferproc) %s, // bf_getbuffer\n", getSlot(n, "feature:bf_getbuffer")); - Printf(f, " (releasebufferproc) %s, // bf_releasebuffer\n", getSlot(n, "feature:bf_releasebuffer")); + Printf(f, " (getbufferproc) %s, // bf_getbuffer\n", getSlot(n, "feature:python:bf_getbuffer")); + Printf(f, " (releasebufferproc) %s, // bf_releasebuffer\n", getSlot(n, "feature:python:bf_releasebuffer")); Printv(f, "#else\n", NIL); - Printf(f, " (readbufferproc) %s, // bf_getreadbuffer\n", getSlot(n, "feature:bf_getreadbuffer")); - Printf(f, " (writebufferproc) %s, // bf_getwritebuffer\n", getSlot(n, "feature:bf_getwritebuffer")); - Printf(f, " (segcountproc) %s, // bf_getsegcount\n", getSlot(n, "feature:bf_getsegcount")); - Printf(f, " (charbufferproc) %s, // bf_getcharbuffer\n", getSlot(n, "feature:bf_getcharbuffer")); + Printf(f, " (readbufferproc) %s, // bf_getreadbuffer\n", getSlot(n, "feature:python:bf_getreadbuffer")); + Printf(f, " (writebufferproc) %s, // bf_getwritebuffer\n", getSlot(n, "feature:python:bf_getwritebuffer")); + Printf(f, " (segcountproc) %s, // bf_getsegcount\n", getSlot(n, "feature:python:bf_getsegcount")); + Printf(f, " (charbufferproc) %s, // bf_getcharbuffer\n", getSlot(n, "feature:python:bf_getcharbuffer")); Printv(f, "#endif\n", NIL); Printf(f, " },\n"); // PyObject *ht_name, *ht_slots - Printf(f, " (PyObject*) %s, // ht_name\n", getSlot(n, "feature:ht_name")); - Printf(f, " (PyObject*) %s, // ht_slots\n", getSlot(n, "feature:ht_slots")); + Printf(f, " (PyObject*) %s, // ht_name\n", getSlot(n, "feature:python:ht_name")); + Printf(f, " (PyObject*) %s, // ht_slots\n", getSlot(n, "feature:python:ht_slots")); Printf(f, "};\n\n"); String *clientdata = NewString(""); Printf(clientdata, "&%s_clientdata", templ); - //SwigType_remember_clientdata(pname, clientdata); SwigType_remember_mangleddata(pmname, clientdata); String *smartptr = Getattr(n, "feature:smartptr"); @@ -3486,7 +3520,6 @@ public: SwigType *smart = SwigType_typedef_resolve_all(spt); SwigType_add_pointer(smart); String *smart_pmname = SwigType_manglestr(smart); - //SwigType_remember_clientdata(smart, clientdata); SwigType_remember_mangleddata(smart_pmname, clientdata); Delete(spt); Delete(smart); @@ -3511,7 +3544,7 @@ public: Printv(f_init, " }\n", NIL); Printv(f_init, " Py_INCREF(builtin_pytype);\n", NIL); Printf(f_init, " PyModule_AddObject(m, \"%s\", (PyObject*) builtin_pytype);\n", symname); - Printf(f_init, " pyswig_add_public_symbol(public_interface, \"%s\");\n", symname); + Printf(f_init, " SwigPyBuiltin_AddPublicSymbol(public_interface, \"%s\");\n", symname); Printv(f_init, " d = md;\n", NIL); Delete(clientdata); @@ -3523,7 +3556,12 @@ public: Delete(tp_dealloc); Delete(tp_flags); Delete(py3_tp_flags); + Delete(quoted_symname); + Delete(quoted_rname); Delete(clientdata_klass); + Delete(richcompare_func); + Delete(getset_name); + Delete(methods_name); } virtual int classHandler(Node *n) { @@ -3597,12 +3635,12 @@ public: Hash *base_richcompare = NULL; Hash *richcompare = NULL; if (base_node) - base_richcompare = Getattr(base_node, "richcompare"); + base_richcompare = Getattr(base_node, "python:richcompare"); if (base_richcompare) richcompare = Copy(base_richcompare); else richcompare = NewHash(); - Setattr(n, "richcompare", richcompare); + Setattr(n, "python:richcompare", richcompare); } /* dealing with abstract base class */ @@ -3615,7 +3653,11 @@ public: } if (builtin) { - + if (have_docstring(n)) { + String *str = cdocstring(n, AUTODOC_CLASS); + Setattr(n, "feature:python:tp_doc", str); + Delete(str); + } } else { Printv(f_shadow, "class ", class_name, NIL); @@ -3852,7 +3894,7 @@ public: int oldshadow; if (builtin) - Swig_save("builtin_memberfunc", n, "noargs", "onearg", NIL); + Swig_save("builtin_memberfunc", n, "python:argcount", NIL); /* Create the default member function */ oldshadow = shadow; /* Disable shadowing when wrapping member functions */ @@ -3868,17 +3910,20 @@ public: String *fullname = Swig_name_member(NULL, class_name, symname); String *wname = Swig_name_wrapper(fullname); Setattr(class_members, symname, n); + int argcount = Getattr(n, "python:argcount") ? atoi(Char(Getattr(n, "python:argcount"))) : 2; + String *ds = have_docstring(n) ? cdocstring(n, AUTODOC_FUNC) : NewString(""); if (check_kwargs(n)) { - Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_VARARGS|METH_KEYWORDS, \"\" },\n", symname, wname); - } else if (GetFlagAttr(n, "noargs")) { - Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_NOARGS, \"\" },\n", symname, wname); - } else if (GetFlagAttr(n, "onearg")) { - Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_O, \"\" },\n", symname, wname); + Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_VARARGS|METH_KEYWORDS, (char*) \"%s\" },\n", symname, wname, ds); + } else if (argcount == 0) { + Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_NOARGS, (char*) \"%s },\n", symname, wname, ds); + } else if (argcount == 1) { + Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_O, (char*) \"%s\" },\n", symname, wname, ds); } else { - Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_VARARGS, \"\" },\n", symname, wname); + Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_VARARGS, (char*) \"%s\" },\n", symname, wname, ds); } Delete(fullname); Delete(wname); + Delete(ds); } } @@ -3949,8 +3994,8 @@ public: virtual int staticmemberfunctionHandler(Node *n) { String *symname = Getattr(n, "sym:name"); if (builtin && in_class) { - Swig_save("builtin_memberconstantHandler", n, "builtin_sym:name", NIL); - Setattr(n, "builtin_sym:name", symname); + Swig_save("builtin_memberconstantHandler", n, "pybuiltin:symname", NIL); + Setattr(n, "pybuiltin:symname", symname); } Language::staticmemberfunctionHandler(n); if (builtin && in_class) { @@ -3965,13 +4010,20 @@ public: Setattr(class_members, symname, n); int funpack = modernargs && fastunpack && !Getattr(n, "sym:overloaded"); String *pyflags = NewString("METH_STATIC|"); - if (funpack && GetFlagAttr(n, "noargs")) + int argcount = Getattr(n, "python:argcount") ? atoi(Char(Getattr(n, "python:argcount"))) : 2; + if (funpack && argcount == 0) Append(pyflags, "METH_NOARGS"); - else if (funpack && GetFlagAttr(n, "onearg")) + else if (funpack && argcount == 1) Append(pyflags, "METH_O"); else Append(pyflags, "METH_VARARGS"); - Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", symname, wname, pyflags); + if (have_docstring(n)) { + String *ds = cdocstring(n, AUTODOC_STATICFUNC); + Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, %s, (char*) \"%s\" },\n", symname, wname, pyflags, ds); + Delete(ds); + } else { + Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", symname, wname, pyflags); + } Delete(fullname); Delete(wname); Delete(pyflags); @@ -4171,10 +4223,10 @@ public: if (builtin && in_class) { Node *cls = Swig_methodclass(n); - if (!Getattr(cls, "feature:tp_dealloc")) { + if (!Getattr(cls, "feature:python:tp_dealloc")) { String *dealloc = Swig_name_destroy(NSPACE_TODO, symname); String *wdealloc = Swig_name_wrapper(dealloc); - Setattr(cls, "feature:tp_dealloc", wdealloc); + Setattr(cls, "feature:python:tp_dealloc", wdealloc); Delete(wdealloc); Delete(dealloc); } @@ -4326,8 +4378,8 @@ public: Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL); } } - String *getter = Getattr(n, "builtin:getter"); - String *setter = Getattr(n, "builtin:setter"); + String *getter = Getattr(n, "pybuiltin:getter"); + String *setter = Getattr(n, "pybuiltin:setter"); Hash *h = NULL; if (getter || setter) { h = Getattr(builtin_getset, symname); @@ -4362,8 +4414,8 @@ public: virtual int memberconstantHandler(Node *n) { String *symname = Getattr(n, "sym:name"); if (builtin && in_class) { - Swig_save("builtin_memberconstantHandler", n, "builtin_sym:name", NIL); - Setattr(n, "builtin_sym:name", symname); + Swig_save("builtin_memberconstantHandler", n, "pybuiltin:symname", NIL); + Setattr(n, "pybuiltin:symname", symname); } int oldshadow = shadow; if (shadow) @@ -4571,6 +4623,9 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { } } + if (builtin) + Printv(w->code, "PyObject *self = NULL;\n", NIL); + if (ignored_method) { if (!pure_virtual) { if (!is_void) @@ -4692,7 +4747,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL); Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst); Printf(wrap_args, "if (!%s) {\n", director); - Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); + Printf(wrap_args, "%s = SWIG_InternalNewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); Append(wrap_args, "} else {\n"); Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director); Printf(wrap_args, "Py_INCREF((PyObject *)%s);\n", source); @@ -4701,7 +4756,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { Printv(arglist, source, NIL); } else { Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL); - Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); + Printf(wrap_args, "%s = SWIG_InternalNewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); //Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n", // source, nonconst, base); Printv(arglist, source, NIL);