From f4e5cd4f882d5001acc93d029cd141bf07c390e3 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Tue, 7 Dec 2010 20:32:19 +0000 Subject: [PATCH 01/56] Branch for development of -builtin option for python. With this option, swig will produce new built-in python types for all wrapped classes. Built-in types offer a substantial performance benefit compared to the current shadow class implementation. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12326 626c5289-ae23-0410-ae9c-e8d60b6d4f22 From ee3a6623dadeb5d06e19dcbd7372fa049e9ef4b2 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Tue, 7 Dec 2010 21:50:00 +0000 Subject: [PATCH 02/56] First cut. Works for wrapping OpenAccess, but there's plenty left to do. Currently, the test suite hurls at director_stl. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12332 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/builtin.swg | 28 + Lib/python/pycontainer.swg | 5 + Lib/python/pyinit.swg | 12 +- Lib/python/pyiterators.swg | 23 + Lib/python/pyrun.swg | 208 ++-- Lib/python/pyruntime.swg | 1 + Lib/python/pytypemaps.swg | 17 + Source/Modules/python.cxx | 2266 +++++++++++++++++++++--------------- 8 files changed, 1520 insertions(+), 1040 deletions(-) create mode 100644 Lib/python/builtin.swg diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg new file mode 100644 index 000000000..556b113af --- /dev/null +++ b/Lib/python/builtin.swg @@ -0,0 +1,28 @@ +#ifdef __cplusplus + +namespace { + +template struct PySwigBuiltin : public SwigPyObject { + + typedef PySwigBuiltin<_Tp> this_type; + typedef _Tp obj_type; + typedef obj_type* pointer; + typedef obj_type& reference; + + static PyMethodDef methods[]; + static PyTypeObject pytype; + static SwigPyClientData clientdata; +}; + +template void py_builtin_dealloc (PyObject *pyobj) +{ + typedef PySwigBuiltin<_Tp> builtin_type; + builtin_type *obj = (builtin_type*) pyobj; + if (obj->own) + delete reinterpret_cast<_Tp*>(obj->ptr); + (*pyobj->ob_type->tp_free)(pyobj); +} + +} // namespace { + +#endif diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg index 40506e15b..27e145362 100644 --- a/Lib/python/pycontainer.swg +++ b/Lib/python/pycontainer.swg @@ -580,6 +580,9 @@ namespace swig %fragment("SwigPySequence_Cont"); +# if defined(SWIGPYTHON_BUILTIN) + %feature("tp_iter") Sequence "&swig::make_output_iterator_builtin< Sequence >"; +# else %newobject iterator(PyObject **PYTHON_SELF); %extend { swig::SwigPyIterator* iterator(PyObject **PYTHON_SELF) { @@ -588,6 +591,8 @@ namespace swig %pythoncode {def __iter__(self): return self.iterator()} } +# endif // SWIGPYTHON_BUILTIN + #endif //SWIG_EXPORT_ITERATOR_METHODS %enddef diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index 5af8d2491..5ee13f34b 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -320,7 +320,8 @@ SWIGEXPORT void #endif SWIG_init(void) { - PyObject *m, *d; + PyObject *m, *d, *md; + PyTypeObject *builtin_type; #if PY_VERSION_HEX >= 0x03000000 static struct PyModuleDef SWIG_module = { PyModuleDef_HEAD_INIT, @@ -335,6 +336,13 @@ SWIG_init(void) { }; #endif +#if defined(SWIGPYTHON_BUILTIN) + PyTypeObject *builtin_pytype = 0; + swig_type_info *builtin_basetype = 0; + + SWIG_Python_builtin_imports(); +#endif + /* Fix SwigMethods to carry the callback ptrs when needed */ SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial); @@ -343,7 +351,7 @@ SWIG_init(void) { #else m = Py_InitModule((char *) SWIG_name, SwigMethods); #endif - d = PyModule_GetDict(m); + md = d = PyModule_GetDict(m); SWIG_InitializeModule(0); SWIG_InstallConstants(d,swig_const_table); diff --git a/Lib/python/pyiterators.swg b/Lib/python/pyiterators.swg index 3c39f9710..ecbc54270 100644 --- a/Lib/python/pyiterators.swg +++ b/Lib/python/pyiterators.swg @@ -302,6 +302,24 @@ namespace swig { { return new SwigPyIteratorOpen_T(current, seq); } + + template + inline PyObject* make_output_iterator_builtin (PyObject *pyself) + { + SwigPyObject *builtin_obj = (SwigPyObject*) pyself; + Sequence *seq = reinterpret_cast< Sequence * >(builtin_obj->ptr); + 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); + } + + template <> + inline PyObject* make_output_iterator_builtin (PyObject *pyself) + { + Py_INCREF(pyself); + return pyself; + } } } @@ -329,9 +347,14 @@ namespace swig %newobject SwigPyIterator::operator - (ptrdiff_t n) const; %nodirector SwigPyIterator; + +#if defined(SWIGPYTHON_BUILTIN) + %feature("tp_iter") SwigPyIterator "&swig::make_output_iterator_builtin"; +#else %extend SwigPyIterator { %pythoncode {def __iter__(self): return self} } +#endif %catches(swig::stop_iteration) SwigPyIterator::value() const; %catches(swig::stop_iteration) SwigPyIterator::incr(size_t n = 1); diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 5043e6ec0..432d5dcf6 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -244,6 +244,7 @@ typedef struct { PyObject *destroy; int delargs; int implicitconv; + PyTypeObject *pytype; } SwigPyClientData; SWIGRUNTIMEINLINE int @@ -310,6 +311,7 @@ SwigPyClientData_New(PyObject* obj) data->delargs = 0; } data->implicitconv = 0; + data->pytype = 0; return data; } } @@ -1064,91 +1066,101 @@ 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) { - if (ptr) *ptr = 0; - return SWIG_OK; - } else { + if (!obj) return SWIG_ERROR; + if (obj == Py_None) { + if (ptr) *ptr = 0; + return SWIG_OK; + } + if (ty && ty->clientdata && ((SwigPyClientData*) ty->clientdata)->pytype) { + PyTypeObject *target_tp = ((SwigPyClientData*) ty->clientdata)->pytype; + PyTypeObject *obj_tp; + for (obj_tp = obj->ob_type; obj_tp; obj_tp = obj_tp->tp_base) { + if (obj_tp == target_tp) { + if (ptr) + *ptr = ((SwigPyObject*) obj)->ptr; + return SWIG_OK; + } + } + } SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj); if (own) - *own = 0; + *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; + 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 { - 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 (ptr) *ptr = vptr; break; - } } - } else { - if (ptr) *ptr = vptr; - break; - } } if (sobj) { - if (own) - *own = *own | sobj->own; - if (flags & SWIG_POINTER_DISOWN) { - sobj->own = 0; - } - return SWIG_OK; - } else { - int res = SWIG_ERROR; - 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); - } - } + if (own) + *own = *own | sobj->own; + if (flags & SWIG_POINTER_DISOWN) { + sobj->own = 0; } - } - return res; + return SWIG_OK; + } else { + int res = SWIG_ERROR; + 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); + } + } + } + } + return res; } - } } /* Convert a function ptr value */ @@ -1319,21 +1331,32 @@ SWIG_Python_InitShadowInstance(PyObject *args) { SWIGRUNTIME PyObject * SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) { - if (!ptr) { - return SWIG_Py_Void(); - } else { - int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; - PyObject *robj = SwigPyObject_New(ptr, type, own); + if (!ptr) + return SWIG_Py_Void(); + SwigPyClientData *clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0; + int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; + if (clientdata && clientdata->pytype) { + SwigPyObject *newobj = PyObject_New(SwigPyObject, clientdata->pytype); + if (newobj) { + newobj->ptr = ptr; + newobj->ty = type; + newobj->own = own; + newobj->next = 0; + return (PyObject*) newobj; + } + return SWIG_Py_Void(); + } + + PyObject *robj = SwigPyObject_New(ptr, type, own); if (clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { - PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); - if (inst) { - Py_DECREF(robj); - robj = inst; - } + PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); + if (inst) { + Py_DECREF(robj); + robj = inst; + } } return robj; - } } /* Create a new packed object */ @@ -1343,6 +1366,19 @@ 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); + SwigPyClientData *clientdata = (SwigPyClientData *)(type->clientdata); + assert(clientdata); + assert(clientdata->pytype); + int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; + SwigPyObject *newobj = (SwigPyObject*) self; + newobj->ptr = ptr; + newobj->own = own; + return 0; +} + /* -----------------------------------------------------------------------------* * Get type list * -----------------------------------------------------------------------------*/ diff --git a/Lib/python/pyruntime.swg b/Lib/python/pyruntime.swg index 00f15a144..77abd47bd 100644 --- a/Lib/python/pyruntime.swg +++ b/Lib/python/pyruntime.swg @@ -11,3 +11,4 @@ %insert(runtime) "pyapi.swg"; /* Python API */ %insert(runtime) "pyrun.swg"; /* Python run-time code */ +%insert(runtime) "builtin.swg"; /* Specialization for classes with single inheritance */ diff --git a/Lib/python/pytypemaps.swg b/Lib/python/pytypemaps.swg index 817ed1d90..0cc1e976c 100644 --- a/Lib/python/pytypemaps.swg +++ b/Lib/python/pytypemaps.swg @@ -96,3 +96,20 @@ } +/* ------------------------------------------------------------- + * Output typemap for the __init__ method of a built-in type. + * ------------------------------------------------------------ */ + +/* 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)); +} diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 6d5f500a4..6d6b060d3 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -21,6 +21,7 @@ static int treduce = SWIG_cparse_template_reduce(0); #include #define PYSHADOW_MEMBER 0x2 +#define WARN_PYTHON_MULTIPLE_INH 405 static String *const_code = 0; static String *module = 0; @@ -43,8 +44,10 @@ static File *f_init = 0; static File *f_shadow_py = 0; static String *f_shadow = 0; static String *f_shadow_imports = 0; +static String *f_shadow_import_stmts = 0; static String *f_shadow_stubs = 0; + static String *methods; static String *class_name; static String *shadow_indent = 0; @@ -56,6 +59,12 @@ static int no_header_file = 0; static int py3 = 0; +static Hash *class_members = 0; + +static int builtin = 0; +static File *f_builtins = 0; +static String *builtin_tp_init = 0; + /* C++ Support + Shadow Classes */ static int have_constructor; @@ -154,9 +163,18 @@ static const char *usage3 = (char *) "\ Function annotation \n\ \n"; +static String* +getSlot (Node *n, const char *key) +{ + static String *slot_default = NewString("0"); + String *val = Getattr(n, key); + return val ? val : slot_default; +} + + class PYTHON:public Language { public: - PYTHON() { + PYTHON() { /* Add code to manage protected constructors and directors */ director_prot_ctor_code = NewString(""); Printv(director_prot_ctor_code, @@ -430,9 +448,13 @@ public: fputs(usage2, stdout); fputs(usage3, stdout); } else if (strcmp(argv[i], "-py3") == 0) { - py3 = 1; - Swig_mark_arg(i); - } + py3 = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-builtin") == 0) { + builtin = 1; + Preprocessor_define("SWIGPYTHON_BUILTIN", 0); + Swig_mark_arg(i); + } } } /* for */ @@ -532,6 +554,11 @@ public: f_directors_h = NewString(""); f_directors = NewString(""); + if (builtin) { + f_builtins = NewString(""); + Printf(f_builtins, "namespace {\n\n"); + } + if (directorsEnabled()) { if (!no_header_file) { f_runtime_h = NewFile(outfile_h, "w", SWIG_output_files()); @@ -610,6 +637,10 @@ public: Printf(f_runtime, "#define SWIG_PYTHON_CLASSIC\n"); } + if (builtin) { + Printf(f_runtime, "#define SWIGPYTHON_BUILTIN\n"); + } + Printf(f_runtime, "\n"); Printf(f_header, "#if (PY_VERSION_HEX <= 0x02000000)\n"); @@ -668,155 +699,164 @@ public: /* If shadow classing is enabled, we're going to change the module name to "_module" */ if (shadow) { - String *filen = NewStringf("%s%s.py", SWIG_output_directory(), Char(module)); - // If we don't have an interface then change the module name X to _X - if (interface) - module = interface; - else - Insert(module, 0, "_"); - if ((f_shadow_py = NewFile(filen, "w", SWIG_output_files())) == 0) { - FileErrorDisplay(filen); - SWIG_exit(EXIT_FAILURE); - } - Delete(filen); - filen = NULL; - - f_shadow = NewString(""); - f_shadow_imports = NewString(""); - f_shadow_stubs = NewString(""); - - Swig_register_filebyname("shadow", f_shadow); - Swig_register_filebyname("python", f_shadow); - - Swig_banner_target_lang(f_shadow, "#"); - - if (!modern) { - Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL); - } - - if (mod_docstring && Len(mod_docstring)) { - Printv(f_shadow, "\n\"\"\"\n", mod_docstring, "\n\"\"\"\n", NIL); - Delete(mod_docstring); - mod_docstring = NULL; - } - - Printv(f_shadow, "\nfrom sys import version_info\n", NULL); - - if(fastproxy) - { - Printv(f_shadow, "if version_info >= (3,0,0):\n", NULL); - Printf(f_shadow, tab4 "new_instancemethod = lambda func, inst, cls: %s.SWIG_PyInstanceMethod_New(func)\n", module); - Printv(f_shadow, "else:\n", NULL); - Printv(f_shadow, tab4, "from new import instancemethod as new_instancemethod\n", NULL); - } - /* Import the C-extension module. This should be a relative import, - * since the shadow module may also have been imported by a relative - * import, and there is thus no guarantee that the C-extension is on - * sys.path. Relative imports must be explicitly specified from 2.6.0 - * onwards (implicit relative imports will raise a DeprecationWarning - * in 2.6, and fail in 2.7 onwards), but the relative import syntax - * isn't available in python 2.4 or earlier, so we have to write some - * code conditional on the python version. - */ - Printv(f_shadow, "if version_info >= (2,6,0):\n", NULL); - Printv(f_shadow, tab4, "def swig_import_helper():\n", NULL); - Printv(f_shadow, tab8, "from os.path import dirname\n", NULL); - Printv(f_shadow, tab8, "import imp\n", NULL); - Printv(f_shadow, tab8, "fp = None\n", NULL); - Printv(f_shadow, tab8, "try:\n", NULL); - Printf(f_shadow, tab4 tab8 "fp, pathname, description = imp.find_module('%s', [dirname(__file__)])\n", module); - Printf(f_shadow, tab8 "except ImportError:\n"); - /* At here, the module may already loaded, so simply import it. */ - Printf(f_shadow, tab4 tab8 "import %s\n", module); - Printf(f_shadow, tab4 tab8 "return %s\n", module); - Printv(f_shadow, tab8 "if fp is not None:\n", NULL); - Printv(f_shadow, tab4 tab8 "try:\n", NULL); - Printf(f_shadow, tab8 tab8 "_mod = imp.load_module('%s', fp, pathname, description)\n", module); - Printv(f_shadow, tab4 tab8, "finally:\n", NULL); - Printv(f_shadow, tab8 tab8, "fp.close()\n", NULL); - Printv(f_shadow, tab4 tab8, "return _mod\n", NULL); - Printf(f_shadow, tab4 "%s = swig_import_helper()\n", module); - Printv(f_shadow, tab4, "del swig_import_helper\n", NULL); - Printv(f_shadow, "else:\n", NULL); - Printf(f_shadow, tab4 "import %s\n", module); - - /* Delete the version_info symbol since we don't use it elsewhere in the - * module. */ - Printv(f_shadow, "del version_info\n", NULL); - - if (modern || !classic) { - Printv(f_shadow, "try:\n", tab4, "_swig_property = property\n", "except NameError:\n", tab4, "pass # Python < 2.2 doesn't have 'property'.\n", NULL); - } - /* if (!modern) */ - /* always needed, a class can be forced to be no-modern, such as an exception */ - { - // Python-2.2 object hack - Printv(f_shadow, - "def _swig_setattr_nondynamic(self,class_type,name,value,static=1):\n", - tab4, "if (name == \"thisown\"): return self.this.own(value)\n", - tab4, "if (name == \"this\"):\n", tab4, tab4, "if type(value).__name__ == 'SwigPyObject':\n", tab4, tab8, "self.__dict__[name] = value\n", -#ifdef USE_THISOWN - tab4, tab8, "if hasattr(value,\"thisown\"): self.__dict__[\"thisown\"] = value.thisown\n", tab4, tab8, "del value.thisown\n", -#endif - tab4, tab8, "return\n", tab4, "method = class_type.__swig_setmethods__.get(name,None)\n", tab4, "if method: return method(self,value)\n", -#ifdef USE_THISOWN - tab4, "if (not static) or hasattr(self,name) or (name == \"thisown\"):\n", -#else - tab4, "if (not static) or hasattr(self,name):\n", -#endif - tab4, tab4, "self.__dict__[name] = value\n", - tab4, "else:\n", - tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n\n", - "def _swig_setattr(self,class_type,name,value):\n", tab4, "return _swig_setattr_nondynamic(self,class_type,name,value,0)\n\n", NIL); - - Printv(f_shadow, - "def _swig_getattr(self,class_type,name):\n", - tab4, "if (name == \"thisown\"): return self.this.own()\n", - tab4, "method = class_type.__swig_getmethods__.get(name,None)\n", - tab4, "if method: return method(self)\n", tab4, "raise AttributeError(name)\n\n", NIL); - - Printv(f_shadow, - "def _swig_repr(self):\n", - tab4, "try: strthis = \"proxy of \" + self.this.__repr__()\n", - tab4, "except: strthis = \"\"\n", tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", NIL); - - if (!classic) { - /* Usage of types.ObjectType is deprecated. - * But don't sure wether this would broken old Python? - */ - Printv(f_shadow, -// "import types\n", - "try:\n", -// " _object = types.ObjectType\n", - " _object = object\n", - " _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n", -// "del types\n", - "\n\n", NIL); + String *filen = NewStringf("%s%s.py", SWIG_output_directory(), Char(module)); + // If we don't have an interface then change the module name X to _X + if (interface) + module = interface; + else + Insert(module, 0, "_"); + if ((f_shadow_py = NewFile(filen, "w", SWIG_output_files())) == 0) { + FileErrorDisplay(filen); + SWIG_exit(EXIT_FAILURE); } - } - if (modern) { - Printv(f_shadow, "def _swig_setattr_nondynamic_method(set):\n", tab4, "def set_attr(self,name,value):\n", + Delete(filen); + filen = NULL; + + f_shadow = NewString(""); + f_shadow_imports = NewString(""); + f_shadow_import_stmts = NewString(""); + f_shadow_stubs = NewString(""); + + Printv(f_shadow_import_stmts, "SWIGINTERN void\n", NIL); + Printv(f_shadow_import_stmts, "SWIG_Python_builtin_imports()\n", NIL); + Printv(f_shadow_import_stmts, "{\n", NIL); + Printv(f_shadow_import_stmts, tab4 "PyObject *import_str = NULL;\n", NIL); + + Swig_register_filebyname("shadow", f_shadow); + Swig_register_filebyname("python", f_shadow); + + Swig_banner_target_lang(f_shadow, "#"); + + if (!modern) { + Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL); + } + + if (mod_docstring && Len(mod_docstring)) { + Printv(f_shadow, "\"\"\"\n", mod_docstring, "\n\"\"\"\n\n", NIL); + Delete(mod_docstring); + mod_docstring = NULL; + } + + Printv(f_shadow, "\nfrom sys import version_info\n", NULL); + + if (!builtin && fastproxy) { + Printv(f_shadow, "if version_info >= (3,0,0):\n", NULL); + Printf(f_shadow, tab4 "new_instancemethod = lambda func, inst, cls: %s.SWIG_PyInstanceMethod_New(func)\n", module); + Printv(f_shadow, "else:\n", NULL); + Printv(f_shadow, tab4, "from new import instancemethod as new_instancemethod\n", NULL); + } + + /* Import the C-extension module. This should be a relative import, + * since the shadow module may also have been imported by a relative + * import, and there is thus no guarantee that the C-extension is on + * sys.path. Relative imports must be explicitly specified from 2.6.0 + * onwards (implicit relative imports will raise a DeprecationWarning + * in 2.6, and fail in 2.7 onwards), but the relative import syntax + * isn't available in python 2.4 or earlier, so we have to write some + * code conditional on the python version. + */ + Printv(f_shadow, "if version_info >= (2,6,0):\n", NULL); + Printv(f_shadow, tab4, "def swig_import_helper():\n", NULL); + Printv(f_shadow, tab8, "from os.path import dirname\n", NULL); + Printv(f_shadow, tab8, "import imp\n", NULL); + Printv(f_shadow, tab8, "fp = None\n", NULL); + Printv(f_shadow, tab8, "try:\n", NULL); + Printf(f_shadow, tab4 tab8 "fp, pathname, description = imp.find_module('%s', [dirname(__file__)])\n", module); + Printf(f_shadow, tab8 "except ImportError:\n"); + /* At here, the module may already loaded, so simply import it. */ + Printf(f_shadow, tab4 tab8 "import %s\n", module); + Printf(f_shadow, tab4 tab8 "return %s\n", module); + Printv(f_shadow, tab8 "if fp is not None:\n", NULL); + Printv(f_shadow, tab4 tab8 "try:\n", NULL); + Printf(f_shadow, tab8 tab8 "_mod = imp.load_module('%s', fp, pathname, description)\n", module); + Printv(f_shadow, tab4 tab8, "finally:\n", NULL); + Printv(f_shadow, tab8 tab8, "fp.close()\n", NULL); + Printv(f_shadow, tab4 tab8, "return _mod\n", NULL); + Printf(f_shadow, tab4 "%s = swig_import_helper()\n", module); + Printv(f_shadow, tab4, "del swig_import_helper\n", NULL); + Printv(f_shadow, "else:\n", NULL); + Printf(f_shadow, tab4 "import %s\n", module); + + /* Delete the version_info symbol since we don't use it elsewhere in the + * module. */ + Printv(f_shadow, "del version_info\n", NULL); + + if (builtin) { + Printf(f_shadow, "from %s import *\n", module); + } + if (modern || !classic) { + Printv(f_shadow, "try:\n", tab4, "_swig_property = property\n", "except NameError:\n", tab4, "pass # Python < 2.2 doesn't have 'property'.\n", NULL); + } + /* if (!modern) */ + /* always needed, a class can be forced to be no-modern, such as an exception */ + { + // Python-2.2 object hack + Printv(f_shadow, + "def _swig_setattr_nondynamic(self,class_type,name,value,static=1):\n", + tab4, "if (name == \"thisown\"): return self.this.own(value)\n", + tab4, "if (name == \"this\"):\n", tab4, tab4, "if type(value).__name__ == 'SwigPyObject':\n", tab4, tab8, "self.__dict__[name] = value\n", #ifdef USE_THISOWN - tab4, tab4, "if hasattr(self,name) or (name in (\"this\", \"thisown\")):\n", -#else - tab4, tab4, "if (name == \"thisown\"): return self.this.own(value)\n", tab4, tab4, "if hasattr(self,name) or (name == \"this\"):\n", + tab4, tab8, "if hasattr(value,\"thisown\"): self.__dict__[\"thisown\"] = value.thisown\n", tab4, tab8, "del value.thisown\n", #endif - tab4, tab4, tab4, "set(self,name,value)\n", - tab4, tab4, "else:\n", - tab4, tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n", tab4, "return set_attr\n\n\n", NIL); - } + tab4, tab8, "return\n", tab4, "method = class_type.__swig_setmethods__.get(name,None)\n", tab4, "if method: return method(self,value)\n", +#ifdef USE_THISOWN + tab4, "if (not static) or hasattr(self,name) or (name == \"thisown\"):\n", +#else + tab4, "if (not static) or hasattr(self,name):\n", +#endif + tab4, tab4, "self.__dict__[name] = value\n", + tab4, "else:\n", + tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n\n", + "def _swig_setattr(self,class_type,name,value):\n", tab4, "return _swig_setattr_nondynamic(self,class_type,name,value,0)\n\n", NIL); - if (directorsEnabled()) { - // Try loading weakref.proxy, which is only available in Python 2.1 and higher - Printv(f_shadow, - "try:\n", tab4, "import weakref\n", tab4, "weakref_proxy = weakref.proxy\n", "except:\n", tab4, "weakref_proxy = lambda x: x\n", "\n\n", NIL); - } - // Include some information in the code - Printf(f_header, "\n/*-----------------------------------------------\n @(target):= %s.so\n\ + Printv(f_shadow, + "def _swig_getattr(self,class_type,name):\n", + tab4, "if (name == \"thisown\"): return self.this.own()\n", + tab4, "method = class_type.__swig_getmethods__.get(name,None)\n", + tab4, "if method: return method(self)\n", tab4, "raise AttributeError(name)\n\n", NIL); + + Printv(f_shadow, + "def _swig_repr(self):\n", + tab4, "try: strthis = \"proxy of \" + self.this.__repr__()\n", + tab4, "except: strthis = \"\"\n", tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", NIL); + + if (!classic) { + /* Usage of types.ObjectType is deprecated. + * But don't sure wether this would broken old Python? + */ + Printv(f_shadow, + // "import types\n", + "try:\n", + // " _object = types.ObjectType\n", + " _object = object\n", + " _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n", + // "del types\n", + "\n\n", NIL); + } + } + if (modern) { + Printv(f_shadow, "def _swig_setattr_nondynamic_method(set):\n", tab4, "def set_attr(self,name,value):\n", +#ifdef USE_THISOWN + tab4, tab4, "if hasattr(self,name) or (name in (\"this\", \"thisown\")):\n", +#else + tab4, tab4, "if (name == \"thisown\"): return self.this.own(value)\n", tab4, tab4, "if hasattr(self,name) or (name == \"this\"):\n", +#endif + tab4, tab4, tab4, "set(self,name,value)\n", + tab4, tab4, "else:\n", + tab4, tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n", tab4, "return set_attr\n\n\n", NIL); + } + + if (directorsEnabled()) { + // Try loading weakref.proxy, which is only available in Python 2.1 and higher + Printv(f_shadow, + "try:\n", tab4, "import weakref\n", tab4, "weakref_proxy = weakref.proxy\n", "except:\n", tab4, "weakref_proxy = lambda x: x\n", "\n\n", NIL); + } + } + + // Include some information in the code + Printf(f_header, "\n/*-----------------------------------------------\n @(target):= %s.so\n\ ------------------------------------------------*/\n", module); - } - Printf(f_header, "#if PY_VERSION_HEX >= 0x03000000\n"); Printf(f_header, "# define SWIG_init PyInit_%s\n\n", module); Printf(f_header, "#else\n"); @@ -833,6 +873,11 @@ public: /* the method exported for replacement of new.instancemethod in Python 3 */ add_pyinstancemethod_new(); + if (builtin) { + Printf(f_init, "PyTypeObject *builtin_pytype = 0;\n"); + Printf(f_init, "swig_type_info *builtin_basetype = 0;\n"); + } + /* emit code */ Language::top(n); @@ -858,17 +903,23 @@ public: Printf(f_init, " return;\n"); Printf(f_init, "#endif\n"); Printf(f_init, "}\n"); + if (builtin) + Printf(f_builtins, "} // namespace {\n\n"); Printf(f_wrappers, "#ifdef __cplusplus\n"); Printf(f_wrappers, "}\n"); Printf(f_wrappers, "#endif\n"); if (shadow) { - Printv(f_shadow_py, f_shadow, "\n", NIL); - Printv(f_shadow_py, f_shadow_stubs, "\n", NIL); + if (builtin) { + Printv(f_shadow_import_stmts, "}\n", NIL); + Printv(f_header, f_shadow_import_stmts, NIL); + } + Printv(f_shadow_py, f_shadow, "\n", NIL); + Printv(f_shadow_py, f_shadow_stubs, "\n", NIL); - Close(f_shadow_py); - Delete(f_shadow_py); + Close(f_shadow_py); + Delete(f_shadow_py); } /* Close all of the files */ @@ -885,10 +936,13 @@ public: } Dump(f_wrappers, f_begin); + if (builtin) + Dump(f_builtins, f_begin); Wrapper_pretty_print(f_init, f_begin); Delete(f_header); Delete(f_wrappers); + Delete(f_builtins); Delete(f_init); Delete(f_directors); Delete(f_directors_h); @@ -943,12 +997,24 @@ public: if (!options || (!Getattr(options, "noshadow") && !Getattr(options, "noproxy"))) { Printf(import, "_%s\n", modname); if (!Strstr(f_shadow_imports, import)) { - if (pkg && (!package || Strcmp(pkg, package) != 0)) { - Printf(f_shadow, "import %s.%s\n", pkg, modname); - } else { - Printf(f_shadow, "import %s\n", modname); - } - Printv(f_shadow_imports, import, NULL); + if (pkg && (!package || Strcmp(pkg, package) != 0)) { + if (builtin) { + Printf(f_shadow_import_stmts, tab4 "import_str = PyString_FromString(\"%s.%s\");\n", pkg, modname); + Printf(f_shadow_import_stmts, tab4 "PyImport_Import(import_str);\n"); + Printf(f_shadow_import_stmts, tab4 "Py_XDECREF(import_str);\n"); + } else { + Printf(f_shadow, "import %s.%s\n", pkg, modname); + } + } else { + if (builtin) { + Printf(f_shadow_import_stmts, tab4 "import_str = PyString_FromString(\"%s\");\n", modname); + Printf(f_shadow_import_stmts, tab4 "PyImport_Import(import_str);\n"); + Printf(f_shadow_import_stmts, tab4 "Py_XDECREF(import_str);\n"); + } else { + Printf(f_shadow, "import %s\n", modname); + } + } + Printv(f_shadow_imports, import, NULL); } } } @@ -1696,21 +1762,11 @@ public: * add_method() * ------------------------------------------------------------ */ - void add_method(String *name, String *function, int kw, Node *n = 0, int funpack = 0, int num_required = -1, int num_arguments = -1) { + void add_method(String *name, String *function, int kw, Node *n = 0, int = 0, int = -1, int = -1) { if (!kw) { - if (n && funpack) { - if (num_required == 0 && num_arguments == 0) { - Printf(methods, "\t { (char *)\"%s\", (PyCFunction)%s, METH_NOARGS, ", name, function); - } else if (num_required == 1 && num_arguments == 1) { - Printf(methods, "\t { (char *)\"%s\", (PyCFunction)%s, METH_O, ", name, function); - } else { - Printf(methods, "\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function); - } - } else { Printf(methods, "\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function); - } } else { - Printf(methods, "\t { (char *)\"%s\", (PyCFunction) %s, METH_VARARGS | METH_KEYWORDS, ", name, function); + Printf(methods, "\t { (char *)\"%s\", (PyCFunction) %s, METH_VARARGS | METH_KEYWORDS, ", name, function); } if (!n) { @@ -1741,11 +1797,12 @@ public: /* ------------------------------------------------------------ * dispatchFunction() * ------------------------------------------------------------ */ - void dispatchFunction(Node *n, int funpack = 0) { + void dispatchFunction(Node *n, int funpack = 0, bool builtin_self = false, bool constructor = false) { /* Last node in overloaded chain */ int maxargs; + char const *wrap_return = (builtin_self && constructor) ? "int " : "PyObject *"; String *tmp = NewString(""); String *dispatch; const char *dispatch_code = funpack ? "return %s(self, argc, argv);" : "return %s(self, args);"; @@ -1762,23 +1819,29 @@ public: String *symname = Getattr(n, "sym:name"); String *wname = Swig_name_wrapper(symname); - Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *self, PyObject *args) {", NIL); + Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL); Wrapper_add_local(f, "argc", "int argc"); Printf(tmp, "PyObject *argv[%d]", maxargs + 1); Wrapper_add_local(f, "argv", tmp); if (!fastunpack) { - Wrapper_add_local(f, "ii", "int ii"); - Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n"); - Append(f->code, "argc = (int)PyObject_Length(args);\n"); - Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n", maxargs); - Append(f->code, "argv[ii] = PyTuple_GET_ITEM(args,ii);\n"); - Append(f->code, "}\n"); + bool add_self = builtin_self && !constructor; + Wrapper_add_local(f, "ii", "int ii"); + if (maxargs - (add_self ? 1 : 0) > 0) + Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n"); + Append(f->code, "argc = args ? (int)PyObject_Length(args) : 0;\n"); + if (add_self) + Append(f->code, "argv[0] = self;\n"); + Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n", add_self ? maxargs-1 : maxargs); + Printf(f->code, "argv[ii%s] = PyTuple_GET_ITEM(args,ii);\n", add_self ? " + 1" : ""); + Append(f->code, "}\n"); + if (add_self) + Append(f->code, "argc++;\n"); } else { - String *iname = Getattr(n, "sym:name"); - Printf(f->code, "if (!(argc = SWIG_Python_UnpackTuple(args,\"%s\",0,%d,argv))) SWIG_fail;\n", iname, maxargs); - Append(f->code, "--argc;\n"); + String *iname = Getattr(n, "sym:name"); + Printf(f->code, "if (!(argc = SWIG_Python_UnpackTuple(args,\"%s\",0,%d,argv))) SWIG_fail;\n", iname, maxargs); + Append(f->code, "--argc;\n"); } Replaceall(dispatch, "$args", "self,args"); @@ -1800,16 +1863,17 @@ public: Append(f->code, "fail:\n"); Printf(f->code, "SWIG_SetErrorMsg(PyExc_NotImplementedError," "\"Wrong number or type of arguments for overloaded function '%s'.\\n\"" "\n\" Possible C/C++ prototypes are:\\n\"%s);\n", symname, protoTypes); - Append(f->code, "return NULL;\n"); + Printf(f->code, "return (%s) 0;\n", wrap_return); Delete(protoTypes); } Printv(f->code, "}\n", NIL); Wrapper_print(f, f_wrappers); Node *p = Getattr(n, "sym:previousSibling"); - add_method(symname, wname, 0, p); + if (!builtin_self) + add_method(symname, wname, 0, p); /* Create a shadow for this function (if enabled and not in a member function) */ - if ((shadow) && (!(shadow & PYSHADOW_MEMBER))) { + if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) { emitFunctionShadowHelper(n, f_shadow_stubs, symname, 0); } DelWrapper(f); @@ -1838,12 +1902,14 @@ public: String *iname = Getattr(n, "sym:name"); SwigType *d = Getattr(n, "type"); ParmList *l = Getattr(n, "parms"); + int director_method = 0; Parm *p; int i; char source[64]; Wrapper *f; + String *self_parse; String *parse_args; String *arglist; String *get_pointers; @@ -1855,6 +1921,8 @@ public: int num_required; int num_arguments; + int tuple_required; + int tuple_arguments; int varargs = 0; int allow_kwargs = check_kwargs(n); @@ -1873,7 +1941,10 @@ public: handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0); Delete(cname); } - + bool builtin_self = builtin && in_class && (constructor || (l && Getattr(l, "self"))); + bool builtin_ctor = builtin_self && constructor; + char const *self_param = builtin_self ? "self" : "SWIGUNUSEDPARM(self)"; + char const *wrap_return = builtin_ctor ? "int " : "PyObject *"; if (Getattr(n, "sym:overloaded")) { overname = Getattr(n, "sym:overname"); @@ -1883,6 +1954,7 @@ public: } f = NewWrapper(); + self_parse = NewString(""); parse_args = NewString(""); arglist = NewString(""); get_pointers = NewString(""); @@ -1892,8 +1964,11 @@ public: int allow_thread = threads_enable(n); - Wrapper_add_local(f, "resultobj", "PyObject *resultobj = 0"); - + if (builtin_ctor) + Wrapper_add_local(f, "resultobj", "int resultobj = 0"); + else + Wrapper_add_local(f, "resultobj", "PyObject *resultobj = 0"); + // Emit all of the local variables for holding arguments. emit_parameter_variables(l, f); @@ -1901,8 +1976,12 @@ public: emit_attach_parmmaps(l, f); Setattr(n, "wrap:parms", l); /* Get number of required and total arguments */ - num_arguments = emit_num_arguments(l); - num_required = emit_num_required(l); + tuple_arguments = num_arguments = emit_num_arguments(l); + tuple_required = num_required = emit_num_required(l); + if (builtin_self && !constructor) { + --tuple_arguments; + --tuple_required; + } if (((num_arguments == 0) && (num_required == 0)) || ((num_arguments == 1) && (num_required == 1) && Getattr(l, "self"))) allow_kwargs = 0; varargs = emit_isvarargs(l); @@ -1914,9 +1993,9 @@ public: if (!allow_kwargs || Getattr(n, "sym:overloaded")) { if (!varargs) { - Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); + Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL); } else { - Printv(f->def, "SWIGINTERN PyObject *", wname, "__varargs__", "(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *varargs) {", NIL); + Printv(f->def, "SWIGINTERN ", wrap_return, wname, "__varargs__", "(PyObject *", self_param, ", PyObject *args, PyObject *varargs) {", NIL); } if (allow_kwargs) { Swig_warning(WARN_LANG_OVERLOAD_KEYWORD, input_file, line_number, "Can't use keyword arguments with overloaded functions (%s).\n", Swig_name_decl(n)); @@ -1927,13 +2006,15 @@ public: Swig_warning(WARN_LANG_VARARGS_KEYWORD, input_file, line_number, "Can't wrap varargs with keyword arguments enabled\n"); varargs = 0; } - Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {", NIL); + Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args, PyObject *kwargs) {", NIL); } - if (!allow_kwargs) { - Append(parse_args, " if (!PyArg_ParseTuple(args,(char *)\""); - } else { - Append(parse_args, " if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)\""); - Append(arglist, ",kwnames"); + if (!builtin || !in_class || tuple_arguments > 0) { + if (!allow_kwargs) { + Append(parse_args, " if (!PyArg_ParseTuple(args,(char *)\""); + } else { + Append(parse_args, " if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)\""); + Append(arglist, ",kwnames"); + } } int funpack = modernargs && fastunpack && !varargs && !allow_kwargs; @@ -1967,6 +2048,9 @@ public: } } + if (builtin_self && !builtin_ctor) + Printf(self_parse, "%s = self;\n", funpack ? "swig_obj[0]" : "obj0"); + int use_parse = 0; Append(kwargs, "{"); for (i = 0, p = l; i < num_arguments; i++) { @@ -1977,17 +2061,17 @@ public: SwigType *pt = Getattr(p, "type"); String *pn = Getattr(p, "name"); String *ln = Getattr(p, "lname"); - if (funpack) { - sprintf(source, "swig_obj[%d]", i); - } else { - sprintf(source, "obj%d", i); + if (funpack) + sprintf(source, "swig_obj[%d]", builtin_ctor ? i + 1 : i); + else + sprintf(source, "obj%d", builtin_ctor ? i + 1 : i); + + if (!builtin_self || builtin_ctor || i > 0) { + Putc(',', arglist); + if (i == num_required) + Putc('|', parse_args); /* Optional argument separator */ } - - Putc(',', arglist); - if (i == num_required) - Putc('|', parse_args); /* Optional argument separator */ - /* Keyword argument handling */ if (allow_kwargs) { if (Len(pn)) { @@ -2034,10 +2118,12 @@ public: Setattr(p, "implicitconv", convflag); } - Putc('O', parse_args); + if (i > 0 || !builtin_self || builtin_ctor) + Putc('O', parse_args); if (!funpack) { Wrapper_add_localv(f, source, "PyObject *", source, "= 0", NIL); - Printf(arglist, "&%s", source); + if (!builtin_self || builtin_ctor || i > 0) + Printf(arglist, "&%s", source); } if (i >= num_required) Printv(get_pointers, "if (", source, ") {\n", NIL); @@ -2048,7 +2134,8 @@ public: } else { use_parse = 1; Append(parse_args, parse); - Printf(arglist, "&%s", ln); + if (!builtin_self || builtin_ctor || i > 0) + Printf(arglist, "&%s", ln); } p = Getattr(p, "tmap:in:next"); continue; @@ -2064,7 +2151,7 @@ public: Printv(f->locals, " char * kwnames[] = ", kwargs, ";\n", NIL); } - if (use_parse || allow_kwargs || !modernargs) { + if (tuple_arguments > 0 && (use_parse || allow_kwargs || !modernargs)) { Printf(parse_args, ":%s\"", iname); Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL); funpack = 0; @@ -2074,16 +2161,16 @@ public: Clear(f->def); if (overname) { if (noargs) { - Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL); + Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL); } else { - Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **swig_obj) {", NIL); + Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **swig_obj) {", NIL); } Printf(parse_args, "if ((nobjs < %d) || (nobjs > %d)) SWIG_fail;\n", num_required, num_arguments); } else { if (noargs) { - Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); + Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL); } else { - Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); + Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL); } if (onearg) { Printf(parse_args, "if (!args) SWIG_fail;\n"); @@ -2094,14 +2181,14 @@ public: Printf(parse_args, "if (!SWIG_Python_UnpackTuple(args,\"%s\",%d,%d,0)) SWIG_fail;\n", iname, num_required, num_arguments); } } - } else { - Printf(parse_args, "if(!PyArg_UnpackTuple(args,(char *)\"%s\",%d,%d", iname, num_required, num_arguments); + } else if (tuple_arguments > 0) { + Printf(parse_args, "if(!PyArg_UnpackTuple(args,(char *)\"%s\",%d,%d", iname, tuple_required, tuple_arguments); Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL); } } /* Now piece together the first part of the wrapper function */ - Printv(f->code, parse_args, get_pointers, NIL); + Printv(f->code, self_parse, parse_args, get_pointers, NIL); /* Check for trailing varargs */ if (varargs) { @@ -2227,7 +2314,14 @@ public: /* This part below still needs cleanup */ /* Return the function value */ - if ((tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode))) { + 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); + } + + if (tm) { if (funpack) { Replaceall(tm, "$self", "swig_obj[0]"); } else { @@ -2329,7 +2423,10 @@ public: if (need_cleanup) { Printv(f->code, cleanup, NIL); } - Printv(f->code, " return NULL;\n", NIL); + if (builtin_self && constructor) + Printv(f->code, " return 0;\n", NIL); + else + Printv(f->code, " return NULL;\n", NIL); if (funpack) { @@ -2363,12 +2460,13 @@ public: if (varargs) { DelWrapper(f); f = NewWrapper(); - Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *self, PyObject *args) {", NIL); - Wrapper_add_local(f, "resultobj", "PyObject *resultobj"); + Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL); + Wrapper_add_local(f, "resultobj", constructor && builtin_self ? "int resultobj" : "PyObject *resultobj"); Wrapper_add_local(f, "varargs", "PyObject *varargs"); Wrapper_add_local(f, "newargs", "PyObject *newargs"); - 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); + int first_arg = builtin_self ? 1 : 0; + Printf(f->code, "newargs = PyTuple_GetSlice(args,%d,%d);\n", first_arg, first_arg + num_arguments); + Printf(f->code, "varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args)+1);\n", first_arg + num_arguments); Printf(f->code, "resultobj = %s__varargs__(self,newargs,varargs);\n", wname); Append(f->code, "Py_XDECREF(newargs);\n"); Append(f->code, "Py_XDECREF(varargs);\n"); @@ -2379,17 +2477,19 @@ public: /* Now register the function with the interpreter. */ if (!Getattr(n, "sym:overloaded")) { - add_method(iname, wname, allow_kwargs, n, funpack, num_required, num_arguments); + if (!builtin_self) + add_method(iname, wname, allow_kwargs, n, funpack, num_required, num_arguments); /* Create a shadow for this function (if enabled and not in a member function) */ - if ((shadow) && (!(shadow & PYSHADOW_MEMBER))) { + if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) { emitFunctionShadowHelper(n, in_class ? f_shadow_stubs : f_shadow, iname, allow_kwargs); } } else { if (!Getattr(n, "sym:nextSibling")) { - dispatchFunction(n, funpack); + dispatchFunction(n, funpack, builtin_self, constructor); } } + Delete(self_parse); Delete(parse_args); Delete(arglist); Delete(get_pointers); @@ -2428,17 +2528,14 @@ public: if (!have_globals) { Printf(f_init, "\t PyDict_SetItemString(d,(char*)\"%s\", SWIG_globals());\n", global_name); have_globals = 1; - if ((shadow) && (!(shadow & PYSHADOW_MEMBER))) { + if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) { Printf(f_shadow_stubs, "%s = %s.%s\n", global_name, module, global_name); } } int assignable = is_assignable(n); - if ((shadow) && !assignable) { - if (!in_class) { + if (!builtin && (shadow) && !assignable && !in_class) Printf(f_shadow_stubs, "%s = %s.%s\n", iname, global_name, iname); - } - } String *getname = Swig_name_get(NSPACE_TODO, iname); String *setname = Swig_name_set(NSPACE_TODO, iname); @@ -2516,57 +2613,69 @@ public: * constantWrapper() * ------------------------------------------------------------ */ - virtual int constantWrapper(Node *n) { - String *name = Getattr(n, "name"); - String *iname = Getattr(n, "sym:name"); - SwigType *type = Getattr(n, "type"); - String *rawval = Getattr(n, "rawval"); - String *value = rawval ? rawval : Getattr(n, "value"); - String *tm; - int have_tm = 0; + virtual int constantWrapper(Node *n) { + String *name = Getattr(n, "name"); + String *iname = Getattr(n, "sym:name"); + SwigType *type = Getattr(n, "type"); + String *rawval = Getattr(n, "rawval"); + String *value = rawval ? rawval : Getattr(n, "value"); + String *tm; + int have_tm = 0; - if (!addSymbol(iname, n)) - return SWIG_ERROR; + if (!addSymbol(iname, n)) + return SWIG_ERROR; - /* Special hook for member pointer */ - if (SwigType_type(type) == T_MPOINTER) { - String *wname = Swig_name_wrapper(iname); - String *str = SwigType_str(type, wname); - Printf(f_header, "static %s = %s;\n", str, value); - Delete(str); - value = wname; - } - if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) { - Replaceall(tm, "$source", value); - Replaceall(tm, "$target", name); - Replaceall(tm, "$value", value); - Printf(const_code, "%s,\n", tm); - Delete(tm); - have_tm = 1; - } - if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) { - Replaceall(tm, "$source", value); - Replaceall(tm, "$target", name); - Replaceall(tm, "$value", value); - Printf(f_init, "%s\n", tm); - Delete(tm); - have_tm = 1; - } - if (!have_tm) { - Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); - return SWIG_NOWRAP; - } - if ((shadow) && (!(shadow & PYSHADOW_MEMBER))) { - if (!in_class) { - Printv(f_shadow, iname, " = ", module, ".", iname, "\n", NIL); - } else { - if (!(Getattr(n, "feature:python:callback"))) { - Printv(f_shadow_stubs, iname, " = ", module, ".", iname, "\n", NIL); + /* Special hook for member pointer */ + if (SwigType_type(type) == T_MPOINTER) { + String *wname = Swig_name_wrapper(iname); + String *str = SwigType_str(type, wname); + Printf(f_header, "static %s = %s;\n", str, value); + Delete(str); + value = wname; } - } + + if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) { + Replaceall(tm, "$source", value); + Replaceall(tm, "$target", name); + Replaceall(tm, "$value", value); + Printf(const_code, "%s,\n", tm); + Delete(tm); + have_tm = 1; + } + + if (builtin && in_class) { + Swig_require("builtin_constantWrapper", n, "*sym:name", "builtin_sym:name", NIL); + Setattr(n, "sym:name", Getattr(n, "builtin_sym:name")); + } + + if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) { + Replaceall(tm, "$source", value); + Replaceall(tm, "$target", name); + Replaceall(tm, "$value", value); + Printf(f_init, "%s\n", tm); + Delete(tm); + have_tm = 1; + } + + if (builtin && in_class) + Swig_restore(n); + + if (!have_tm) { + Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); + return SWIG_NOWRAP; + } + + if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) { + if (!in_class) { + Printv(f_shadow, iname, " = ", module, ".", iname, "\n", NIL); + } else { + if (!(Getattr(n, "feature:python:callback"))) { + Printv(f_shadow_stubs, iname, " = ", module, ".", iname, "\n", NIL); + } + } + } + return SWIG_OK; } - return SWIG_OK; - } /* ------------------------------------------------------------ @@ -2581,7 +2690,7 @@ public: return SWIG_ERROR; add_method(name, wrapname, 0); - if (shadow) { + if (!builtin && shadow) { Printv(f_shadow_stubs, name, " = ", module, ".", name, "\n", NIL); } return SWIG_OK; @@ -2796,261 +2905,434 @@ public: /* ------------------------------------------------------------ * classDeclaration() * ------------------------------------------------------------ */ - - virtual int classDeclaration(Node *n) { - if (shadow && !Getattr(n, "feature:onlychildren")) { - Node *mod = Getattr(n, "module"); - if (mod) { - String *importname = NewString(""); - String *modname = Getattr(mod, "name"); - if (Strcmp(modname, mainmodule) != 0) { - // check if the module has a package option - Node *options = Getattr(mod, "options"); - String *pkg = options ? Getattr(options, "package") : 0; - if (pkg && (!package || Strcmp(pkg, package) != 0)) { - Printf(importname, "%s.", pkg); - } - Printf(importname, "%s.", modname); + + virtual bool get_single_base (Node *n, Node **base = NULL) + { + if (base) + *base = NULL; + if (Getattr(n, "single_inh")) + return true; + List *baselist = Getattr(n, "bases"); + if (!baselist || Len(baselist) == 0) { + Setattr(n, "single_inh", "1"); + return true; } - Append(importname, Getattr(n, "sym:name")); - Setattr(n, "python:proxy", importname); - } + if (baselist && Len(baselist) == 1) { + Iterator b = First(baselist); + if (this->get_single_base(b.item)) { + if (base) + *base = b.item; + Setattr(n, "single_inh", "1"); + return true; + } + } + return false; + } + + virtual int classDeclaration(Node *n) { + if (shadow && !Getattr(n, "feature:onlychildren")) { + Node *mod = Getattr(n, "module"); + if (mod) { + String *importname = NewString(""); + String *modname = Getattr(mod, "name"); + if (Strcmp(modname, mainmodule) != 0) { + // check if the module has a package option + Node *options = Getattr(mod, "options"); + String *pkg = options ? Getattr(options, "package") : 0; + if (pkg && (!package || Strcmp(pkg, package) != 0)) { + Printf(importname, "%s.", pkg); + } + Printf(importname, "%s.", modname); + } + Append(importname, Getattr(n, "sym:name")); + Setattr(n, "python:proxy", importname); + } + } + int result = Language::classDeclaration(n); + return result; } - return Language::classDeclaration(n); - } /* ------------------------------------------------------------ * classHandler() * ------------------------------------------------------------ */ - virtual int classHandler(Node *n) { - int oldclassic = classic; - int oldmodern = modern; - File *f_shadow_file = f_shadow; - - if (shadow) { - - /* Create new strings for building up a wrapper function */ - have_constructor = 0; - have_repr = 0; - - if (GetFlag(n, "feature:classic")) { - classic = 1; - modern = 0; - } - if (GetFlag(n, "feature:modern")) { - classic = 0; - modern = 1; - } - if (GetFlag(n, "feature:exceptionclass")) { - classic = 1; - modern = 0; - } - - shadow_indent = (String *) tab4; - - class_name = Getattr(n, "sym:name"); - real_classname = Getattr(n, "name"); - - if (!addSymbol(class_name, n)) - return SWIG_ERROR; - - /* Handle inheritance */ - String *base_class = NewString(""); - List *baselist = Getattr(n, "bases"); - if (baselist && Len(baselist)) { - Iterator b; - b = First(baselist); - while (b.item) { - String *bname = Getattr(b.item, "python:proxy"); - bool ignore = GetFlag(b.item, "feature:ignore") ? true : false; - if (!bname || ignore) { - if (!bname && !ignore) { - Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(n), Getline(n), - "Base class '%s' ignored - unknown module name for base. Either import the appropriate module interface file or specify the name of the module in the %%import directive.\n", SwigType_namestr(Getattr(b.item, "name"))); - } - b = Next(b); - continue; - } - Printv(base_class, bname, NIL); - b = Next(b); - if (b.item) { - Putc(',', base_class); - } - } - } - - /* dealing with abstract base class */ - String *abcs = Getattr(n, "feature:python:abc"); - if (py3 && abcs) { - if (Len(base_class)) { - Putc(',', base_class); - } - Printv(base_class, abcs, NIL); - } - - Printv(f_shadow, "class ", class_name, NIL); - - if (Len(base_class)) { - Printf(f_shadow, "(%s)", base_class); - } else { - if (!classic) { - Printf(f_shadow, modern ? "(object)" : "(_object)"); - } - if (GetFlag(n, "feature:exceptionclass") ) { - Printf(f_shadow, "(Exception)"); - } - } - Printf(f_shadow, ":\n"); - if (have_docstring(n)) { - String *str = docstring(n, AUTODOC_CLASS, tab4); - if (str && Len(str)) - Printv(f_shadow, tab4, str, "\n", NIL); - } - if (!modern) { - Printv(f_shadow, tab4, "__swig_setmethods__ = {}\n", NIL); - if (Len(base_class)) { - Printf(f_shadow, "%sfor _s in [%s]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{}))\n", tab4, base_class); - } - - if (!GetFlag(n, "feature:python:nondynamic")) { - Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr(self, ", class_name, ", name, value)\n", NIL); - } else { - Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr_nondynamic(self, ", class_name, ", name, value)\n", NIL); - } - - Printv(f_shadow, tab4, "__swig_getmethods__ = {}\n", NIL); - if (Len(base_class)) { - Printf(f_shadow, "%sfor _s in [%s]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{}))\n", tab4, base_class); - } - - Printv(f_shadow, tab4, "__getattr__ = lambda self, name: _swig_getattr(self, ", class_name, ", name)\n", NIL); - } else { - Printv(f_shadow, tab4, "thisown = _swig_property(lambda x: x.this.own(), ", "lambda x, v: x.this.own(v), doc='The membership flag')\n", NIL); - /* Add static attribute */ - if (GetFlag(n, "feature:python:nondynamic")) { - Printv(f_shadow_file, - tab4, "__setattr__ = _swig_setattr_nondynamic_method(object.__setattr__)\n", - tab4, "class __metaclass__(type):\n", tab4, tab4, "__setattr__ = _swig_setattr_nondynamic_method(type.__setattr__)\n", NIL); - } - } - } - - /* Emit all of the members */ - - in_class = 1; - - /* Overide the shadow file so we can capture its methods */ - f_shadow = NewString(""); - - Language::classHandler(n); - in_class = 0; - - /* Complete the class */ - if (shadow) { - /* Generate a class registration function */ - { - String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers) - SwigType *smart = 0; - if (smartptr) { - SwigType *cpt = Swig_cparse_type(smartptr); - if (cpt) { - smart = SwigType_typedef_resolve_all(cpt); - Delete(cpt); - } else { - // TODO: report line number of where the feature comes from - Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, real_classname); - } - } - SwigType *ct = Copy(smart ? smart : real_classname); - SwigType_add_pointer(ct); - SwigType *realct = Copy(real_classname); - SwigType_add_pointer(realct); - SwigType_remember(realct); - Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL); - Printv(f_wrappers, " PyObject *obj;\n", NIL); - if (modernargs) { - if (fastunpack) { - Printv(f_wrappers, " if (!SWIG_Python_UnpackTuple(args,(char*)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL); - } else { - Printv(f_wrappers, " if (!PyArg_UnpackTuple(args,(char*)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL); - } - } else { - Printv(f_wrappers, " if (!PyArg_ParseTuple(args,(char*)\"O:swigregister\", &obj)) return NULL;\n", NIL); - } - - Printv(f_wrappers, - " SWIG_TypeNewClientData(SWIGTYPE", SwigType_manglestr(ct), ", SWIG_NewClientData(obj));\n", - " return SWIG_Py_Void();\n", "}\n\n", NIL); - String *cname = NewStringf("%s_swigregister", class_name); - add_method(cname, cname, 0); - Delete(smart); - Delete(cname); - Delete(ct); - Delete(realct); - } - if (!have_constructor) { - Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined", (Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL); - } else if (fastinit) { - - Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL); - Printv(f_wrappers, " return SWIG_Python_InitShadowInstance(args);\n", "}\n\n", NIL); - String *cname = NewStringf("%s_swiginit", class_name); - add_method(cname, cname, 0); - Delete(cname); - } - if (!have_repr) { - /* Supply a repr method for this class */ - String *rname = SwigType_namestr(real_classname); - if (new_repr) { - Printv(f_shadow_file, tab4, "__repr__ = _swig_repr\n", NIL); - } else { - Printv(f_shadow_file, tab4, "def __repr__(self):\n", tab8, "return \"\" % (self.this,)\n", NIL); + void builtin_pre_decl (Node *n, Node *base_node) + { + String *name = Getattr(n, "name"); + String *rname = SwigType_namestr(name); + Printf(f_init, " builtin_pytype = &PySwigBuiltin< %s >::pytype;\n", rname); + Printf(f_init, " builtin_pytype->tp_new = PyType_GenericNew;\n"); + if (base_node) { + String *base_name = Copy(Getattr(base_node, "name")); + SwigType_add_pointer(base_name); + String *base_mname = SwigType_manglestr(base_name); + Printf(f_init, " builtin_basetype = SWIG_MangledTypeQuery(\"%s\");\n", base_mname); + Printf(f_init, " if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) {\n"); + Printf(f_init, " builtin_pytype->tp_base = ((SwigPyClientData*) builtin_basetype->clientdata)->pytype;\n"); + Printf(f_init, " }\n"); + Delete(base_mname); + Delete(base_name); } + Printf(f_init, " builtin_pytype->tp_dict = d = PyDict_New();\n"); Delete(rname); - } - - - /* Now emit methods */ - Printv(f_shadow_file, f_shadow, NIL); - - /* Now the Ptr class */ - if (classptr) { - Printv(f_shadow_file, "\nclass ", class_name, "Ptr(", class_name, "):\n", tab4, "def __init__(self, this):\n", NIL); - if (!modern) { - Printv(f_shadow_file, - tab8, "try: self.this.append(this)\n", - tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL); - } else { - Printv(f_shadow_file, - tab8, "try: self.this.append(this)\n", - tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL); - } - } - - if (fastproxy) { - List *shadow_list = Getattr(n, "shadow_methods"); - for (int i = 0; i < Len(shadow_list); ++i) { - String *symname = Getitem(shadow_list, i); - Printf(f_shadow_file, "%s.%s = new_instancemethod(%s.%s,None,%s)\n", class_name, symname, module, Swig_name_member(NSPACE_TODO, class_name, symname), class_name); - } - } - Printf(f_shadow_file, "%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name); - Printf(f_shadow_file, "%s_swigregister(%s)\n", class_name, class_name); - - shadow_indent = 0; - Printf(f_shadow_file, "%s\n", f_shadow_stubs); - Clear(f_shadow_stubs); } - classic = oldclassic; - modern = oldmodern; - /* Restore shadow file back to original version */ - Delete(f_shadow); - f_shadow = f_shadow_file; + void builtin_post_decl (File *f, Node *n) + { + String *name = Getattr(n, "name"); + String *pname = Copy(name); + SwigType_add_pointer(pname); + String *symname = Getattr(n, "sym:name"); + String *rname = SwigType_namestr(name); + String *mname = SwigType_manglestr(pname); + String *templ = NewString(""); + Printf(templ, "PySwigBuiltin< %s >", rname); + char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : "0"; - return SWIG_OK; - } + // Check for non-public destructor, in which case tp_dealloc should be "0" + String *tp_dealloc = NewString(""); + String *dtor_name = NewString("delete"); + if (Getattr(class_members, "delete")) + Printf(tp_dealloc, "py_builtin_dealloc< %s >", rname); + else + Printv(tp_dealloc, "0", NIL); + Delete(dtor_name); + + Printf(f, "template <> PyTypeObject PySwigBuiltin< %s >::pytype = {\n", rname); + Printf(f, " PyObject_HEAD_INIT(NULL)\n"); + Printf(f, " 0, /*ob_size*/\n"); + Printf(f, " \"%s\", /*tp_name*/\n", symname); + Printf(f, " sizeof(%s), /*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")); + Printf(f, " %s, /*tp_as_number*/\n", getSlot(n, "feature:tp_as_number")); + Printf(f, " %s, /*tp_as_sequence*/\n", getSlot(n, "feature:tp_as_sequence")); + Printf(f, " %s, /*tp_as_mapping*/\n", getSlot(n, "feature:tp_as_mapping")); + 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")); + Printf(f, " %s, /*tp_as_buffer*/\n", getSlot(n, "feature:tp_as_buffer")); + Printf(f, " Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_RICHCOMPARE, /*tp_flags*/\n"); + 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, /* tp_richcompare */\n", getSlot(n, "feature:tp_richcompare")); + Printf(f, " %s, /* tp_weaklistoffset */\n", getSlot(n, "feature:tp_weaklistoffset")); + Printf(f, " %s, /* tp_iter */\n", getSlot(n, "feature:tp_iter")); + Printf(f, " %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, /* tp_getset */\n", getSlot(n, "feature:tp_getset")); + 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")); + Printf(f, " %s, /* tp_dictoffset */\n", getSlot(n, "feature:tp_dictoffset")); + 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")); + Printf(f, "};\n\n"); + + String *clientdata = NewString(""); + Printf(clientdata, "&%s::clientdata", templ); + SwigType_remember_clientdata(pname, clientdata); + + Printf(f, "template <> SwigPyClientData %s::clientdata = {0, 0, 0, 0, 0, 0, &%s::pytype};\n\n", templ, templ); + + Printv(f_init, " d = md;\n", NIL); + Printv(f_init, " if (PyType_Ready(builtin_pytype) < 0) {\n", NIL); + Printf(f_init, " fprintf(stderr, \"Couldn't create type %s\");\n", symname); + Printv(f_init, " return;\n", NIL); + 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); + + Delete(clientdata); + Delete(templ); + Delete(mname); + Delete(rname); + Delete(pname); + Delete(tp_dealloc); + } + + virtual int classHandler(Node *n) { + int oldclassic = classic; + int oldmodern = modern; + File *f_shadow_file = f_shadow; + bool single_inh = false; + Node *base_node = NULL; + + if (shadow) { + + /* Create new strings for building up a wrapper function */ + have_constructor = 0; + have_repr = 0; + + if (GetFlag(n, "feature:classic")) { + classic = 1; + modern = 0; + } + if (GetFlag(n, "feature:modern")) { + classic = 0; + modern = 1; + } + if (GetFlag(n, "feature:exceptionclass")) { + classic = 1; + modern = 0; + } + + class_name = Getattr(n, "sym:name"); + real_classname = Getattr(n, "name"); + + if (!addSymbol(class_name, n)) + return SWIG_ERROR; + + single_inh = builtin && get_single_base(n, &base_node); + if (builtin && !single_inh) { + Swig_warning(WARN_PYTHON_MULTIPLE_INH, Getfile(n), Getline(n), + "Class '%s' ignored, because it has multiple inheritance, which is incompatible with the '-builtin' option.\n", real_classname); + return SWIG_OK; + } + + shadow_indent = (String *) tab4; + + /* Handle inheritance */ + String *base_class = NewString(""); + List *baselist = Getattr(n, "bases"); + if (baselist && Len(baselist)) { + Iterator b; + b = First(baselist); + while (b.item) { + String *bname = Getattr(b.item, "python:proxy"); + bool ignore = GetFlag(b.item, "feature:ignore") ? true : false; + if (!bname || ignore) { + if (!bname && !ignore) { + Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(n), Getline(n), + "Base class '%s' ignored - unknown module name for base. Either import the appropriate module interface file or specify the name of the module in the %%import directive.\n", SwigType_namestr(Getattr(b.item, "name"))); + } + b = Next(b); + continue; + } + Printv(base_class, bname, NIL); + b = Next(b); + if (b.item) { + Putc(',', base_class); + } + } + } + + /* dealing with abstract base class */ + String *abcs = Getattr(n, "feature:python:abc"); + if (py3 && abcs) { + if (Len(base_class)) { + Putc(',', base_class); + } + Printv(base_class, abcs, NIL); + } + + if (!single_inh) { + Printv(f_shadow, "class ", class_name, NIL); + + if (Len(base_class)) { + Printf(f_shadow, "(%s)", base_class); + } else { + if (!classic) { + Printf(f_shadow, modern ? "(object)" : "(_object)"); + } + if (GetFlag(n, "feature:exceptionclass") ) { + Printf(f_shadow, "(Exception)"); + } + } + + Printf(f_shadow, ":\n"); + if (have_docstring(n)) { + String *str = docstring(n, AUTODOC_CLASS, tab4); + if (str && Len(str)) + Printv(f_shadow, tab4, str, "\n", NIL); + } + + if (!modern) { + Printv(f_shadow, tab4, "__swig_setmethods__ = {}\n", NIL); + if (Len(base_class)) { + Printf(f_shadow, "%sfor _s in [%s]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{}))\n", tab4, base_class); + } + + if (!GetFlag(n, "feature:python:nondynamic")) { + Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr(self, ", class_name, ", name, value)\n", NIL); + } else { + Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr_nondynamic(self, ", class_name, ", name, value)\n", NIL); + } + + Printv(f_shadow, tab4, "__swig_getmethods__ = {}\n", NIL); + if (Len(base_class)) { + Printf(f_shadow, "%sfor _s in [%s]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{}))\n", tab4, base_class); + } + + Printv(f_shadow, tab4, "__getattr__ = lambda self, name: _swig_getattr(self, ", class_name, ", name)\n", NIL); + } else { + Printv(f_shadow, tab4, "thisown = _swig_property(lambda x: x.this.own(), ", "lambda x, v: x.this.own(v), doc='The membership flag')\n", NIL); + /* Add static attribute */ + if (GetFlag(n, "feature:python:nondynamic")) { + Printv(f_shadow_file, + tab4, "__setattr__ = _swig_setattr_nondynamic_method(object.__setattr__)\n", + tab4, "class __metaclass__(type):\n", tab4, tab4, "__setattr__ = _swig_setattr_nondynamic_method(type.__setattr__)\n", NIL); + } + } + } + } + + /* Emit all of the members */ + + in_class = 1; + if (single_inh) { + class_members = NewHash(); + builtin_pre_decl(n, base_node); + } + + /* Overide the shadow file so we can capture its methods */ + f_shadow = NewString(""); + + Language::classHandler(n); + + in_class = 0; + + /* Complete the class */ + if (shadow) { + /* Generate a class registration function */ + if (!single_inh) { + String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers) + SwigType *smart = 0; + if (smartptr) { + SwigType *cpt = Swig_cparse_type(smartptr); + if (cpt) { + smart = SwigType_typedef_resolve_all(cpt); + Delete(cpt); + } else { + // TODO: report line number of where the feature comes from + Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, real_classname); + } + } + SwigType *ct = Copy(smart ? smart : real_classname); + SwigType_add_pointer(ct); + SwigType *realct = Copy(real_classname); + SwigType_add_pointer(realct); + SwigType_remember(realct); + Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL); + Printv(f_wrappers, " PyObject *obj;\n", NIL); + if (modernargs) { + if (fastunpack) { + Printv(f_wrappers, " if (!SWIG_Python_UnpackTuple(args,(char*)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL); + } else { + Printv(f_wrappers, " if (!PyArg_UnpackTuple(args,(char*)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL); + } + } else { + Printv(f_wrappers, " if (!PyArg_ParseTuple(args,(char*)\"O:swigregister\", &obj)) return NULL;\n", NIL); + } + + Printv(f_wrappers, + " SWIG_TypeNewClientData(SWIGTYPE", SwigType_manglestr(ct), ", SWIG_NewClientData(obj));\n", + " return SWIG_Py_Void();\n", "}\n\n", NIL); + String *cname = NewStringf("%s_swigregister", class_name); + add_method(cname, cname, 0); + Delete(smart); + Delete(cname); + Delete(ct); + Delete(realct); + } + if (!have_constructor) { + if (!single_inh) + Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined", (Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL); + } else if (fastinit && !single_inh) { + + Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL); + Printv(f_wrappers, " return SWIG_Python_InitShadowInstance(args);\n", "}\n\n", NIL); + String *cname = NewStringf("%s_swiginit", class_name); + add_method(cname, cname, 0); + Delete(cname); + } + if (!have_repr && !single_inh) { + /* Supply a repr method for this class */ + String *rname = SwigType_namestr(real_classname); + if (new_repr) { + Printv(f_shadow_file, tab4, "__repr__ = _swig_repr\n", NIL); + } else { + Printv(f_shadow_file, tab4, "def __repr__(self):\n", tab8, "return \"\" % (self.this,)\n", NIL); + } + Delete(rname); + } + + if (single_inh) { + builtin_post_decl(f_builtins, n); + String *rname = SwigType_namestr(real_classname); + Printf(f_builtins, "template <> PyMethodDef PySwigBuiltin< %s >::methods[] = {\n", rname); + Delete(rname); + } + + if (builtin_tp_init) { + Delete(builtin_tp_init); + builtin_tp_init = 0; + } + + /* Now emit methods */ + if (!single_inh) + Printv(f_shadow_file, f_shadow, NIL); + + /* Now the Ptr class */ + if (classptr && !single_inh) { + Printv(f_shadow_file, "\nclass ", class_name, "Ptr(", class_name, "):\n", tab4, "def __init__(self, this):\n", NIL); + if (!modern) { + Printv(f_shadow_file, + tab8, "try: self.this.append(this)\n", + tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL); + } else { + Printv(f_shadow_file, + tab8, "try: self.this.append(this)\n", + tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL); + } + } + + if (!single_inh) { + if (fastproxy) { + List *shadow_list = Getattr(n, "shadow_methods"); + for (int i = 0; i < Len(shadow_list); ++i) { + String *symname = Getitem(shadow_list, i); + Printf(f_shadow_file, "%s.%s = new_instancemethod(%s.%s,None,%s)\n", class_name, symname, module, Swig_name_member(NSPACE_TODO, class_name, symname), class_name); + } + } + Printf(f_shadow_file, "%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name); + Printf(f_shadow_file, "%s_swigregister(%s)\n", class_name, class_name); + + shadow_indent = 0; + Printf(f_shadow_file, "%s\n", f_shadow_stubs); + } + shadow_indent = 0; + Clear(f_shadow_stubs); + } + + if (single_inh) { + Dump(f_shadow, f_builtins); + Printf(f_builtins, " {NULL} // Sentinel\n};\n\n"); + Delete(class_members); + class_members = 0; + } + + classic = oldclassic; + modern = oldmodern; + + /* Restore shadow file back to original version */ + Delete(f_shadow); + f_shadow = f_shadow_file; + + return SWIG_OK; + } /* ------------------------------------------------------------ * functionHandler() - Mainly overloaded for callback handling @@ -3076,495 +3358,575 @@ public: * memberfunctionHandler() * ------------------------------------------------------------ */ - virtual int memberfunctionHandler(Node *n) { - String *symname = Getattr(n, "sym:name"); - int oldshadow; + virtual int memberfunctionHandler(Node *n) { + String *symname = Getattr(n, "sym:name"); + int oldshadow; - /* Create the default member function */ - oldshadow = shadow; /* Disable shadowing when wrapping member functions */ - if (shadow) - shadow = shadow | PYSHADOW_MEMBER; - Language::memberfunctionHandler(n); - shadow = oldshadow; + /* Create the default member function */ + oldshadow = shadow; /* Disable shadowing when wrapping member functions */ + if (shadow) + shadow = shadow | PYSHADOW_MEMBER; + Language::memberfunctionHandler(n); + shadow = oldshadow; - if (!Getattr(n, "sym:nextSibling")) { - if (shadow) { - int allow_kwargs = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; - int fproxy = fastproxy; - if (Strcmp(symname, "__repr__") == 0) { - have_repr = 1; - } - if (Getattr(n, "feature:shadow")) { - String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); - String *pyaction = NewStringf("%s.%s", module, Swig_name_member(NSPACE_TODO, class_name, symname)); - Replaceall(pycode, "$action", pyaction); - Delete(pyaction); - Printv(f_shadow, pycode, "\n", NIL); - Delete(pycode); - fproxy = 0; - } else { - String *parms = make_pyParmList(n, true, false, allow_kwargs); - String *callParms = make_pyParmList(n, true, true, allow_kwargs); - if (!have_addtofunc(n)) { - if (!fastproxy || olddefs) { - Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":", NIL); - Printv(f_shadow, " return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL); + if (!Getattr(n, "sym:nextSibling")) { + if (builtin && in_class) { + String *name = Getattr(n, "name"); + if (checkAttribute(n, "access", "public") && strncmp(Char(name), "operator ", 9) && !Getattr(class_members, name)) { + String *fullname = Swig_name_member(NULL, class_name, symname); + String *wname = Swig_name_wrapper(fullname); + Setattr(class_members, name, name); + ParmList *parms = Getattr(n, "parms"); + bool noArgs = !parms || Len(parms) == 0; + String *pyflags = NewString(noArgs ? "METH_NOARGS" : "METH_VARARGS"); + Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", Char(name), wname, Char(pyflags)); + Delete(name); + Delete(fullname); + Delete(wname); + Delete(pyflags); + } + } else if (shadow) { + int allow_kwargs = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; + int fproxy = fastproxy; + if (Strcmp(symname, "__repr__") == 0) { + have_repr = 1; + } + if (Getattr(n, "feature:shadow")) { + String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); + String *pyaction = NewStringf("%s.%s", module, Swig_name_member(NSPACE_TODO, class_name, symname)); + Replaceall(pycode, "$action", pyaction); + Delete(pyaction); + Printv(f_shadow, pycode, "\n", NIL); + Delete(pycode); + fproxy = 0; + } else { + String *parms = make_pyParmList(n, true, false, allow_kwargs); + String *callParms = make_pyParmList(n, true, true, allow_kwargs); + if (!have_addtofunc(n)) { + if (!fastproxy || olddefs) { + Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":", NIL); + Printv(f_shadow, " return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL); + } + } else { + Printv(f_shadow, tab4, "def ", symname, "(",parms , ")", returnTypeAnnotation(n), ":", NIL); + Printv(f_shadow, "\n", NIL); + if (have_docstring(n)) + Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL); + if (have_pythonprepend(n)) { + fproxy = 0; + Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); + } + if (have_pythonappend(n)) { + fproxy = 0; + Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL); + Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL); + Printv(f_shadow, tab8, "return val\n\n", NIL); + } else { + Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL); + } + } + } + if (fproxy) { + List *shadow_list = Getattr(getCurrentClass(), "shadow_methods"); + if (!shadow_list) { + shadow_list = NewList(); + Setattr(getCurrentClass(), "shadow_methods", shadow_list); + Delete(shadow_list); + } + Append(shadow_list, symname); + } } - } else { - Printv(f_shadow, tab4, "def ", symname, "(",parms , ")", returnTypeAnnotation(n), ":", NIL); - Printv(f_shadow, "\n", NIL); - if (have_docstring(n)) - Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL); - if (have_pythonprepend(n)) { - fproxy = 0; - Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); - } - if (have_pythonappend(n)) { - fproxy = 0; - Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL); - Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL); - Printv(f_shadow, tab8, "return val\n\n", NIL); - } else { - Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL); - } - } } - if (fproxy) { - List *shadow_list = Getattr(getCurrentClass(), "shadow_methods"); - if (!shadow_list) { - shadow_list = NewList(); - Setattr(getCurrentClass(), "shadow_methods", shadow_list); - Delete(shadow_list); - } - Append(shadow_list, symname); - } - } + return SWIG_OK; } - return SWIG_OK; - } /* ------------------------------------------------------------ * staticmemberfunctionHandler() * ------------------------------------------------------------ */ - virtual int staticmemberfunctionHandler(Node *n) { - String *symname = Getattr(n, "sym:name"); - Language::staticmemberfunctionHandler(n); + 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); + } + Language::staticmemberfunctionHandler(n); + if (builtin && in_class) { + Swig_restore(n); + } - if (Getattr(n, "sym:nextSibling")) { - return SWIG_OK; + if (Getattr(n, "sym:nextSibling")) { + return SWIG_OK; + } + + if (builtin && in_class) { + String *name = Getattr(n, "name"); + if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) { + String *fullname = Swig_name_member(NULL, class_name, name); + String *wname = Swig_name_wrapper(fullname); + Setattr(class_members, name, name); + String *pyflags = NewString("METH_VARARGS|METH_STATIC"); + Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", Char(name), wname, Char(pyflags)); + Delete(name); + Delete(fullname); + Delete(wname); + Delete(pyflags); + } + } else if (shadow ) { + if (!classic && !Getattr(n, "feature:python:callback") && have_addtofunc(n)) { + int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; + String *parms = make_pyParmList(n, false, false, kw); + String *callParms = make_pyParmList(n, false, true, kw); + Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); + if (have_docstring(n)) + Printv(f_shadow, tab8, docstring(n, AUTODOC_STATICFUNC, tab8), "\n", NIL); + if (have_pythonprepend(n)) + Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); + if (have_pythonappend(n)) { + Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL); + Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL); + Printv(f_shadow, tab8, "return val\n\n", NIL); + } else { + Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL); + } + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", symname, ")\n", NIL); + + if (!modern) { + Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", symname, "\n", NIL); + } + + } else { + if (!modern) { + Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL); + } + if (!classic) { + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), ")\n", NIL); + } + } + } + return SWIG_OK; } - if (shadow) { - if (!classic && !Getattr(n, "feature:python:callback") && have_addtofunc(n)) { - int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; - String *parms = make_pyParmList(n, false, false, kw); - String *callParms = make_pyParmList(n, false, true, kw); - Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); - if (have_docstring(n)) - Printv(f_shadow, tab8, docstring(n, AUTODOC_STATICFUNC, tab8), "\n", NIL); - if (have_pythonprepend(n)) - Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); - if (have_pythonappend(n)) { - Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL); - Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL); - Printv(f_shadow, tab8, "return val\n\n", NIL); - } else { - Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL); - } - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", symname, ")\n", NIL); - - if (!modern) { - Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", symname, "\n", NIL); - } - - } else { - if (!modern) { - Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL); - } - if (!classic) { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), ")\n", NIL); - } - } - } - return SWIG_OK; - } - /* ------------------------------------------------------------ * constructorDeclaration() * ------------------------------------------------------------ */ - virtual int constructorHandler(Node *n) { - String *symname = Getattr(n, "sym:name"); - int oldshadow = shadow; - int use_director = Swig_directorclass(n); + virtual int constructorHandler(Node *n) { + String *symname = Getattr(n, "sym:name"); + int oldshadow = shadow; + int use_director = Swig_directorclass(n); - /* - * If we're wrapping the constructor of a C++ director class, prepend a new parameter - * to receive the scripting language object (e.g. 'self') - * - */ - Swig_save("python:constructorHandler", n, "parms", NIL); - if (use_director) { - Parm *parms = Getattr(n, "parms"); - Parm *self; - String *name = NewString("self"); - String *type = NewString("PyObject"); - SwigType_add_pointer(type); - self = NewParm(type, name, n); - Delete(type); - Delete(name); - Setattr(self, "lname", "O"); - if (parms) - set_nextSibling(self, parms); - Setattr(n, "parms", self); - Setattr(n, "wrap:self", "1"); - Setattr(n, "hidden", "1"); - Delete(self); - } - - if (shadow) - shadow = shadow | PYSHADOW_MEMBER; - Language::constructorHandler(n); - shadow = oldshadow; - - Delattr(n, "wrap:self"); - Swig_restore(n); - - if (!Getattr(n, "sym:nextSibling")) { - if (shadow) { - int allow_kwargs = (check_kwargs(n) && (!Getattr(n, "sym:overloaded"))) ? 1 : 0; - int handled_as_init = 0; - if (!have_constructor) { - String *nname = Getattr(n, "sym:name"); - String *sname = Getattr(getCurrentClass(), "sym:name"); - String *cname = Swig_name_construct(NSPACE_TODO, sname); - handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0); - Delete(cname); + /* + * If we're wrapping the constructor of a C++ director class, prepend a new parameter + * to receive the scripting language object (e.g. 'self') + * + */ + Swig_save("python:constructorHandler", n, "parms", NIL); + if (use_director) { + Parm *parms = Getattr(n, "parms"); + Parm *self; + String *name = NewString("self"); + String *type = NewString("PyObject"); + SwigType_add_pointer(type); + self = NewParm(type, name, n); + Delete(type); + Delete(name); + Setattr(self, "lname", "O"); + if (parms) + set_nextSibling(self, parms); + Setattr(n, "parms", self); + Setattr(n, "wrap:self", "1"); + Setattr(n, "hidden", "1"); + Delete(self); } + + if (shadow) + shadow = shadow | PYSHADOW_MEMBER; + Language::constructorHandler(n); + shadow = oldshadow; + + Delattr(n, "wrap:self"); + Swig_restore(n); + + if (!Getattr(n, "sym:nextSibling")) { + if (builtin && in_class) { + String *name = NewString("new"); + if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) { + Setattr(class_members, name, name); + String *fullname = Swig_name_member(NULL, name, class_name); + if (!builtin_tp_init) + builtin_tp_init = Swig_name_wrapper(fullname); + /* + ParmList *parms = Getattr(n, "parms"); + char const *pyflags = (!parms || Len(parms) == 0) ? "METH_NOARGS" : (Len(parms) == 1) ? "METH_0" : "METH_VARARGS"; + Printf(f_shadow, " { \"__init__\", (PyCFunction) %s, %s, \"\" },\n", builtin_tp_init, Char(pyflags)); + */ + Delete(fullname); + } + Delete(name); + } else if (shadow) { + int allow_kwargs = (check_kwargs(n) && (!Getattr(n, "sym:overloaded"))) ? 1 : 0; + int handled_as_init = 0; + if (!have_constructor) { + String *nname = Getattr(n, "sym:name"); + String *sname = Getattr(getCurrentClass(), "sym:name"); + String *cname = Swig_name_construct(NSPACE_TODO, sname); + handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0); + Delete(cname); + } - if (!have_constructor && handled_as_init) { - if (Getattr(n, "feature:shadow")) { - String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); - String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); - Replaceall(pycode, "$action", pyaction); - Delete(pyaction); - Printv(f_shadow, pycode, "\n", NIL); - Delete(pycode); - } else { - String *pass_self = NewString(""); - Node *parent = Swig_methodclass(n); - String *classname = Swig_class_name(parent); - String *rclassname = Swig_class_name(getCurrentClass()); - assert(rclassname); + if (!have_constructor && handled_as_init) { + if (Getattr(n, "feature:shadow")) { + String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); + String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); + Replaceall(pycode, "$action", pyaction); + Delete(pyaction); + Printv(f_shadow, pycode, "\n", NIL); + Delete(pycode); + } else { + String *pass_self = NewString(""); + Node *parent = Swig_methodclass(n); + String *classname = Swig_class_name(parent); + String *rclassname = Swig_class_name(getCurrentClass()); + assert(rclassname); - String *parms = make_pyParmList(n, true, false, allow_kwargs); - /* Pass 'self' only if using director */ - String *callParms = make_pyParmList(n, false, true, allow_kwargs); + String *parms = make_pyParmList(n, true, false, allow_kwargs); + /* Pass 'self' only if using director */ + String *callParms = make_pyParmList(n, false, true, allow_kwargs); - if (use_director) { - Insert(callParms, 0, "_self, "); - Printv(pass_self, tab8, NIL); - Printf(pass_self, "if self.__class__ == %s:\n", classname); - //Printv(pass_self, tab8, tab4, "args = (None,) + args\n", tab8, "else:\n", tab8, tab4, "args = (self,) + args\n", NIL); - Printv(pass_self, tab8, tab4, "_self = None\n", tab8, "else:\n", tab8, tab4, "_self = self\n", NIL); - } + if (use_director) { + Insert(callParms, 0, "_self, "); + Printv(pass_self, tab8, NIL); + Printf(pass_self, "if self.__class__ == %s:\n", classname); + //Printv(pass_self, tab8, tab4, "args = (None,) + args\n", tab8, "else:\n", tab8, tab4, "args = (self,) + args\n", NIL); + Printv(pass_self, tab8, tab4, "_self = None\n", tab8, "else:\n", tab8, tab4, "_self = self\n", NIL); + } - Printv(f_shadow, tab4, "def __init__(", parms, ")", returnTypeAnnotation(n), ": \n", NIL); - if (have_docstring(n)) - Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL); - if (have_pythonprepend(n)) - Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); - Printv(f_shadow, pass_self, NIL); - if (fastinit) { - Printv(f_shadow, tab8, module, ".", class_name, "_swiginit(self,", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), ")\n", NIL); - } else { - Printv(f_shadow, - tab8, "this = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", - tab8, "try: self.this.append(this)\n", tab8, "except: self.this = this\n", NIL); - } - if (have_pythonappend(n)) - Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n\n", NIL); - Delete(pass_self); - } - have_constructor = 1; - } else { - /* Hmmm. We seem to be creating a different constructor. We're just going to create a - function for it. */ + Printv(f_shadow, tab4, "def __init__(", parms, ")", returnTypeAnnotation(n), ": \n", NIL); + if (have_docstring(n)) + Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL); + if (have_pythonprepend(n)) + Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); + Printv(f_shadow, pass_self, NIL); + if (fastinit) { + Printv(f_shadow, tab8, module, ".", class_name, "_swiginit(self,", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), ")\n", NIL); + } else { + Printv(f_shadow, + tab8, "this = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", + tab8, "try: self.this.append(this)\n", tab8, "except: self.this = this\n", NIL); + } + if (have_pythonappend(n)) + Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n\n", NIL); + Delete(pass_self); + } + have_constructor = 1; + } else { + /* Hmmm. We seem to be creating a different constructor. We're just going to create a + function for it. */ - if (Getattr(n, "feature:shadow")) { - String *pycode = pythoncode(Getattr(n, "feature:shadow"), ""); - String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); - Replaceall(pycode, "$action", pyaction); - Delete(pyaction); - Printv(f_shadow_stubs, pycode, "\n", NIL); - Delete(pycode); - } else { - String *parms = make_pyParmList(n, false, false, allow_kwargs); - String *callParms = make_pyParmList(n, false, true, allow_kwargs); + if (Getattr(n, "feature:shadow")) { + String *pycode = pythoncode(Getattr(n, "feature:shadow"), ""); + String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); + Replaceall(pycode, "$action", pyaction); + Delete(pyaction); + Printv(f_shadow_stubs, pycode, "\n", NIL); + Delete(pycode); + } else { + String *parms = make_pyParmList(n, false, false, allow_kwargs); + String *callParms = make_pyParmList(n, false, true, allow_kwargs); - Printv(f_shadow_stubs, "\ndef ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); - if (have_docstring(n)) - Printv(f_shadow_stubs, tab4, docstring(n, AUTODOC_CTOR, tab4), "\n", NIL); - if (have_pythonprepend(n)) - Printv(f_shadow_stubs, pythoncode(pythonprepend(n), tab4), "\n", NIL); - Printv(f_shadow_stubs, tab4, "val = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", NIL); + Printv(f_shadow_stubs, "\ndef ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); + if (have_docstring(n)) + Printv(f_shadow_stubs, tab4, docstring(n, AUTODOC_CTOR, tab4), "\n", NIL); + if (have_pythonprepend(n)) + Printv(f_shadow_stubs, pythoncode(pythonprepend(n), tab4), "\n", NIL); + Printv(f_shadow_stubs, tab4, "val = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", NIL); #ifdef USE_THISOWN - Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL); + Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL); #endif - if (have_pythonappend(n)) - Printv(f_shadow_stubs, pythoncode(pythonappend(n), tab4), "\n", NIL); - Printv(f_shadow_stubs, tab4, "return val\n", NIL); - } + if (have_pythonappend(n)) + Printv(f_shadow_stubs, pythoncode(pythonappend(n), tab4), "\n", NIL); + Printv(f_shadow_stubs, tab4, "return val\n", NIL); + } + } + } } - } + return SWIG_OK; } - return SWIG_OK; - } /* ------------------------------------------------------------ * destructorHandler() * ------------------------------------------------------------ */ - virtual int destructorHandler(Node *n) { - String *symname = Getattr(n, "sym:name"); - int oldshadow = shadow; - - if (shadow) - shadow = shadow | PYSHADOW_MEMBER; - //Setattr(n,"emit:dealloc","1"); - Language::destructorHandler(n); - shadow = oldshadow; - if (shadow) { - if (Getattr(n, "feature:shadow")) { - String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); - String *pyaction = NewStringf("%s.%s", module, Swig_name_destroy(NSPACE_TODO, symname)); - Replaceall(pycode, "$action", pyaction); - Delete(pyaction); - Printv(f_shadow, pycode, "\n", NIL); - Delete(pycode); - } else { - Printv(f_shadow, tab4, "__swig_destroy__ = ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "\n", NIL); - if (!have_pythonprepend(n) && !have_pythonappend(n)) { - if (proxydel) { - Printv(f_shadow, tab4, "__del__ = lambda self : None;\n", NIL); - } - return SWIG_OK; + virtual int destructorHandler(Node *n) { + if (builtin && in_class) { + String *name = NewString("delete"); + if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) { + Setattr(class_members, name, name); + /* + String *fullname = Swig_name_member(NULL, name, class_name); + String *wname = Swig_name_wrapper(fullname); + ParmList *parms = Getattr(n, "parms"); + char const *pyflags = (!parms || Len(parms) == 0) ? "METH_NOARGS" : (Len(parms) == 1) ? "METH_0" : "METH_VARARGS"; + Printf(f_shadow, " { \"__del__\", (PyCFunction) %s, %s, \"\" },\n", wname, Char(pyflags)); + Delete(fullname); + Delete(wname); + */ + } + Delete(name); + return SWIG_OK; } - Printv(f_shadow, tab4, "def __del__(self):\n", NIL); - if (have_docstring(n)) - Printv(f_shadow, tab8, docstring(n, AUTODOC_DTOR, tab8), "\n", NIL); - if (have_pythonprepend(n)) - Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); + + String *symname = Getattr(n, "sym:name"); + int oldshadow = shadow; + + if (shadow) + shadow = shadow | PYSHADOW_MEMBER; + //Setattr(n,"emit:dealloc","1"); + Language::destructorHandler(n); + shadow = oldshadow; + + if (shadow) { + if (Getattr(n, "feature:shadow")) { + String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); + String *pyaction = NewStringf("%s.%s", module, Swig_name_destroy(NSPACE_TODO, symname)); + Replaceall(pycode, "$action", pyaction); + Delete(pyaction); + Printv(f_shadow, pycode, "\n", NIL); + Delete(pycode); + } else { + Printv(f_shadow, tab4, "__swig_destroy__ = ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "\n", NIL); + if (!have_pythonprepend(n) && !have_pythonappend(n)) { + if (proxydel) { + Printv(f_shadow, tab4, "__del__ = lambda self : None;\n", NIL); + } + return SWIG_OK; + } + Printv(f_shadow, tab4, "def __del__(self):\n", NIL); + if (have_docstring(n)) + Printv(f_shadow, tab8, docstring(n, AUTODOC_DTOR, tab8), "\n", NIL); + if (have_pythonprepend(n)) + Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); #ifdef USE_THISOWN - Printv(f_shadow, tab8, "try:\n", NIL); - Printv(f_shadow, tab8, tab4, "if self.thisown: ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "(self)\n", NIL); - Printv(f_shadow, tab8, "except: pass\n", NIL); + Printv(f_shadow, tab8, "try:\n", NIL); + Printv(f_shadow, tab8, tab4, "if self.thisown: ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "(self)\n", NIL); + Printv(f_shadow, tab8, "except: pass\n", NIL); #else #endif - if (have_pythonappend(n)) - Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL); - Printv(f_shadow, tab8, "pass\n", NIL); - Printv(f_shadow, "\n", NIL); - } - } - return SWIG_OK; - } - - /* ------------------------------------------------------------ - * membervariableHandler() - * ------------------------------------------------------------ */ - - virtual int membervariableHandler(Node *n) { - String *symname = Getattr(n, "sym:name"); - - int oldshadow = shadow; - if (shadow) - shadow = shadow | PYSHADOW_MEMBER; - Language::membervariableHandler(n); - shadow = oldshadow; - - if (shadow) { - String *mname = Swig_name_member(NSPACE_TODO, class_name, symname); - String *setname = Swig_name_set(NSPACE_TODO, mname); - String *getname = Swig_name_get(NSPACE_TODO, mname); - if (shadow) { - int assignable = is_assignable(n); - if (!modern) { - if (assignable) { - Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL); - } - Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL); + if (have_pythonappend(n)) + Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL); + Printv(f_shadow, tab8, "pass\n", NIL); + Printv(f_shadow, "\n", NIL); + } } - if (!classic) { - if (!assignable) { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL); - } else { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL); - } + return SWIG_OK; + } + + /* ------------------------------------------------------------ + * membervariableHandler() + * ------------------------------------------------------------ */ + + virtual int membervariableHandler(Node *n) { + String *symname = Getattr(n, "sym:name"); + + int oldshadow = shadow; + if (shadow) + shadow = shadow | PYSHADOW_MEMBER; + Language::membervariableHandler(n); + shadow = oldshadow; + + if (builtin && in_class) { + } else if (shadow) { + String *mname = Swig_name_member(NSPACE_TODO, class_name, symname); + String *setname = Swig_name_set(NSPACE_TODO, mname); + String *getname = Swig_name_get(NSPACE_TODO, mname); + int assignable = is_assignable(n); + if (!modern) { + if (assignable) { + Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL); + } + Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL); + } + if (!classic) { + if (!assignable) { + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL); + } else { + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL); + } + } + Delete(mname); + Delete(setname); + Delete(getname); } - } - Delete(mname); - Delete(setname); - Delete(getname); + + return SWIG_OK; } - return SWIG_OK; - } + /* ------------------------------------------------------------ + * staticmembervariableHandler() + * ------------------------------------------------------------ */ - /* ------------------------------------------------------------ - * staticmembervariableHandler() - * ------------------------------------------------------------ */ + virtual int staticmembervariableHandler(Node *n) { + Swig_save("builtin_staticmembervariableHandler", n, "builtin_symname", NIL); + Language::staticmembervariableHandler(n); + Swig_restore(n); - virtual int staticmembervariableHandler(Node *n) { - Language::staticmembervariableHandler(n); + if (GetFlag(n, "wrappedasconstant")) + return SWIG_OK; - if (shadow && !GetFlag(n, "wrappedasconstant")) { - String *symname = Getattr(n, "sym:name"); - if (GetFlag(n, "hasconsttype")) { - String *mname = Swig_name_member(NSPACE_TODO, class_name, symname); - Printf(f_shadow_stubs, "%s.%s = %s.%s.%s\n", class_name, symname, module, global_name, mname); - Delete(mname); - } else { - String *mname = Swig_name_member(NSPACE_TODO, class_name, symname); - String *getname = Swig_name_get(NSPACE_TODO, mname); - String *wrapgetname = Swig_name_wrapper(getname); - String *vargetname = NewStringf("Swig_var_%s", getname); - String *setname = Swig_name_set(NSPACE_TODO, mname); - String *wrapsetname = Swig_name_wrapper(setname); - String *varsetname = NewStringf("Swig_var_%s", setname); + String *symname = Getattr(n, "sym:name"); - Wrapper *f = NewWrapper(); - Printv(f->def, "SWIGINTERN PyObject *", wrapgetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *SWIGUNUSEDPARM(args)) {", NIL); - Printv(f->code, " return ", vargetname, "();\n", NIL); - Append(f->code, "}\n"); - add_method(getname, wrapgetname, 0); - Wrapper_print(f, f_wrappers); - DelWrapper(f); - int assignable = is_assignable(n); - if (assignable) { - Wrapper *f = NewWrapper(); - Printv(f->def, "SWIGINTERN PyObject *", wrapsetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); - Wrapper_add_local(f, "value", "PyObject *value"); - Wrapper_add_local(f, "res", "int res"); - Append(f->code, "if (!PyArg_ParseTuple(args,(char *)\"O:set\",&value)) return NULL;\n"); - Printv(f->code, "res = ", varsetname, "(value);\n", NIL); - Append(f->code, "return !res ? SWIG_Py_Void() : NULL;\n"); - Append(f->code, "}\n"); - Wrapper_print(f, f_wrappers); - add_method(setname, wrapsetname, 0); - DelWrapper(f); + if (shadow) { + if (GetFlag(n, "hasconsttype")) { + String *mname = Swig_name_member(NSPACE_TODO, class_name, symname); + Printf(f_shadow_stubs, "%s.%s = %s.%s.%s\n", class_name, symname, module, global_name, mname); + Delete(mname); + } else { + String *mname = Swig_name_member(NSPACE_TODO, class_name, symname); + String *getname = Swig_name_get(NSPACE_TODO, mname); + String *wrapgetname = Swig_name_wrapper(getname); + String *vargetname = NewStringf("Swig_var_%s", getname); + String *setname = Swig_name_set(NSPACE_TODO, mname); + String *wrapsetname = Swig_name_wrapper(setname); + String *varsetname = NewStringf("Swig_var_%s", setname); + + Wrapper *f = NewWrapper(); + Printv(f->def, "SWIGINTERN PyObject *", wrapgetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *SWIGUNUSEDPARM(args)) {", NIL); + Printv(f->code, " return ", vargetname, "();\n", NIL); + Append(f->code, "}\n"); + add_method(getname, wrapgetname, 0); + Wrapper_print(f, f_wrappers); + DelWrapper(f); + int assignable = is_assignable(n); + if (assignable) { + Wrapper *f = NewWrapper(); + Printv(f->def, "SWIGINTERN PyObject *", wrapsetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); + Wrapper_add_local(f, "value", "PyObject *value"); + Wrapper_add_local(f, "res", "int res"); + Append(f->code, "if (!PyArg_ParseTuple(args,(char *)\"O:set\",&value)) return NULL;\n"); + Printv(f->code, "res = ", varsetname, "(value);\n", NIL); + Append(f->code, "return !res ? SWIG_Py_Void() : NULL;\n"); + Append(f->code, "}\n"); + Wrapper_print(f, f_wrappers); + add_method(setname, wrapsetname, 0); + DelWrapper(f); + } + if (!modern) { + if (assignable) { + Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL); + } + Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL); + } + if (!classic) { + if (!assignable) { + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL); + } else { + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL); + } + } + Delete(mname); + Delete(getname); + Delete(wrapgetname); + Delete(vargetname); + Delete(setname); + Delete(wrapsetname); + Delete(varsetname); + } } - if (!modern) { - if (assignable) { - Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL); - } - Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL); + return SWIG_OK; + } + + /* ------------------------------------------------------------ + * memberconstantHandler() + * ------------------------------------------------------------ */ + + 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); } - if (!classic) { - if (!assignable) { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL); - } else { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL); - } + int oldshadow = shadow; + if (shadow) + shadow = shadow | PYSHADOW_MEMBER; + Language::memberconstantHandler(n); + shadow = oldshadow; + + if (builtin && in_class) { + Swig_restore(n); + } else if (shadow) { + Printv(f_shadow, tab4, symname, " = ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL); } - Delete(mname); - Delete(getname); - Delete(wrapgetname); - Delete(vargetname); - Delete(setname); - Delete(wrapsetname); - Delete(varsetname); - } + return SWIG_OK; } - return SWIG_OK; - } - /* ------------------------------------------------------------ - * memberconstantHandler() - * ------------------------------------------------------------ */ + /* ------------------------------------------------------------ + * insertDirective() + * + * Hook for %insert directive. We're going to look for special %shadow inserts + * as a special case so we can do indenting correctly + * ------------------------------------------------------------ */ - virtual int memberconstantHandler(Node *n) { - String *symname = Getattr(n, "sym:name"); - int oldshadow = shadow; - if (shadow) - shadow = shadow | PYSHADOW_MEMBER; - Language::memberconstantHandler(n); - shadow = oldshadow; + virtual int insertDirective(Node *n) { + String *code = Getattr(n, "code"); + String *section = Getattr(n, "section"); - if (shadow) { - Printv(f_shadow, tab4, symname, " = ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL); + if ((!ImportMode) && ((Cmp(section, "python") == 0) || (Cmp(section, "shadow") == 0))) { + if (shadow) { + String *pycode = pythoncode(code, shadow_indent); + Printv(f_shadow, pycode, NIL); + Delete(pycode); + } + } else { + Language::insertDirective(n); + } + return SWIG_OK; } - return SWIG_OK; - } - /* ------------------------------------------------------------ - * insertDirective() - * - * Hook for %insert directive. We're going to look for special %shadow inserts - * as a special case so we can do indenting correctly - * ------------------------------------------------------------ */ + virtual String *runtimeCode() { + String *s = NewString(""); + String *shead = Swig_include_sys("pyhead.swg"); + if (!shead) { + Printf(stderr, "*** Unable to open 'pyhead.swg'\n"); + } else { + Append(s, shead); + Delete(shead); + } + String *serrors = Swig_include_sys("pyerrors.swg"); + if (!serrors) { + Printf(stderr, "*** Unable to open 'pyerrors.swg'\n"); + } else { + Append(s, serrors); + Delete(serrors); + } + String *sthread = Swig_include_sys("pythreads.swg"); + if (!sthread) { + Printf(stderr, "*** Unable to open 'pythreads.swg'\n"); + } else { + Append(s, sthread); + Delete(sthread); + } + String *sapi = Swig_include_sys("pyapi.swg"); + if (!sapi) { + Printf(stderr, "*** Unable to open 'pyapi.swg'\n"); + } else { + Append(s, sapi); + Delete(sapi); + } + String *srun = Swig_include_sys("pyrun.swg"); + if (!srun) { + Printf(stderr, "*** Unable to open 'pyrun.swg'\n"); + } else { + Append(s, srun); + Delete(srun); + } + return s; + } - virtual int insertDirective(Node *n) { - String *code = Getattr(n, "code"); - String *section = Getattr(n, "section"); - - if ((!ImportMode) && ((Cmp(section, "python") == 0) || (Cmp(section, "shadow") == 0))) { - if (shadow) { - String *pycode = pythoncode(code, shadow_indent); - Printv(f_shadow, pycode, NIL); - Delete(pycode); - } - } else { - Language::insertDirective(n); + virtual String *defaultExternalRuntimeFilename() { + return NewString("swigpyrun.h"); } - return SWIG_OK; - } - - virtual String *runtimeCode() { - String *s = NewString(""); - String *shead = Swig_include_sys("pyhead.swg"); - if (!shead) { - Printf(stderr, "*** Unable to open 'pyhead.swg'\n"); - } else { - Append(s, shead); - Delete(shead); - } - String *serrors = Swig_include_sys("pyerrors.swg"); - if (!serrors) { - Printf(stderr, "*** Unable to open 'pyerrors.swg'\n"); - } else { - Append(s, serrors); - Delete(serrors); - } - String *sthread = Swig_include_sys("pythreads.swg"); - if (!sthread) { - Printf(stderr, "*** Unable to open 'pythreads.swg'\n"); - } else { - Append(s, sthread); - Delete(sthread); - } - String *sapi = Swig_include_sys("pyapi.swg"); - if (!sapi) { - Printf(stderr, "*** Unable to open 'pyapi.swg'\n"); - } else { - Append(s, sapi); - Delete(sapi); - } - String *srun = Swig_include_sys("pyrun.swg"); - if (!srun) { - Printf(stderr, "*** Unable to open 'pyrun.swg'\n"); - } else { - Append(s, srun); - Delete(srun); - } - return s; - } - - virtual String *defaultExternalRuntimeFilename() { - return NewString("swigpyrun.h"); - } }; From 399ae62561459b913bb25a4aab03642ff52d8c4b Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Wed, 8 Dec 2010 21:57:27 +0000 Subject: [PATCH 03/56] Basic director support (passes first few director tests). Now fails on iadd_runme, because member variable support is missing. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12340 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/director.swg | 11 ++++++ Lib/python/pyrun.swg | 2 + Source/Modules/python.cxx | 81 +++++++++++++++++++++++++-------------- 3 files changed, 66 insertions(+), 28 deletions(-) diff --git a/Lib/python/director.swg b/Lib/python/director.swg index fcd174711..00ab9b03f 100644 --- a/Lib/python/director.swg +++ b/Lib/python/director.swg @@ -459,6 +459,17 @@ namespace Swig { } return own; } + + template + static PyObject* pyobj_disown (PyObject *pyobj, PyObject *SWIGUNUSEDPARM(args)) + { + SwigPyObject *sobj = (SwigPyObject *) pyobj; + sobj->own = 0; + Director *d = SWIG_DIRECTOR_CAST(reinterpret_cast<_Tp*>(sobj->ptr)); + if (d) d->swig_disown(); + return SWIG_Py_Void(); + } + }; #ifdef __THREAD__ diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 432d5dcf6..6221dbcc1 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1376,6 +1376,8 @@ SWIG_Python_NewBuiltinObj(PyObject *self, void *ptr, swig_type_info *type, int f SwigPyObject *newobj = (SwigPyObject*) self; newobj->ptr = ptr; newobj->own = own; + newobj->ty = type; + newobj->next = 0; return 0; } diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 6d6b060d3..618f15f9e 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -873,11 +873,6 @@ public: /* the method exported for replacement of new.instancemethod in Python 3 */ add_pyinstancemethod_new(); - if (builtin) { - Printf(f_init, "PyTypeObject *builtin_pytype = 0;\n"); - Printf(f_init, "swig_type_info *builtin_basetype = 0;\n"); - } - /* emit code */ Language::top(n); @@ -1826,7 +1821,8 @@ public: Wrapper_add_local(f, "argv", tmp); if (!fastunpack) { - bool add_self = builtin_self && !constructor; + bool director_class = (getCurrentClass() && Swig_directorclass(getCurrentClass())); + bool add_self = builtin_self && (!constructor || director_class); Wrapper_add_local(f, "ii", "int ii"); if (maxargs - (add_self ? 1 : 0) > 0) Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n"); @@ -1943,6 +1939,7 @@ public: } bool builtin_self = builtin && in_class && (constructor || (l && Getattr(l, "self"))); bool builtin_ctor = builtin_self && constructor; + bool director_class = (getCurrentClass() && Swig_directorclass(getCurrentClass())); char const *self_param = builtin_self ? "self" : "SWIGUNUSEDPARM(self)"; char const *wrap_return = builtin_ctor ? "int " : "PyObject *"; @@ -1978,7 +1975,7 @@ public: /* Get number of required and total arguments */ tuple_arguments = num_arguments = emit_num_arguments(l); tuple_required = num_required = emit_num_required(l); - if (builtin_self && !constructor) { + if (builtin_self && (!constructor || (constructor && director_class))) { --tuple_arguments; --tuple_required; } @@ -2051,9 +2048,13 @@ public: if (builtin_self && !builtin_ctor) Printf(self_parse, "%s = self;\n", funpack ? "swig_obj[0]" : "obj0"); + if (constructor && director_class) + Printv(self_parse, funpack ? "swig_obj[1]" : "obj1", " = self;\n", NIL); + int use_parse = 0; Append(kwargs, "{"); for (i = 0, p = l; i < num_arguments; i++) { + bool parse_from_tuple = (i > 0 || !builtin_self || (builtin_ctor && !director_class)); while (checkAttribute(p, "tmap:in:numinputs", "0")) { p = Getattr(p, "tmap:in:next"); } @@ -2066,7 +2067,7 @@ public: else sprintf(source, "obj%d", builtin_ctor ? i + 1 : i); - if (!builtin_self || builtin_ctor || i > 0) { + if (parse_from_tuple) { Putc(',', arglist); if (i == num_required) Putc('|', parse_args); /* Optional argument separator */ @@ -2118,11 +2119,13 @@ public: Setattr(p, "implicitconv", convflag); } - if (i > 0 || !builtin_self || builtin_ctor) + bool parse_from_tuple = (i > 0 || !builtin_self || (builtin_ctor && !director_class)); + + if (parse_from_tuple) Putc('O', parse_args); if (!funpack) { Wrapper_add_localv(f, source, "PyObject *", source, "= 0", NIL); - if (!builtin_self || builtin_ctor || i > 0) + if (parse_from_tuple) Printf(arglist, "&%s", source); } if (i >= num_required) @@ -2134,7 +2137,7 @@ public: } else { use_parse = 1; Append(parse_args, parse); - if (!builtin_self || builtin_ctor || i > 0) + if (parse_from_tuple) Printf(arglist, "&%s", ln); } p = Getattr(p, "tmap:in:next"); @@ -2882,17 +2885,21 @@ public: result = Language::classDirectorDisown(n); shadow = oldshadow; if (shadow) { - String *symname = Getattr(n, "sym:name"); - String *mrename = Swig_name_disown(NSPACE_TODO, symname); //Getattr(n, "name")); - Printv(f_shadow, tab4, "def __disown__(self):\n", NIL); + if (builtin) { + Printf(f_shadow, tab4, "{ \"disown\", (PyCFunction) Swig::Director::pyobj_disown< %s >, METH_NOARGS, \"\" },\n", real_classname); + } else { + String *symname = Getattr(n, "sym:name"); + String *mrename = Swig_name_disown(NSPACE_TODO, symname); //Getattr(n, "name")); + Printv(f_shadow, tab4, "def __disown__(self):\n", NIL); #ifdef USE_THISOWN - Printv(f_shadow, tab8, "self.thisown = 0\n", NIL); + Printv(f_shadow, tab8, "self.thisown = 0\n", NIL); #else - Printv(f_shadow, tab8, "self.this.disown()\n", NIL); + Printv(f_shadow, tab8, "self.this.disown()\n", NIL); #endif - Printv(f_shadow, tab8, module, ".", mrename, "(self)\n", NIL); - Printv(f_shadow, tab8, "return weakref_proxy(self)\n", NIL); - Delete(mrename); + Printv(f_shadow, tab8, module, ".", mrename, "(self)\n", NIL); + Printv(f_shadow, tab8, "return weakref_proxy(self)\n", NIL); + Delete(mrename); + } } return result; } @@ -2960,20 +2967,23 @@ public: { String *name = Getattr(n, "name"); String *rname = SwigType_namestr(name); - Printf(f_init, " builtin_pytype = &PySwigBuiltin< %s >::pytype;\n", rname); - Printf(f_init, " builtin_pytype->tp_new = PyType_GenericNew;\n"); + Printf(f_init, tab4 "builtin_pytype = &PySwigBuiltin< %s >::pytype;\n", rname); + Printf(f_init, tab4 "builtin_pytype->tp_new = PyType_GenericNew;\n"); if (base_node) { String *base_name = Copy(Getattr(base_node, "name")); SwigType_add_pointer(base_name); String *base_mname = SwigType_manglestr(base_name); - Printf(f_init, " builtin_basetype = SWIG_MangledTypeQuery(\"%s\");\n", base_mname); - Printf(f_init, " if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) {\n"); - Printf(f_init, " builtin_pytype->tp_base = ((SwigPyClientData*) builtin_basetype->clientdata)->pytype;\n"); - Printf(f_init, " }\n"); + Printf(f_init, tab4 "builtin_basetype = SWIG_MangledTypeQuery(\"%s\");\n", base_mname); + Printf(f_init, tab4 "if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) {\n"); + Printf(f_init, tab8 "builtin_pytype->tp_base = ((SwigPyClientData*) builtin_basetype->clientdata)->pytype;\n"); + Printf(f_init, tab4 "}\n"); Delete(base_mname); Delete(base_name); + } else { + //Printv(f_init, tab4, "builtin_pytype->tp_base = SwigPyObject_type();\n", NIL); + Printv(f_init, tab4, "builtin_pytype->tp_base = &PyBaseObject_Type;\n", NIL); } - Printf(f_init, " builtin_pytype->tp_dict = d = PyDict_New();\n"); + Printf(f_init, tab4 "builtin_pytype->tp_dict = d = PyDict_New();\n"); Delete(rname); } @@ -3019,7 +3029,7 @@ public: Printf(f, " %s, /*tp_getattro*/\n", getSlot(n, "feature:tp_getattro")); Printf(f, " %s, /*tp_setattro*/\n", getSlot(n, "feature:tp_setattro")); Printf(f, " %s, /*tp_as_buffer*/\n", getSlot(n, "feature:tp_as_buffer")); - Printf(f, " Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_RICHCOMPARE, /*tp_flags*/\n"); + Printf(f, " Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_RICHCOMPARE, /*tp_flags*/\n"); 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")); @@ -3200,6 +3210,21 @@ public: /* Overide the shadow file so we can capture its methods */ f_shadow = NewString(""); + // Set up type check for director class constructor + Clear(none_comparison); + if (builtin && Swig_directorclass(n)) { + String *p_real_classname = Copy(real_classname); + SwigType_add_pointer(p_real_classname); + String *mangle = SwigType_manglestr(p_real_classname); + String *descriptor = NewStringf("SWIGTYPE%s", mangle); + Printv(none_comparison, "self->ob_type != ((SwigPyClientData*) (", descriptor, ")->clientdata)->pytype", NIL); + Delete(descriptor); + Delete(mangle); + Delete(p_real_classname); + } else { + Printv(none_comparison, "$arg != Py_None", NIL); + } + Language::classHandler(n); in_class = 0; @@ -3551,7 +3576,7 @@ public: if (!Getattr(n, "sym:nextSibling")) { if (builtin && in_class) { String *name = NewString("new"); - if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) { + if ((use_director || checkAttribute(n, "access", "public")) && !Getattr(class_members, name)) { Setattr(class_members, name, name); String *fullname = Swig_name_member(NULL, name, class_name); if (!builtin_tp_init) From b1682d4d8010991d1735778fc2a873a198d3391b Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Tue, 14 Dec 2010 00:08:45 +0000 Subject: [PATCH 04/56] Added support for operator overrides (PyNumberMethods) and member variable access. test suite now croaks on inplaceadd. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12345 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/builtin.swg | 40 + Lib/python/pyopers.swg | 82 +- Lib/python/pyrun.swg | 7 +- Source/Modules/python.cxx | 3559 +++++++++++++++++++------------------ 4 files changed, 1933 insertions(+), 1755 deletions(-) diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index 556b113af..fde5339d5 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -1,3 +1,18 @@ +extern int +pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure) +{ + if (!closure) + return -1; + PyObject *tuple = PyTuple_New(1); + assert(tuple); + PyTuple_SET_ITEM(tuple, 0, val); + Py_XINCREF(val); + PyObject *result = ((PyCFunction) closure)(obj, tuple); + Py_DECREF(tuple); + Py_XDECREF(result); + return result ? 0 : -1; +} + #ifdef __cplusplus namespace { @@ -10,6 +25,8 @@ template struct PySwigBuiltin : public SwigPyObject { typedef obj_type& reference; static PyMethodDef methods[]; + static PyGetSetDef getset[]; + static PyNumberMethods number_methods; static PyTypeObject pytype; static SwigPyClientData clientdata; }; @@ -23,6 +40,29 @@ template void py_builtin_dealloc (PyObject *pyobj) (*pyobj->ob_type->tp_free)(pyobj); } +template PyObject* +pyswig_binaryfunc_closure (PyObject *a, PyObject *b) +{ + PyObject *tuple = PyTuple_New(1); + assert(tuple); + PyTuple_SET_ITEM(tuple, 0, b); + PyObject *result = func(a, tuple); + Py_DECREF(tuple); + return result; +} + +template PyObject* +pyswig_ternaryfunc_closure (PyObject *a, PyObject *b, PyObject *c) +{ + PyObject *tuple = PyTuple_New(2); + assert(tuple); + PyTuple_SET_ITEM(tuple, 0, b); + PyTuple_SET_ITEM(tuple, 1, c); + PyObject *result = func(a, tuple); + Py_DECREF(tuple); + return result; +} + } // namespace { #endif diff --git a/Lib/python/pyopers.swg b/Lib/python/pyopers.swg index 30775b84e..3074eaa9e 100644 --- a/Lib/python/pyopers.swg +++ b/Lib/python/pyopers.swg @@ -5,41 +5,53 @@ #ifdef __cplusplus -#define %pybinoperator(pyname,oper) %rename(pyname) oper; %pythonmaybecall oper - -%pybinoperator(__add__, *::operator+); -%pybinoperator(__pos__, *::operator+()); -%pybinoperator(__pos__, *::operator+() const); -%pybinoperator(__sub__, *::operator-); -%pybinoperator(__neg__, *::operator-()); -%pybinoperator(__neg__, *::operator-() const); -%pybinoperator(__mul__, *::operator*); -%pybinoperator(__div__, *::operator/); -%pybinoperator(__mod__, *::operator%); -%pybinoperator(__lshift__, *::operator<<); -%pybinoperator(__rshift__, *::operator>>); -%pybinoperator(__and__, *::operator&); -%pybinoperator(__or__, *::operator|); -%pybinoperator(__xor__, *::operator^); -%pybinoperator(__lt__, *::operator<); -%pybinoperator(__le__, *::operator<=); -%pybinoperator(__gt__, *::operator>); -%pybinoperator(__ge__, *::operator>=); -%pybinoperator(__eq__, *::operator==); -%pybinoperator(__ne__, *::operator!=); +#if defined(SWIGPYTHON_BUILTIN) +#define %pybinoperator(pyname,oper,functp,slot) %rename(pyname) oper; %pythonmaybecall oper; %feature("pyslot", #slot, functype=#functp) oper; +#define %pycompare(pyname,oper,comptype) %rename(pyname) oper; %pythonmaybecall oper; %feature("pycompare", #comptype) oper; +#else +#define %pybinoperator(pyname,oper,functp,slot) %rename(pyname) oper; %pythonmaybecall oper +#define %pycompare(pyname,oper,comptype) %pybinoperator(pyname,oper,,comptype) +#endif +%pybinoperator(__add__, *::operator+, binary_func, nb_add); +%pybinoperator(__pos__, *::operator+(), unary_func, nb_positive); +%pybinoperator(__pos__, *::operator+() const, unary_func, nb_positive); +%pybinoperator(__sub__, *::operator-, binary_func, nb_subtract); +%pybinoperator(__neg__, *::operator-(), unary_func, nb_negative); +%pybinoperator(__neg__, *::operator-() const, unary_func, nb_negative); +%pybinoperator(__mul__, *::operator*, binary_func, nb_multiply); +%pybinoperator(__div__, *::operator/, binary_func, nb_div); +%pybinoperator(__mod__, *::operator%, binary_func, nb_remainder); +%pybinoperator(__lshift__, *::operator<<, binary_func, nb_lshift); +%pybinoperator(__rshift__, *::operator>>, binary_func, nb_rshift); +%pybinoperator(__and__, *::operator&, binary_func, nb_and); +%pybinoperator(__or__, *::operator|, binary_func, nb_or); +%pybinoperator(__xor__, *::operator^, binary_func, nb_xor); +%pycompare(__lt__, *::operator<, Py_LT); +%pycompare(__le__, *::operator<=, Py_LE); +%pycompare(__gt__, *::operator>, Py_GT); +%pycompare(__ge__, *::operator>=, Py_GE); +%pycompare(__eq__, *::operator==, Py_EQ); +%pycompare(__ne__, *::operator!=, Py_NE); +%feature("pyslot", "nb_truediv", functype="binary_func") *::operator/; /* Special cases */ %rename(__invert__) *::operator~; +%feature("pyslot", "nb_invert", functype="unary_func") *::operator~; %rename(__call__) *::operator(); +%feature("pyslot", "tp_call", functype="ternary_func") *::operator(); +#if defined(SWIGPYTHON_BUILTIN) +%pybinoperator(__nonzero__, *::operator bool, unary_func, nb_nonzero); +#else %feature("shadow") *::operator bool %{ def __nonzero__(self): return $action(self) __bool__ = __nonzero__ %}; %rename(__nonzero__) *::operator bool; +#endif /* Ignored operators */ %ignoreoperator(LNOT) operator!; @@ -90,18 +102,22 @@ __bool__ = __nonzero__ */ -#define %pyinplaceoper(SwigPyOper, Oper) %delobject Oper; %newobject Oper; %rename(SwigPyOper) Oper +#if defined(SWIGPYTHON_BUILTIN) +#define %pyinplaceoper(SwigPyOper, Oper, functp, slot) %rename(SwigPyOper) Oper; %feature("pyslot", #slot, functype=#functp) Oper; +#else +#define %pyinplaceoper(SwigPyOper, Oper, functp, slot) %delobject Oper; %newobject Oper; %rename(SwigPyOper) Oper +#endif -%pyinplaceoper(__iadd__ , *::operator +=); -%pyinplaceoper(__isub__ , *::operator -=); -%pyinplaceoper(__imul__ , *::operator *=); -%pyinplaceoper(__idiv__ , *::operator /=); -%pyinplaceoper(__imod__ , *::operator %=); -%pyinplaceoper(__iand__ , *::operator &=); -%pyinplaceoper(__ior__ , *::operator |=); -%pyinplaceoper(__ixor__ , *::operator ^=); -%pyinplaceoper(__ilshift__, *::operator <<=); -%pyinplaceoper(__irshift__, *::operator >>=); +%pyinplaceoper(__iadd__ , *::operator +=, binary_func, nb_inplace_add); +%pyinplaceoper(__isub__ , *::operator -=, binary_func, nb_inplace_subtract); +%pyinplaceoper(__imul__ , *::operator *=, binary_func, nb_inplace_multiply); +%pyinplaceoper(__idiv__ , *::operator /=, binary_func, nb_inplace_divide); +%pyinplaceoper(__imod__ , *::operator %=, binary_func, nb_inplace_remainder); +%pyinplaceoper(__iand__ , *::operator &=, binary_func, nb_inplace_and); +%pyinplaceoper(__ior__ , *::operator |=, binary_func, nb_inplace_or); +%pyinplaceoper(__ixor__ , *::operator ^=, binary_func, nb_inplace_xor); +%pyinplaceoper(__ilshift__, *::operator <<=, binary_func, nb_inplace_lshift); +%pyinplaceoper(__irshift__, *::operator >>=, binary_func, nb_inplace_rshift); /* Finally, in python we need to mark the binary operations to fail as diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 6221dbcc1..3f93c4575 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1076,8 +1076,13 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int PyTypeObject *obj_tp; for (obj_tp = obj->ob_type; obj_tp; obj_tp = obj_tp->tp_base) { if (obj_tp == target_tp) { + SwigPyObject *sobj = (SwigPyObject*) obj; + if (own) + *own = *own | sobj->own; + if (flags & SWIG_POINTER_DISOWN) + sobj->own = 0; if (ptr) - *ptr = ((SwigPyObject*) obj)->ptr; + *ptr = sobj->ptr; return SWIG_OK; } } diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 618f15f9e..55bfd8815 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -1,3 +1,4 @@ +/* mode: c++; c-basic-offset: 2 */ /* ----------------------------------------------------------------------------- * This file is part of SWIG, which is licensed as a whole under version 3 * (or any later version) of the GNU General Public License. Some additional @@ -46,7 +47,7 @@ static String *f_shadow = 0; static String *f_shadow_imports = 0; static String *f_shadow_import_stmts = 0; static String *f_shadow_stubs = 0; - +static Hash *builtin_getset = 0; static String *methods; static String *class_name; @@ -166,15 +167,15 @@ static const char *usage3 = (char *) "\ static String* getSlot (Node *n, const char *key) { - static String *slot_default = NewString("0"); - String *val = Getattr(n, key); - return val ? val : slot_default; + static String *slot_default = NewString("0"); + String *val = Getattr(n, key); + return val ? val : slot_default; } class PYTHON:public Language { public: - PYTHON() { + PYTHON() { /* Add code to manage protected constructors and directors */ director_prot_ctor_code = NewString(""); Printv(director_prot_ctor_code, @@ -448,20 +449,20 @@ public: fputs(usage2, stdout); fputs(usage3, stdout); } else if (strcmp(argv[i], "-py3") == 0) { - py3 = 1; - Swig_mark_arg(i); + py3 = 1; + Swig_mark_arg(i); } else if (strcmp(argv[i], "-builtin") == 0) { - builtin = 1; - Preprocessor_define("SWIGPYTHON_BUILTIN", 0); - Swig_mark_arg(i); + builtin = 1; + Preprocessor_define("SWIGPYTHON_BUILTIN", 0); + Swig_mark_arg(i); } } } /* for */ if (py3) { - /* force disable features that not compatible with Python 3.x */ - classic = 0; + /* force disable features that not compatible with Python 3.x */ + classic = 0; } if (cppcast) { @@ -553,10 +554,11 @@ public: f_wrappers = NewString(""); f_directors_h = NewString(""); f_directors = NewString(""); + builtin_getset = NewHash(); if (builtin) { - f_builtins = NewString(""); - Printf(f_builtins, "namespace {\n\n"); + f_builtins = NewString(""); + Printf(f_builtins, "namespace {\n\n"); } if (directorsEnabled()) { @@ -699,159 +701,159 @@ public: /* If shadow classing is enabled, we're going to change the module name to "_module" */ if (shadow) { - String *filen = NewStringf("%s%s.py", SWIG_output_directory(), Char(module)); - // If we don't have an interface then change the module name X to _X - if (interface) - module = interface; - else - Insert(module, 0, "_"); - if ((f_shadow_py = NewFile(filen, "w", SWIG_output_files())) == 0) { - FileErrorDisplay(filen); - SWIG_exit(EXIT_FAILURE); - } - Delete(filen); - filen = NULL; + String *filen = NewStringf("%s%s.py", SWIG_output_directory(), Char(module)); + // If we don't have an interface then change the module name X to _X + if (interface) + module = interface; + else + Insert(module, 0, "_"); + if ((f_shadow_py = NewFile(filen, "w", SWIG_output_files())) == 0) { + FileErrorDisplay(filen); + SWIG_exit(EXIT_FAILURE); + } + Delete(filen); + filen = NULL; - f_shadow = NewString(""); - f_shadow_imports = NewString(""); - f_shadow_import_stmts = NewString(""); - f_shadow_stubs = NewString(""); + f_shadow = NewString(""); + f_shadow_imports = NewString(""); + f_shadow_import_stmts = NewString(""); + f_shadow_stubs = NewString(""); - Printv(f_shadow_import_stmts, "SWIGINTERN void\n", NIL); - Printv(f_shadow_import_stmts, "SWIG_Python_builtin_imports()\n", NIL); - Printv(f_shadow_import_stmts, "{\n", NIL); - Printv(f_shadow_import_stmts, tab4 "PyObject *import_str = NULL;\n", NIL); + Printv(f_shadow_import_stmts, "SWIGINTERN void\n", NIL); + Printv(f_shadow_import_stmts, "SWIG_Python_builtin_imports()\n", NIL); + Printv(f_shadow_import_stmts, "{\n", NIL); + Printv(f_shadow_import_stmts, tab4 "PyObject *import_str = NULL;\n", NIL); - Swig_register_filebyname("shadow", f_shadow); - Swig_register_filebyname("python", f_shadow); + Swig_register_filebyname("shadow", f_shadow); + Swig_register_filebyname("python", f_shadow); - Swig_banner_target_lang(f_shadow, "#"); + Swig_banner_target_lang(f_shadow, "#"); - if (!modern) { - Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL); - } + if (!modern) { + Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL); + } - if (mod_docstring && Len(mod_docstring)) { - Printv(f_shadow, "\"\"\"\n", mod_docstring, "\n\"\"\"\n\n", NIL); - Delete(mod_docstring); - mod_docstring = NULL; - } + if (mod_docstring && Len(mod_docstring)) { + Printv(f_shadow, "\"\"\"\n", mod_docstring, "\n\"\"\"\n\n", NIL); + Delete(mod_docstring); + mod_docstring = NULL; + } - Printv(f_shadow, "\nfrom sys import version_info\n", NULL); + Printv(f_shadow, "\nfrom sys import version_info\n", NULL); - if (!builtin && fastproxy) { - Printv(f_shadow, "if version_info >= (3,0,0):\n", NULL); - Printf(f_shadow, tab4 "new_instancemethod = lambda func, inst, cls: %s.SWIG_PyInstanceMethod_New(func)\n", module); - Printv(f_shadow, "else:\n", NULL); - Printv(f_shadow, tab4, "from new import instancemethod as new_instancemethod\n", NULL); - } - - /* Import the C-extension module. This should be a relative import, - * since the shadow module may also have been imported by a relative - * import, and there is thus no guarantee that the C-extension is on - * sys.path. Relative imports must be explicitly specified from 2.6.0 - * onwards (implicit relative imports will raise a DeprecationWarning - * in 2.6, and fail in 2.7 onwards), but the relative import syntax - * isn't available in python 2.4 or earlier, so we have to write some - * code conditional on the python version. - */ - Printv(f_shadow, "if version_info >= (2,6,0):\n", NULL); - Printv(f_shadow, tab4, "def swig_import_helper():\n", NULL); - Printv(f_shadow, tab8, "from os.path import dirname\n", NULL); - Printv(f_shadow, tab8, "import imp\n", NULL); - Printv(f_shadow, tab8, "fp = None\n", NULL); - Printv(f_shadow, tab8, "try:\n", NULL); - Printf(f_shadow, tab4 tab8 "fp, pathname, description = imp.find_module('%s', [dirname(__file__)])\n", module); - Printf(f_shadow, tab8 "except ImportError:\n"); - /* At here, the module may already loaded, so simply import it. */ - Printf(f_shadow, tab4 tab8 "import %s\n", module); - Printf(f_shadow, tab4 tab8 "return %s\n", module); - Printv(f_shadow, tab8 "if fp is not None:\n", NULL); - Printv(f_shadow, tab4 tab8 "try:\n", NULL); - Printf(f_shadow, tab8 tab8 "_mod = imp.load_module('%s', fp, pathname, description)\n", module); - Printv(f_shadow, tab4 tab8, "finally:\n", NULL); - Printv(f_shadow, tab8 tab8, "fp.close()\n", NULL); - Printv(f_shadow, tab4 tab8, "return _mod\n", NULL); - Printf(f_shadow, tab4 "%s = swig_import_helper()\n", module); - Printv(f_shadow, tab4, "del swig_import_helper\n", NULL); + if (!builtin && fastproxy) { + Printv(f_shadow, "if version_info >= (3,0,0):\n", NULL); + Printf(f_shadow, tab4 "new_instancemethod = lambda func, inst, cls: %s.SWIG_PyInstanceMethod_New(func)\n", module); Printv(f_shadow, "else:\n", NULL); - Printf(f_shadow, tab4 "import %s\n", module); + Printv(f_shadow, tab4, "from new import instancemethod as new_instancemethod\n", NULL); + } - /* Delete the version_info symbol since we don't use it elsewhere in the - * module. */ - Printv(f_shadow, "del version_info\n", NULL); + /* Import the C-extension module. This should be a relative import, + * since the shadow module may also have been imported by a relative + * import, and there is thus no guarantee that the C-extension is on + * sys.path. Relative imports must be explicitly specified from 2.6.0 + * onwards (implicit relative imports will raise a DeprecationWarning + * in 2.6, and fail in 2.7 onwards), but the relative import syntax + * isn't available in python 2.4 or earlier, so we have to write some + * code conditional on the python version. + */ + Printv(f_shadow, "if version_info >= (2,6,0):\n", NULL); + Printv(f_shadow, tab4, "def swig_import_helper():\n", NULL); + Printv(f_shadow, tab8, "from os.path import dirname\n", NULL); + Printv(f_shadow, tab8, "import imp\n", NULL); + Printv(f_shadow, tab8, "fp = None\n", NULL); + Printv(f_shadow, tab8, "try:\n", NULL); + Printf(f_shadow, tab4 tab8 "fp, pathname, description = imp.find_module('%s', [dirname(__file__)])\n", module); + Printf(f_shadow, tab8 "except ImportError:\n"); + /* At here, the module may already loaded, so simply import it. */ + Printf(f_shadow, tab4 tab8 "import %s\n", module); + Printf(f_shadow, tab4 tab8 "return %s\n", module); + Printv(f_shadow, tab8 "if fp is not None:\n", NULL); + Printv(f_shadow, tab4 tab8 "try:\n", NULL); + Printf(f_shadow, tab8 tab8 "_mod = imp.load_module('%s', fp, pathname, description)\n", module); + Printv(f_shadow, tab4 tab8, "finally:\n", NULL); + Printv(f_shadow, tab8 tab8, "fp.close()\n", NULL); + Printv(f_shadow, tab4 tab8, "return _mod\n", NULL); + Printf(f_shadow, tab4 "%s = swig_import_helper()\n", module); + Printv(f_shadow, tab4, "del swig_import_helper\n", NULL); + Printv(f_shadow, "else:\n", NULL); + Printf(f_shadow, tab4 "import %s\n", module); - if (builtin) { - Printf(f_shadow, "from %s import *\n", module); - } - if (modern || !classic) { - Printv(f_shadow, "try:\n", tab4, "_swig_property = property\n", "except NameError:\n", tab4, "pass # Python < 2.2 doesn't have 'property'.\n", NULL); - } - /* if (!modern) */ - /* always needed, a class can be forced to be no-modern, such as an exception */ - { - // Python-2.2 object hack - Printv(f_shadow, - "def _swig_setattr_nondynamic(self,class_type,name,value,static=1):\n", - tab4, "if (name == \"thisown\"): return self.this.own(value)\n", - tab4, "if (name == \"this\"):\n", tab4, tab4, "if type(value).__name__ == 'SwigPyObject':\n", tab4, tab8, "self.__dict__[name] = value\n", + /* Delete the version_info symbol since we don't use it elsewhere in the + * module. */ + Printv(f_shadow, "del version_info\n", NULL); + + if (builtin) { + Printf(f_shadow, "from %s import *\n", module); + } + if (modern || !classic) { + Printv(f_shadow, "try:\n", tab4, "_swig_property = property\n", "except NameError:\n", tab4, "pass # Python < 2.2 doesn't have 'property'.\n", NULL); + } + /* if (!modern) */ + /* always needed, a class can be forced to be no-modern, such as an exception */ + { + // Python-2.2 object hack + Printv(f_shadow, + "def _swig_setattr_nondynamic(self,class_type,name,value,static=1):\n", + tab4, "if (name == \"thisown\"): return self.this.own(value)\n", + tab4, "if (name == \"this\"):\n", tab4, tab4, "if type(value).__name__ == 'SwigPyObject':\n", tab4, tab8, "self.__dict__[name] = value\n", #ifdef USE_THISOWN - tab4, tab8, "if hasattr(value,\"thisown\"): self.__dict__[\"thisown\"] = value.thisown\n", tab4, tab8, "del value.thisown\n", + tab4, tab8, "if hasattr(value,\"thisown\"): self.__dict__[\"thisown\"] = value.thisown\n", tab4, tab8, "del value.thisown\n", #endif - tab4, tab8, "return\n", tab4, "method = class_type.__swig_setmethods__.get(name,None)\n", tab4, "if method: return method(self,value)\n", + tab4, tab8, "return\n", tab4, "method = class_type.__swig_setmethods__.get(name,None)\n", tab4, "if method: return method(self,value)\n", #ifdef USE_THISOWN - tab4, "if (not static) or hasattr(self,name) or (name == \"thisown\"):\n", + tab4, "if (not static) or hasattr(self,name) or (name == \"thisown\"):\n", #else - tab4, "if (not static) or hasattr(self,name):\n", + tab4, "if (not static) or hasattr(self,name):\n", #endif - tab4, tab4, "self.__dict__[name] = value\n", - tab4, "else:\n", - tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n\n", - "def _swig_setattr(self,class_type,name,value):\n", tab4, "return _swig_setattr_nondynamic(self,class_type,name,value,0)\n\n", NIL); + tab4, tab4, "self.__dict__[name] = value\n", + tab4, "else:\n", + tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n\n", + "def _swig_setattr(self,class_type,name,value):\n", tab4, "return _swig_setattr_nondynamic(self,class_type,name,value,0)\n\n", NIL); - Printv(f_shadow, - "def _swig_getattr(self,class_type,name):\n", - tab4, "if (name == \"thisown\"): return self.this.own()\n", - tab4, "method = class_type.__swig_getmethods__.get(name,None)\n", - tab4, "if method: return method(self)\n", tab4, "raise AttributeError(name)\n\n", NIL); + Printv(f_shadow, + "def _swig_getattr(self,class_type,name):\n", + tab4, "if (name == \"thisown\"): return self.this.own()\n", + tab4, "method = class_type.__swig_getmethods__.get(name,None)\n", + tab4, "if method: return method(self)\n", tab4, "raise AttributeError(name)\n\n", NIL); - Printv(f_shadow, - "def _swig_repr(self):\n", - tab4, "try: strthis = \"proxy of \" + self.this.__repr__()\n", - tab4, "except: strthis = \"\"\n", tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", NIL); + Printv(f_shadow, + "def _swig_repr(self):\n", + tab4, "try: strthis = \"proxy of \" + self.this.__repr__()\n", + tab4, "except: strthis = \"\"\n", tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", NIL); - if (!classic) { - /* Usage of types.ObjectType is deprecated. - * But don't sure wether this would broken old Python? - */ - Printv(f_shadow, - // "import types\n", - "try:\n", - // " _object = types.ObjectType\n", - " _object = object\n", - " _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n", - // "del types\n", - "\n\n", NIL); - } + if (!classic) { + /* Usage of types.ObjectType is deprecated. + * But don't sure wether this would broken old Python? + */ + Printv(f_shadow, + // "import types\n", + "try:\n", + // " _object = types.ObjectType\n", + " _object = object\n", + " _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n", + // "del types\n", + "\n\n", NIL); } - if (modern) { - Printv(f_shadow, "def _swig_setattr_nondynamic_method(set):\n", tab4, "def set_attr(self,name,value):\n", + } + if (modern) { + Printv(f_shadow, "def _swig_setattr_nondynamic_method(set):\n", tab4, "def set_attr(self,name,value):\n", #ifdef USE_THISOWN - tab4, tab4, "if hasattr(self,name) or (name in (\"this\", \"thisown\")):\n", + tab4, tab4, "if hasattr(self,name) or (name in (\"this\", \"thisown\")):\n", #else - tab4, tab4, "if (name == \"thisown\"): return self.this.own(value)\n", tab4, tab4, "if hasattr(self,name) or (name == \"this\"):\n", + tab4, tab4, "if (name == \"thisown\"): return self.this.own(value)\n", tab4, tab4, "if hasattr(self,name) or (name == \"this\"):\n", #endif - tab4, tab4, tab4, "set(self,name,value)\n", - tab4, tab4, "else:\n", - tab4, tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n", tab4, "return set_attr\n\n\n", NIL); - } + tab4, tab4, tab4, "set(self,name,value)\n", + tab4, tab4, "else:\n", + tab4, tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n", tab4, "return set_attr\n\n\n", NIL); + } - if (directorsEnabled()) { - // Try loading weakref.proxy, which is only available in Python 2.1 and higher - Printv(f_shadow, - "try:\n", tab4, "import weakref\n", tab4, "weakref_proxy = weakref.proxy\n", "except:\n", tab4, "weakref_proxy = lambda x: x\n", "\n\n", NIL); - } - } + if (directorsEnabled()) { + // Try loading weakref.proxy, which is only available in Python 2.1 and higher + Printv(f_shadow, + "try:\n", tab4, "import weakref\n", tab4, "weakref_proxy = weakref.proxy\n", "except:\n", tab4, "weakref_proxy = lambda x: x\n", "\n\n", NIL); + } + } // Include some information in the code Printf(f_header, "\n/*-----------------------------------------------\n @(target):= %s.so\n\ @@ -899,22 +901,22 @@ public: Printf(f_init, "#endif\n"); Printf(f_init, "}\n"); if (builtin) - Printf(f_builtins, "} // namespace {\n\n"); + Printf(f_builtins, "} // namespace {\n\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); - Printv(f_header, f_shadow_import_stmts, NIL); - } - Printv(f_shadow_py, f_shadow, "\n", NIL); - Printv(f_shadow_py, f_shadow_stubs, "\n", NIL); + if (builtin) { + Printv(f_shadow_import_stmts, "}\n", NIL); + Printv(f_header, f_shadow_import_stmts, NIL); + } + Printv(f_shadow_py, f_shadow, "\n", NIL); + Printv(f_shadow_py, f_shadow_stubs, "\n", NIL); - Close(f_shadow_py); - Delete(f_shadow_py); + Close(f_shadow_py); + Delete(f_shadow_py); } /* Close all of the files */ @@ -932,7 +934,7 @@ public: Dump(f_wrappers, f_begin); if (builtin) - Dump(f_builtins, f_begin); + Dump(f_builtins, f_begin); Wrapper_pretty_print(f_init, f_begin); Delete(f_header); @@ -992,24 +994,24 @@ public: if (!options || (!Getattr(options, "noshadow") && !Getattr(options, "noproxy"))) { Printf(import, "_%s\n", modname); if (!Strstr(f_shadow_imports, import)) { - if (pkg && (!package || Strcmp(pkg, package) != 0)) { - if (builtin) { - Printf(f_shadow_import_stmts, tab4 "import_str = PyString_FromString(\"%s.%s\");\n", pkg, modname); - Printf(f_shadow_import_stmts, tab4 "PyImport_Import(import_str);\n"); - Printf(f_shadow_import_stmts, tab4 "Py_XDECREF(import_str);\n"); - } else { - Printf(f_shadow, "import %s.%s\n", pkg, modname); - } + if (pkg && (!package || Strcmp(pkg, package) != 0)) { + if (builtin) { + Printf(f_shadow_import_stmts, tab4 "import_str = PyString_FromString(\"%s.%s\");\n", pkg, modname); + Printf(f_shadow_import_stmts, tab4 "PyImport_Import(import_str);\n"); + Printf(f_shadow_import_stmts, tab4 "Py_XDECREF(import_str);\n"); } else { - if (builtin) { - Printf(f_shadow_import_stmts, tab4 "import_str = PyString_FromString(\"%s\");\n", modname); - Printf(f_shadow_import_stmts, tab4 "PyImport_Import(import_str);\n"); - Printf(f_shadow_import_stmts, tab4 "Py_XDECREF(import_str);\n"); - } else { - Printf(f_shadow, "import %s\n", modname); - } + Printf(f_shadow, "import %s.%s\n", pkg, modname); } - Printv(f_shadow_imports, import, NULL); + } else { + if (builtin) { + Printf(f_shadow_import_stmts, tab4 "import_str = PyString_FromString(\"%s\");\n", modname); + Printf(f_shadow_import_stmts, tab4 "PyImport_Import(import_str);\n"); + Printf(f_shadow_import_stmts, tab4 "Py_XDECREF(import_str);\n"); + } else { + Printf(f_shadow, "import %s\n", modname); + } + } + Printv(f_shadow_imports, import, NULL); } } } @@ -1026,12 +1028,12 @@ public: * module. Using proper argument and calling style for * given node n. * ------------------------------------------------------------ */ - String *funcCall(String *name, String *parms) { + String *funcCall(String *name, String *parms) { String *str = NewString(""); Printv(str, module, ".", name, "(", parms, ")", NIL); return str; - } + } /* ------------------------------------------------------------ @@ -1200,7 +1202,7 @@ public: return doc; } - /* ----------------------------------------------------------------------------- + /* ----------------------------------------------------------------------------- * makeParameterName() * Note: the generated name should consist with that in kwnames[] * @@ -1585,26 +1587,26 @@ public: if (is_real_overloaded(n) || GetFlag(n, "feature:compactdefaultargs") || !is_primitive_defaultargs(n)) - { - String *parms = NewString(""); - if(in_class) - Printf(parms, "self, "); - Printf(parms, "*args"); - if (kw) - Printf(parms, ", **kwargs"); - return parms; - } + { + String *parms = NewString(""); + if(in_class) + Printf(parms, "self, "); + Printf(parms, "*args"); + if (kw) + Printf(parms, ", **kwargs"); + return parms; + } bool funcanno = py3 ? true : false; String *params = NewString(""); String *_params = make_autodocParmList(n, false, is_calling, funcanno); if (in_class) - { - Printf(params, "self"); - if(Len(_params) > 0) - Printf(params, ", "); - } + { + Printf(params, "self"); + if(Len(_params) > 0) + Printf(params, ", "); + } Printv(params, _params, NULL); @@ -1707,7 +1709,7 @@ public: if (ret) ret = SwigType_str(ret, 0); } return (ret && py3) ? NewStringf(" -> \"%s\" ", ret) - : NewString(""); + : NewString(""); } /* ------------------------------------------------------------ @@ -1731,7 +1733,7 @@ public: Printv(f_dest, pythoncode(pythonappend(n), " "), "\n", NIL); Printv(f_dest, " return val\n", NIL); } else { - Printv(f_dest, " return ", funcCall(name, callParms), "\n", NIL); + Printv(f_dest, " return ", funcCall(name, callParms), "\n", NIL); } if (Getattr(n, "feature:python:callback") || !have_addtofunc(n)) { @@ -1748,7 +1750,7 @@ public: int check_kwargs(Node *n) { return (use_kw || GetFlag(n, "feature:kwargs")) - && !GetFlag(n, "memberset") && !GetFlag(n, "memberget"); + && !GetFlag(n, "memberset") && !GetFlag(n, "memberget"); } @@ -1759,9 +1761,9 @@ public: void add_method(String *name, String *function, int kw, Node *n = 0, int = 0, int = -1, int = -1) { if (!kw) { - Printf(methods, "\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function); + Printf(methods, "\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function); } else { - Printf(methods, "\t { (char *)\"%s\", (PyCFunction) %s, METH_VARARGS | METH_KEYWORDS, ", name, function); + Printf(methods, "\t { (char *)\"%s\", (PyCFunction) %s, METH_VARARGS | METH_KEYWORDS, ", name, function); } if (!n) { @@ -1792,7 +1794,7 @@ public: /* ------------------------------------------------------------ * dispatchFunction() * ------------------------------------------------------------ */ - void dispatchFunction(Node *n, int funpack = 0, bool builtin_self = false, bool constructor = false) { + void dispatchFunction(Node *n, String *linkage, int funpack = 0, bool builtin_self = false, bool constructor = false) { /* Last node in overloaded chain */ int maxargs; @@ -1814,30 +1816,30 @@ public: String *symname = Getattr(n, "sym:name"); String *wname = Swig_name_wrapper(symname); - Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL); + Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL); Wrapper_add_local(f, "argc", "int argc"); Printf(tmp, "PyObject *argv[%d]", maxargs + 1); Wrapper_add_local(f, "argv", tmp); if (!fastunpack) { - bool director_class = (getCurrentClass() && Swig_directorclass(getCurrentClass())); - bool add_self = builtin_self && (!constructor || director_class); - Wrapper_add_local(f, "ii", "int ii"); - if (maxargs - (add_self ? 1 : 0) > 0) - Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n"); - Append(f->code, "argc = args ? (int)PyObject_Length(args) : 0;\n"); - if (add_self) - Append(f->code, "argv[0] = self;\n"); - Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n", add_self ? maxargs-1 : maxargs); - Printf(f->code, "argv[ii%s] = PyTuple_GET_ITEM(args,ii);\n", add_self ? " + 1" : ""); - Append(f->code, "}\n"); - if (add_self) - Append(f->code, "argc++;\n"); + bool director_class = (getCurrentClass() && Swig_directorclass(getCurrentClass())); + bool add_self = builtin_self && (!constructor || director_class); + Wrapper_add_local(f, "ii", "int ii"); + if (maxargs - (add_self ? 1 : 0) > 0) + Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n"); + Append(f->code, "argc = args ? (int)PyObject_Length(args) : 0;\n"); + if (add_self) + Append(f->code, "argv[0] = self;\n"); + Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n", add_self ? maxargs-1 : maxargs); + Printf(f->code, "argv[ii%s] = PyTuple_GET_ITEM(args,ii);\n", add_self ? " + 1" : ""); + Append(f->code, "}\n"); + if (add_self) + Append(f->code, "argc++;\n"); } else { - String *iname = Getattr(n, "sym:name"); - Printf(f->code, "if (!(argc = SWIG_Python_UnpackTuple(args,\"%s\",0,%d,argv))) SWIG_fail;\n", iname, maxargs); - Append(f->code, "--argc;\n"); + String *iname = Getattr(n, "sym:name"); + Printf(f->code, "if (!(argc = SWIG_Python_UnpackTuple(args,\"%s\",0,%d,argv))) SWIG_fail;\n", iname, maxargs); + Append(f->code, "--argc;\n"); } Replaceall(dispatch, "$args", "self,args"); @@ -1866,7 +1868,7 @@ public: Wrapper_print(f, f_wrappers); Node *p = Getattr(n, "sym:previousSibling"); if (!builtin_self) - add_method(symname, wname, 0, p); + add_method(symname, wname, 0, p); /* Create a shadow for this function (if enabled and not in a member function) */ if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) { @@ -1940,8 +1942,23 @@ public: bool builtin_self = builtin && in_class && (constructor || (l && Getattr(l, "self"))); bool builtin_ctor = builtin_self && constructor; bool director_class = (getCurrentClass() && Swig_directorclass(getCurrentClass())); + bool builtin_getter = (builtin && GetFlag(n, "memberget")); + bool builtin_setter = (builtin && GetFlag(n, "memberset") && !builtin_getter); char const *self_param = builtin_self ? "self" : "SWIGUNUSEDPARM(self)"; char const *wrap_return = builtin_ctor ? "int " : "PyObject *"; + String *linkage = NewString("SWIGINTERN "); + String *slot = Getattr(n, "feature:pyslot"); + if (builtin_setter || builtin_getter) { + Clear(linkage); + Printv(linkage, "extern ", NIL); + } + if (slot) { + String *functype = Getattr(n, "feature:pyslot:functype"); + if (!strcmp(Char(functype), "binary_func") || !strcmp(Char(functype), "ternary_func")) { + Clear(linkage); + Printv(linkage, "extern ", NIL); + } + } if (Getattr(n, "sym:overloaded")) { overname = Getattr(n, "sym:overname"); @@ -1962,9 +1979,9 @@ public: int allow_thread = threads_enable(n); if (builtin_ctor) - Wrapper_add_local(f, "resultobj", "int resultobj = 0"); + 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); @@ -1976,8 +1993,8 @@ public: tuple_arguments = num_arguments = emit_num_arguments(l); tuple_required = num_required = emit_num_required(l); if (builtin_self && (!constructor || (constructor && director_class))) { - --tuple_arguments; - --tuple_required; + --tuple_arguments; + --tuple_required; } if (((num_arguments == 0) && (num_required == 0)) || ((num_arguments == 1) && (num_required == 1) && Getattr(l, "self"))) allow_kwargs = 0; @@ -1990,9 +2007,9 @@ public: if (!allow_kwargs || Getattr(n, "sym:overloaded")) { if (!varargs) { - Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL); + Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL); } else { - Printv(f->def, "SWIGINTERN ", wrap_return, wname, "__varargs__", "(PyObject *", self_param, ", PyObject *args, PyObject *varargs) {", NIL); + Printv(f->def, linkage, wrap_return, wname, "__varargs__", "(PyObject *", self_param, ", PyObject *args, PyObject *varargs) {", NIL); } if (allow_kwargs) { Swig_warning(WARN_LANG_OVERLOAD_KEYWORD, input_file, line_number, "Can't use keyword arguments with overloaded functions (%s).\n", Swig_name_decl(n)); @@ -2003,15 +2020,15 @@ public: Swig_warning(WARN_LANG_VARARGS_KEYWORD, input_file, line_number, "Can't wrap varargs with keyword arguments enabled\n"); varargs = 0; } - Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args, PyObject *kwargs) {", NIL); + Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args, PyObject *kwargs) {", NIL); } if (!builtin || !in_class || tuple_arguments > 0) { - if (!allow_kwargs) { - Append(parse_args, " if (!PyArg_ParseTuple(args,(char *)\""); - } else { - Append(parse_args, " if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)\""); - Append(arglist, ",kwnames"); - } + if (!allow_kwargs) { + Append(parse_args, " if (!PyArg_ParseTuple(args,(char *)\""); + } else { + Append(parse_args, " if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)\""); + Append(arglist, ",kwnames"); + } } int funpack = modernargs && fastunpack && !varargs && !allow_kwargs; @@ -2046,10 +2063,10 @@ public: } if (builtin_self && !builtin_ctor) - Printf(self_parse, "%s = self;\n", funpack ? "swig_obj[0]" : "obj0"); + Printf(self_parse, "%s = self;\n", funpack ? "swig_obj[0]" : "obj0"); - if (constructor && director_class) - Printv(self_parse, funpack ? "swig_obj[1]" : "obj1", " = self;\n", NIL); + if (builtin_ctor && director_class) + Printv(self_parse, funpack ? "swig_obj[1]" : "obj1", " = self;\n", NIL); int use_parse = 0; Append(kwargs, "{"); @@ -2063,14 +2080,14 @@ public: String *pn = Getattr(p, "name"); String *ln = Getattr(p, "lname"); if (funpack) - sprintf(source, "swig_obj[%d]", builtin_ctor ? i + 1 : i); + sprintf(source, "swig_obj[%d]", builtin_ctor ? i + 1 : i); else sprintf(source, "obj%d", builtin_ctor ? i + 1 : i); if (parse_from_tuple) { - Putc(',', arglist); - if (i == num_required) - Putc('|', parse_args); /* Optional argument separator */ + Putc(',', arglist); + if (i == num_required) + Putc('|', parse_args); /* Optional argument separator */ } /* Keyword argument handling */ @@ -2122,11 +2139,11 @@ public: bool parse_from_tuple = (i > 0 || !builtin_self || (builtin_ctor && !director_class)); if (parse_from_tuple) - Putc('O', parse_args); + Putc('O', parse_args); if (!funpack) { Wrapper_add_localv(f, source, "PyObject *", source, "= 0", NIL); if (parse_from_tuple) - Printf(arglist, "&%s", source); + Printf(arglist, "&%s", source); } if (i >= num_required) Printv(get_pointers, "if (", source, ") {\n", NIL); @@ -2138,7 +2155,7 @@ public: use_parse = 1; Append(parse_args, parse); if (parse_from_tuple) - Printf(arglist, "&%s", ln); + Printf(arglist, "&%s", ln); } p = Getattr(p, "tmap:in:next"); continue; @@ -2164,16 +2181,16 @@ public: Clear(f->def); if (overname) { if (noargs) { - Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL); + Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL); } else { - Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **swig_obj) {", NIL); + Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **swig_obj) {", NIL); } Printf(parse_args, "if ((nobjs < %d) || (nobjs > %d)) SWIG_fail;\n", num_required, num_arguments); } else { if (noargs) { - Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL); + Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL); } else { - Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL); + Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL); } if (onearg) { Printf(parse_args, "if (!args) SWIG_fail;\n"); @@ -2318,10 +2335,10 @@ public: /* Return the function value */ if (builtin_ctor) { - Printf(f->code, "%s\n", actioncode); - tm = Swig_typemap_lookup("builtin_init", n, "result", f); + 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) { @@ -2426,10 +2443,10 @@ public: if (need_cleanup) { Printv(f->code, cleanup, NIL); } - if (builtin_self && constructor) - Printv(f->code, " return 0;\n", NIL); + if (builtin_ctor) + Printv(f->code, " return 0;\n", NIL); else - Printv(f->code, " return NULL;\n", NIL); + Printv(f->code, " return NULL;\n", NIL); if (funpack) { @@ -2463,7 +2480,7 @@ public: if (varargs) { DelWrapper(f); f = NewWrapper(); - Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL); + Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL); Wrapper_add_local(f, "resultobj", constructor && builtin_self ? "int resultobj" : "PyObject *resultobj"); Wrapper_add_local(f, "varargs", "PyObject *varargs"); Wrapper_add_local(f, "newargs", "PyObject *newargs"); @@ -2480,8 +2497,8 @@ public: /* Now register the function with the interpreter. */ if (!Getattr(n, "sym:overloaded")) { - if (!builtin_self) - add_method(iname, wname, allow_kwargs, n, funpack, num_required, num_arguments); + if (!builtin_self) + add_method(iname, wname, allow_kwargs, n, funpack, num_required, num_arguments); /* Create a shadow for this function (if enabled and not in a member function) */ if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) { @@ -2489,11 +2506,53 @@ public: } } else { if (!Getattr(n, "sym:nextSibling")) { - dispatchFunction(n, funpack, builtin_self, constructor); + dispatchFunction(n, linkage, funpack, builtin_self, constructor); } } + + String *wrapper_name = Swig_name_wrapper(iname); + + /* If this is a builtin type, create a PyGetSetDef entry for this member variable. */ + if (builtin_getter) { + Hash *h = Getattr(builtin_getset, name); + if (!h) { + h = NewHash(); + Setattr(builtin_getset, name, h); + Delete(h); + } + Setattr(h, "getter", wrapper_name); + } + if (builtin_setter) { + Hash *h = Getattr(builtin_getset, name); + if (!h) { + h = NewHash(); + Setattr(builtin_getset, name, h); + Delete(h); + } + Setattr(h, "setter", wrapper_name); + } + + /* Handle builtin operator overloads */ + if (slot) { + String *functype = Getattr(n, "feature:pyslot:functype"); + String *feature_name = NewStringf("feature:%s", slot); + String *closure_name = NewString(""); + if (!strcmp(Char(functype), "binary_func")) { + Printf(closure_name, "pyswig_binaryfunc_closure< %s >", wrapper_name); + } else if (!strcmp(Char(functype), "ternary_func")) { + Printf(closure_name, "pyswig_ternaryfunc_closure< %s >", wrapper_name); + } else { + Append(closure_name, wrapper_name); + } + Node *parent = Swig_methodclass(n); + Setattr(parent, feature_name, closure_name); + Delete(feature_name); + Delete(closure_name); + } + Delete(self_parse); Delete(parse_args); + Delete(linkage); Delete(arglist); Delete(get_pointers); Delete(cleanup); @@ -2501,6 +2560,7 @@ public: Delete(kwargs); Delete(wname); DelWrapper(f); + Delete(wrapper_name); return SWIG_OK; } @@ -2538,7 +2598,7 @@ public: int assignable = is_assignable(n); if (!builtin && (shadow) && !assignable && !in_class) - Printf(f_shadow_stubs, "%s = %s.%s\n", iname, global_name, iname); + Printf(f_shadow_stubs, "%s = %s.%s\n", iname, global_name, iname); String *getname = Swig_name_get(NSPACE_TODO, iname); String *setname = Swig_name_set(NSPACE_TODO, iname); @@ -2616,70 +2676,70 @@ public: * constantWrapper() * ------------------------------------------------------------ */ - virtual int constantWrapper(Node *n) { - String *name = Getattr(n, "name"); - String *iname = Getattr(n, "sym:name"); - SwigType *type = Getattr(n, "type"); - String *rawval = Getattr(n, "rawval"); - String *value = rawval ? rawval : Getattr(n, "value"); - String *tm; - int have_tm = 0; + virtual int constantWrapper(Node *n) { + String *name = Getattr(n, "name"); + String *iname = Getattr(n, "sym:name"); + SwigType *type = Getattr(n, "type"); + String *rawval = Getattr(n, "rawval"); + String *value = rawval ? rawval : Getattr(n, "value"); + String *tm; + int have_tm = 0; - if (!addSymbol(iname, n)) - return SWIG_ERROR; + if (!addSymbol(iname, n)) + return SWIG_ERROR; - /* Special hook for member pointer */ - if (SwigType_type(type) == T_MPOINTER) { - String *wname = Swig_name_wrapper(iname); - String *str = SwigType_str(type, wname); - Printf(f_header, "static %s = %s;\n", str, value); - Delete(str); - value = wname; - } - - if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) { - Replaceall(tm, "$source", value); - Replaceall(tm, "$target", name); - Replaceall(tm, "$value", value); - Printf(const_code, "%s,\n", tm); - Delete(tm); - have_tm = 1; - } - - if (builtin && in_class) { - Swig_require("builtin_constantWrapper", n, "*sym:name", "builtin_sym:name", NIL); - Setattr(n, "sym:name", Getattr(n, "builtin_sym:name")); - } - - if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) { - Replaceall(tm, "$source", value); - Replaceall(tm, "$target", name); - Replaceall(tm, "$value", value); - Printf(f_init, "%s\n", tm); - Delete(tm); - have_tm = 1; - } - - if (builtin && in_class) - Swig_restore(n); - - if (!have_tm) { - Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); - return SWIG_NOWRAP; - } - - if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) { - if (!in_class) { - Printv(f_shadow, iname, " = ", module, ".", iname, "\n", NIL); - } else { - if (!(Getattr(n, "feature:python:callback"))) { - Printv(f_shadow_stubs, iname, " = ", module, ".", iname, "\n", NIL); - } - } - } - return SWIG_OK; + /* Special hook for member pointer */ + if (SwigType_type(type) == T_MPOINTER) { + String *wname = Swig_name_wrapper(iname); + String *str = SwigType_str(type, wname); + Printf(f_header, "static %s = %s;\n", str, value); + Delete(str); + value = wname; } + if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) { + Replaceall(tm, "$source", value); + Replaceall(tm, "$target", name); + Replaceall(tm, "$value", value); + Printf(const_code, "%s,\n", tm); + Delete(tm); + have_tm = 1; + } + + if (builtin && in_class) { + Swig_require("builtin_constantWrapper", n, "*sym:name", "builtin_sym:name", NIL); + Setattr(n, "sym:name", Getattr(n, "builtin_sym:name")); + } + + if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) { + Replaceall(tm, "$source", value); + Replaceall(tm, "$target", name); + Replaceall(tm, "$value", value); + Printf(f_init, "%s\n", tm); + Delete(tm); + have_tm = 1; + } + + if (builtin && in_class) + Swig_restore(n); + + if (!have_tm) { + Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); + return SWIG_NOWRAP; + } + + if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) { + if (!in_class) { + Printv(f_shadow, iname, " = ", module, ".", iname, "\n", NIL); + } else { + if (!(Getattr(n, "feature:python:callback"))) { + Printv(f_shadow_stubs, iname, " = ", module, ".", iname, "\n", NIL); + } + } + } + return SWIG_OK; + } + /* ------------------------------------------------------------ * nativeWrapper() @@ -2701,17 +2761,17 @@ public: -/* ---------------------------------------------------------------------------- - * BEGIN C++ Director Class modifications - * ------------------------------------------------------------------------- */ + /* ---------------------------------------------------------------------------- + * BEGIN C++ Director Class modifications + * ------------------------------------------------------------------------- */ -/* C++/Python polymorphism demo code, copyright (C) 2002 Mark Rose - * - * TODO - * - * Move some boilerplate code generation to Swig_...() functions. - * - */ + /* C++/Python polymorphism demo code, copyright (C) 2002 Mark Rose + * + * TODO + * + * Move some boilerplate code generation to Swig_...() functions. + * + */ /* --------------------------------------------------------------- * classDirectorMethod() @@ -2823,13 +2883,13 @@ public: if (dirprot_mode()) { /* - This implementation uses a std::map. + This implementation uses a std::map. - It should be possible to rewrite it using a more elegant way, - like copying the Java approach for the 'override' array. + It should be possible to rewrite it using a more elegant way, + like copying the Java approach for the 'override' array. - But for now, this seems to be the least intrusive way. - */ + But for now, this seems to be the least intrusive way. + */ Printf(f_directors_h, "\n\n"); Printf(f_directors_h, "/* Internal Director utilities */\n"); Printf(f_directors_h, "public:\n"); @@ -2885,480 +2945,538 @@ public: result = Language::classDirectorDisown(n); shadow = oldshadow; if (shadow) { - if (builtin) { - Printf(f_shadow, tab4, "{ \"disown\", (PyCFunction) Swig::Director::pyobj_disown< %s >, METH_NOARGS, \"\" },\n", real_classname); - } else { - String *symname = Getattr(n, "sym:name"); - String *mrename = Swig_name_disown(NSPACE_TODO, symname); //Getattr(n, "name")); - Printv(f_shadow, tab4, "def __disown__(self):\n", NIL); + if (builtin) { + Printf(f_shadow, tab4, "{ \"disown\", (PyCFunction) Swig::Director::pyobj_disown< %s >, METH_NOARGS, \"\" },\n", real_classname); + } else { + String *symname = Getattr(n, "sym:name"); + String *mrename = Swig_name_disown(NSPACE_TODO, symname); //Getattr(n, "name")); + Printv(f_shadow, tab4, "def __disown__(self):\n", NIL); #ifdef USE_THISOWN - Printv(f_shadow, tab8, "self.thisown = 0\n", NIL); + Printv(f_shadow, tab8, "self.thisown = 0\n", NIL); #else - Printv(f_shadow, tab8, "self.this.disown()\n", NIL); + Printv(f_shadow, tab8, "self.this.disown()\n", NIL); #endif - Printv(f_shadow, tab8, module, ".", mrename, "(self)\n", NIL); - Printv(f_shadow, tab8, "return weakref_proxy(self)\n", NIL); - Delete(mrename); - } + Printv(f_shadow, tab8, module, ".", mrename, "(self)\n", NIL); + Printv(f_shadow, tab8, "return weakref_proxy(self)\n", NIL); + Delete(mrename); + } } return result; } -/* ---------------------------------------------------------------------------- - * END of C++ Director Class modifications - * ------------------------------------------------------------------------- */ + /* ---------------------------------------------------------------------------- + * END of C++ Director Class modifications + * ------------------------------------------------------------------------- */ /* ------------------------------------------------------------ * classDeclaration() * ------------------------------------------------------------ */ - virtual bool get_single_base (Node *n, Node **base = NULL) - { + virtual bool get_single_base (Node *n, Node **base = NULL) + { + if (base) + *base = NULL; + if (Getattr(n, "single_inh")) + return true; + List *baselist = Getattr(n, "bases"); + if (!baselist || Len(baselist) == 0) { + Setattr(n, "single_inh", "1"); + return true; + } + if (baselist && Len(baselist) == 1) { + Iterator b = First(baselist); + if (this->get_single_base(b.item)) { if (base) - *base = NULL; - if (Getattr(n, "single_inh")) - return true; - List *baselist = Getattr(n, "bases"); - if (!baselist || Len(baselist) == 0) { - Setattr(n, "single_inh", "1"); - return true; - } - if (baselist && Len(baselist) == 1) { - Iterator b = First(baselist); - if (this->get_single_base(b.item)) { - if (base) - *base = b.item; - Setattr(n, "single_inh", "1"); - return true; - } - } - return false; + *base = b.item; + Setattr(n, "single_inh", "1"); + return true; + } } + return false; + } - virtual int classDeclaration(Node *n) { - if (shadow && !Getattr(n, "feature:onlychildren")) { - Node *mod = Getattr(n, "module"); - if (mod) { - String *importname = NewString(""); - String *modname = Getattr(mod, "name"); - if (Strcmp(modname, mainmodule) != 0) { - // check if the module has a package option - Node *options = Getattr(mod, "options"); - String *pkg = options ? Getattr(options, "package") : 0; - if (pkg && (!package || Strcmp(pkg, package) != 0)) { - Printf(importname, "%s.", pkg); - } - Printf(importname, "%s.", modname); - } - Append(importname, Getattr(n, "sym:name")); - Setattr(n, "python:proxy", importname); - } + virtual int classDeclaration(Node *n) { + if (shadow && !Getattr(n, "feature:onlychildren")) { + Node *mod = Getattr(n, "module"); + if (mod) { + String *importname = NewString(""); + String *modname = Getattr(mod, "name"); + if (Strcmp(modname, mainmodule) != 0) { + // check if the module has a package option + Node *options = Getattr(mod, "options"); + String *pkg = options ? Getattr(options, "package") : 0; + if (pkg && (!package || Strcmp(pkg, package) != 0)) { + Printf(importname, "%s.", pkg); + } + Printf(importname, "%s.", modname); } - int result = Language::classDeclaration(n); - return result; + Append(importname, Getattr(n, "sym:name")); + Setattr(n, "python:proxy", importname); + } } + int result = Language::classDeclaration(n); + return result; + } /* ------------------------------------------------------------ * classHandler() * ------------------------------------------------------------ */ - void builtin_pre_decl (Node *n, Node *base_node) - { - String *name = Getattr(n, "name"); - String *rname = SwigType_namestr(name); - Printf(f_init, tab4 "builtin_pytype = &PySwigBuiltin< %s >::pytype;\n", rname); - Printf(f_init, tab4 "builtin_pytype->tp_new = PyType_GenericNew;\n"); - if (base_node) { - String *base_name = Copy(Getattr(base_node, "name")); - SwigType_add_pointer(base_name); - String *base_mname = SwigType_manglestr(base_name); - Printf(f_init, tab4 "builtin_basetype = SWIG_MangledTypeQuery(\"%s\");\n", base_mname); - Printf(f_init, tab4 "if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) {\n"); - Printf(f_init, tab8 "builtin_pytype->tp_base = ((SwigPyClientData*) builtin_basetype->clientdata)->pytype;\n"); - Printf(f_init, tab4 "}\n"); - Delete(base_mname); - Delete(base_name); - } else { - //Printv(f_init, tab4, "builtin_pytype->tp_base = SwigPyObject_type();\n", NIL); - Printv(f_init, tab4, "builtin_pytype->tp_base = &PyBaseObject_Type;\n", NIL); - } - Printf(f_init, tab4 "builtin_pytype->tp_dict = d = PyDict_New();\n"); - Delete(rname); + void builtin_pre_decl (Node *n, Node *base_node) + { + String *name = Getattr(n, "name"); + String *rname = SwigType_namestr(name); + Printf(f_init, tab4 "builtin_pytype = &PySwigBuiltin< %s >::pytype;\n", rname); + Printf(f_init, tab4 "builtin_pytype->tp_new = PyType_GenericNew;\n"); + if (base_node) { + String *base_name = Copy(Getattr(base_node, "name")); + SwigType_add_pointer(base_name); + String *base_mname = SwigType_manglestr(base_name); + Printf(f_init, tab4 "builtin_basetype = SWIG_MangledTypeQuery(\"%s\");\n", base_mname); + Printf(f_init, tab4 "if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) {\n"); + Printf(f_init, tab8 "builtin_pytype->tp_base = ((SwigPyClientData*) builtin_basetype->clientdata)->pytype;\n"); + Printf(f_init, tab4 "}\n"); + Delete(base_mname); + Delete(base_name); + } else { + //Printv(f_init, tab4, "builtin_pytype->tp_base = SwigPyObject_type();\n", NIL); + Printv(f_init, tab4, "builtin_pytype->tp_base = &PyBaseObject_Type;\n", NIL); } + Printf(f_init, tab4 "builtin_pytype->tp_dict = d = PyDict_New();\n"); + Delete(rname); + } - void builtin_post_decl (File *f, Node *n) - { - String *name = Getattr(n, "name"); - String *pname = Copy(name); - SwigType_add_pointer(pname); - String *symname = Getattr(n, "sym:name"); - String *rname = SwigType_namestr(name); - String *mname = SwigType_manglestr(pname); - String *templ = NewString(""); - Printf(templ, "PySwigBuiltin< %s >", rname); - char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : "0"; + void builtin_post_decl (File *f, Node *n) + { + String *name = Getattr(n, "name"); + String *pname = Copy(name); + SwigType_add_pointer(pname); + String *symname = Getattr(n, "sym:name"); + String *rname = SwigType_namestr(name); + String *mname = SwigType_manglestr(pname); + String *templ = NewString(""); + Printf(templ, "PySwigBuiltin< %s >", rname); + char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : "0"; - // Check for non-public destructor, in which case tp_dealloc should be "0" - String *tp_dealloc = NewString(""); - String *dtor_name = NewString("delete"); - if (Getattr(class_members, "delete")) - Printf(tp_dealloc, "py_builtin_dealloc< %s >", rname); - else - Printv(tp_dealloc, "0", NIL); - Delete(dtor_name); + // Check for non-public destructor, in which case tp_dealloc should be "0" + String *tp_dealloc = NewString(""); + String *dtor_name = NewString("delete"); + if (Getattr(class_members, "delete")) + Printf(tp_dealloc, "py_builtin_dealloc< %s >", rname); + else + Printv(tp_dealloc, "0", NIL); + Delete(dtor_name); - Printf(f, "template <> PyTypeObject PySwigBuiltin< %s >::pytype = {\n", rname); - Printf(f, " PyObject_HEAD_INIT(NULL)\n"); - Printf(f, " 0, /*ob_size*/\n"); - Printf(f, " \"%s\", /*tp_name*/\n", symname); - Printf(f, " sizeof(%s), /*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")); - Printf(f, " %s, /*tp_as_number*/\n", getSlot(n, "feature:tp_as_number")); - Printf(f, " %s, /*tp_as_sequence*/\n", getSlot(n, "feature:tp_as_sequence")); - Printf(f, " %s, /*tp_as_mapping*/\n", getSlot(n, "feature:tp_as_mapping")); - 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")); - Printf(f, " %s, /*tp_as_buffer*/\n", getSlot(n, "feature:tp_as_buffer")); - Printf(f, " Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_RICHCOMPARE, /*tp_flags*/\n"); - 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, /* tp_richcompare */\n", getSlot(n, "feature:tp_richcompare")); - Printf(f, " %s, /* tp_weaklistoffset */\n", getSlot(n, "feature:tp_weaklistoffset")); - Printf(f, " %s, /* tp_iter */\n", getSlot(n, "feature:tp_iter")); - Printf(f, " %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, /* tp_getset */\n", getSlot(n, "feature:tp_getset")); - 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")); - Printf(f, " %s, /* tp_dictoffset */\n", getSlot(n, "feature:tp_dictoffset")); - 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")); - Printf(f, "};\n\n"); + Printf(f, "template <> PyGetSetDef PySwigBuiltin< %s >::getset[] = {\n", rname); + for (DohIterator member_iter = First(builtin_getset); member_iter.item; member_iter = Next(member_iter)) { + String *mname = member_iter.key; + Hash *mgetset = member_iter.item; + String *getter = Getattr(mgetset, "getter"); + String *setter = Getattr(mgetset, "setter"); + Printf(f, tab4 "{ const_cast(\"%s\"), (getter) %s, (setter) pyswig_setter_closure, const_cast(\"%s.%s\"), (void*) &%s },\n", + mname, getter ? getter : "0", name, mname, setter ? setter : "0"); + } + Printv(f, " {NULL} // Sentinel\n", NIL); + Printv(f, "};\n\n", NIL); + Clear(builtin_getset); + + Printf(f, "template <> PyNumberMethods PySwigBuiltin< %s >::number_methods = {\n", rname); + 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")); + Printf(f, " (binaryfunc) %s, // nb_divide;\n", getSlot(n, "feature:nb_divide")); + 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")); + Printf(f, " (coercion) %s, // nb_coerce;\n", getSlot(n, "feature:nb_coerce")); + Printf(f, " (unaryfunc) %s, // nb_int;\n", getSlot(n, "feature:nb_int")); + Printf(f, " (unaryfunc) %s, // nb_long;\n", getSlot(n, "feature:nb_long")); + Printf(f, " (unaryfunc) %s, // nb_float;\n", getSlot(n, "feature:nb_float")); + Printf(f, " (unaryfunc) %s, // nb_oct;\n", getSlot(n, "feature:nb_oct")); + Printf(f, " (unaryfunc) %s, // nb_hex;\n", getSlot(n, "feature:nb_hex")); + 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")); + Printf(f, " (binaryfunc) %s, // nb_inplace_divide;\n", getSlot(n, "feature:nb_inplace_divide")); + 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")); + Printf(f, "};\n\n"); - String *clientdata = NewString(""); - Printf(clientdata, "&%s::clientdata", templ); - SwigType_remember_clientdata(pname, clientdata); + String *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES"); + // TODO: Add more flags based on slots + Printf(f, "template <> PyTypeObject PySwigBuiltin< %s >::pytype = {\n", rname); + Printf(f, " PyObject_HEAD_INIT(NULL)\n"); + Printf(f, " 0, /*ob_size*/\n"); + Printf(f, " \"%s\", /*tp_name*/\n", symname); + Printf(f, " sizeof(%s), /*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")); + Printf(f, " &%s::number_methods, /*tp_as_number*/\n", templ); + Printf(f, " %s, /*tp_as_sequence*/\n", getSlot(n, "feature:tp_as_sequence")); + Printf(f, " %s, /*tp_as_mapping*/\n", getSlot(n, "feature:tp_as_mapping")); + 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")); + Printf(f, " %s, /*tp_as_buffer*/\n", getSlot(n, "feature:tp_as_buffer")); + Printf(f, " %s, /*tp_flags*/\n", tp_flags); + 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, /* tp_richcompare */\n", getSlot(n, "feature:tp_richcompare")); + Printf(f, " %s, /* tp_weaklistoffset */\n", getSlot(n, "feature:tp_weaklistoffset")); + Printf(f, " %s, /* tp_iter */\n", getSlot(n, "feature:tp_iter")); + Printf(f, " %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")); + Printf(f, " %s, /* tp_dictoffset */\n", getSlot(n, "feature:tp_dictoffset")); + 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")); + Printf(f, "};\n\n"); - Printf(f, "template <> SwigPyClientData %s::clientdata = {0, 0, 0, 0, 0, 0, &%s::pytype};\n\n", templ, templ); + String *clientdata = NewString(""); + Printf(clientdata, "&%s::clientdata", templ); + SwigType_remember_clientdata(pname, clientdata); - Printv(f_init, " d = md;\n", NIL); - Printv(f_init, " if (PyType_Ready(builtin_pytype) < 0) {\n", NIL); - Printf(f_init, " fprintf(stderr, \"Couldn't create type %s\");\n", symname); - Printv(f_init, " return;\n", NIL); - 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, "template <> SwigPyClientData %s::clientdata = {0, 0, 0, 0, 0, 0, &%s::pytype};\n\n", templ, templ); - Delete(clientdata); - Delete(templ); - Delete(mname); - Delete(rname); - Delete(pname); - Delete(tp_dealloc); - } + Printv(f_init, " d = md;\n", NIL); + Printv(f_init, " if (PyType_Ready(builtin_pytype) < 0) {\n", NIL); + Printf(f_init, " fprintf(stderr, \"Couldn't create type %s\");\n", symname); + Printv(f_init, " return;\n", NIL); + 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); - virtual int classHandler(Node *n) { - int oldclassic = classic; - int oldmodern = modern; - File *f_shadow_file = f_shadow; - bool single_inh = false; - Node *base_node = NULL; + Delete(clientdata); + Delete(templ); + Delete(mname); + Delete(rname); + Delete(pname); + Delete(tp_dealloc); + Delete(tp_flags); + } - if (shadow) { + virtual int classHandler(Node *n) { + int oldclassic = classic; + int oldmodern = modern; + File *f_shadow_file = f_shadow; + bool single_inh = false; + Node *base_node = NULL; - /* Create new strings for building up a wrapper function */ - have_constructor = 0; - have_repr = 0; + if (shadow) { - if (GetFlag(n, "feature:classic")) { - classic = 1; - modern = 0; - } - if (GetFlag(n, "feature:modern")) { - classic = 0; - modern = 1; - } - if (GetFlag(n, "feature:exceptionclass")) { - classic = 1; - modern = 0; - } + /* Create new strings for building up a wrapper function */ + have_constructor = 0; + have_repr = 0; - class_name = Getattr(n, "sym:name"); - real_classname = Getattr(n, "name"); + if (GetFlag(n, "feature:classic")) { + classic = 1; + modern = 0; + } + if (GetFlag(n, "feature:modern")) { + classic = 0; + modern = 1; + } + if (GetFlag(n, "feature:exceptionclass")) { + classic = 1; + modern = 0; + } - if (!addSymbol(class_name, n)) - return SWIG_ERROR; + class_name = Getattr(n, "sym:name"); + real_classname = Getattr(n, "name"); - single_inh = builtin && get_single_base(n, &base_node); - if (builtin && !single_inh) { - Swig_warning(WARN_PYTHON_MULTIPLE_INH, Getfile(n), Getline(n), - "Class '%s' ignored, because it has multiple inheritance, which is incompatible with the '-builtin' option.\n", real_classname); - return SWIG_OK; - } - - shadow_indent = (String *) tab4; - - /* Handle inheritance */ - String *base_class = NewString(""); - List *baselist = Getattr(n, "bases"); - if (baselist && Len(baselist)) { - Iterator b; - b = First(baselist); - while (b.item) { - String *bname = Getattr(b.item, "python:proxy"); - bool ignore = GetFlag(b.item, "feature:ignore") ? true : false; - if (!bname || ignore) { - if (!bname && !ignore) { - Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(n), Getline(n), - "Base class '%s' ignored - unknown module name for base. Either import the appropriate module interface file or specify the name of the module in the %%import directive.\n", SwigType_namestr(Getattr(b.item, "name"))); - } - b = Next(b); - continue; - } - Printv(base_class, bname, NIL); - b = Next(b); - if (b.item) { - Putc(',', base_class); - } - } - } - - /* dealing with abstract base class */ - String *abcs = Getattr(n, "feature:python:abc"); - if (py3 && abcs) { - if (Len(base_class)) { - Putc(',', base_class); - } - Printv(base_class, abcs, NIL); - } - - if (!single_inh) { - Printv(f_shadow, "class ", class_name, NIL); - - if (Len(base_class)) { - Printf(f_shadow, "(%s)", base_class); - } else { - if (!classic) { - Printf(f_shadow, modern ? "(object)" : "(_object)"); - } - if (GetFlag(n, "feature:exceptionclass") ) { - Printf(f_shadow, "(Exception)"); - } - } - - Printf(f_shadow, ":\n"); - if (have_docstring(n)) { - String *str = docstring(n, AUTODOC_CLASS, tab4); - if (str && Len(str)) - Printv(f_shadow, tab4, str, "\n", NIL); - } - - if (!modern) { - Printv(f_shadow, tab4, "__swig_setmethods__ = {}\n", NIL); - if (Len(base_class)) { - Printf(f_shadow, "%sfor _s in [%s]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{}))\n", tab4, base_class); - } - - if (!GetFlag(n, "feature:python:nondynamic")) { - Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr(self, ", class_name, ", name, value)\n", NIL); - } else { - Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr_nondynamic(self, ", class_name, ", name, value)\n", NIL); - } - - Printv(f_shadow, tab4, "__swig_getmethods__ = {}\n", NIL); - if (Len(base_class)) { - Printf(f_shadow, "%sfor _s in [%s]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{}))\n", tab4, base_class); - } - - Printv(f_shadow, tab4, "__getattr__ = lambda self, name: _swig_getattr(self, ", class_name, ", name)\n", NIL); - } else { - Printv(f_shadow, tab4, "thisown = _swig_property(lambda x: x.this.own(), ", "lambda x, v: x.this.own(v), doc='The membership flag')\n", NIL); - /* Add static attribute */ - if (GetFlag(n, "feature:python:nondynamic")) { - Printv(f_shadow_file, - tab4, "__setattr__ = _swig_setattr_nondynamic_method(object.__setattr__)\n", - tab4, "class __metaclass__(type):\n", tab4, tab4, "__setattr__ = _swig_setattr_nondynamic_method(type.__setattr__)\n", NIL); - } - } - } - } - - /* Emit all of the members */ - - in_class = 1; - if (single_inh) { - class_members = NewHash(); - builtin_pre_decl(n, base_node); - } - - /* Overide the shadow file so we can capture its methods */ - f_shadow = NewString(""); - - // Set up type check for director class constructor - Clear(none_comparison); - if (builtin && Swig_directorclass(n)) { - String *p_real_classname = Copy(real_classname); - SwigType_add_pointer(p_real_classname); - String *mangle = SwigType_manglestr(p_real_classname); - String *descriptor = NewStringf("SWIGTYPE%s", mangle); - Printv(none_comparison, "self->ob_type != ((SwigPyClientData*) (", descriptor, ")->clientdata)->pytype", NIL); - Delete(descriptor); - Delete(mangle); - Delete(p_real_classname); - } else { - Printv(none_comparison, "$arg != Py_None", NIL); - } - - Language::classHandler(n); - - in_class = 0; - - /* Complete the class */ - if (shadow) { - /* Generate a class registration function */ - if (!single_inh) { - String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers) - SwigType *smart = 0; - if (smartptr) { - SwigType *cpt = Swig_cparse_type(smartptr); - if (cpt) { - smart = SwigType_typedef_resolve_all(cpt); - Delete(cpt); - } else { - // TODO: report line number of where the feature comes from - Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, real_classname); - } - } - SwigType *ct = Copy(smart ? smart : real_classname); - SwigType_add_pointer(ct); - SwigType *realct = Copy(real_classname); - SwigType_add_pointer(realct); - SwigType_remember(realct); - Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL); - Printv(f_wrappers, " PyObject *obj;\n", NIL); - if (modernargs) { - if (fastunpack) { - Printv(f_wrappers, " if (!SWIG_Python_UnpackTuple(args,(char*)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL); - } else { - Printv(f_wrappers, " if (!PyArg_UnpackTuple(args,(char*)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL); - } - } else { - Printv(f_wrappers, " if (!PyArg_ParseTuple(args,(char*)\"O:swigregister\", &obj)) return NULL;\n", NIL); - } - - Printv(f_wrappers, - " SWIG_TypeNewClientData(SWIGTYPE", SwigType_manglestr(ct), ", SWIG_NewClientData(obj));\n", - " return SWIG_Py_Void();\n", "}\n\n", NIL); - String *cname = NewStringf("%s_swigregister", class_name); - add_method(cname, cname, 0); - Delete(smart); - Delete(cname); - Delete(ct); - Delete(realct); - } - if (!have_constructor) { - if (!single_inh) - Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined", (Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL); - } else if (fastinit && !single_inh) { - - Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL); - Printv(f_wrappers, " return SWIG_Python_InitShadowInstance(args);\n", "}\n\n", NIL); - String *cname = NewStringf("%s_swiginit", class_name); - add_method(cname, cname, 0); - Delete(cname); - } - if (!have_repr && !single_inh) { - /* Supply a repr method for this class */ - String *rname = SwigType_namestr(real_classname); - if (new_repr) { - Printv(f_shadow_file, tab4, "__repr__ = _swig_repr\n", NIL); - } else { - Printv(f_shadow_file, tab4, "def __repr__(self):\n", tab8, "return \"\" % (self.this,)\n", NIL); - } - Delete(rname); - } - - if (single_inh) { - builtin_post_decl(f_builtins, n); - String *rname = SwigType_namestr(real_classname); - Printf(f_builtins, "template <> PyMethodDef PySwigBuiltin< %s >::methods[] = {\n", rname); - Delete(rname); - } - - if (builtin_tp_init) { - Delete(builtin_tp_init); - builtin_tp_init = 0; - } - - /* Now emit methods */ - if (!single_inh) - Printv(f_shadow_file, f_shadow, NIL); - - /* Now the Ptr class */ - if (classptr && !single_inh) { - Printv(f_shadow_file, "\nclass ", class_name, "Ptr(", class_name, "):\n", tab4, "def __init__(self, this):\n", NIL); - if (!modern) { - Printv(f_shadow_file, - tab8, "try: self.this.append(this)\n", - tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL); - } else { - Printv(f_shadow_file, - tab8, "try: self.this.append(this)\n", - tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL); - } - } - - if (!single_inh) { - if (fastproxy) { - List *shadow_list = Getattr(n, "shadow_methods"); - for (int i = 0; i < Len(shadow_list); ++i) { - String *symname = Getitem(shadow_list, i); - Printf(f_shadow_file, "%s.%s = new_instancemethod(%s.%s,None,%s)\n", class_name, symname, module, Swig_name_member(NSPACE_TODO, class_name, symname), class_name); - } - } - Printf(f_shadow_file, "%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name); - Printf(f_shadow_file, "%s_swigregister(%s)\n", class_name, class_name); - - shadow_indent = 0; - Printf(f_shadow_file, "%s\n", f_shadow_stubs); - } - shadow_indent = 0; - Clear(f_shadow_stubs); - } - - if (single_inh) { - Dump(f_shadow, f_builtins); - Printf(f_builtins, " {NULL} // Sentinel\n};\n\n"); - Delete(class_members); - class_members = 0; - } - - classic = oldclassic; - modern = oldmodern; - - /* Restore shadow file back to original version */ - Delete(f_shadow); - f_shadow = f_shadow_file; + if (!addSymbol(class_name, n)) + return SWIG_ERROR; + single_inh = builtin && get_single_base(n, &base_node); + if (builtin && !single_inh) { + Swig_warning(WARN_PYTHON_MULTIPLE_INH, Getfile(n), Getline(n), + "Class '%s' ignored, because it has multiple inheritance, which is incompatible with the '-builtin' option.\n", real_classname); return SWIG_OK; + } + + shadow_indent = (String *) tab4; + + /* Handle inheritance */ + String *base_class = NewString(""); + List *baselist = Getattr(n, "bases"); + if (baselist && Len(baselist)) { + Iterator b; + b = First(baselist); + while (b.item) { + String *bname = Getattr(b.item, "python:proxy"); + bool ignore = GetFlag(b.item, "feature:ignore") ? true : false; + if (!bname || ignore) { + if (!bname && !ignore) { + Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(n), Getline(n), + "Base class '%s' ignored - unknown module name for base. Either import the appropriate module interface file or specify the name of the module in the %%import directive.\n", SwigType_namestr(Getattr(b.item, "name"))); + } + b = Next(b); + continue; + } + Printv(base_class, bname, NIL); + b = Next(b); + if (b.item) { + Putc(',', base_class); + } + } + } + + /* dealing with abstract base class */ + String *abcs = Getattr(n, "feature:python:abc"); + if (py3 && abcs) { + if (Len(base_class)) { + Putc(',', base_class); + } + Printv(base_class, abcs, NIL); + } + + if (!single_inh) { + Printv(f_shadow, "class ", class_name, NIL); + + if (Len(base_class)) { + Printf(f_shadow, "(%s)", base_class); + } else { + if (!classic) { + Printf(f_shadow, modern ? "(object)" : "(_object)"); + } + if (GetFlag(n, "feature:exceptionclass") ) { + Printf(f_shadow, "(Exception)"); + } + } + + Printf(f_shadow, ":\n"); + if (have_docstring(n)) { + String *str = docstring(n, AUTODOC_CLASS, tab4); + if (str && Len(str)) + Printv(f_shadow, tab4, str, "\n", NIL); + } + + if (!modern) { + Printv(f_shadow, tab4, "__swig_setmethods__ = {}\n", NIL); + if (Len(base_class)) { + Printf(f_shadow, "%sfor _s in [%s]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{}))\n", tab4, base_class); + } + + if (!GetFlag(n, "feature:python:nondynamic")) { + Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr(self, ", class_name, ", name, value)\n", NIL); + } else { + Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr_nondynamic(self, ", class_name, ", name, value)\n", NIL); + } + + Printv(f_shadow, tab4, "__swig_getmethods__ = {}\n", NIL); + if (Len(base_class)) { + Printf(f_shadow, "%sfor _s in [%s]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{}))\n", tab4, base_class); + } + + Printv(f_shadow, tab4, "__getattr__ = lambda self, name: _swig_getattr(self, ", class_name, ", name)\n", NIL); + } else { + Printv(f_shadow, tab4, "thisown = _swig_property(lambda x: x.this.own(), ", "lambda x, v: x.this.own(v), doc='The membership flag')\n", NIL); + /* Add static attribute */ + if (GetFlag(n, "feature:python:nondynamic")) { + Printv(f_shadow_file, + tab4, "__setattr__ = _swig_setattr_nondynamic_method(object.__setattr__)\n", + tab4, "class __metaclass__(type):\n", tab4, tab4, "__setattr__ = _swig_setattr_nondynamic_method(type.__setattr__)\n", NIL); + } + } + } } + /* Emit all of the members */ + + in_class = 1; + if (single_inh) { + class_members = NewHash(); + builtin_pre_decl(n, base_node); + } + + /* Overide the shadow file so we can capture its methods */ + f_shadow = NewString(""); + + // Set up type check for director class constructor + Clear(none_comparison); + if (builtin && Swig_directorclass(n)) { + String *p_real_classname = Copy(real_classname); + SwigType_add_pointer(p_real_classname); + String *mangle = SwigType_manglestr(p_real_classname); + String *descriptor = NewStringf("SWIGTYPE%s", mangle); + Printv(none_comparison, "self->ob_type != ((SwigPyClientData*) (", descriptor, ")->clientdata)->pytype", NIL); + Delete(descriptor); + Delete(mangle); + Delete(p_real_classname); + } else { + Printv(none_comparison, "$arg != Py_None", NIL); + } + + Language::classHandler(n); + + in_class = 0; + + /* Complete the class */ + if (shadow) { + /* Generate a class registration function */ + if (!single_inh) { + String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers) + SwigType *smart = 0; + if (smartptr) { + SwigType *cpt = Swig_cparse_type(smartptr); + if (cpt) { + smart = SwigType_typedef_resolve_all(cpt); + Delete(cpt); + } else { + // TODO: report line number of where the feature comes from + Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, real_classname); + } + } + SwigType *ct = Copy(smart ? smart : real_classname); + SwigType_add_pointer(ct); + SwigType *realct = Copy(real_classname); + SwigType_add_pointer(realct); + SwigType_remember(realct); + Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL); + Printv(f_wrappers, " PyObject *obj;\n", NIL); + if (modernargs) { + if (fastunpack) { + Printv(f_wrappers, " if (!SWIG_Python_UnpackTuple(args,(char*)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL); + } else { + Printv(f_wrappers, " if (!PyArg_UnpackTuple(args,(char*)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL); + } + } else { + Printv(f_wrappers, " if (!PyArg_ParseTuple(args,(char*)\"O:swigregister\", &obj)) return NULL;\n", NIL); + } + + Printv(f_wrappers, + " SWIG_TypeNewClientData(SWIGTYPE", SwigType_manglestr(ct), ", SWIG_NewClientData(obj));\n", + " return SWIG_Py_Void();\n", "}\n\n", NIL); + String *cname = NewStringf("%s_swigregister", class_name); + add_method(cname, cname, 0); + Delete(smart); + Delete(cname); + Delete(ct); + Delete(realct); + } + if (!have_constructor) { + if (!single_inh) + Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined", (Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL); + } else if (fastinit && !single_inh) { + + Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL); + Printv(f_wrappers, " return SWIG_Python_InitShadowInstance(args);\n", "}\n\n", NIL); + String *cname = NewStringf("%s_swiginit", class_name); + add_method(cname, cname, 0); + Delete(cname); + } + if (!have_repr && !single_inh) { + /* Supply a repr method for this class */ + String *rname = SwigType_namestr(real_classname); + if (new_repr) { + Printv(f_shadow_file, tab4, "__repr__ = _swig_repr\n", NIL); + } else { + Printv(f_shadow_file, tab4, "def __repr__(self):\n", tab8, "return \"\" % (self.this,)\n", NIL); + } + Delete(rname); + } + + if (single_inh) { + builtin_post_decl(f_builtins, n); + String *rname = SwigType_namestr(real_classname); + Printf(f_builtins, "template <> PyMethodDef PySwigBuiltin< %s >::methods[] = {\n", rname); + Delete(rname); + } + + if (builtin_tp_init) { + Delete(builtin_tp_init); + builtin_tp_init = 0; + } + + /* Now emit methods */ + if (!single_inh) + Printv(f_shadow_file, f_shadow, NIL); + + /* Now the Ptr class */ + if (classptr && !single_inh) { + Printv(f_shadow_file, "\nclass ", class_name, "Ptr(", class_name, "):\n", tab4, "def __init__(self, this):\n", NIL); + if (!modern) { + Printv(f_shadow_file, + tab8, "try: self.this.append(this)\n", + tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL); + } else { + Printv(f_shadow_file, + tab8, "try: self.this.append(this)\n", + tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL); + } + } + + if (!single_inh) { + if (fastproxy) { + List *shadow_list = Getattr(n, "shadow_methods"); + for (int i = 0; i < Len(shadow_list); ++i) { + String *symname = Getitem(shadow_list, i); + Printf(f_shadow_file, "%s.%s = new_instancemethod(%s.%s,None,%s)\n", class_name, symname, module, Swig_name_member(NSPACE_TODO, class_name, symname), class_name); + } + } + Printf(f_shadow_file, "%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name); + Printf(f_shadow_file, "%s_swigregister(%s)\n", class_name, class_name); + + shadow_indent = 0; + Printf(f_shadow_file, "%s\n", f_shadow_stubs); + } + shadow_indent = 0; + Clear(f_shadow_stubs); + } + + if (single_inh) { + Dump(f_shadow, f_builtins); + Printf(f_builtins, " {NULL} // Sentinel\n};\n\n"); + Delete(class_members); + class_members = 0; + } + + classic = oldclassic; + modern = oldmodern; + + /* Restore shadow file back to original version */ + Delete(f_shadow); + f_shadow = f_shadow_file; + + return SWIG_OK; + } + /* ------------------------------------------------------------ * functionHandler() - Mainly overloaded for callback handling * ------------------------------------------------------------ */ @@ -3383,575 +3501,574 @@ public: * memberfunctionHandler() * ------------------------------------------------------------ */ - virtual int memberfunctionHandler(Node *n) { - String *symname = Getattr(n, "sym:name"); - int oldshadow; + virtual int memberfunctionHandler(Node *n) { + String *symname = Getattr(n, "sym:name"); + int oldshadow; - /* Create the default member function */ - oldshadow = shadow; /* Disable shadowing when wrapping member functions */ - if (shadow) - shadow = shadow | PYSHADOW_MEMBER; - Language::memberfunctionHandler(n); - shadow = oldshadow; + /* Create the default member function */ + oldshadow = shadow; /* Disable shadowing when wrapping member functions */ + if (shadow) + shadow = shadow | PYSHADOW_MEMBER; + Language::memberfunctionHandler(n); + shadow = oldshadow; - if (!Getattr(n, "sym:nextSibling")) { - if (builtin && in_class) { - String *name = Getattr(n, "name"); - if (checkAttribute(n, "access", "public") && strncmp(Char(name), "operator ", 9) && !Getattr(class_members, name)) { - String *fullname = Swig_name_member(NULL, class_name, symname); - String *wname = Swig_name_wrapper(fullname); - Setattr(class_members, name, name); - ParmList *parms = Getattr(n, "parms"); - bool noArgs = !parms || Len(parms) == 0; - String *pyflags = NewString(noArgs ? "METH_NOARGS" : "METH_VARARGS"); - Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", Char(name), wname, Char(pyflags)); - Delete(name); - Delete(fullname); - Delete(wname); - Delete(pyflags); - } - } else if (shadow) { - int allow_kwargs = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; - int fproxy = fastproxy; - if (Strcmp(symname, "__repr__") == 0) { - have_repr = 1; - } - if (Getattr(n, "feature:shadow")) { - String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); - String *pyaction = NewStringf("%s.%s", module, Swig_name_member(NSPACE_TODO, class_name, symname)); - Replaceall(pycode, "$action", pyaction); - Delete(pyaction); - Printv(f_shadow, pycode, "\n", NIL); - Delete(pycode); - fproxy = 0; - } else { - String *parms = make_pyParmList(n, true, false, allow_kwargs); - String *callParms = make_pyParmList(n, true, true, allow_kwargs); - if (!have_addtofunc(n)) { - if (!fastproxy || olddefs) { - Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":", NIL); - Printv(f_shadow, " return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL); - } - } else { - Printv(f_shadow, tab4, "def ", symname, "(",parms , ")", returnTypeAnnotation(n), ":", NIL); - Printv(f_shadow, "\n", NIL); - if (have_docstring(n)) - Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL); - if (have_pythonprepend(n)) { - fproxy = 0; - Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); - } - if (have_pythonappend(n)) { - fproxy = 0; - Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL); - Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL); - Printv(f_shadow, tab8, "return val\n\n", NIL); - } else { - Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL); - } - } - } - if (fproxy) { - List *shadow_list = Getattr(getCurrentClass(), "shadow_methods"); - if (!shadow_list) { - shadow_list = NewList(); - Setattr(getCurrentClass(), "shadow_methods", shadow_list); - Delete(shadow_list); - } - Append(shadow_list, symname); - } - } + if (!Getattr(n, "sym:nextSibling")) { + if (builtin && in_class) { + String *name = Getattr(n, "name"); + if (checkAttribute(n, "access", "public") && strncmp(Char(name), "operator ", 9) && !Getattr(class_members, name)) { + String *fullname = Swig_name_member(NULL, class_name, symname); + String *wname = Swig_name_wrapper(fullname); + Setattr(class_members, name, name); + ParmList *parms = Getattr(n, "parms"); + bool noArgs = !parms || Len(parms) == 0; + String *pyflags = NewString("METH_VARARGS"); + Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", Char(name), wname, Char(pyflags)); + Delete(name); + Delete(fullname); + Delete(wname); + Delete(pyflags); } - return SWIG_OK; + } else if (shadow) { + int allow_kwargs = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; + int fproxy = fastproxy; + if (Strcmp(symname, "__repr__") == 0) { + have_repr = 1; + } + if (Getattr(n, "feature:shadow")) { + String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); + String *pyaction = NewStringf("%s.%s", module, Swig_name_member(NSPACE_TODO, class_name, symname)); + Replaceall(pycode, "$action", pyaction); + Delete(pyaction); + Printv(f_shadow, pycode, "\n", NIL); + Delete(pycode); + fproxy = 0; + } else { + String *parms = make_pyParmList(n, true, false, allow_kwargs); + String *callParms = make_pyParmList(n, true, true, allow_kwargs); + if (!have_addtofunc(n)) { + if (!fastproxy || olddefs) { + Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":", NIL); + Printv(f_shadow, " return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL); + } + } else { + Printv(f_shadow, tab4, "def ", symname, "(",parms , ")", returnTypeAnnotation(n), ":", NIL); + Printv(f_shadow, "\n", NIL); + if (have_docstring(n)) + Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL); + if (have_pythonprepend(n)) { + fproxy = 0; + Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); + } + if (have_pythonappend(n)) { + fproxy = 0; + Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL); + Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL); + Printv(f_shadow, tab8, "return val\n\n", NIL); + } else { + Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL); + } + } + } + if (fproxy) { + List *shadow_list = Getattr(getCurrentClass(), "shadow_methods"); + if (!shadow_list) { + shadow_list = NewList(); + Setattr(getCurrentClass(), "shadow_methods", shadow_list); + Delete(shadow_list); + } + Append(shadow_list, symname); + } + } } + return SWIG_OK; + } /* ------------------------------------------------------------ * staticmemberfunctionHandler() * ------------------------------------------------------------ */ - 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); - } - Language::staticmemberfunctionHandler(n); - if (builtin && in_class) { - Swig_restore(n); - } - - if (Getattr(n, "sym:nextSibling")) { - return SWIG_OK; - } - - if (builtin && in_class) { - String *name = Getattr(n, "name"); - if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) { - String *fullname = Swig_name_member(NULL, class_name, name); - String *wname = Swig_name_wrapper(fullname); - Setattr(class_members, name, name); - String *pyflags = NewString("METH_VARARGS|METH_STATIC"); - Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", Char(name), wname, Char(pyflags)); - Delete(name); - Delete(fullname); - Delete(wname); - Delete(pyflags); - } - } else if (shadow ) { - if (!classic && !Getattr(n, "feature:python:callback") && have_addtofunc(n)) { - int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; - String *parms = make_pyParmList(n, false, false, kw); - String *callParms = make_pyParmList(n, false, true, kw); - Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); - if (have_docstring(n)) - Printv(f_shadow, tab8, docstring(n, AUTODOC_STATICFUNC, tab8), "\n", NIL); - if (have_pythonprepend(n)) - Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); - if (have_pythonappend(n)) { - Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL); - Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL); - Printv(f_shadow, tab8, "return val\n\n", NIL); - } else { - Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL); - } - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", symname, ")\n", NIL); - - if (!modern) { - Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", symname, "\n", NIL); - } - - } else { - if (!modern) { - Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL); - } - if (!classic) { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), ")\n", NIL); - } - } - } - return SWIG_OK; + 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); } + Language::staticmemberfunctionHandler(n); + if (builtin && in_class) { + Swig_restore(n); + } + + if (Getattr(n, "sym:nextSibling")) { + return SWIG_OK; + } + + if (builtin && in_class) { + String *name = Getattr(n, "name"); + if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) { + String *fullname = Swig_name_member(NULL, class_name, name); + String *wname = Swig_name_wrapper(fullname); + Setattr(class_members, name, name); + String *pyflags = NewString("METH_VARARGS|METH_STATIC"); + Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", Char(name), wname, Char(pyflags)); + Delete(name); + Delete(fullname); + Delete(wname); + Delete(pyflags); + } + } else if (shadow ) { + if (!classic && !Getattr(n, "feature:python:callback") && have_addtofunc(n)) { + int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; + String *parms = make_pyParmList(n, false, false, kw); + String *callParms = make_pyParmList(n, false, true, kw); + Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); + if (have_docstring(n)) + Printv(f_shadow, tab8, docstring(n, AUTODOC_STATICFUNC, tab8), "\n", NIL); + if (have_pythonprepend(n)) + Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); + if (have_pythonappend(n)) { + Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL); + Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL); + Printv(f_shadow, tab8, "return val\n\n", NIL); + } else { + Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL); + } + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", symname, ")\n", NIL); + + if (!modern) { + Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", symname, "\n", NIL); + } + + } else { + if (!modern) { + Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL); + } + if (!classic) { + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), ")\n", NIL); + } + } + } + return SWIG_OK; + } /* ------------------------------------------------------------ * constructorDeclaration() * ------------------------------------------------------------ */ - virtual int constructorHandler(Node *n) { - String *symname = Getattr(n, "sym:name"); - int oldshadow = shadow; - int use_director = Swig_directorclass(n); + virtual int constructorHandler(Node *n) { + String *symname = Getattr(n, "sym:name"); + int oldshadow = shadow; + int use_director = Swig_directorclass(n); - /* - * If we're wrapping the constructor of a C++ director class, prepend a new parameter - * to receive the scripting language object (e.g. 'self') - * - */ - Swig_save("python:constructorHandler", n, "parms", NIL); - if (use_director) { - Parm *parms = Getattr(n, "parms"); - Parm *self; - String *name = NewString("self"); - String *type = NewString("PyObject"); - SwigType_add_pointer(type); - self = NewParm(type, name, n); - Delete(type); - Delete(name); - Setattr(self, "lname", "O"); - if (parms) - set_nextSibling(self, parms); - Setattr(n, "parms", self); - Setattr(n, "wrap:self", "1"); - Setattr(n, "hidden", "1"); - Delete(self); + /* + * If we're wrapping the constructor of a C++ director class, prepend a new parameter + * to receive the scripting language object (e.g. 'self') + * + */ + Swig_save("python:constructorHandler", n, "parms", NIL); + if (use_director) { + Parm *parms = Getattr(n, "parms"); + Parm *self; + String *name = NewString("self"); + String *type = NewString("PyObject"); + SwigType_add_pointer(type); + self = NewParm(type, name, n); + Delete(type); + Delete(name); + Setattr(self, "lname", "O"); + if (parms) + set_nextSibling(self, parms); + Setattr(n, "parms", self); + Setattr(n, "wrap:self", "1"); + Setattr(n, "hidden", "1"); + Delete(self); + } + + if (shadow) + shadow = shadow | PYSHADOW_MEMBER; + Language::constructorHandler(n); + shadow = oldshadow; + + Delattr(n, "wrap:self"); + Swig_restore(n); + + if (!Getattr(n, "sym:nextSibling")) { + if (builtin && in_class) { + String *name = NewString("new"); + if ((use_director || checkAttribute(n, "access", "public")) && !Getattr(class_members, name)) { + Setattr(class_members, name, name); + String *fullname = Swig_name_member(NULL, name, class_name); + if (!builtin_tp_init) + builtin_tp_init = Swig_name_wrapper(fullname); + /* + ParmList *parms = Getattr(n, "parms"); + char const *pyflags = (!parms || Len(parms) == 0) ? "METH_NOARGS" : (Len(parms) == 1) ? "METH_0" : "METH_VARARGS"; + Printf(f_shadow, " { \"__init__\", (PyCFunction) %s, %s, \"\" },\n", builtin_tp_init, Char(pyflags)); + */ + Delete(fullname); + } + Delete(name); + } else if (shadow) { + int allow_kwargs = (check_kwargs(n) && (!Getattr(n, "sym:overloaded"))) ? 1 : 0; + int handled_as_init = 0; + if (!have_constructor) { + String *nname = Getattr(n, "sym:name"); + String *sname = Getattr(getCurrentClass(), "sym:name"); + String *cname = Swig_name_construct(NSPACE_TODO, sname); + handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0); + Delete(cname); } - - if (shadow) - shadow = shadow | PYSHADOW_MEMBER; - Language::constructorHandler(n); - shadow = oldshadow; - - Delattr(n, "wrap:self"); - Swig_restore(n); - - if (!Getattr(n, "sym:nextSibling")) { - if (builtin && in_class) { - String *name = NewString("new"); - if ((use_director || checkAttribute(n, "access", "public")) && !Getattr(class_members, name)) { - Setattr(class_members, name, name); - String *fullname = Swig_name_member(NULL, name, class_name); - if (!builtin_tp_init) - builtin_tp_init = Swig_name_wrapper(fullname); - /* - ParmList *parms = Getattr(n, "parms"); - char const *pyflags = (!parms || Len(parms) == 0) ? "METH_NOARGS" : (Len(parms) == 1) ? "METH_0" : "METH_VARARGS"; - Printf(f_shadow, " { \"__init__\", (PyCFunction) %s, %s, \"\" },\n", builtin_tp_init, Char(pyflags)); - */ - Delete(fullname); - } - Delete(name); - } else if (shadow) { - int allow_kwargs = (check_kwargs(n) && (!Getattr(n, "sym:overloaded"))) ? 1 : 0; - int handled_as_init = 0; - if (!have_constructor) { - String *nname = Getattr(n, "sym:name"); - String *sname = Getattr(getCurrentClass(), "sym:name"); - String *cname = Swig_name_construct(NSPACE_TODO, sname); - handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0); - Delete(cname); - } - if (!have_constructor && handled_as_init) { - if (Getattr(n, "feature:shadow")) { - String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); - String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); - Replaceall(pycode, "$action", pyaction); - Delete(pyaction); - Printv(f_shadow, pycode, "\n", NIL); - Delete(pycode); - } else { - String *pass_self = NewString(""); - Node *parent = Swig_methodclass(n); - String *classname = Swig_class_name(parent); - String *rclassname = Swig_class_name(getCurrentClass()); - assert(rclassname); + if (!have_constructor && handled_as_init) { + if (Getattr(n, "feature:shadow")) { + String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); + String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); + Replaceall(pycode, "$action", pyaction); + Delete(pyaction); + Printv(f_shadow, pycode, "\n", NIL); + Delete(pycode); + } else { + String *pass_self = NewString(""); + Node *parent = Swig_methodclass(n); + String *classname = Swig_class_name(parent); + String *rclassname = Swig_class_name(getCurrentClass()); + assert(rclassname); - String *parms = make_pyParmList(n, true, false, allow_kwargs); - /* Pass 'self' only if using director */ - String *callParms = make_pyParmList(n, false, true, allow_kwargs); + String *parms = make_pyParmList(n, true, false, allow_kwargs); + /* Pass 'self' only if using director */ + String *callParms = make_pyParmList(n, false, true, allow_kwargs); - if (use_director) { - Insert(callParms, 0, "_self, "); - Printv(pass_self, tab8, NIL); - Printf(pass_self, "if self.__class__ == %s:\n", classname); - //Printv(pass_self, tab8, tab4, "args = (None,) + args\n", tab8, "else:\n", tab8, tab4, "args = (self,) + args\n", NIL); - Printv(pass_self, tab8, tab4, "_self = None\n", tab8, "else:\n", tab8, tab4, "_self = self\n", NIL); - } - - Printv(f_shadow, tab4, "def __init__(", parms, ")", returnTypeAnnotation(n), ": \n", NIL); - if (have_docstring(n)) - Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL); - if (have_pythonprepend(n)) - Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); - Printv(f_shadow, pass_self, NIL); - if (fastinit) { - Printv(f_shadow, tab8, module, ".", class_name, "_swiginit(self,", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), ")\n", NIL); - } else { - Printv(f_shadow, - tab8, "this = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", - tab8, "try: self.this.append(this)\n", tab8, "except: self.this = this\n", NIL); - } - if (have_pythonappend(n)) - Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n\n", NIL); - Delete(pass_self); - } - have_constructor = 1; - } else { - /* Hmmm. We seem to be creating a different constructor. We're just going to create a - function for it. */ - - if (Getattr(n, "feature:shadow")) { - String *pycode = pythoncode(Getattr(n, "feature:shadow"), ""); - String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); - Replaceall(pycode, "$action", pyaction); - Delete(pyaction); - Printv(f_shadow_stubs, pycode, "\n", NIL); - Delete(pycode); - } else { - String *parms = make_pyParmList(n, false, false, allow_kwargs); - String *callParms = make_pyParmList(n, false, true, allow_kwargs); - - Printv(f_shadow_stubs, "\ndef ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); - if (have_docstring(n)) - Printv(f_shadow_stubs, tab4, docstring(n, AUTODOC_CTOR, tab4), "\n", NIL); - if (have_pythonprepend(n)) - Printv(f_shadow_stubs, pythoncode(pythonprepend(n), tab4), "\n", NIL); - Printv(f_shadow_stubs, tab4, "val = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", NIL); -#ifdef USE_THISOWN - Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL); -#endif - if (have_pythonappend(n)) - Printv(f_shadow_stubs, pythoncode(pythonappend(n), tab4), "\n", NIL); - Printv(f_shadow_stubs, tab4, "return val\n", NIL); - } - } + if (use_director) { + Insert(callParms, 0, "_self, "); + Printv(pass_self, tab8, NIL); + Printf(pass_self, "if self.__class__ == %s:\n", classname); + //Printv(pass_self, tab8, tab4, "args = (None,) + args\n", tab8, "else:\n", tab8, tab4, "args = (self,) + args\n", NIL); + Printv(pass_self, tab8, tab4, "_self = None\n", tab8, "else:\n", tab8, tab4, "_self = self\n", NIL); } + + Printv(f_shadow, tab4, "def __init__(", parms, ")", returnTypeAnnotation(n), ": \n", NIL); + if (have_docstring(n)) + Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL); + if (have_pythonprepend(n)) + Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); + Printv(f_shadow, pass_self, NIL); + if (fastinit) { + Printv(f_shadow, tab8, module, ".", class_name, "_swiginit(self,", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), ")\n", NIL); + } else { + Printv(f_shadow, + tab8, "this = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", + tab8, "try: self.this.append(this)\n", tab8, "except: self.this = this\n", NIL); + } + if (have_pythonappend(n)) + Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n\n", NIL); + Delete(pass_self); + } + have_constructor = 1; + } else { + /* Hmmm. We seem to be creating a different constructor. We're just going to create a + function for it. */ + + if (Getattr(n, "feature:shadow")) { + String *pycode = pythoncode(Getattr(n, "feature:shadow"), ""); + String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); + Replaceall(pycode, "$action", pyaction); + Delete(pyaction); + Printv(f_shadow_stubs, pycode, "\n", NIL); + Delete(pycode); + } else { + String *parms = make_pyParmList(n, false, false, allow_kwargs); + String *callParms = make_pyParmList(n, false, true, allow_kwargs); + + Printv(f_shadow_stubs, "\ndef ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); + if (have_docstring(n)) + Printv(f_shadow_stubs, tab4, docstring(n, AUTODOC_CTOR, tab4), "\n", NIL); + if (have_pythonprepend(n)) + Printv(f_shadow_stubs, pythoncode(pythonprepend(n), tab4), "\n", NIL); + Printv(f_shadow_stubs, tab4, "val = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", NIL); +#ifdef USE_THISOWN + Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL); +#endif + if (have_pythonappend(n)) + Printv(f_shadow_stubs, pythoncode(pythonappend(n), tab4), "\n", NIL); + Printv(f_shadow_stubs, tab4, "return val\n", NIL); + } } - return SWIG_OK; + } } + return SWIG_OK; + } /* ------------------------------------------------------------ * destructorHandler() * ------------------------------------------------------------ */ - virtual int destructorHandler(Node *n) { - if (builtin && in_class) { - String *name = NewString("delete"); - if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) { - Setattr(class_members, name, name); - /* - String *fullname = Swig_name_member(NULL, name, class_name); - String *wname = Swig_name_wrapper(fullname); - ParmList *parms = Getattr(n, "parms"); - char const *pyflags = (!parms || Len(parms) == 0) ? "METH_NOARGS" : (Len(parms) == 1) ? "METH_0" : "METH_VARARGS"; - Printf(f_shadow, " { \"__del__\", (PyCFunction) %s, %s, \"\" },\n", wname, Char(pyflags)); - Delete(fullname); - Delete(wname); - */ - } - Delete(name); - return SWIG_OK; + virtual int destructorHandler(Node *n) { + if (builtin && in_class) { + String *name = NewString("delete"); + if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) { + Setattr(class_members, name, name); + /* + String *fullname = Swig_name_member(NULL, name, class_name); + String *wname = Swig_name_wrapper(fullname); + ParmList *parms = Getattr(n, "parms"); + char const *pyflags = (!parms || Len(parms) == 0) ? "METH_NOARGS" : (Len(parms) == 1) ? "METH_0" : "METH_VARARGS"; + Printf(f_shadow, " { \"__del__\", (PyCFunction) %s, %s, \"\" },\n", wname, Char(pyflags)); + Delete(fullname); + Delete(wname); + */ + } + Delete(name); + return SWIG_OK; + } + + String *symname = Getattr(n, "sym:name"); + int oldshadow = shadow; + + if (shadow) + shadow = shadow | PYSHADOW_MEMBER; + //Setattr(n,"emit:dealloc","1"); + Language::destructorHandler(n); + shadow = oldshadow; + + if (shadow) { + if (Getattr(n, "feature:shadow")) { + String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); + String *pyaction = NewStringf("%s.%s", module, Swig_name_destroy(NSPACE_TODO, symname)); + Replaceall(pycode, "$action", pyaction); + Delete(pyaction); + Printv(f_shadow, pycode, "\n", NIL); + Delete(pycode); + } else { + Printv(f_shadow, tab4, "__swig_destroy__ = ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "\n", NIL); + if (!have_pythonprepend(n) && !have_pythonappend(n)) { + if (proxydel) { + Printv(f_shadow, tab4, "__del__ = lambda self : None;\n", NIL); + } + return SWIG_OK; } - - String *symname = Getattr(n, "sym:name"); - int oldshadow = shadow; - - if (shadow) - shadow = shadow | PYSHADOW_MEMBER; - //Setattr(n,"emit:dealloc","1"); - Language::destructorHandler(n); - shadow = oldshadow; - - if (shadow) { - if (Getattr(n, "feature:shadow")) { - String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); - String *pyaction = NewStringf("%s.%s", module, Swig_name_destroy(NSPACE_TODO, symname)); - Replaceall(pycode, "$action", pyaction); - Delete(pyaction); - Printv(f_shadow, pycode, "\n", NIL); - Delete(pycode); - } else { - Printv(f_shadow, tab4, "__swig_destroy__ = ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "\n", NIL); - if (!have_pythonprepend(n) && !have_pythonappend(n)) { - if (proxydel) { - Printv(f_shadow, tab4, "__del__ = lambda self : None;\n", NIL); - } - return SWIG_OK; - } - Printv(f_shadow, tab4, "def __del__(self):\n", NIL); - if (have_docstring(n)) - Printv(f_shadow, tab8, docstring(n, AUTODOC_DTOR, tab8), "\n", NIL); - if (have_pythonprepend(n)) - Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); + Printv(f_shadow, tab4, "def __del__(self):\n", NIL); + if (have_docstring(n)) + Printv(f_shadow, tab8, docstring(n, AUTODOC_DTOR, tab8), "\n", NIL); + if (have_pythonprepend(n)) + Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); #ifdef USE_THISOWN - Printv(f_shadow, tab8, "try:\n", NIL); - Printv(f_shadow, tab8, tab4, "if self.thisown: ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "(self)\n", NIL); - Printv(f_shadow, tab8, "except: pass\n", NIL); + Printv(f_shadow, tab8, "try:\n", NIL); + Printv(f_shadow, tab8, tab4, "if self.thisown: ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "(self)\n", NIL); + Printv(f_shadow, tab8, "except: pass\n", NIL); #else #endif - if (have_pythonappend(n)) - Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL); - Printv(f_shadow, tab8, "pass\n", NIL); - Printv(f_shadow, "\n", NIL); - } - } - return SWIG_OK; + if (have_pythonappend(n)) + Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL); + Printv(f_shadow, tab8, "pass\n", NIL); + Printv(f_shadow, "\n", NIL); + } } + return SWIG_OK; + } - /* ------------------------------------------------------------ - * membervariableHandler() - * ------------------------------------------------------------ */ + /* ------------------------------------------------------------ + * membervariableHandler() + * ------------------------------------------------------------ */ - virtual int membervariableHandler(Node *n) { - String *symname = Getattr(n, "sym:name"); + virtual int membervariableHandler(Node *n) { + String *symname = Getattr(n, "sym:name"); - int oldshadow = shadow; - if (shadow) - shadow = shadow | PYSHADOW_MEMBER; - Language::membervariableHandler(n); - shadow = oldshadow; + int oldshadow = shadow; + if (shadow) + shadow = shadow | PYSHADOW_MEMBER; + Language::membervariableHandler(n); + shadow = oldshadow; - if (builtin && in_class) { - } else if (shadow) { - String *mname = Swig_name_member(NSPACE_TODO, class_name, symname); - String *setname = Swig_name_set(NSPACE_TODO, mname); - String *getname = Swig_name_get(NSPACE_TODO, mname); - int assignable = is_assignable(n); - if (!modern) { - if (assignable) { - Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL); - } - Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL); - } - if (!classic) { - if (!assignable) { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL); - } else { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL); - } - } - Delete(mname); - Delete(setname); - Delete(getname); + if (shadow && !builtin) { + String *mname = Swig_name_member(NSPACE_TODO, class_name, symname); + String *setname = Swig_name_set(NSPACE_TODO, mname); + String *getname = Swig_name_get(NSPACE_TODO, mname); + int assignable = is_assignable(n); + if (!modern) { + if (assignable) { + Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL); } - - return SWIG_OK; - } - - /* ------------------------------------------------------------ - * staticmembervariableHandler() - * ------------------------------------------------------------ */ - - virtual int staticmembervariableHandler(Node *n) { - Swig_save("builtin_staticmembervariableHandler", n, "builtin_symname", NIL); - Language::staticmembervariableHandler(n); - Swig_restore(n); - - if (GetFlag(n, "wrappedasconstant")) - return SWIG_OK; - - String *symname = Getattr(n, "sym:name"); - - if (shadow) { - if (GetFlag(n, "hasconsttype")) { - String *mname = Swig_name_member(NSPACE_TODO, class_name, symname); - Printf(f_shadow_stubs, "%s.%s = %s.%s.%s\n", class_name, symname, module, global_name, mname); - Delete(mname); - } else { - String *mname = Swig_name_member(NSPACE_TODO, class_name, symname); - String *getname = Swig_name_get(NSPACE_TODO, mname); - String *wrapgetname = Swig_name_wrapper(getname); - String *vargetname = NewStringf("Swig_var_%s", getname); - String *setname = Swig_name_set(NSPACE_TODO, mname); - String *wrapsetname = Swig_name_wrapper(setname); - String *varsetname = NewStringf("Swig_var_%s", setname); - - Wrapper *f = NewWrapper(); - Printv(f->def, "SWIGINTERN PyObject *", wrapgetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *SWIGUNUSEDPARM(args)) {", NIL); - Printv(f->code, " return ", vargetname, "();\n", NIL); - Append(f->code, "}\n"); - add_method(getname, wrapgetname, 0); - Wrapper_print(f, f_wrappers); - DelWrapper(f); - int assignable = is_assignable(n); - if (assignable) { - Wrapper *f = NewWrapper(); - Printv(f->def, "SWIGINTERN PyObject *", wrapsetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); - Wrapper_add_local(f, "value", "PyObject *value"); - Wrapper_add_local(f, "res", "int res"); - Append(f->code, "if (!PyArg_ParseTuple(args,(char *)\"O:set\",&value)) return NULL;\n"); - Printv(f->code, "res = ", varsetname, "(value);\n", NIL); - Append(f->code, "return !res ? SWIG_Py_Void() : NULL;\n"); - Append(f->code, "}\n"); - Wrapper_print(f, f_wrappers); - add_method(setname, wrapsetname, 0); - DelWrapper(f); - } - if (!modern) { - if (assignable) { - Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL); - } - Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL); - } - if (!classic) { - if (!assignable) { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL); - } else { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL); - } - } - Delete(mname); - Delete(getname); - Delete(wrapgetname); - Delete(vargetname); - Delete(setname); - Delete(wrapsetname); - Delete(varsetname); - } - } - return SWIG_OK; - } - - /* ------------------------------------------------------------ - * memberconstantHandler() - * ------------------------------------------------------------ */ - - 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); - } - int oldshadow = shadow; - if (shadow) - shadow = shadow | PYSHADOW_MEMBER; - Language::memberconstantHandler(n); - shadow = oldshadow; - - if (builtin && in_class) { - Swig_restore(n); - } else if (shadow) { - Printv(f_shadow, tab4, symname, " = ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL); - } - return SWIG_OK; - } - - /* ------------------------------------------------------------ - * insertDirective() - * - * Hook for %insert directive. We're going to look for special %shadow inserts - * as a special case so we can do indenting correctly - * ------------------------------------------------------------ */ - - virtual int insertDirective(Node *n) { - String *code = Getattr(n, "code"); - String *section = Getattr(n, "section"); - - if ((!ImportMode) && ((Cmp(section, "python") == 0) || (Cmp(section, "shadow") == 0))) { - if (shadow) { - String *pycode = pythoncode(code, shadow_indent); - Printv(f_shadow, pycode, NIL); - Delete(pycode); - } + Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL); + } + if (!classic) { + if (!assignable) { + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL); } else { - Language::insertDirective(n); + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL); } - return SWIG_OK; + } + Delete(mname); + Delete(setname); + Delete(getname); } - virtual String *runtimeCode() { - String *s = NewString(""); - String *shead = Swig_include_sys("pyhead.swg"); - if (!shead) { - Printf(stderr, "*** Unable to open 'pyhead.swg'\n"); - } else { - Append(s, shead); - Delete(shead); - } - String *serrors = Swig_include_sys("pyerrors.swg"); - if (!serrors) { - Printf(stderr, "*** Unable to open 'pyerrors.swg'\n"); - } else { - Append(s, serrors); - Delete(serrors); - } - String *sthread = Swig_include_sys("pythreads.swg"); - if (!sthread) { - Printf(stderr, "*** Unable to open 'pythreads.swg'\n"); - } else { - Append(s, sthread); - Delete(sthread); - } - String *sapi = Swig_include_sys("pyapi.swg"); - if (!sapi) { - Printf(stderr, "*** Unable to open 'pyapi.swg'\n"); - } else { - Append(s, sapi); - Delete(sapi); - } - String *srun = Swig_include_sys("pyrun.swg"); - if (!srun) { - Printf(stderr, "*** Unable to open 'pyrun.swg'\n"); - } else { - Append(s, srun); - Delete(srun); - } - return s; - } + return SWIG_OK; + } - virtual String *defaultExternalRuntimeFilename() { - return NewString("swigpyrun.h"); + /* ------------------------------------------------------------ + * staticmembervariableHandler() + * ------------------------------------------------------------ */ + + virtual int staticmembervariableHandler(Node *n) { + Swig_save("builtin_staticmembervariableHandler", n, "builtin_symname", NIL); + Language::staticmembervariableHandler(n); + Swig_restore(n); + + if (GetFlag(n, "wrappedasconstant")) + return SWIG_OK; + + String *symname = Getattr(n, "sym:name"); + + if (shadow) { + if (GetFlag(n, "hasconsttype")) { + String *mname = Swig_name_member(NSPACE_TODO, class_name, symname); + Printf(f_shadow_stubs, "%s.%s = %s.%s.%s\n", class_name, symname, module, global_name, mname); + Delete(mname); + } else { + String *mname = Swig_name_member(NSPACE_TODO, class_name, symname); + String *getname = Swig_name_get(NSPACE_TODO, mname); + String *wrapgetname = Swig_name_wrapper(getname); + String *vargetname = NewStringf("Swig_var_%s", getname); + String *setname = Swig_name_set(NSPACE_TODO, mname); + String *wrapsetname = Swig_name_wrapper(setname); + String *varsetname = NewStringf("Swig_var_%s", setname); + + Wrapper *f = NewWrapper(); + Printv(f->def, "SWIGINTERN PyObject *", wrapgetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *SWIGUNUSEDPARM(args)) {", NIL); + Printv(f->code, " return ", vargetname, "();\n", NIL); + Append(f->code, "}\n"); + add_method(getname, wrapgetname, 0); + Wrapper_print(f, f_wrappers); + DelWrapper(f); + int assignable = is_assignable(n); + if (assignable) { + Wrapper *f = NewWrapper(); + Printv(f->def, "SWIGINTERN PyObject *", wrapsetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); + Wrapper_add_local(f, "value", "PyObject *value"); + Wrapper_add_local(f, "res", "int res"); + Append(f->code, "if (!PyArg_ParseTuple(args,(char *)\"O:set\",&value)) return NULL;\n"); + Printv(f->code, "res = ", varsetname, "(value);\n", NIL); + Append(f->code, "return !res ? SWIG_Py_Void() : NULL;\n"); + Append(f->code, "}\n"); + Wrapper_print(f, f_wrappers); + add_method(setname, wrapsetname, 0); + DelWrapper(f); + } + if (!modern) { + if (assignable) { + Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL); + } + Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL); + } + if (!classic) { + if (!assignable) { + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL); + } else { + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL); + } + } + Delete(mname); + Delete(getname); + Delete(wrapgetname); + Delete(vargetname); + Delete(setname); + Delete(wrapsetname); + Delete(varsetname); + } } + return SWIG_OK; + } + + /* ------------------------------------------------------------ + * memberconstantHandler() + * ------------------------------------------------------------ */ + + 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); + } + int oldshadow = shadow; + if (shadow) + shadow = shadow | PYSHADOW_MEMBER; + Language::memberconstantHandler(n); + shadow = oldshadow; + + if (builtin && in_class) { + Swig_restore(n); + } else if (shadow) { + Printv(f_shadow, tab4, symname, " = ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL); + } + return SWIG_OK; + } + + /* ------------------------------------------------------------ + * insertDirective() + * + * Hook for %insert directive. We're going to look for special %shadow inserts + * as a special case so we can do indenting correctly + * ------------------------------------------------------------ */ + + virtual int insertDirective(Node *n) { + String *code = Getattr(n, "code"); + String *section = Getattr(n, "section"); + + if ((!ImportMode) && ((Cmp(section, "python") == 0) || (Cmp(section, "shadow") == 0))) { + if (shadow) { + String *pycode = pythoncode(code, shadow_indent); + Printv(f_shadow, pycode, NIL); + Delete(pycode); + } + } else { + Language::insertDirective(n); + } + return SWIG_OK; + } + + virtual String *runtimeCode() { + String *s = NewString(""); + String *shead = Swig_include_sys("pyhead.swg"); + if (!shead) { + Printf(stderr, "*** Unable to open 'pyhead.swg'\n"); + } else { + Append(s, shead); + Delete(shead); + } + String *serrors = Swig_include_sys("pyerrors.swg"); + if (!serrors) { + Printf(stderr, "*** Unable to open 'pyerrors.swg'\n"); + } else { + Append(s, serrors); + Delete(serrors); + } + String *sthread = Swig_include_sys("pythreads.swg"); + if (!sthread) { + Printf(stderr, "*** Unable to open 'pythreads.swg'\n"); + } else { + Append(s, sthread); + Delete(sthread); + } + String *sapi = Swig_include_sys("pyapi.swg"); + if (!sapi) { + Printf(stderr, "*** Unable to open 'pyapi.swg'\n"); + } else { + Append(s, sapi); + Delete(sapi); + } + String *srun = Swig_include_sys("pyrun.swg"); + if (!srun) { + Printf(stderr, "*** Unable to open 'pyrun.swg'\n"); + } else { + Append(s, srun); + Delete(srun); + } + return s; + } + + virtual String *defaultExternalRuntimeFilename() { + return NewString("swigpyrun.h"); + } }; @@ -3964,489 +4081,489 @@ public: * ** Moved it here due to internal error on gcc-2.96 ** * --------------------------------------------------------------- */ int PYTHON::classDirectorMethods(Node *n) { - director_method_index = 0; - return Language::classDirectorMethods(n); + director_method_index = 0; + return Language::classDirectorMethods(n); } int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { - int is_void = 0; - int is_pointer = 0; - String *decl; - String *type; - String *name; - String *classname; - String *c_classname = Getattr(parent, "name"); - String *declaration; - ParmList *l; - Wrapper *w; - String *tm; - String *wrap_args = NewString(""); - String *return_type; - String *value = Getattr(n, "value"); - String *storage = Getattr(n, "storage"); - bool pure_virtual = false; - int status = SWIG_OK; - int idx; - bool ignored_method = GetFlag(n, "feature:ignore") ? true : false; + int is_void = 0; + int is_pointer = 0; + String *decl; + String *type; + String *name; + String *classname; + String *c_classname = Getattr(parent, "name"); + String *declaration; + ParmList *l; + Wrapper *w; + String *tm; + String *wrap_args = NewString(""); + String *return_type; + String *value = Getattr(n, "value"); + String *storage = Getattr(n, "storage"); + bool pure_virtual = false; + int status = SWIG_OK; + int idx; + bool ignored_method = GetFlag(n, "feature:ignore") ? true : false; - if (Cmp(storage, "virtual") == 0) { - if (Cmp(value, "0") == 0) { - pure_virtual = true; + if (Cmp(storage, "virtual") == 0) { + if (Cmp(value, "0") == 0) { + pure_virtual = true; + } } - } - classname = Getattr(parent, "sym:name"); - type = Getattr(n, "type"); - name = Getattr(n, "name"); + classname = Getattr(parent, "sym:name"); + type = Getattr(n, "type"); + name = Getattr(n, "name"); - w = NewWrapper(); - declaration = NewString(""); + w = NewWrapper(); + declaration = NewString(""); - /* determine if the method returns a pointer */ - decl = Getattr(n, "decl"); - is_pointer = SwigType_ispointer_return(decl); - is_void = (!Cmp(type, "void") && !is_pointer); + /* determine if the method returns a pointer */ + decl = Getattr(n, "decl"); + is_pointer = SwigType_ispointer_return(decl); + is_void = (!Cmp(type, "void") && !is_pointer); - /* form complete return type */ - return_type = Copy(type); - { - SwigType *t = Copy(decl); - SwigType *f = 0; - f = SwigType_pop_function(t); - SwigType_push(return_type, t); - Delete(f); - Delete(t); - } + /* form complete return type */ + return_type = Copy(type); + { + SwigType *t = Copy(decl); + SwigType *f = 0; + f = SwigType_pop_function(t); + SwigType_push(return_type, t); + Delete(f); + Delete(t); + } - /* virtual method definition */ - l = Getattr(n, "parms"); - String *target; - String *pclassname = NewStringf("SwigDirector_%s", classname); - String *qualified_name = NewStringf("%s::%s", pclassname, name); - SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type; - target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); - Printf(w->def, "%s", target); - Delete(qualified_name); - Delete(target); - /* header declaration */ - target = Swig_method_decl(rtype, decl, name, l, 0, 1); - Printf(declaration, " virtual %s", target); - Delete(target); + /* virtual method definition */ + l = Getattr(n, "parms"); + String *target; + String *pclassname = NewStringf("SwigDirector_%s", classname); + String *qualified_name = NewStringf("%s::%s", pclassname, name); + SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type; + target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); + Printf(w->def, "%s", target); + Delete(qualified_name); + Delete(target); + /* header declaration */ + target = Swig_method_decl(rtype, decl, name, l, 0, 1); + Printf(declaration, " virtual %s", target); + Delete(target); - // Get any exception classes in the throws typemap - ParmList *throw_parm_list = 0; + // Get any exception classes in the throws typemap + ParmList *throw_parm_list = 0; - if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) { - Parm *p; - int gencomma = 0; + if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) { + Parm *p; + int gencomma = 0; - Append(w->def, " throw("); - Append(declaration, " throw("); + Append(w->def, " throw("); + Append(declaration, " throw("); - if (throw_parm_list) - Swig_typemap_attach_parms("throws", throw_parm_list, 0); - for (p = throw_parm_list; p; p = nextSibling(p)) { - if ((tm = Getattr(p, "tmap:throws"))) { - if (gencomma++) { - Append(w->def, ", "); - Append(declaration, ", "); + if (throw_parm_list) + Swig_typemap_attach_parms("throws", throw_parm_list, 0); + for (p = throw_parm_list; p; p = nextSibling(p)) { + if ((tm = Getattr(p, "tmap:throws"))) { + if (gencomma++) { + Append(w->def, ", "); + Append(declaration, ", "); + } + String *str = SwigType_str(Getattr(p, "type"), 0); + Append(w->def, str); + Append(declaration, str); + Delete(str); } - String *str = SwigType_str(Getattr(p, "type"), 0); - Append(w->def, str); - Append(declaration, str); - Delete(str); + } + + Append(w->def, ")"); + Append(declaration, ")"); + } + + Append(w->def, " {"); + Append(declaration, ";\n"); + + /* declare method return value + * if the return value is a reference or const reference, a specialized typemap must + * handle it, including declaration of c_result ($result). + */ + if (!is_void) { + if (!(ignored_method && !pure_virtual)) { + String *cres = SwigType_lstr(return_type, "c_result"); + Printf(w->code, "%s;\n", cres); + Delete(cres); } } - Append(w->def, ")"); - Append(declaration, ")"); - } - - Append(w->def, " {"); - Append(declaration, ";\n"); - - /* declare method return value - * if the return value is a reference or const reference, a specialized typemap must - * handle it, including declaration of c_result ($result). - */ - if (!is_void) { - if (!(ignored_method && !pure_virtual)) { - String *cres = SwigType_lstr(return_type, "c_result"); - Printf(w->code, "%s;\n", cres); - Delete(cres); - } - } - - if (ignored_method) { - if (!pure_virtual) { - if (!is_void) - Printf(w->code, "return "); - String *super_call = Swig_method_call(super, l); - Printf(w->code, "%s;\n", super_call); - Delete(super_call); + if (ignored_method) { + if (!pure_virtual) { + if (!is_void) + Printf(w->code, "return "); + String *super_call = Swig_method_call(super, l); + Printf(w->code, "%s;\n", super_call); + Delete(super_call); + } else { + Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname), + SwigType_namestr(name)); + } } else { - Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname), - SwigType_namestr(name)); - } - } else { - /* attach typemaps to arguments (C/C++ -> Python) */ - String *arglist = NewString(""); - String *parse_args = NewString(""); + /* attach typemaps to arguments (C/C++ -> Python) */ + String *arglist = NewString(""); + String *parse_args = NewString(""); - /* remove the wrapper 'w' since it was producing spurious temps */ - Swig_typemap_attach_parms("in", l, 0); - Swig_typemap_attach_parms("directorin", l, 0); - Swig_typemap_attach_parms("directorargout", l, w); + /* remove the wrapper 'w' since it was producing spurious temps */ + Swig_typemap_attach_parms("in", l, 0); + Swig_typemap_attach_parms("directorin", l, 0); + Swig_typemap_attach_parms("directorargout", l, w); - Parm *p; - char source[256]; + Parm *p; + char source[256]; - int outputs = 0; - if (!is_void) - outputs++; - - /* build argument list and type conversion string */ - idx = 0; - p = l; - int use_parse = 0; - while (p) { - if (checkAttribute(p, "tmap:in:numinputs", "0")) { - p = Getattr(p, "tmap:in:next"); - continue; - } - - /* old style? caused segfaults without the p!=0 check - in the for() condition, and seems dangerous in the - while loop as well. - while (Getattr(p, "tmap:ignore")) { - p = Getattr(p, "tmap:ignore:next"); - } - */ - - if (Getattr(p, "tmap:directorargout") != 0) + int outputs = 0; + if (!is_void) outputs++; - String *pname = Getattr(p, "name"); - String *ptype = Getattr(p, "type"); - - Putc(',', arglist); - if ((tm = Getattr(p, "tmap:directorin")) != 0) { - String *parse = Getattr(p, "tmap:directorin:parse"); - if (!parse) { - sprintf(source, "obj%d", idx++); - String *input = NewString(source); - Replaceall(tm, "$input", input); - Delete(input); - Replaceall(tm, "$owner", "0"); - /* Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL); */ - Printv(wrap_args, "swig::SwigVar_PyObject ", source, ";\n", NIL); - - Printv(wrap_args, tm, "\n", NIL); - Printv(arglist, "(PyObject *)", source, NIL); - Putc('O', parse_args); - } else { - use_parse = 1; - Append(parse_args, parse); - Replaceall(tm, "$input", pname); - Replaceall(tm, "$owner", "0"); - if (Len(tm) == 0) - Append(tm, pname); - Append(arglist, tm); + /* build argument list and type conversion string */ + idx = 0; + p = l; + int use_parse = 0; + while (p) { + if (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); + continue; } - p = Getattr(p, "tmap:directorin:next"); - continue; - } else if (Cmp(ptype, "void")) { - /* special handling for pointers to other C++ director classes. - * ideally this would be left to a typemap, but there is currently no - * way to selectively apply the dynamic_cast<> to classes that have - * directors. in other words, the type "SwigDirector_$1_lname" only exists - * for classes with directors. we avoid the problem here by checking - * module.wrap::directormap, but it's not clear how to get a typemap to - * do something similar. perhaps a new default typemap (in addition - * to SWIGTYPE) called DIRECTORTYPE? - */ - if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) { - Node *module = Getattr(parent, "module"); - Node *target = Swig_directormap(module, ptype); - sprintf(source, "obj%d", idx++); - String *nonconst = 0; - /* strip pointer/reference --- should move to Swig/stype.c */ - String *nptype = NewString(Char(ptype) + 2); - /* name as pointer */ - String *ppname = Copy(pname); - if (SwigType_isreference(ptype)) { - Insert(ppname, 0, "&"); - } - /* if necessary, cast away const since Python doesn't support it! */ - if (SwigType_isconst(nptype)) { - nonconst = NewStringf("nc_tmp_%s", pname); - String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname); - Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL); - Delete(nonconst_i); - Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number, - "Target language argument '%s' discards const in director method %s::%s.\n", - SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name)); + + /* old style? caused segfaults without the p!=0 check + in the for() condition, and seems dangerous in the + while loop as well. + while (Getattr(p, "tmap:ignore")) { + p = Getattr(p, "tmap:ignore:next"); + } + */ + + if (Getattr(p, "tmap:directorargout") != 0) + outputs++; + + String *pname = Getattr(p, "name"); + String *ptype = Getattr(p, "type"); + + Putc(',', arglist); + if ((tm = Getattr(p, "tmap:directorin")) != 0) { + String *parse = Getattr(p, "tmap:directorin:parse"); + if (!parse) { + sprintf(source, "obj%d", idx++); + String *input = NewString(source); + Replaceall(tm, "$input", input); + Delete(input); + Replaceall(tm, "$owner", "0"); + /* Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL); */ + Printv(wrap_args, "swig::SwigVar_PyObject ", source, ";\n", NIL); + + Printv(wrap_args, tm, "\n", NIL); + Printv(arglist, "(PyObject *)", source, NIL); + Putc('O', parse_args); } else { - nonconst = Copy(ppname); + use_parse = 1; + Append(parse_args, parse); + Replaceall(tm, "$input", pname); + Replaceall(tm, "$owner", "0"); + if (Len(tm) == 0) + Append(tm, pname); + Append(arglist, tm); } - Delete(nptype); - Delete(ppname); - String *mangle = SwigType_manglestr(ptype); - if (target) { - String *director = NewStringf("director_%s", mangle); - Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL); - 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); - 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); - Append(wrap_args, "}\n"); - Delete(director); - Printv(arglist, source, NIL); + p = Getattr(p, "tmap:directorin:next"); + continue; + } else if (Cmp(ptype, "void")) { + /* special handling for pointers to other C++ director classes. + * ideally this would be left to a typemap, but there is currently no + * way to selectively apply the dynamic_cast<> to classes that have + * directors. in other words, the type "SwigDirector_$1_lname" only exists + * for classes with directors. we avoid the problem here by checking + * module.wrap::directormap, but it's not clear how to get a typemap to + * do something similar. perhaps a new default typemap (in addition + * to SWIGTYPE) called DIRECTORTYPE? + */ + if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) { + Node *module = Getattr(parent, "module"); + Node *target = Swig_directormap(module, ptype); + sprintf(source, "obj%d", idx++); + String *nonconst = 0; + /* strip pointer/reference --- should move to Swig/stype.c */ + String *nptype = NewString(Char(ptype) + 2); + /* name as pointer */ + String *ppname = Copy(pname); + if (SwigType_isreference(ptype)) { + Insert(ppname, 0, "&"); + } + /* if necessary, cast away const since Python doesn't support it! */ + if (SwigType_isconst(nptype)) { + nonconst = NewStringf("nc_tmp_%s", pname); + String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname); + Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL); + Delete(nonconst_i); + Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number, + "Target language argument '%s' discards const in director method %s::%s.\n", + SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name)); + } else { + nonconst = Copy(ppname); + } + Delete(nptype); + Delete(ppname); + String *mangle = SwigType_manglestr(ptype); + if (target) { + String *director = NewStringf("director_%s", mangle); + Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL); + 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); + 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); + Append(wrap_args, "}\n"); + Delete(director); + 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_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n", + // source, nonconst, base); + Printv(arglist, source, NIL); + } + Putc('O', parse_args); + Delete(mangle); + Delete(nonconst); } 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_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n", - // source, nonconst, base); - Printv(arglist, source, NIL); + Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, + "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0), + SwigType_namestr(c_classname), SwigType_namestr(name)); + status = SWIG_NOWRAP; + break; } - Putc('O', parse_args); - Delete(mangle); - Delete(nonconst); - } else { - Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, - "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0), - SwigType_namestr(c_classname), SwigType_namestr(name)); - status = SWIG_NOWRAP; - break; } - } - p = nextSibling(p); - } - - /* add the method name as a PyString */ - String *pyname = Getattr(n, "sym:name"); - - int allow_thread = threads_enable(n); - - if (allow_thread) { - thread_begin_block(n, w->code); - Append(w->code, "{\n"); - } - - /* wrap complex arguments to PyObjects */ - Printv(w->code, wrap_args, NIL); - - /* pass the method call on to the Python object */ - if (dirprot_mode() && !is_public(n)) { - Printf(w->code, "swig_set_inner(\"%s\", true);\n", name); - } - - - Append(w->code, "if (!swig_get_self()) {\n"); - Printf(w->code, " Swig::DirectorException::raise(\"'self' uninitialized, maybe you forgot to call %s.__init__.\");\n", classname); - Append(w->code, "}\n"); - Append(w->code, "#if defined(SWIG_PYTHON_DIRECTOR_VTABLE)\n"); - Printf(w->code, "const size_t swig_method_index = %d;\n", director_method_index++); - Printf(w->code, "const char * const swig_method_name = \"%s\";\n", pyname); - - Append(w->code, "PyObject* method = swig_get_method(swig_method_index, swig_method_name);\n"); - if (Len(parse_args) > 0) { - if (use_parse || !modernargs) { - Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunction(method, (char *)\"(%s)\" %s);\n", parse_args, arglist); - } else { - Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunctionObjArgs(method %s, NULL);\n", arglist); - } - } else { - if (modernargs) { - Append(w->code, "swig::SwigVar_PyObject args = PyTuple_New(0);\n"); - Append(w->code, "swig::SwigVar_PyObject result = PyObject_Call(method, (PyObject*) args, NULL);\n"); - } else { - Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunction(method, NULL, NULL);\n"); - } - } - Append(w->code, "#else\n"); - if (Len(parse_args) > 0) { - if (use_parse || !modernargs) { - Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethod(swig_get_self(), (char *)\"%s\", (char *)\"(%s)\" %s);\n", - pyname, parse_args, arglist); - } else { - Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname); - Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name %s, NULL);\n", arglist); - } - } else { - if (!modernargs) { - Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethod(swig_get_self(), (char *) \"%s\", NULL);\n", pyname); - } else { - Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname); - Append(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name, NULL);\n"); - } - } - Append(w->code, "#endif\n"); - - if (dirprot_mode() && !is_public(n)) - Printf(w->code, "swig_set_inner(\"%s\", false);\n", name); - - /* exception handling */ - tm = Swig_typemap_lookup("director:except", n, "result", 0); - if (!tm) { - tm = Getattr(n, "feature:director:except"); - if (tm) - tm = Copy(tm); - } - Append(w->code, "if (!result) {\n"); - Append(w->code, " PyObject *error = PyErr_Occurred();\n"); - if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) { - Replaceall(tm, "$error", "error"); - Printv(w->code, Str(tm), "\n", NIL); - } else { - Append(w->code, " if (error) {\n"); - Printf(w->code, " Swig::DirectorMethodException::raise(\"Error detected when calling '%s.%s'\");\n", classname, pyname); - Append(w->code, " }\n"); - } - Append(w->code, "}\n"); - Delete(tm); - - /* - * Python method may return a simple object, or a tuple. - * for in/out aruments, we have to extract the appropriate PyObjects from the tuple, - * then marshal everything back to C/C++ (return value and output arguments). - * - */ - - /* marshal return value and other outputs (if any) from PyObject to C/C++ type */ - - String *cleanup = NewString(""); - String *outarg = NewString(""); - - if (outputs > 1) { - Wrapper_add_local(w, "output", "PyObject *output"); - Append(w->code, "if (!PyTuple_Check(result)) {\n"); - Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Python method %s.%sfailed to return a tuple.\");\n", classname, pyname); - Append(w->code, "}\n"); - } - - idx = 0; - - /* marshal return value */ - if (!is_void) { - /* this seems really silly. the node's type excludes - * qualifier/pointer/reference markers, which have to be retrieved - * from the decl field to construct return_type. but the typemap - * lookup routine uses the node's type, so we have to swap in and - * out the correct type. it's not just me, similar silliness also - * occurs in Language::cDeclaration(). - */ - Setattr(n, "type", return_type); - tm = Swig_typemap_lookup("directorout", n, "result", w); - Setattr(n, "type", type); - if (tm != 0) { - if (outputs > 1) { - Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++); - Replaceall(tm, "$input", "output"); - } else { - Replaceall(tm, "$input", "result"); - } - char temp[24]; - sprintf(temp, "%d", idx); - Replaceall(tm, "$argnum", temp); - - /* TODO check this */ - if (Getattr(n, "wrap:disown")) { - Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); - } else { - Replaceall(tm, "$disown", "0"); - } - if (Getattr(n, "tmap:directorout:implicitconv")) { - Replaceall(tm, "$implicitconv", get_implicitconv_flag(n)); - } - Replaceall(tm, "$result", "c_result"); - Printv(w->code, tm, "\n", NIL); - Delete(tm); - } else { - Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, - "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), SwigType_namestr(c_classname), - SwigType_namestr(name)); - status = SWIG_ERROR; - } - } - - /* marshal outputs */ - for (p = l; p;) { - if ((tm = Getattr(p, "tmap:directorargout")) != 0) { - if (outputs > 1) { - Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++); - Replaceall(tm, "$input", "output"); - } else { - Replaceall(tm, "$input", "result"); - } - Replaceall(tm, "$result", Getattr(p, "name")); - Printv(w->code, tm, "\n", NIL); - p = Getattr(p, "tmap:directorargout:next"); - } else { p = nextSibling(p); } - } - /* any existing helper functions to handle this? */ - if (allow_thread) { - Append(w->code, "}\n"); - thread_end_block(n, w->code); - } + /* add the method name as a PyString */ + String *pyname = Getattr(n, "sym:name"); - Delete(parse_args); - Delete(arglist); - Delete(cleanup); - Delete(outarg); - } + int allow_thread = threads_enable(n); - if (!is_void) { - if (!(ignored_method && !pure_virtual)) { - String *rettype = SwigType_str(return_type, 0); - if (!SwigType_isreference(return_type)) { - Printf(w->code, "return (%s) c_result;\n", rettype); - } else { - Printf(w->code, "return (%s) *c_result;\n", rettype); + if (allow_thread) { + thread_begin_block(n, w->code); + Append(w->code, "{\n"); } - Delete(rettype); + + /* wrap complex arguments to PyObjects */ + Printv(w->code, wrap_args, NIL); + + /* pass the method call on to the Python object */ + if (dirprot_mode() && !is_public(n)) { + Printf(w->code, "swig_set_inner(\"%s\", true);\n", name); + } + + + Append(w->code, "if (!swig_get_self()) {\n"); + Printf(w->code, " Swig::DirectorException::raise(\"'self' uninitialized, maybe you forgot to call %s.__init__.\");\n", classname); + Append(w->code, "}\n"); + Append(w->code, "#if defined(SWIG_PYTHON_DIRECTOR_VTABLE)\n"); + Printf(w->code, "const size_t swig_method_index = %d;\n", director_method_index++); + Printf(w->code, "const char * const swig_method_name = \"%s\";\n", pyname); + + Append(w->code, "PyObject* method = swig_get_method(swig_method_index, swig_method_name);\n"); + if (Len(parse_args) > 0) { + if (use_parse || !modernargs) { + Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunction(method, (char *)\"(%s)\" %s);\n", parse_args, arglist); + } else { + Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunctionObjArgs(method %s, NULL);\n", arglist); + } + } else { + if (modernargs) { + Append(w->code, "swig::SwigVar_PyObject args = PyTuple_New(0);\n"); + Append(w->code, "swig::SwigVar_PyObject result = PyObject_Call(method, (PyObject*) args, NULL);\n"); + } else { + Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunction(method, NULL, NULL);\n"); + } + } + Append(w->code, "#else\n"); + if (Len(parse_args) > 0) { + if (use_parse || !modernargs) { + Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethod(swig_get_self(), (char *)\"%s\", (char *)\"(%s)\" %s);\n", + pyname, parse_args, arglist); + } else { + Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname); + Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name %s, NULL);\n", arglist); + } + } else { + if (!modernargs) { + Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethod(swig_get_self(), (char *) \"%s\", NULL);\n", pyname); + } else { + Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname); + Append(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name, NULL);\n"); + } + } + Append(w->code, "#endif\n"); + + if (dirprot_mode() && !is_public(n)) + Printf(w->code, "swig_set_inner(\"%s\", false);\n", name); + + /* exception handling */ + tm = Swig_typemap_lookup("director:except", n, "result", 0); + if (!tm) { + tm = Getattr(n, "feature:director:except"); + if (tm) + tm = Copy(tm); + } + Append(w->code, "if (!result) {\n"); + Append(w->code, " PyObject *error = PyErr_Occurred();\n"); + if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) { + Replaceall(tm, "$error", "error"); + Printv(w->code, Str(tm), "\n", NIL); + } else { + Append(w->code, " if (error) {\n"); + Printf(w->code, " Swig::DirectorMethodException::raise(\"Error detected when calling '%s.%s'\");\n", classname, pyname); + Append(w->code, " }\n"); + } + Append(w->code, "}\n"); + Delete(tm); + + /* + * Python method may return a simple object, or a tuple. + * for in/out aruments, we have to extract the appropriate PyObjects from the tuple, + * then marshal everything back to C/C++ (return value and output arguments). + * + */ + + /* marshal return value and other outputs (if any) from PyObject to C/C++ type */ + + String *cleanup = NewString(""); + String *outarg = NewString(""); + + if (outputs > 1) { + Wrapper_add_local(w, "output", "PyObject *output"); + Append(w->code, "if (!PyTuple_Check(result)) {\n"); + Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Python method %s.%sfailed to return a tuple.\");\n", classname, pyname); + Append(w->code, "}\n"); + } + + idx = 0; + + /* marshal return value */ + if (!is_void) { + /* this seems really silly. the node's type excludes + * qualifier/pointer/reference markers, which have to be retrieved + * from the decl field to construct return_type. but the typemap + * lookup routine uses the node's type, so we have to swap in and + * out the correct type. it's not just me, similar silliness also + * occurs in Language::cDeclaration(). + */ + Setattr(n, "type", return_type); + tm = Swig_typemap_lookup("directorout", n, "result", w); + Setattr(n, "type", type); + if (tm != 0) { + if (outputs > 1) { + Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++); + Replaceall(tm, "$input", "output"); + } else { + Replaceall(tm, "$input", "result"); + } + char temp[24]; + sprintf(temp, "%d", idx); + Replaceall(tm, "$argnum", temp); + + /* TODO check this */ + if (Getattr(n, "wrap:disown")) { + Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); + } else { + Replaceall(tm, "$disown", "0"); + } + if (Getattr(n, "tmap:directorout:implicitconv")) { + Replaceall(tm, "$implicitconv", get_implicitconv_flag(n)); + } + Replaceall(tm, "$result", "c_result"); + Printv(w->code, tm, "\n", NIL); + Delete(tm); + } else { + Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, + "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), SwigType_namestr(c_classname), + SwigType_namestr(name)); + status = SWIG_ERROR; + } + } + + /* marshal outputs */ + for (p = l; p;) { + if ((tm = Getattr(p, "tmap:directorargout")) != 0) { + if (outputs > 1) { + Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++); + Replaceall(tm, "$input", "output"); + } else { + Replaceall(tm, "$input", "result"); + } + Replaceall(tm, "$result", Getattr(p, "name")); + Printv(w->code, tm, "\n", NIL); + p = Getattr(p, "tmap:directorargout:next"); + } else { + p = nextSibling(p); + } + } + + /* any existing helper functions to handle this? */ + if (allow_thread) { + Append(w->code, "}\n"); + thread_end_block(n, w->code); + } + + Delete(parse_args); + Delete(arglist); + Delete(cleanup); + Delete(outarg); } - } - Append(w->code, "}\n"); - - // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method - String *inline_extra_method = NewString(""); - if (dirprot_mode() && !is_public(n) && !pure_virtual) { - Printv(inline_extra_method, declaration, NIL); - String *extra_method_name = NewStringf("%sSwigPublic", name); - Replaceall(inline_extra_method, name, extra_method_name); - Replaceall(inline_extra_method, ";\n", " {\n "); - if (!is_void) - Printf(inline_extra_method, "return "); - String *methodcall = Swig_method_call(super, l); - Printv(inline_extra_method, methodcall, ";\n }\n", NIL); - Delete(methodcall); - Delete(extra_method_name); - } - - /* emit the director method */ - if (status == SWIG_OK) { - if (!Getattr(n, "defaultargs")) { - Wrapper_print(w, f_directors); - Printv(f_directors_h, declaration, NIL); - Printv(f_directors_h, inline_extra_method, NIL); + if (!is_void) { + if (!(ignored_method && !pure_virtual)) { + String *rettype = SwigType_str(return_type, 0); + if (!SwigType_isreference(return_type)) { + Printf(w->code, "return (%s) c_result;\n", rettype); + } else { + Printf(w->code, "return (%s) *c_result;\n", rettype); + } + Delete(rettype); + } } - } - /* clean up */ - Delete(wrap_args); - Delete(return_type); - Delete(pclassname); - DelWrapper(w); - return status; + Append(w->code, "}\n"); + + // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method + String *inline_extra_method = NewString(""); + if (dirprot_mode() && !is_public(n) && !pure_virtual) { + Printv(inline_extra_method, declaration, NIL); + String *extra_method_name = NewStringf("%sSwigPublic", name); + Replaceall(inline_extra_method, name, extra_method_name); + Replaceall(inline_extra_method, ";\n", " {\n "); + if (!is_void) + Printf(inline_extra_method, "return "); + String *methodcall = Swig_method_call(super, l); + Printv(inline_extra_method, methodcall, ";\n }\n", NIL); + Delete(methodcall); + Delete(extra_method_name); + } + + /* emit the director method */ + if (status == SWIG_OK) { + if (!Getattr(n, "defaultargs")) { + Wrapper_print(w, f_directors); + Printv(f_directors_h, declaration, NIL); + Printv(f_directors_h, inline_extra_method, NIL); + } + } + + /* clean up */ + Delete(wrap_args); + Delete(return_type); + Delete(pclassname); + DelWrapper(w); + return status; } /* ----------------------------------------------------------------------------- From 8a7ad756d087681304f567b66c1c2df31704ceeb Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Tue, 14 Dec 2010 21:11:02 +0000 Subject: [PATCH 05/56] Added sequence and mapping support for builtin types. Fixed object ownership in %pyswigbinoperator. Test suite now fails on li_std_vector_extra. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12346 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/builtin.swg | 135 ++++++++++++++++++++++++++++--------- Lib/python/pycontainer.swg | 19 +++++- Lib/python/pyopers.swg | 58 ++++++++-------- Source/Modules/python.cxx | 82 ++++++++++++++++------ 4 files changed, 212 insertions(+), 82 deletions(-) diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index fde5339d5..f99e25890 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -1,16 +1,97 @@ -extern int -pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure) -{ - if (!closure) - return -1; - PyObject *tuple = PyTuple_New(1); - assert(tuple); - PyTuple_SET_ITEM(tuple, 0, val); - Py_XINCREF(val); - PyObject *result = ((PyCFunction) closure)(obj, tuple); - Py_DECREF(tuple); - Py_XDECREF(result); - return result ? 0 : -1; +#define PYSWIG_BINARYFUNC_CLOSURE(wrapper) \ +SWIGINTERN PyObject* \ +wrapper##_closure (PyObject *a, PyObject *b) \ +{ \ + PyObject *tuple = PyTuple_New(1); \ + assert(tuple); \ + PyTuple_SET_ITEM(tuple, 0, b); \ + Py_XINCREF(b); \ + PyObject *result = wrapper(a, tuple); \ + Py_DECREF(tuple); \ + return result; \ +} + +#define PYSWIG_TERNARYFUNC_CLOSURE(wrapper) \ +SWIGINTERN PyObject* \ +wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \ +{ \ + PyObject *tuple = PyTuple_New(2); \ + assert(tuple); \ + PyTuple_SET_ITEM(tuple, 0, b); \ + PyTuple_SET_ITEM(tuple, 1, c); \ + Py_XINCREF(b); \ + Py_XINCREF(c); \ + PyObject *result = wrapper(a, tuple); \ + Py_DECREF(tuple); \ + return result; \ +} + +#define PYSWIG_LENFUNC_CLOSURE(wrapper) \ +SWIGINTERN Py_ssize_t \ +wrapper##_closure (PyObject *a) \ +{ \ + PyObject *resultobj = wrapper(a, NULL); \ + Py_ssize_t result = _PyLong_AsSsize_t(resultobj); \ + Py_DECREF(resultobj); \ + return result; \ +} + +#define PYSWIG_SSIZESSIZEARGFUNC_CLOSURE(wrapper) \ +SWIGINTERN PyObject* \ +wrapper##_closure (PyObject *a, Py_ssize_t b, Py_ssize_t c) \ +{ \ + PyObject *tuple = PyTuple_New(2); \ + assert(tuple); \ + PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \ + PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c)); \ + PyObject *result = wrapper(a, tuple); \ + Py_DECREF(tuple); \ + return result; \ +} + +#define PYSWIG_SSIZESSIZEOBJARGPROC_CLOSURE(wrapper) \ +SWIGINTERN int \ +wrapper##_closure (PyObject *a, Py_ssize_t b, Py_ssize_t c, PyObject *d) \ +{ \ + PyObject *tuple = PyTuple_New(3); \ + assert(tuple); \ + PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \ + PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c)); \ + PyTuple_SET_ITEM(tuple, 2, d); \ + Py_XINCREF(d); \ + PyObject *resultobj = wrapper(a, tuple); \ + int result = resultobj ? 0 : -1; \ + Py_DECREF(tuple); \ + Py_XDECREF(resultobj); \ + return result; \ +} + +#define PYSWIG_SSIZEARGFUNC_CLOSURE(wrapper) \ +SWIGINTERN PyObject* \ +wrapper##_closure (PyObject *a, Py_ssize_t b) \ +{ \ + PyObject *tuple = PyTuple_New(1); \ + assert(tuple); \ + PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \ + PyObject *result = wrapper(a, tuple); \ + Py_DECREF(tuple); \ + return result; \ +} + +#define PYSWIG_SSIZEOBJARGPROC_CLOSURE(wrapper) \ +SWIGINTERN int \ +wrapper##_closure (PyObject *a, Py_ssize_t b, PyObject *c) \ +{ \ + PyObject *tuple = PyTuple_New(2); \ + assert(tuple); \ + PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \ + PyTuple_SET_ITEM(tuple, 1, c); \ + Py_XINCREF(c); \ + PyObject *resultobj = wrapper(a, tuple); \ + int result = resultobj ? 0 : -1; \ + Py_XDECREF(resultobj); \ + Py_DECREF(tuple); \ + return result; \ } #ifdef __cplusplus @@ -27,6 +108,8 @@ template struct PySwigBuiltin : public SwigPyObject { static PyMethodDef methods[]; static PyGetSetDef getset[]; static PyNumberMethods number_methods; + static PySequenceMethods sequence_methods; + static PyMappingMethods mapping_methods; static PyTypeObject pytype; static SwigPyClientData clientdata; }; @@ -40,27 +123,19 @@ template void py_builtin_dealloc (PyObject *pyobj) (*pyobj->ob_type->tp_free)(pyobj); } -template PyObject* -pyswig_binaryfunc_closure (PyObject *a, PyObject *b) +SWIGINTERN int +pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure) { + if (!closure) + return -1; PyObject *tuple = PyTuple_New(1); assert(tuple); - PyTuple_SET_ITEM(tuple, 0, b); - PyObject *result = func(a, tuple); + PyTuple_SET_ITEM(tuple, 0, val); + Py_XINCREF(val); + PyObject *result = ((PyCFunction) closure)(obj, tuple); Py_DECREF(tuple); - return result; -} - -template PyObject* -pyswig_ternaryfunc_closure (PyObject *a, PyObject *b, PyObject *c) -{ - PyObject *tuple = PyTuple_New(2); - assert(tuple); - PyTuple_SET_ITEM(tuple, 0, b); - PyTuple_SET_ITEM(tuple, 1, c); - PyObject *result = func(a, tuple); - Py_DECREF(tuple); - return result; + Py_XDECREF(result); + return result ? 0 : -1; } } // namespace { diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg index 27e145362..5578f1af9 100644 --- a/Lib/python/pycontainer.swg +++ b/Lib/python/pycontainer.swg @@ -599,7 +599,6 @@ namespace swig /**** The python container methods ****/ - %define %swig_container_methods(Container...) %newobject __getslice__; @@ -618,8 +617,16 @@ namespace swig return self->size(); } } + +#if defined(SWIGPYTHON_BUILTIN) +%pybinoperator(__nonzero__, __nonzero__, unaryfunc, nb_nonzero); +%pybinoperator(__len__, __len__, lenfunc, sq_length); +#endif // SWIGPYTHON_BUILTIN + %enddef + + %define %swig_sequence_methods_common(Sequence...) %swig_sequence_iterator(%arg(Sequence)) %swig_container_methods(%arg(Sequence)) @@ -697,6 +704,14 @@ namespace swig } } + +#if defined(SWIGPYTHON_BUILTIN) +%pybinoperator(__getitem__, __getitem__, ssizeargfunc, sq_item); +%pybinoperator(__getslice__, __getslice__, ssizessizeargfunc, sq_slice); +%pybinoperator(__setitem__, __setitem__, ssizeobjargproc, sq_ass_item); +%pybinoperator(__setslice__, __setslice__, ssizessizeobjargproc, sq_ass_slice); +#endif // SWIGPYTHON_BUILTIN + %enddef %define %swig_sequence_methods(Sequence...) @@ -714,6 +729,7 @@ namespace swig self->push_back(x); } } + %enddef %define %swig_sequence_methods_val(Sequence...) @@ -731,6 +747,7 @@ namespace swig self->push_back(x); } } + %enddef diff --git a/Lib/python/pyopers.swg b/Lib/python/pyopers.swg index 3074eaa9e..851524219 100644 --- a/Lib/python/pyopers.swg +++ b/Lib/python/pyopers.swg @@ -13,20 +13,20 @@ #define %pycompare(pyname,oper,comptype) %pybinoperator(pyname,oper,,comptype) #endif -%pybinoperator(__add__, *::operator+, binary_func, nb_add); -%pybinoperator(__pos__, *::operator+(), unary_func, nb_positive); -%pybinoperator(__pos__, *::operator+() const, unary_func, nb_positive); -%pybinoperator(__sub__, *::operator-, binary_func, nb_subtract); -%pybinoperator(__neg__, *::operator-(), unary_func, nb_negative); -%pybinoperator(__neg__, *::operator-() const, unary_func, nb_negative); -%pybinoperator(__mul__, *::operator*, binary_func, nb_multiply); -%pybinoperator(__div__, *::operator/, binary_func, nb_div); -%pybinoperator(__mod__, *::operator%, binary_func, nb_remainder); -%pybinoperator(__lshift__, *::operator<<, binary_func, nb_lshift); -%pybinoperator(__rshift__, *::operator>>, binary_func, nb_rshift); -%pybinoperator(__and__, *::operator&, binary_func, nb_and); -%pybinoperator(__or__, *::operator|, binary_func, nb_or); -%pybinoperator(__xor__, *::operator^, binary_func, nb_xor); +%pybinoperator(__add__, *::operator+, binaryfunc, nb_add); +%pybinoperator(__pos__, *::operator+(), unaryfunc, nb_positive); +%pybinoperator(__pos__, *::operator+() const, unaryfunc, nb_positive); +%pybinoperator(__sub__, *::operator-, binaryfunc, nb_subtract); +%pybinoperator(__neg__, *::operator-(), unaryfunc, nb_negative); +%pybinoperator(__neg__, *::operator-() const, unaryfunc, nb_negative); +%pybinoperator(__mul__, *::operator*, binaryfunc, nb_multiply); +%pybinoperator(__div__, *::operator/, binaryfunc, nb_div); +%pybinoperator(__mod__, *::operator%, binaryfunc, nb_remainder); +%pybinoperator(__lshift__, *::operator<<, binaryfunc, nb_lshift); +%pybinoperator(__rshift__, *::operator>>, binaryfunc, nb_rshift); +%pybinoperator(__and__, *::operator&, binaryfunc, nb_and); +%pybinoperator(__or__, *::operator|, binaryfunc, nb_or); +%pybinoperator(__xor__, *::operator^, binaryfunc, nb_xor); %pycompare(__lt__, *::operator<, Py_LT); %pycompare(__le__, *::operator<=, Py_LE); %pycompare(__gt__, *::operator>, Py_GT); @@ -34,16 +34,16 @@ %pycompare(__eq__, *::operator==, Py_EQ); %pycompare(__ne__, *::operator!=, Py_NE); -%feature("pyslot", "nb_truediv", functype="binary_func") *::operator/; +%feature("pyslot", "nb_truediv", functype="binaryfunc") *::operator/; /* Special cases */ %rename(__invert__) *::operator~; -%feature("pyslot", "nb_invert", functype="unary_func") *::operator~; +%feature("pyslot", "nb_invert", functype="unaryfunc") *::operator~; %rename(__call__) *::operator(); -%feature("pyslot", "tp_call", functype="ternary_func") *::operator(); +%feature("pyslot", "tp_call", functype="ternaryfunc") *::operator(); #if defined(SWIGPYTHON_BUILTIN) -%pybinoperator(__nonzero__, *::operator bool, unary_func, nb_nonzero); +%pybinoperator(__nonzero__, *::operator bool, unaryfunc, nb_nonzero); #else %feature("shadow") *::operator bool %{ def __nonzero__(self): @@ -103,21 +103,21 @@ __bool__ = __nonzero__ */ #if defined(SWIGPYTHON_BUILTIN) -#define %pyinplaceoper(SwigPyOper, Oper, functp, slot) %rename(SwigPyOper) Oper; %feature("pyslot", #slot, functype=#functp) Oper; +#define %pyinplaceoper(SwigPyOper, Oper, functp, slot) %delobject Oper; %newobject Oper; %feature("pyslot", #slot, functype=#functp) Oper; %rename(SwigPyOper) Oper #else #define %pyinplaceoper(SwigPyOper, Oper, functp, slot) %delobject Oper; %newobject Oper; %rename(SwigPyOper) Oper #endif -%pyinplaceoper(__iadd__ , *::operator +=, binary_func, nb_inplace_add); -%pyinplaceoper(__isub__ , *::operator -=, binary_func, nb_inplace_subtract); -%pyinplaceoper(__imul__ , *::operator *=, binary_func, nb_inplace_multiply); -%pyinplaceoper(__idiv__ , *::operator /=, binary_func, nb_inplace_divide); -%pyinplaceoper(__imod__ , *::operator %=, binary_func, nb_inplace_remainder); -%pyinplaceoper(__iand__ , *::operator &=, binary_func, nb_inplace_and); -%pyinplaceoper(__ior__ , *::operator |=, binary_func, nb_inplace_or); -%pyinplaceoper(__ixor__ , *::operator ^=, binary_func, nb_inplace_xor); -%pyinplaceoper(__ilshift__, *::operator <<=, binary_func, nb_inplace_lshift); -%pyinplaceoper(__irshift__, *::operator >>=, binary_func, nb_inplace_rshift); +%pyinplaceoper(__iadd__ , *::operator +=, binaryfunc, nb_inplace_add); +%pyinplaceoper(__isub__ , *::operator -=, binaryfunc, nb_inplace_subtract); +%pyinplaceoper(__imul__ , *::operator *=, binaryfunc, nb_inplace_multiply); +%pyinplaceoper(__idiv__ , *::operator /=, binaryfunc, nb_inplace_divide); +%pyinplaceoper(__imod__ , *::operator %=, binaryfunc, nb_inplace_remainder); +%pyinplaceoper(__iand__ , *::operator &=, binaryfunc, nb_inplace_and); +%pyinplaceoper(__ior__ , *::operator |=, binaryfunc, nb_inplace_or); +%pyinplaceoper(__ixor__ , *::operator ^=, binaryfunc, nb_inplace_xor); +%pyinplaceoper(__ilshift__, *::operator <<=, binaryfunc, nb_inplace_lshift); +%pyinplaceoper(__irshift__, *::operator >>=, binaryfunc, nb_inplace_rshift); /* Finally, in python we need to mark the binary operations to fail as diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 55bfd8815..6dbaf0ea0 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -172,6 +172,30 @@ getSlot (Node *n, const char *key) return val ? val : slot_default; } +static String* +getClosure (String *functype, String *wrapper) +{ + static const char *functypes[] = { + "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", + NULL + }; + + if (!functype) + return NULL; + char *c = Char(functype); + int i; + for (i = 0; functypes[i] != NULL; i += 2) { + if (!strcmp(c, functypes[i])) + return NewStringf("%s(%s)", functypes[i+1], wrapper); + } + return NULL; +} class PYTHON:public Language { public: @@ -1947,18 +1971,18 @@ public: char const *self_param = builtin_self ? "self" : "SWIGUNUSEDPARM(self)"; char const *wrap_return = builtin_ctor ? "int " : "PyObject *"; String *linkage = NewString("SWIGINTERN "); + String *wrapper_name = Swig_name_wrapper(iname); String *slot = Getattr(n, "feature:pyslot"); + String *closure_decl = NULL; + if (slot) + closure_decl = getClosure(Getattr(n, "feature:pyslot:functype"), wrapper_name); + + /* if (builtin_setter || builtin_getter) { Clear(linkage); Printv(linkage, "extern ", NIL); } - if (slot) { - String *functype = Getattr(n, "feature:pyslot:functype"); - if (!strcmp(Char(functype), "binary_func") || !strcmp(Char(functype), "ternary_func")) { - Clear(linkage); - Printv(linkage, "extern ", NIL); - } - } + */ if (Getattr(n, "sym:overloaded")) { overname = Getattr(n, "sym:overname"); @@ -2000,7 +2024,7 @@ public: allow_kwargs = 0; varargs = emit_isvarargs(l); - String *wname = Swig_name_wrapper(iname); + String *wname = Copy(wrapper_name); if (overname) { Append(wname, overname); } @@ -2510,8 +2534,6 @@ public: } } - String *wrapper_name = Swig_name_wrapper(iname); - /* If this is a builtin type, create a PyGetSetDef entry for this member variable. */ if (builtin_getter) { Hash *h = Getattr(builtin_getset, name); @@ -2534,15 +2556,12 @@ public: /* Handle builtin operator overloads */ if (slot) { - String *functype = Getattr(n, "feature:pyslot:functype"); String *feature_name = NewStringf("feature:%s", slot); - String *closure_name = NewString(""); - if (!strcmp(Char(functype), "binary_func")) { - Printf(closure_name, "pyswig_binaryfunc_closure< %s >", wrapper_name); - } else if (!strcmp(Char(functype), "ternary_func")) { - Printf(closure_name, "pyswig_ternaryfunc_closure< %s >", wrapper_name); - } else { - Append(closure_name, wrapper_name); + String *closure_name = Copy(wrapper_name); + if (closure_decl) { + if (!Getattr(n, "sym:overloaded") || !Getattr(n, "sym:nextSibling")) + Printv(f_wrappers, closure_decl, "\n\n", NIL); + Append(closure_name, "_closure"); } Node *parent = Swig_methodclass(n); Setattr(parent, feature_name, closure_name); @@ -2561,6 +2580,8 @@ public: Delete(wname); DelWrapper(f); Delete(wrapper_name); + if (closure_decl) + Delete(closure_decl); return SWIG_OK; } @@ -3123,6 +3144,25 @@ public: Printf(f, " (unaryfunc) %s, // nb_index;\n", getSlot(n, "feature:nb_index")); Printf(f, "};\n\n"); + Printf(f, "template <> PySequenceMethods PySwigBuiltin< %s >::sequence_methods = {\n", rname); + Printf(f, " (lenfunc) %s, // sq_length\n", getSlot(n, "sq_length")); + Printf(f, " (binaryfunc) %s, // sq_concat\n", getSlot(n, "sq_concat")); + Printf(f, " (ssizeargfunc) %s, // sq_repeat\n", getSlot(n, "sq_repeat")); + Printf(f, " (ssizeargfunc) %s, // sq_item\n", getSlot(n, "sq_item")); + Printf(f, " (ssizessizeargfunc) %s, // sq_slice\n", getSlot(n, "sq_slice")); + Printf(f, " (ssizeobjargproc) %s, // sq_ass_item\n", getSlot(n, "sq_ass_item")); + Printf(f, " (ssizessizeobjargproc) %s, // sq_ass_slice\n", getSlot(n, "sq_ass_slice")); + Printf(f, " (objobjproc) %s, // sq_contains\n", getSlot(n, "sq_contains")); + Printf(f, " (binaryfunc) %s, // sq_inplace_concat\n", getSlot(n, "sq_inplace_concat")); + Printf(f, " (ssizeargfunc) %s, // sq_inplace_repeat\n", getSlot(n, "sq_inplace_repeat")); + Printf(f, "};\n\n"); + + Printf(f, "template <> PyMappingMethods PySwigBuiltin< %s >::mapping_methods = {\n", rname); + Printf(f, " (lenfunc) %s, // mp_length;\n", getSlot(n, "mp_length")); + Printf(f, " (binaryfunc) %s, // mp_subscript;\n", getSlot(n, "mp_subscript")); + Printf(f, " (objobjargproc) %s, // mp_ass_subscript;\n", getSlot(n, "mp_ass_subscript")); + Printf(f, "};\n\n"); + String *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES"); // TODO: Add more flags based on slots Printf(f, "template <> PyTypeObject PySwigBuiltin< %s >::pytype = {\n", rname); @@ -3138,8 +3178,8 @@ public: Printf(f, " %s, /*tp_compare*/\n", getSlot(n, "feature:tp_compare")); Printf(f, " %s, /*tp_repr*/\n", getSlot(n, "feature:tp_repr")); Printf(f, " &%s::number_methods, /*tp_as_number*/\n", templ); - Printf(f, " %s, /*tp_as_sequence*/\n", getSlot(n, "feature:tp_as_sequence")); - Printf(f, " %s, /*tp_as_mapping*/\n", getSlot(n, "feature:tp_as_mapping")); + Printf(f, " &%s::sequence_methods, /*tp_as_sequence*/\n", templ); + Printf(f, " &%s::mapping_methods, /*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")); @@ -3519,8 +3559,6 @@ public: String *fullname = Swig_name_member(NULL, class_name, symname); String *wname = Swig_name_wrapper(fullname); Setattr(class_members, name, name); - ParmList *parms = Getattr(n, "parms"); - bool noArgs = !parms || Len(parms) == 0; String *pyflags = NewString("METH_VARARGS"); Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", Char(name), wname, Char(pyflags)); Delete(name); From dd465f9588ed9575470b0cc08fd3b605e3ba240d Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Wed, 15 Dec 2010 23:04:20 +0000 Subject: [PATCH 06/56] Finished std::pair and std::map support. li_std_pair_extra test fails, because the _runme.py uses the secret 'this' member variable, which doesn't exist when the -builtin option is used. Seems like a flaw in the test. Test suite now fails on li_std_string_extra, because static member variables are not fully implemented. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12351 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/builtin.swg | 31 +- Lib/python/pycontainer.swg | 38 +- Lib/python/pyiterators.swg | 2 +- Lib/python/pyrun.swg | 9 + Lib/python/std_map.i | 63 +- Lib/python/std_pair.i | 50 ++ Source/Modules/python.cxx | 1324 ++++++++++++++++++------------------ 7 files changed, 827 insertions(+), 690 deletions(-) diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index f99e25890..7a5ad8664 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -31,7 +31,7 @@ SWIGINTERN Py_ssize_t \ wrapper##_closure (PyObject *a) \ { \ PyObject *resultobj = wrapper(a, NULL); \ - Py_ssize_t result = _PyLong_AsSsize_t(resultobj); \ + Py_ssize_t result = PyNumber_AsSsize_t(resultobj, NULL); \ Py_DECREF(resultobj); \ return result; \ } @@ -53,12 +53,14 @@ wrapper##_closure (PyObject *a, Py_ssize_t b, Py_ssize_t c) \ SWIGINTERN int \ wrapper##_closure (PyObject *a, Py_ssize_t b, Py_ssize_t c, PyObject *d) \ { \ - PyObject *tuple = PyTuple_New(3); \ + PyObject *tuple = PyTuple_New(d ? 3 : 2); \ assert(tuple); \ PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \ PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c)); \ - PyTuple_SET_ITEM(tuple, 2, d); \ - Py_XINCREF(d); \ + if (d) { \ + PyTuple_SET_ITEM(tuple, 2, d); \ + Py_INCREF(d); \ + } \ PyObject *resultobj = wrapper(a, tuple); \ int result = resultobj ? 0 : -1; \ Py_DECREF(tuple); \ @@ -94,6 +96,25 @@ wrapper##_closure (PyObject *a, Py_ssize_t b, PyObject *c) \ return result; \ } +#define PYSWIG_OBJOBJARGPROC_CLOSURE(wrapper) \ +SWIGINTERN int \ +wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \ +{ \ + PyObject *tuple = PyTuple_New(c ? 2 : 1); \ + assert(tuple); \ + PyTuple_SET_ITEM(tuple, 0, b); \ + Py_XINCREF(b); \ + if (c) { \ + PyTuple_SET_ITEM(tuple, 1, c); \ + Py_XINCREF(c); \ + } \ + PyObject *resultobj = wrapper(a, tuple); \ + int result = resultobj ? 0 : -1; \ + Py_XDECREF(resultobj); \ + Py_DECREF(tuple); \ + return result; \ +} + #ifdef __cplusplus namespace { @@ -105,6 +126,8 @@ template struct PySwigBuiltin : public SwigPyObject { typedef obj_type* pointer; typedef obj_type& reference; + static PyObject* richcompare (PyObject *self, PyObject *other, int op); + static PyMethodDef methods[]; static PyGetSetDef getset[]; static PyNumberMethods number_methods; diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg index 5578f1af9..cd38eeee1 100644 --- a/Lib/python/pycontainer.swg +++ b/Lib/python/pycontainer.swg @@ -245,7 +245,7 @@ namespace swig { template inline void - setslice(Sequence* self, Difference i, Difference j, const InputSeq& v) { + setslice(Sequence* self, Difference i, Difference j, const InputSeq& v = InputSeq()) { typename Sequence::size_type size = self->size(); typename Sequence::size_type ii = swig::check_index(i, size, true); typename Sequence::size_type jj = swig::slice_index(j, size); @@ -580,18 +580,18 @@ namespace swig %fragment("SwigPySequence_Cont"); -# if defined(SWIGPYTHON_BUILTIN) - %feature("tp_iter") Sequence "&swig::make_output_iterator_builtin< Sequence >"; -# else %newobject iterator(PyObject **PYTHON_SELF); %extend { swig::SwigPyIterator* iterator(PyObject **PYTHON_SELF) { return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF); } - %pythoncode {def __iter__(self): return self.iterator()} +#if defined(SWIGPYTHON_BUILTIN) + %feature("pyslot", "tp_iter", functype="getiterfunc") iterator; +#else + %pythoncode {def __iter__(self): return self.iterator()} +#endif } -# endif // SWIGPYTHON_BUILTIN #endif //SWIG_EXPORT_ITERATOR_METHODS %enddef @@ -603,6 +603,11 @@ namespace swig %newobject __getslice__; +#if defined(SWIGPYTHON_BUILTIN) + %feature("pyslot", "nb_nonzero", functype="unaryfunc") __nonzero__; + %feature("pyslot", "sq_length", functype="lenfunc") __len__; +#endif // SWIGPYTHON_BUILTIN + %extend { bool __nonzero__() const { return !(self->empty()); @@ -618,11 +623,6 @@ namespace swig } } -#if defined(SWIGPYTHON_BUILTIN) -%pybinoperator(__nonzero__, __nonzero__, unaryfunc, nb_nonzero); -%pybinoperator(__len__, __len__, lenfunc, sq_length); -#endif // SWIGPYTHON_BUILTIN - %enddef @@ -633,6 +633,13 @@ 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__; +#endif // SWIGPYTHON_BUILTIN + %extend { value_type pop() throw (std::out_of_range) { if (self->size() == 0) @@ -654,7 +661,7 @@ namespace swig return swig::getslice(self, i, j); } - void __setslice__(difference_type i, difference_type j, const Sequence& v) + void __setslice__(difference_type i, difference_type j, const Sequence& v = Sequence()) throw (std::out_of_range, std::invalid_argument) { swig::setslice(self, i, j, v); } @@ -705,13 +712,6 @@ namespace swig } -#if defined(SWIGPYTHON_BUILTIN) -%pybinoperator(__getitem__, __getitem__, ssizeargfunc, sq_item); -%pybinoperator(__getslice__, __getslice__, ssizessizeargfunc, sq_slice); -%pybinoperator(__setitem__, __setitem__, ssizeobjargproc, sq_ass_item); -%pybinoperator(__setslice__, __setslice__, ssizessizeobjargproc, sq_ass_slice); -#endif // SWIGPYTHON_BUILTIN - %enddef %define %swig_sequence_methods(Sequence...) diff --git a/Lib/python/pyiterators.swg b/Lib/python/pyiterators.swg index ecbc54270..d5ca73ec8 100644 --- a/Lib/python/pyiterators.swg +++ b/Lib/python/pyiterators.swg @@ -350,6 +350,7 @@ namespace swig #if defined(SWIGPYTHON_BUILTIN) %feature("tp_iter") SwigPyIterator "&swig::make_output_iterator_builtin"; + %feature("pyslot", "tp_iternext", functype="iternextfunc") SwigPyIterator::__next__; #else %extend SwigPyIterator { %pythoncode {def __iter__(self): return self} @@ -370,7 +371,6 @@ namespace swig %catches(swig::stop_iteration) SwigPyIterator::operator + (ptrdiff_t n) const; %catches(swig::stop_iteration) SwigPyIterator::operator - (ptrdiff_t n) const; - struct SwigPyIterator { protected: diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 3f93c4575..96fdcf085 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -465,8 +465,17 @@ SwigPyObject_type(void) { SWIGRUNTIMEINLINE int SwigPyObject_Check(PyObject *op) { +#ifdef SWIGPYTHON_BUILTIN + PyTypeObject *target_tp = SwigPyObject_type(); + PyTypeObject *obj_tp; + for (obj_tp = op->ob_type; obj_tp; obj_tp = obj_tp->tp_base) + if (obj_tp == target_tp) + return 1; + return (strcmp(op->ob_type->tp_name, "SwigPyObject") == 0); +#else return (Py_TYPE(op) == SwigPyObject_type()) || (strcmp(Py_TYPE(op)->tp_name,"SwigPyObject") == 0); +#endif } SWIGRUNTIME PyObject * diff --git a/Lib/python/std_map.i b/Lib/python/std_map.i index 074c43180..8f06a97d9 100644 --- a/Lib/python/std_map.i +++ b/Lib/python/std_map.i @@ -119,6 +119,17 @@ return new SwigPyMapKeyIterator_T(current, begin, end, seq); } + template + inline PyObject* make_output_key_iterator_builtin (PyObject *pyself) + { + SwigPyObject *builtin_obj = (SwigPyObject*) pyself; + Sequence *seq = reinterpret_cast< Sequence * >(builtin_obj->ptr); + 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); + } + template > struct SwigPyMapValueITerator_T : SwigPyMapIterator_T @@ -136,6 +147,7 @@ { return new SwigPyMapValueITerator_T(current, begin, end, seq); } + } } @@ -143,6 +155,37 @@ %swig_sequence_iterator(Map); %swig_container_methods(Map) +#if defined(SWIGPYTHON_BUILTIN) + %feature("pyslot", "mp_length", functype="lenfunc") __len__; + %feature("pyslot", "mp_subscript", functype="binaryfunc") __getitem__; + %feature("tp_iter") Map "&swig::make_output_key_iterator_builtin< Map >"; + + %extend { + %newobject iterkeys(PyObject **PYTHON_SELF); + swig::SwigPyIterator* iterkeys(PyObject **PYTHON_SELF) { + return swig::make_output_key_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF); + } + + %newobject itervalues(PyObject **PYTHON_SELF); + swig::SwigPyIterator* itervalues(PyObject **PYTHON_SELF) { + return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF); + } + + %newobject iteritems(PyObject **PYTHON_SELF); + swig::SwigPyIterator* iteritems(PyObject **PYTHON_SELF) { + return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF); + } + } + +#else + %extend { + %pythoncode {def __iter__(self): return self.key_iterator()} + %pythoncode {def iterkeys(self): return self.key_iterator()} + %pythoncode {def itervalues(self): return self.value_iterator()} + %pythoncode {def iteritems(self): return self.iterator()} + } +#endif + %extend { mapped_type __getitem__(const key_type& key) const throw (std::out_of_range) { Map::const_iterator i = self->find(key); @@ -151,7 +194,7 @@ else throw std::out_of_range("key not found"); } - + void __delitem__(const key_type& key) throw (std::out_of_range) { Map::iterator i = self->find(key); if (i != self->end()) @@ -236,16 +279,24 @@ swig::SwigPyIterator* value_iterator(PyObject **PYTHON_SELF) { return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF); } - - %pythoncode {def __iter__(self): return self.key_iterator()} - %pythoncode {def iterkeys(self): return self.key_iterator()} - %pythoncode {def itervalues(self): return self.value_iterator()} - %pythoncode {def iteritems(self): return self.iterator()} } + %enddef %define %swig_map_methods(Map...) %swig_map_common(Map) + +#if defined(SWIGPYTHON_BUILTIN) + %feature("pyslot", "mp_ass_subscript", functype="objobjargproc") __setitem__; + + %extend { + // This will be called through the mp_ass_subscript slot to delete an entry. + void __setitem__(const key_type& key) { + self->erase(key); + } + } +#endif + %extend { void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) { (*self)[key] = x; diff --git a/Lib/python/std_pair.i b/Lib/python/std_pair.i index bc8ccaade..4cc8fe5c2 100644 --- a/Lib/python/std_pair.i +++ b/Lib/python/std_pair.i @@ -116,9 +116,58 @@ } }; } + +#if defined(SWIGPYTHON_BUILTIN) +SWIGINTERN Py_ssize_t +SwigPython_std_pair_len (PyObject *a) +{ + return 2; +} + +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)); + PyObject *result = PyObject_Repr(tuple); + Py_DECREF(tuple); + return result; +} + +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); + 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); + return result; +} +#endif + } %define %swig_pair_methods(pair...) +#if defined(SWIGPYTHON_BUILTIN) +%feature("sq_length") pair "SwigPython_std_pair_len"; +%feature("tp_repr") pair "SwigPython_std_pair_repr"; +%feature("sq_item") pair "SwigPython_std_pair_getitem"; +%feature("sq_ass_item") pair "SwigPython_std_pair_setitem"; +#else %extend { %pythoncode {def __len__(self): return 2 def __repr__(self): return str((self.first, self.second)) @@ -133,6 +182,7 @@ def __setitem__(self, index, val): else: self.second = val} } +#endif %enddef %include diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 6dbaf0ea0..1a4209092 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -48,6 +48,7 @@ static String *f_shadow_imports = 0; static String *f_shadow_import_stmts = 0; static String *f_shadow_stubs = 0; static Hash *builtin_getset = 0; +static String *builtin_richcompare = 0; static String *methods; static String *class_name; @@ -164,37 +165,34 @@ static const char *usage3 = (char *) "\ Function annotation \n\ \n"; -static String* -getSlot (Node *n, const char *key) -{ +static String *getSlot(Node *n, const char *key) { static String *slot_default = NewString("0"); String *val = Getattr(n, key); return val ? val : slot_default; } -static String* -getClosure (String *functype, String *wrapper) -{ - static const char *functypes[] = { - "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", - NULL - }; +static String *getClosure(String *functype, String *wrapper) { + static const char *functypes[] = { + "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", + NULL + }; - if (!functype) - return NULL; - char *c = Char(functype); - int i; - for (i = 0; functypes[i] != NULL; i += 2) { - if (!strcmp(c, functypes[i])) - return NewStringf("%s(%s)", functypes[i+1], wrapper); - } + if (!functype) return NULL; + char *c = Char(functype); + int i; + for (i = 0; functypes[i] != NULL; i += 2) { + if (!strcmp(c, functypes[i])) + return NewStringf("%s(%s)", functypes[i + 1], wrapper); + } + return NULL; } class PYTHON:public Language { @@ -209,16 +207,11 @@ public: director_multiple_inheritance = 1; director_language = 1; } - /* ------------------------------------------------------------ * Thread Implementation - * ------------------------------------------------------------ */ - - int threads_enable(Node *n) const { + * ------------------------------------------------------------ */ int threads_enable(Node *n) const { return threads && !GetFlagAttr(n, "feature:nothread"); - } - - int initialize_threads(String *f_init) { + } int initialize_threads(String *f_init) { if (!threads) { return SWIG_OK; } @@ -480,9 +473,9 @@ public: Preprocessor_define("SWIGPYTHON_BUILTIN", 0); Swig_mark_arg(i); } - + } - } /* for */ + } /* for */ if (py3) { /* force disable features that not compatible with Python 3.x */ @@ -579,6 +572,7 @@ public: f_directors_h = NewString(""); f_directors = NewString(""); builtin_getset = NewHash(); + builtin_richcompare = NewString(""); if (builtin) { f_builtins = NewString(""); @@ -812,7 +806,7 @@ public: } if (modern || !classic) { Printv(f_shadow, "try:\n", tab4, "_swig_property = property\n", "except NameError:\n", tab4, "pass # Python < 2.2 doesn't have 'property'.\n", NULL); - } + } /* if (!modern) */ /* always needed, a class can be forced to be no-modern, such as an exception */ { @@ -851,11 +845,10 @@ public: * But don't sure wether this would broken old Python? */ Printv(f_shadow, - // "import types\n", + // "import types\n", "try:\n", - // " _object = types.ObjectType\n", - " _object = object\n", - " _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n", + // " _object = types.ObjectType\n", + " _object = object\n", " _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n", // "del types\n", "\n\n", NIL); } @@ -878,7 +871,6 @@ public: "try:\n", tab4, "import weakref\n", tab4, "weakref_proxy = weakref.proxy\n", "except:\n", tab4, "weakref_proxy = lambda x: x\n", "\n\n", NIL); } } - // Include some information in the code Printf(f_header, "\n/*-----------------------------------------------\n @(target):= %s.so\n\ ------------------------------------------------*/\n", module); @@ -974,15 +966,14 @@ public: return SWIG_OK; } - + /* ------------------------------------------------------------ * Emit the wrapper for PyInstanceMethod_New to MethodDef array. * This wrapper is used to implement -fastproxy, * as a replacement of new.instancemethod in Python 3. * ------------------------------------------------------------ */ - int add_pyinstancemethod_new() - { - String* name = NewString("SWIG_PyInstanceMethod_New"); + int add_pyinstancemethod_new() { + String *name = NewString("SWIG_PyInstanceMethod_New"); Printf(methods, "\t { (char *)\"%s\", (PyCFunction)%s, METH_O, NULL},\n", name, name); Delete(name); return 0; @@ -1243,12 +1234,12 @@ public: String *pn = Swig_name_make(p, 0, Getattr(p, "name"), 0, 0); // Use C parameter name unless it is a duplicate or an empty parameter name int count = 0; - if ( SwigType_isvarargs(Getattr(p, "type")) ) { + if (SwigType_isvarargs(Getattr(p, "type"))) { return NewString("*args"); } while (plist) { if ((Cmp(pn, Getattr(plist, "name")) == 0)) - count++; + count++; plist = nextSibling(plist); } arg = (!pn || !Len(pn) || (count > 1)) ? NewStringf("arg%d", arg_num) : Copy(pn); @@ -1263,43 +1254,43 @@ public: * func_annotation: Function annotation support * ------------------------------------------------------------ */ - String *make_autodocParmList(Node *n, bool showTypes, bool calling=false, bool func_annotation=false) { + String *make_autodocParmList(Node *n, bool showTypes, bool calling = false, bool func_annotation = false) { + - String *doc = NewString(""); String *pdocs = Copy(Getattr(n, "feature:pdocs")); ParmList *plist = CopyParmList(Getattr(n, "parms")); Parm *p; Parm *pnext; - Node *lookup; + Node *lookup; int lines = 0; int arg_num = 0; const int maxwidth = 50; - if(calling) + if (calling) func_annotation = false; - + if (pdocs) Append(pdocs, "\n"); Swig_typemap_attach_parms("in", plist, 0); Swig_typemap_attach_parms("doc", plist, 0); - - if (Strcmp(ParmList_protostr(plist), "void")==0) { + + if (Strcmp(ParmList_protostr(plist), "void") == 0) { //No parameters actually return doc; } - + for (p = plist; p; p = pnext) { String *tm = Getattr(p, "tmap:in"); if (tm) { pnext = Getattr(p, "tmap:in:next"); - if (checkAttribute(p, "tmap:in:numinputs", "0")) { - continue; - } + if (checkAttribute(p, "tmap:in:numinputs", "0")) { + continue; + } } else { pnext = nextSibling(p); } @@ -1339,40 +1330,39 @@ public: lines += 1; } } - + type = SwigType_base(type); lookup = Swig_symbol_clookup(type, 0); if (lookup) - type = Getattr(lookup, "sym:name"); - + type = Getattr(lookup, "sym:name"); + // Do the param type too? if (showTypes) - Printf(doc, "%s ", type); + Printf(doc, "%s ", type); + - Append(doc, name); if (pdoc) { - if (!pdocs) - pdocs = NewString("Parameters:\n"); - Printf(pdocs, " %s\n", pdoc); + if (!pdocs) + pdocs = NewString("Parameters:\n"); + Printf(pdocs, " %s\n", pdoc); } - // Write the function annoation if (func_annotation) - Printf(doc, " : '%s'", type); + Printf(doc, " : '%s'", type); // Write default value if (value && !calling) { - String* pv = pyvalue(value, Getattr(p, "type")); - if (pv) - value = pv; + String *pv = pyvalue(value, Getattr(p, "type")); + if (pv) + value = pv; else { lookup = Swig_symbol_clookup(value, 0); if (lookup) { value = Getattr(lookup, "sym:name"); - } + } } - Printf(doc, " = %s", value); + Printf(doc, " = %s", value); } } if (pdocs) @@ -1501,7 +1491,6 @@ public: Printv(doc, "\n", pdocs, NULL); } } - // if it's overloaded then get the next decl and loop around again n = Getattr(n, "sym:nextSibling"); if (n) @@ -1510,29 +1499,28 @@ public: return doc; } - + /* ------------------------------------------------------------ * pyvalue() * Check if string v can be a Python value literal, * (eg. number or string), or translate it to a Python literal. * ------------------------------------------------------------ */ - String* pyvalue(String *v, SwigType *t) - { - if (v && Len(v)>0) { + String *pyvalue(String *v, SwigType *t) { + if (v && Len(v) > 0) { char fc = (Char(v))[0]; - if (('0'<=fc && fc<='9') || '\''==fc || '"'==fc) { - /* number or string (or maybe NULL pointer)*/ - if (SwigType_ispointer(t) && Strcmp(v, "0")==0) - return NewString("None"); - else - return v; + if (('0' <= fc && fc <= '9') || '\'' == fc || '"' == fc) { + /* number or string (or maybe NULL pointer) */ + if (SwigType_ispointer(t) && Strcmp(v, "0") == 0) + return NewString("None"); + else + return v; } - if (Strcmp(v, "true")==0 || Strcmp(v, "FALSE")==0) - return NewString("True"); - if (Strcmp(v, "false")==0 || Strcmp(v, "FALSE")==0) - return NewString("False"); - if (Strcmp(v, "NULL")==0) - return NewString("None"); + if (Strcmp(v, "true") == 0 || Strcmp(v, "FALSE") == 0) + return NewString("True"); + if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0) + return NewString("False"); + if (Strcmp(v, "NULL") == 0) + return NewString("None"); } return 0; } @@ -1542,8 +1530,7 @@ public: * (So we can generate proper parameter list with default * values..) * ------------------------------------------------------------ */ - bool is_primitive_defaultargs(Node *n) - { + bool is_primitive_defaultargs(Node *n) { ParmList *plist = CopyParmList(Getattr(n, "parms")); Parm *p; Parm *pnext; @@ -1552,17 +1539,17 @@ public: for (p = plist; p; p = pnext) { String *tm = Getattr(p, "tmap:in"); if (tm) { - pnext = Getattr(p, "tmap:in:next"); - if (checkAttribute(p, "tmap:in:numinputs", "0")) { - continue; - } + pnext = Getattr(p, "tmap:in:next"); + if (checkAttribute(p, "tmap:in:numinputs", "0")) { + continue; + } } else { - pnext = nextSibling(p); + pnext = nextSibling(p); } String *type = Getattr(p, "type"); String *value = Getattr(p, "value"); if (!pyvalue(value, type)) - return false; + return false; } return true; } @@ -1574,20 +1561,19 @@ public: * siblings generated due to the original function have * default arguments. * ------------------------------------------------------------ */ - bool is_real_overloaded(Node *n) - { + bool is_real_overloaded(Node *n) { Node *h = Getattr(n, "sym:overloaded"); Node *i; if (!h) return false; - + i = Getattr(h, "sym:nextSibling"); while (i) { Node *nn = Getattr(i, "defaultargs"); if (nn != h) { - /* Check if overloaded function has defaultargs and - * pointed to the first overloaded. */ - return true; + /* Check if overloaded function has defaultargs and + * pointed to the first overloaded. */ + return true; } i = Getattr(i, "sym:nextSibling"); } @@ -1600,37 +1586,33 @@ public: * Generate parameter list for Python functions or methods, * reuse make_autodocParmList() to do so. * ------------------------------------------------------------ */ - String* make_pyParmList(Node *n, bool in_class, bool is_calling, int kw) - { + String *make_pyParmList(Node *n, bool in_class, bool is_calling, int kw) { /* Get the original function for a defaultargs copy, * see default_arguments() in parser.y. */ Node *nn = Getattr(n, "defaultargs"); - if (nn) n = nn; + if (nn) + n = nn; /* For overloaded function, just use *args */ - if (is_real_overloaded(n) || - GetFlag(n, "feature:compactdefaultargs") || - !is_primitive_defaultargs(n)) - { - String *parms = NewString(""); - if(in_class) - Printf(parms, "self, "); - Printf(parms, "*args"); - if (kw) - Printf(parms, ", **kwargs"); - return parms; - } + if (is_real_overloaded(n) || GetFlag(n, "feature:compactdefaultargs") || !is_primitive_defaultargs(n)) { + String *parms = NewString(""); + if (in_class) + Printf(parms, "self, "); + Printf(parms, "*args"); + if (kw) + Printf(parms, ", **kwargs"); + return parms; + } bool funcanno = py3 ? true : false; String *params = NewString(""); String *_params = make_autodocParmList(n, false, is_calling, funcanno); - if (in_class) - { - Printf(params, "self"); - if(Len(_params) > 0) - Printf(params, ", "); - } + if (in_class) { + Printf(params, "self"); + if (Len(_params) > 0) + Printf(params, ", "); + } Printv(params, _params, NULL); @@ -1701,27 +1683,26 @@ public: return have_pythonappend(n) || have_pythonprepend(n) || have_docstring(n); } - + /* ------------------------------------------------------------ * returnTypeAnnotation() * Helper function for constructing the function annotation * of the returning type, return a empty string for Python 2.x * ------------------------------------------------------------ */ - String* returnTypeAnnotation(Node *n) - { - String *ret=0; + String *returnTypeAnnotation(Node *n) { + String *ret = 0; Parm *p = Getattr(n, "parms"); String *tm; /* Try to guess the returning type by argout typemap, * however the result may not accurate. */ while (p) { - if ((tm=Getattr(p, "tmap:argout:match_type"))) { - tm = SwigType_str(tm, 0); + if ((tm = Getattr(p, "tmap:argout:match_type"))) { + tm = SwigType_str(tm, 0); if (ret) - Printv(ret, ", ", tm, NULL); - else - ret = tm; - p = Getattr(p, "tmap:argout:next"); + Printv(ret, ", ", tm, NULL); + else + ret = tm; + p = Getattr(p, "tmap:argout:next"); } else { p = nextSibling(p); } @@ -1730,10 +1711,11 @@ public: * the function prototype. */ if (!ret) { ret = Getattr(n, "type"); - if (ret) ret = SwigType_str(ret, 0); + if (ret) + ret = SwigType_str(ret, 0); } return (ret && py3) ? NewStringf(" -> \"%s\" ", ret) - : NewString(""); + : NewString(""); } /* ------------------------------------------------------------ @@ -1763,7 +1745,7 @@ public: if (Getattr(n, "feature:python:callback") || !have_addtofunc(n)) { /* If there is no addtofunc directive then just assign from the extension module (for speed up) */ Printv(f_dest, name, " = ", module, ".", name, "\n", NIL); - } + } } @@ -1774,7 +1756,7 @@ public: int check_kwargs(Node *n) { return (use_kw || GetFlag(n, "feature:kwargs")) - && !GetFlag(n, "memberset") && !GetFlag(n, "memberget"); + && !GetFlag(n, "memberset") && !GetFlag(n, "memberget"); } @@ -1855,7 +1837,7 @@ public: Append(f->code, "argc = args ? (int)PyObject_Length(args) : 0;\n"); if (add_self) Append(f->code, "argv[0] = self;\n"); - Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n", add_self ? maxargs-1 : maxargs); + Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n", add_self ? maxargs - 1 : maxargs); Printf(f->code, "argv[ii%s] = PyTuple_GET_ITEM(args,ii);\n", add_self ? " + 1" : ""); Append(f->code, "}\n"); if (add_self) @@ -1975,14 +1957,14 @@ public: String *slot = Getattr(n, "feature:pyslot"); String *closure_decl = NULL; if (slot) - closure_decl = getClosure(Getattr(n, "feature:pyslot:functype"), wrapper_name); + closure_decl = getClosure(Getattr(n, "feature:pyslot:functype"), wrapper_name); /* - if (builtin_setter || builtin_getter) { - Clear(linkage); - Printv(linkage, "extern ", NIL); - } - */ + if (builtin_setter || builtin_getter) { + Clear(linkage); + Printv(linkage, "extern ", NIL); + } + */ if (Getattr(n, "sym:overloaded")) { overname = Getattr(n, "sym:overname"); @@ -2006,7 +1988,7 @@ public: Wrapper_add_local(f, "resultobj", "int resultobj = 0"); else Wrapper_add_local(f, "resultobj", "PyObject *resultobj = 0"); - + // Emit all of the local variables for holding arguments. emit_parameter_variables(l, f); @@ -2119,7 +2101,7 @@ public: if (Len(pn)) { String *tmp = 0; String *name = pn; - if (!Getattr(p,"hidden")) { + if (!Getattr(p, "hidden")) { name = tmp = Swig_name_make(p, 0, pn, 0, 0); } Printf(kwargs, "(char *) \"%s\",", name); @@ -2152,7 +2134,7 @@ public: if (Getattr(p, "tmap:in:implicitconv")) { const char *convflag = "0"; - if (!Getattr(p,"hidden")) { + if (!Getattr(p, "hidden")) { SwigType *ptype = Getattr(p, "type"); convflag = get_implicitconv_flag(classLookup(ptype)); } @@ -2259,7 +2241,7 @@ public: if (!Getattr(p, "tmap:in:parse") && (tm = Getattr(p, "tmap:freearg"))) { if (Getattr(p, "tmap:freearg:implicitconv")) { const char *convflag = "0"; - if (!Getattr(p,"hidden")) { + if (!Getattr(p, "hidden")) { SwigType *ptype = Getattr(p, "type"); convflag = get_implicitconv_flag(classLookup(ptype)); } @@ -2336,11 +2318,11 @@ public: if (allow_thread) { String *preaction = NewString(""); thread_begin_allow(n, preaction); - Setattr(n,"wrap:preaction", preaction); + Setattr(n, "wrap:preaction", preaction); String *postaction = NewString(""); thread_end_allow(n, postaction); - Setattr(n,"wrap:postaction", postaction); + Setattr(n, "wrap:postaction", postaction); } } @@ -2468,7 +2450,7 @@ public: Printv(f->code, cleanup, NIL); } if (builtin_ctor) - Printv(f->code, " return 0;\n", NIL); + Printv(f->code, " return -1;\n", NIL); else Printv(f->code, " return NULL;\n", NIL); @@ -2559,9 +2541,9 @@ public: String *feature_name = NewStringf("feature:%s", slot); String *closure_name = Copy(wrapper_name); if (closure_decl) { - if (!Getattr(n, "sym:overloaded") || !Getattr(n, "sym:nextSibling")) - Printv(f_wrappers, closure_decl, "\n\n", NIL); - Append(closure_name, "_closure"); + if (!Getattr(n, "sym:overloaded") || !Getattr(n, "sym:nextSibling")) + Printv(f_wrappers, closure_decl, "\n\n", NIL); + Append(closure_name, "_closure"); } Node *parent = Swig_methodclass(n); Setattr(parent, feature_name, closure_name); @@ -2569,6 +2551,11 @@ public: Delete(closure_name); } + /* Handle comparison operators for builtin types */ + String *compare = Getattr(n, "feature:pycompare"); + if (compare) + Printf(builtin_richcompare, " case %s : result = %s(self, tuple); break;\n", compare, wrapper_name); + Delete(self_parse); Delete(parse_args); Delete(linkage); @@ -2581,7 +2568,7 @@ public: DelWrapper(f); Delete(wrapper_name); if (closure_decl) - Delete(closure_decl); + Delete(closure_decl); return SWIG_OK; } @@ -2904,13 +2891,13 @@ public: if (dirprot_mode()) { /* - This implementation uses a std::map. + This implementation uses a std::map. - It should be possible to rewrite it using a more elegant way, - like copying the Java approach for the 'override' array. + It should be possible to rewrite it using a more elegant way, + like copying the Java approach for the 'override' array. - But for now, this seems to be the least intrusive way. - */ + But for now, this seems to be the least intrusive way. + */ Printf(f_directors_h, "\n\n"); Printf(f_directors_h, "/* Internal Director utilities */\n"); Printf(f_directors_h, "public:\n"); @@ -2993,9 +2980,8 @@ public: /* ------------------------------------------------------------ * classDeclaration() * ------------------------------------------------------------ */ - - virtual bool get_single_base (Node *n, Node **base = NULL) - { + + virtual bool get_single_base(Node *n, Node **base = NULL) { if (base) *base = NULL; if (Getattr(n, "single_inh")) @@ -3044,8 +3030,7 @@ public: * classHandler() * ------------------------------------------------------------ */ - void builtin_pre_decl (Node *n, Node *base_node) - { + void builtin_pre_decl(Node *n, Node *base_node) { String *name = Getattr(n, "name"); String *rname = SwigType_namestr(name); Printf(f_init, tab4 "builtin_pytype = &PySwigBuiltin< %s >::pytype;\n", rname); @@ -3061,15 +3046,14 @@ public: Delete(base_mname); Delete(base_name); } else { - //Printv(f_init, tab4, "builtin_pytype->tp_base = SwigPyObject_type();\n", NIL); - Printv(f_init, tab4, "builtin_pytype->tp_base = &PyBaseObject_Type;\n", NIL); + Printv(f_init, tab4, "builtin_pytype->tp_base = SwigPyObject_type();\n", NIL); + //Printv(f_init, tab4, "builtin_pytype->tp_base = &PyBaseObject_Type;\n", NIL); } Printf(f_init, tab4 "builtin_pytype->tp_dict = d = PyDict_New();\n"); Delete(rname); } - void builtin_post_decl (File *f, Node *n) - { + void builtin_post_decl(File *f, Node *n) { String *name = Getattr(n, "name"); String *pname = Copy(name); SwigType_add_pointer(pname); @@ -3081,13 +3065,13 @@ public: char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : "0"; // Check for non-public destructor, in which case tp_dealloc should be "0" + // Any class that doesn't explicitly have a private/protected destructor + // has an implicit public destructor. String *tp_dealloc = NewString(""); - String *dtor_name = NewString("delete"); - if (Getattr(class_members, "delete")) - Printf(tp_dealloc, "py_builtin_dealloc< %s >", rname); - else + if (GetFlag(n, "private_dtor")) Printv(tp_dealloc, "0", NIL); - Delete(dtor_name); + else + Printf(tp_dealloc, "py_builtin_dealloc< %s >", rname); Printf(f, "template <> PyGetSetDef PySwigBuiltin< %s >::getset[] = {\n", rname); for (DohIterator member_iter = First(builtin_getset); member_iter.item; member_iter = Next(member_iter)) { @@ -3095,13 +3079,14 @@ public: Hash *mgetset = member_iter.item; String *getter = Getattr(mgetset, "getter"); String *setter = Getattr(mgetset, "setter"); - Printf(f, tab4 "{ const_cast(\"%s\"), (getter) %s, (setter) pyswig_setter_closure, const_cast(\"%s.%s\"), (void*) &%s },\n", - mname, getter ? getter : "0", name, mname, setter ? setter : "0"); + Printf(f, tab4 "{ const_cast(\"%s\"), (getter) %s, (setter) %s, const_cast(\"%s.%s\"), (void*) %s },\n", + mname, getter ? getter : "0", setter ? "pyswig_setter_closure" : "0", name, mname, setter ? setter : "0"); } Printv(f, " {NULL} // Sentinel\n", NIL); Printv(f, "};\n\n", NIL); Clear(builtin_getset); + // Number methods Printf(f, "template <> PyNumberMethods PySwigBuiltin< %s >::number_methods = {\n", rname); Printf(f, " (binaryfunc) %s, // nb_add;\n", getSlot(n, "feature:nb_add")); Printf(f, " (binaryfunc) %s, // nb_subtract;\n", getSlot(n, "feature:nb_subtract")); @@ -3143,26 +3128,47 @@ public: 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")); Printf(f, "};\n\n"); - + + // Sequence methods Printf(f, "template <> PySequenceMethods PySwigBuiltin< %s >::sequence_methods = {\n", rname); - Printf(f, " (lenfunc) %s, // sq_length\n", getSlot(n, "sq_length")); - Printf(f, " (binaryfunc) %s, // sq_concat\n", getSlot(n, "sq_concat")); - Printf(f, " (ssizeargfunc) %s, // sq_repeat\n", getSlot(n, "sq_repeat")); - Printf(f, " (ssizeargfunc) %s, // sq_item\n", getSlot(n, "sq_item")); - Printf(f, " (ssizessizeargfunc) %s, // sq_slice\n", getSlot(n, "sq_slice")); - Printf(f, " (ssizeobjargproc) %s, // sq_ass_item\n", getSlot(n, "sq_ass_item")); - Printf(f, " (ssizessizeobjargproc) %s, // sq_ass_slice\n", getSlot(n, "sq_ass_slice")); - Printf(f, " (objobjproc) %s, // sq_contains\n", getSlot(n, "sq_contains")); - Printf(f, " (binaryfunc) %s, // sq_inplace_concat\n", getSlot(n, "sq_inplace_concat")); - Printf(f, " (ssizeargfunc) %s, // sq_inplace_repeat\n", getSlot(n, "sq_inplace_repeat")); + 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, " (ssizessizeargfunc) %s, // sq_slice\n", getSlot(n, "feature:sq_slice")); + Printf(f, " (ssizeobjargproc) %s, // sq_ass_item\n", getSlot(n, "feature:sq_ass_item")); + Printf(f, " (ssizessizeobjargproc) %s, // sq_ass_slice\n", getSlot(n, "feature:sq_ass_slice")); + 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, "};\n\n"); + // Mapping methods Printf(f, "template <> PyMappingMethods PySwigBuiltin< %s >::mapping_methods = {\n", rname); - Printf(f, " (lenfunc) %s, // mp_length;\n", getSlot(n, "mp_length")); - Printf(f, " (binaryfunc) %s, // mp_subscript;\n", getSlot(n, "mp_subscript")); - Printf(f, " (objobjargproc) %s, // mp_ass_subscript;\n", getSlot(n, "mp_ass_subscript")); + 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")); Printf(f, "};\n\n"); + // Rich compare function + Printf(f, "template <> PyObject*\n"); + Printf(f, "%s::richcompare (PyObject *self, PyObject *other, int op)\n", templ); + Printf(f, "{\n"); + Printf(f, " PyObject *result = NULL;\n"); + Printf(f, " PyObject *tuple = PyTuple_New(1);\n"); + Printf(f, " assert(tuple);\n"); + Printf(f, " PyTuple_SET_ITEM(tuple, 0, other);\n"); + Printf(f, " Py_XINCREF(other);\n"); + Printf(f, " switch (op) {\n"); + Printv(f, builtin_richcompare, NIL); + Printf(f, " default : PyErr_Format(PyExc_TypeError, \"Cannot compare a(n) '%%s' to a(n) '%%s'\", self->ob_type->tp_name, other ? other->ob_type->tp_name : \"NIL\");\n"); + Printf(f, " }\n"); + Printf(f, " Py_DECREF(tuple);\n"); + Printf(f, " return result;\n"); + Printf(f, "}\n\n"); + Clear(builtin_richcompare); + + // Type object String *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES"); // TODO: Add more flags based on slots Printf(f, "template <> PyTypeObject PySwigBuiltin< %s >::pytype = {\n", rname); @@ -3190,10 +3196,10 @@ public: 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, /* tp_richcompare */\n", getSlot(n, "feature:tp_richcompare")); + Printf(f, " %s::richcompare, /* tp_richcompare */\n", templ); Printf(f, " %s, /* tp_weaklistoffset */\n", getSlot(n, "feature:tp_weaklistoffset")); - Printf(f, " %s, /* tp_iter */\n", getSlot(n, "feature:tp_iter")); - Printf(f, " %s, /* tp_iternext */\n", getSlot(n, "feature:tp_iternext")); + 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); @@ -3226,7 +3232,7 @@ public: Delete(templ); Delete(mname); Delete(rname); - Delete(pname); + Delete(pname); Delete(tp_dealloc); Delete(tp_flags); } @@ -3284,7 +3290,8 @@ public: if (!bname || ignore) { if (!bname && !ignore) { Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(n), Getline(n), - "Base class '%s' ignored - unknown module name for base. Either import the appropriate module interface file or specify the name of the module in the %%import directive.\n", SwigType_namestr(Getattr(b.item, "name"))); + "Base class '%s' ignored - unknown module name for base. Either import the appropriate module interface file or specify the name of the module in the %%import directive.\n", + SwigType_namestr(Getattr(b.item, "name"))); } b = Next(b); continue; @@ -3305,7 +3312,7 @@ public: } Printv(base_class, abcs, NIL); } - + if (!single_inh) { Printv(f_shadow, "class ", class_name, NIL); @@ -3315,7 +3322,7 @@ public: if (!classic) { Printf(f_shadow, modern ? "(object)" : "(_object)"); } - if (GetFlag(n, "feature:exceptionclass") ) { + if (GetFlag(n, "feature:exceptionclass")) { Printf(f_shadow, "(Exception)"); } } @@ -3391,7 +3398,7 @@ public: if (shadow) { /* Generate a class registration function */ if (!single_inh) { - String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers) + String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers) SwigType *smart = 0; if (smartptr) { SwigType *cpt = Swig_cparse_type(smartptr); @@ -3421,8 +3428,7 @@ public: } Printv(f_wrappers, - " SWIG_TypeNewClientData(SWIGTYPE", SwigType_manglestr(ct), ", SWIG_NewClientData(obj));\n", - " return SWIG_Py_Void();\n", "}\n\n", NIL); + " SWIG_TypeNewClientData(SWIGTYPE", SwigType_manglestr(ct), ", SWIG_NewClientData(obj));\n", " return SWIG_Py_Void();\n", "}\n\n", NIL); String *cname = NewStringf("%s_swigregister", class_name); add_method(cname, cname, 0); Delete(smart); @@ -3432,7 +3438,8 @@ public: } if (!have_constructor) { if (!single_inh) - Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined", (Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL); + Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined", + (Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL); } else if (fastinit && !single_inh) { Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL); @@ -3487,7 +3494,8 @@ public: List *shadow_list = Getattr(n, "shadow_methods"); for (int i = 0; i < Len(shadow_list); ++i) { String *symname = Getitem(shadow_list, i); - Printf(f_shadow_file, "%s.%s = new_instancemethod(%s.%s,None,%s)\n", class_name, symname, module, Swig_name_member(NSPACE_TODO, class_name, symname), class_name); + Printf(f_shadow_file, "%s.%s = new_instancemethod(%s.%s,None,%s)\n", class_name, symname, module, + Swig_name_member(NSPACE_TODO, class_name, symname), class_name); } } Printf(f_shadow_file, "%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name); @@ -3555,7 +3563,13 @@ public: if (!Getattr(n, "sym:nextSibling")) { if (builtin && in_class) { String *name = Getattr(n, "name"); - if (checkAttribute(n, "access", "public") && strncmp(Char(name), "operator ", 9) && !Getattr(class_members, name)) { + + // Can't use checkAttribute(n, "access", "public") because + // "access" attr isn't set on %extend methods + if (!checkAttribute(n, "access", "private") && + !checkAttribute(n, "access", "protected") && + strncmp(Char(name), "operator ", 9) && + !Getattr(class_members, name)) { String *fullname = Swig_name_member(NULL, class_name, symname); String *wname = Swig_name_wrapper(fullname); Setattr(class_members, name, name); @@ -3589,7 +3603,7 @@ public: Printv(f_shadow, " return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL); } } else { - Printv(f_shadow, tab4, "def ", symname, "(",parms , ")", returnTypeAnnotation(n), ":", NIL); + Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":", NIL); Printv(f_shadow, "\n", NIL); if (have_docstring(n)) Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL); @@ -3653,7 +3667,7 @@ public: Delete(wname); Delete(pyflags); } - } else if (shadow ) { + } else if (shadow) { if (!classic && !Getattr(n, "feature:python:callback") && have_addtofunc(n)) { int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; String *parms = make_pyParmList(n, false, false, kw); @@ -3678,10 +3692,12 @@ public: } else { if (!modern) { - Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL); + Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", + NIL); } if (!classic) { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), ")\n", NIL); + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), + ")\n", NIL); } } } @@ -3732,18 +3748,18 @@ public: if (!Getattr(n, "sym:nextSibling")) { if (builtin && in_class) { String *name = NewString("new"); - if ((use_director || checkAttribute(n, "access", "public")) && !Getattr(class_members, name)) { + // Can't use checkAttribute(n, "access", "public") because + // "access" attr isn't set on %extend methods + if ((use_director || + (!checkAttribute(n, "access", "protected") && + !checkAttribute(n, "access", "private"))) && + !Getattr(class_members, name)) { Setattr(class_members, name, name); String *fullname = Swig_name_member(NULL, name, class_name); if (!builtin_tp_init) builtin_tp_init = Swig_name_wrapper(fullname); - /* - ParmList *parms = Getattr(n, "parms"); - char const *pyflags = (!parms || Len(parms) == 0) ? "METH_NOARGS" : (Len(parms) == 1) ? "METH_0" : "METH_VARARGS"; - Printf(f_shadow, " { \"__init__\", (PyCFunction) %s, %s, \"\" },\n", builtin_tp_init, Char(pyflags)); - */ Delete(fullname); - } + } Delete(name); } else if (shadow) { int allow_kwargs = (check_kwargs(n) && (!Getattr(n, "sym:overloaded"))) ? 1 : 0; @@ -3755,7 +3771,7 @@ public: handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0); Delete(cname); } - + if (!have_constructor && handled_as_init) { if (Getattr(n, "feature:shadow")) { String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); @@ -3770,7 +3786,7 @@ public: String *classname = Swig_class_name(parent); String *rclassname = Swig_class_name(getCurrentClass()); assert(rclassname); - + String *parms = make_pyParmList(n, true, false, allow_kwargs); /* Pass 'self' only if using director */ @@ -3842,20 +3858,8 @@ public: virtual int destructorHandler(Node *n) { if (builtin && in_class) { - String *name = NewString("delete"); - if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) { - Setattr(class_members, name, name); - /* - String *fullname = Swig_name_member(NULL, name, class_name); - String *wname = Swig_name_wrapper(fullname); - ParmList *parms = Getattr(n, "parms"); - char const *pyflags = (!parms || Len(parms) == 0) ? "METH_NOARGS" : (Len(parms) == 1) ? "METH_0" : "METH_VARARGS"; - Printf(f_shadow, " { \"__del__\", (PyCFunction) %s, %s, \"\" },\n", wname, Char(pyflags)); - Delete(fullname); - Delete(wname); - */ - } - Delete(name); + if (checkAttribute(n, "access", "private") || checkAttribute(n, "access", "protected")) + SetFlag(Swig_methodclass(n), "private_dtor"); return SWIG_OK; } @@ -4119,489 +4123,489 @@ public: * ** Moved it here due to internal error on gcc-2.96 ** * --------------------------------------------------------------- */ int PYTHON::classDirectorMethods(Node *n) { - director_method_index = 0; - return Language::classDirectorMethods(n); + director_method_index = 0; + return Language::classDirectorMethods(n); } int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { - int is_void = 0; - int is_pointer = 0; - String *decl; - String *type; - String *name; - String *classname; - String *c_classname = Getattr(parent, "name"); - String *declaration; - ParmList *l; - Wrapper *w; - String *tm; - String *wrap_args = NewString(""); - String *return_type; - String *value = Getattr(n, "value"); - String *storage = Getattr(n, "storage"); - bool pure_virtual = false; - int status = SWIG_OK; - int idx; - bool ignored_method = GetFlag(n, "feature:ignore") ? true : false; + int is_void = 0; + int is_pointer = 0; + String *decl; + String *type; + String *name; + String *classname; + String *c_classname = Getattr(parent, "name"); + String *declaration; + ParmList *l; + Wrapper *w; + String *tm; + String *wrap_args = NewString(""); + String *return_type; + String *value = Getattr(n, "value"); + String *storage = Getattr(n, "storage"); + bool pure_virtual = false; + int status = SWIG_OK; + int idx; + bool ignored_method = GetFlag(n, "feature:ignore") ? true : false; - if (Cmp(storage, "virtual") == 0) { - if (Cmp(value, "0") == 0) { - pure_virtual = true; - } + if (Cmp(storage, "virtual") == 0) { + if (Cmp(value, "0") == 0) { + pure_virtual = true; } + } - classname = Getattr(parent, "sym:name"); - type = Getattr(n, "type"); - name = Getattr(n, "name"); + classname = Getattr(parent, "sym:name"); + type = Getattr(n, "type"); + name = Getattr(n, "name"); - w = NewWrapper(); - declaration = NewString(""); + w = NewWrapper(); + declaration = NewString(""); - /* determine if the method returns a pointer */ - decl = Getattr(n, "decl"); - is_pointer = SwigType_ispointer_return(decl); - is_void = (!Cmp(type, "void") && !is_pointer); + /* determine if the method returns a pointer */ + decl = Getattr(n, "decl"); + is_pointer = SwigType_ispointer_return(decl); + is_void = (!Cmp(type, "void") && !is_pointer); - /* form complete return type */ - return_type = Copy(type); - { - SwigType *t = Copy(decl); - SwigType *f = 0; - f = SwigType_pop_function(t); - SwigType_push(return_type, t); - Delete(f); - Delete(t); - } + /* form complete return type */ + return_type = Copy(type); + { + SwigType *t = Copy(decl); + SwigType *f = 0; + f = SwigType_pop_function(t); + SwigType_push(return_type, t); + Delete(f); + Delete(t); + } - /* virtual method definition */ - l = Getattr(n, "parms"); - String *target; - String *pclassname = NewStringf("SwigDirector_%s", classname); - String *qualified_name = NewStringf("%s::%s", pclassname, name); - SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type; - target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); - Printf(w->def, "%s", target); - Delete(qualified_name); - Delete(target); - /* header declaration */ - target = Swig_method_decl(rtype, decl, name, l, 0, 1); - Printf(declaration, " virtual %s", target); - Delete(target); + /* virtual method definition */ + l = Getattr(n, "parms"); + String *target; + String *pclassname = NewStringf("SwigDirector_%s", classname); + String *qualified_name = NewStringf("%s::%s", pclassname, name); + SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type; + target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0); + Printf(w->def, "%s", target); + Delete(qualified_name); + Delete(target); + /* header declaration */ + target = Swig_method_decl(rtype, decl, name, l, 0, 1); + Printf(declaration, " virtual %s", target); + Delete(target); - // Get any exception classes in the throws typemap - ParmList *throw_parm_list = 0; + // Get any exception classes in the throws typemap + ParmList *throw_parm_list = 0; - if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) { - Parm *p; - int gencomma = 0; + if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) { + Parm *p; + int gencomma = 0; - Append(w->def, " throw("); - Append(declaration, " throw("); + Append(w->def, " throw("); + Append(declaration, " throw("); - if (throw_parm_list) - Swig_typemap_attach_parms("throws", throw_parm_list, 0); - for (p = throw_parm_list; p; p = nextSibling(p)) { - if ((tm = Getattr(p, "tmap:throws"))) { - if (gencomma++) { - Append(w->def, ", "); - Append(declaration, ", "); - } - String *str = SwigType_str(Getattr(p, "type"), 0); - Append(w->def, str); - Append(declaration, str); - Delete(str); + if (throw_parm_list) + Swig_typemap_attach_parms("throws", throw_parm_list, 0); + for (p = throw_parm_list; p; p = nextSibling(p)) { + if ((tm = Getattr(p, "tmap:throws"))) { + if (gencomma++) { + Append(w->def, ", "); + Append(declaration, ", "); } - } - - Append(w->def, ")"); - Append(declaration, ")"); - } - - Append(w->def, " {"); - Append(declaration, ";\n"); - - /* declare method return value - * if the return value is a reference or const reference, a specialized typemap must - * handle it, including declaration of c_result ($result). - */ - if (!is_void) { - if (!(ignored_method && !pure_virtual)) { - String *cres = SwigType_lstr(return_type, "c_result"); - Printf(w->code, "%s;\n", cres); - Delete(cres); + String *str = SwigType_str(Getattr(p, "type"), 0); + Append(w->def, str); + Append(declaration, str); + Delete(str); } } - if (ignored_method) { - if (!pure_virtual) { - if (!is_void) - Printf(w->code, "return "); - String *super_call = Swig_method_call(super, l); - Printf(w->code, "%s;\n", super_call); - Delete(super_call); - } else { - Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname), - SwigType_namestr(name)); - } - } else { - /* attach typemaps to arguments (C/C++ -> Python) */ - String *arglist = NewString(""); - String *parse_args = NewString(""); + Append(w->def, ")"); + Append(declaration, ")"); + } - /* remove the wrapper 'w' since it was producing spurious temps */ - Swig_typemap_attach_parms("in", l, 0); - Swig_typemap_attach_parms("directorin", l, 0); - Swig_typemap_attach_parms("directorargout", l, w); + Append(w->def, " {"); + Append(declaration, ";\n"); - Parm *p; - char source[256]; + /* declare method return value + * if the return value is a reference or const reference, a specialized typemap must + * handle it, including declaration of c_result ($result). + */ + if (!is_void) { + if (!(ignored_method && !pure_virtual)) { + String *cres = SwigType_lstr(return_type, "c_result"); + Printf(w->code, "%s;\n", cres); + Delete(cres); + } + } - int outputs = 0; + if (ignored_method) { + if (!pure_virtual) { if (!is_void) - outputs++; + Printf(w->code, "return "); + String *super_call = Swig_method_call(super, l); + Printf(w->code, "%s;\n", super_call); + Delete(super_call); + } else { + Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname), + SwigType_namestr(name)); + } + } else { + /* attach typemaps to arguments (C/C++ -> Python) */ + String *arglist = NewString(""); + String *parse_args = NewString(""); - /* build argument list and type conversion string */ - idx = 0; - p = l; - int use_parse = 0; - while (p) { - if (checkAttribute(p, "tmap:in:numinputs", "0")) { - p = Getattr(p, "tmap:in:next"); - continue; - } + /* remove the wrapper 'w' since it was producing spurious temps */ + Swig_typemap_attach_parms("in", l, 0); + Swig_typemap_attach_parms("directorin", l, 0); + Swig_typemap_attach_parms("directorargout", l, w); - /* old style? caused segfaults without the p!=0 check - in the for() condition, and seems dangerous in the - while loop as well. - while (Getattr(p, "tmap:ignore")) { - p = Getattr(p, "tmap:ignore:next"); - } - */ + Parm *p; + char source[256]; - if (Getattr(p, "tmap:directorargout") != 0) - outputs++; + int outputs = 0; + if (!is_void) + outputs++; - String *pname = Getattr(p, "name"); - String *ptype = Getattr(p, "type"); - - Putc(',', arglist); - if ((tm = Getattr(p, "tmap:directorin")) != 0) { - String *parse = Getattr(p, "tmap:directorin:parse"); - if (!parse) { - sprintf(source, "obj%d", idx++); - String *input = NewString(source); - Replaceall(tm, "$input", input); - Delete(input); - Replaceall(tm, "$owner", "0"); - /* Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL); */ - Printv(wrap_args, "swig::SwigVar_PyObject ", source, ";\n", NIL); - - Printv(wrap_args, tm, "\n", NIL); - Printv(arglist, "(PyObject *)", source, NIL); - Putc('O', parse_args); - } else { - use_parse = 1; - Append(parse_args, parse); - Replaceall(tm, "$input", pname); - Replaceall(tm, "$owner", "0"); - if (Len(tm) == 0) - Append(tm, pname); - Append(arglist, tm); - } - p = Getattr(p, "tmap:directorin:next"); - continue; - } else if (Cmp(ptype, "void")) { - /* special handling for pointers to other C++ director classes. - * ideally this would be left to a typemap, but there is currently no - * way to selectively apply the dynamic_cast<> to classes that have - * directors. in other words, the type "SwigDirector_$1_lname" only exists - * for classes with directors. we avoid the problem here by checking - * module.wrap::directormap, but it's not clear how to get a typemap to - * do something similar. perhaps a new default typemap (in addition - * to SWIGTYPE) called DIRECTORTYPE? - */ - if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) { - Node *module = Getattr(parent, "module"); - Node *target = Swig_directormap(module, ptype); - sprintf(source, "obj%d", idx++); - String *nonconst = 0; - /* strip pointer/reference --- should move to Swig/stype.c */ - String *nptype = NewString(Char(ptype) + 2); - /* name as pointer */ - String *ppname = Copy(pname); - if (SwigType_isreference(ptype)) { - Insert(ppname, 0, "&"); - } - /* if necessary, cast away const since Python doesn't support it! */ - if (SwigType_isconst(nptype)) { - nonconst = NewStringf("nc_tmp_%s", pname); - String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname); - Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL); - Delete(nonconst_i); - Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number, - "Target language argument '%s' discards const in director method %s::%s.\n", - SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name)); - } else { - nonconst = Copy(ppname); - } - Delete(nptype); - Delete(ppname); - String *mangle = SwigType_manglestr(ptype); - if (target) { - String *director = NewStringf("director_%s", mangle); - Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL); - 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); - 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); - Append(wrap_args, "}\n"); - Delete(director); - 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_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n", - // source, nonconst, base); - Printv(arglist, source, NIL); - } - Putc('O', parse_args); - Delete(mangle); - Delete(nonconst); - } else { - Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, - "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0), - SwigType_namestr(c_classname), SwigType_namestr(name)); - status = SWIG_NOWRAP; - break; - } - } - p = nextSibling(p); + /* build argument list and type conversion string */ + idx = 0; + p = l; + int use_parse = 0; + while (p) { + if (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); + continue; } - /* add the method name as a PyString */ - String *pyname = Getattr(n, "sym:name"); - - int allow_thread = threads_enable(n); - - if (allow_thread) { - thread_begin_block(n, w->code); - Append(w->code, "{\n"); - } - - /* wrap complex arguments to PyObjects */ - Printv(w->code, wrap_args, NIL); - - /* pass the method call on to the Python object */ - if (dirprot_mode() && !is_public(n)) { - Printf(w->code, "swig_set_inner(\"%s\", true);\n", name); - } - - - Append(w->code, "if (!swig_get_self()) {\n"); - Printf(w->code, " Swig::DirectorException::raise(\"'self' uninitialized, maybe you forgot to call %s.__init__.\");\n", classname); - Append(w->code, "}\n"); - Append(w->code, "#if defined(SWIG_PYTHON_DIRECTOR_VTABLE)\n"); - Printf(w->code, "const size_t swig_method_index = %d;\n", director_method_index++); - Printf(w->code, "const char * const swig_method_name = \"%s\";\n", pyname); - - Append(w->code, "PyObject* method = swig_get_method(swig_method_index, swig_method_name);\n"); - if (Len(parse_args) > 0) { - if (use_parse || !modernargs) { - Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunction(method, (char *)\"(%s)\" %s);\n", parse_args, arglist); - } else { - Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunctionObjArgs(method %s, NULL);\n", arglist); - } - } else { - if (modernargs) { - Append(w->code, "swig::SwigVar_PyObject args = PyTuple_New(0);\n"); - Append(w->code, "swig::SwigVar_PyObject result = PyObject_Call(method, (PyObject*) args, NULL);\n"); - } else { - Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunction(method, NULL, NULL);\n"); - } - } - Append(w->code, "#else\n"); - if (Len(parse_args) > 0) { - if (use_parse || !modernargs) { - Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethod(swig_get_self(), (char *)\"%s\", (char *)\"(%s)\" %s);\n", - pyname, parse_args, arglist); - } else { - Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname); - Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name %s, NULL);\n", arglist); - } - } else { - if (!modernargs) { - Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethod(swig_get_self(), (char *) \"%s\", NULL);\n", pyname); - } else { - Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname); - Append(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name, NULL);\n"); - } - } - Append(w->code, "#endif\n"); - - if (dirprot_mode() && !is_public(n)) - Printf(w->code, "swig_set_inner(\"%s\", false);\n", name); - - /* exception handling */ - tm = Swig_typemap_lookup("director:except", n, "result", 0); - if (!tm) { - tm = Getattr(n, "feature:director:except"); - if (tm) - tm = Copy(tm); - } - Append(w->code, "if (!result) {\n"); - Append(w->code, " PyObject *error = PyErr_Occurred();\n"); - if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) { - Replaceall(tm, "$error", "error"); - Printv(w->code, Str(tm), "\n", NIL); - } else { - Append(w->code, " if (error) {\n"); - Printf(w->code, " Swig::DirectorMethodException::raise(\"Error detected when calling '%s.%s'\");\n", classname, pyname); - Append(w->code, " }\n"); - } - Append(w->code, "}\n"); - Delete(tm); - - /* - * Python method may return a simple object, or a tuple. - * for in/out aruments, we have to extract the appropriate PyObjects from the tuple, - * then marshal everything back to C/C++ (return value and output arguments). - * + /* old style? caused segfaults without the p!=0 check + in the for() condition, and seems dangerous in the + while loop as well. + while (Getattr(p, "tmap:ignore")) { + p = Getattr(p, "tmap:ignore:next"); + } */ - /* marshal return value and other outputs (if any) from PyObject to C/C++ type */ + if (Getattr(p, "tmap:directorargout") != 0) + outputs++; - String *cleanup = NewString(""); - String *outarg = NewString(""); + String *pname = Getattr(p, "name"); + String *ptype = Getattr(p, "type"); - if (outputs > 1) { - Wrapper_add_local(w, "output", "PyObject *output"); - Append(w->code, "if (!PyTuple_Check(result)) {\n"); - Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Python method %s.%sfailed to return a tuple.\");\n", classname, pyname); - Append(w->code, "}\n"); - } + Putc(',', arglist); + if ((tm = Getattr(p, "tmap:directorin")) != 0) { + String *parse = Getattr(p, "tmap:directorin:parse"); + if (!parse) { + sprintf(source, "obj%d", idx++); + String *input = NewString(source); + Replaceall(tm, "$input", input); + Delete(input); + Replaceall(tm, "$owner", "0"); + /* Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL); */ + Printv(wrap_args, "swig::SwigVar_PyObject ", source, ";\n", NIL); - idx = 0; - - /* marshal return value */ - if (!is_void) { - /* this seems really silly. the node's type excludes - * qualifier/pointer/reference markers, which have to be retrieved - * from the decl field to construct return_type. but the typemap - * lookup routine uses the node's type, so we have to swap in and - * out the correct type. it's not just me, similar silliness also - * occurs in Language::cDeclaration(). + Printv(wrap_args, tm, "\n", NIL); + Printv(arglist, "(PyObject *)", source, NIL); + Putc('O', parse_args); + } else { + use_parse = 1; + Append(parse_args, parse); + Replaceall(tm, "$input", pname); + Replaceall(tm, "$owner", "0"); + if (Len(tm) == 0) + Append(tm, pname); + Append(arglist, tm); + } + p = Getattr(p, "tmap:directorin:next"); + continue; + } else if (Cmp(ptype, "void")) { + /* special handling for pointers to other C++ director classes. + * ideally this would be left to a typemap, but there is currently no + * way to selectively apply the dynamic_cast<> to classes that have + * directors. in other words, the type "SwigDirector_$1_lname" only exists + * for classes with directors. we avoid the problem here by checking + * module.wrap::directormap, but it's not clear how to get a typemap to + * do something similar. perhaps a new default typemap (in addition + * to SWIGTYPE) called DIRECTORTYPE? */ - Setattr(n, "type", return_type); - tm = Swig_typemap_lookup("directorout", n, "result", w); - Setattr(n, "type", type); - if (tm != 0) { - if (outputs > 1) { - Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++); - Replaceall(tm, "$input", "output"); + if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) { + Node *module = Getattr(parent, "module"); + Node *target = Swig_directormap(module, ptype); + sprintf(source, "obj%d", idx++); + String *nonconst = 0; + /* strip pointer/reference --- should move to Swig/stype.c */ + String *nptype = NewString(Char(ptype) + 2); + /* name as pointer */ + String *ppname = Copy(pname); + if (SwigType_isreference(ptype)) { + Insert(ppname, 0, "&"); + } + /* if necessary, cast away const since Python doesn't support it! */ + if (SwigType_isconst(nptype)) { + nonconst = NewStringf("nc_tmp_%s", pname); + String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname); + Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL); + Delete(nonconst_i); + Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number, + "Target language argument '%s' discards const in director method %s::%s.\n", + SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name)); } else { - Replaceall(tm, "$input", "result"); + nonconst = Copy(ppname); } - char temp[24]; - sprintf(temp, "%d", idx); - Replaceall(tm, "$argnum", temp); - - /* TODO check this */ - if (Getattr(n, "wrap:disown")) { - Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); + Delete(nptype); + Delete(ppname); + String *mangle = SwigType_manglestr(ptype); + if (target) { + String *director = NewStringf("director_%s", mangle); + Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL); + 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); + 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); + Append(wrap_args, "}\n"); + Delete(director); + Printv(arglist, source, NIL); } else { - Replaceall(tm, "$disown", "0"); + 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_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n", + // source, nonconst, base); + Printv(arglist, source, NIL); } - if (Getattr(n, "tmap:directorout:implicitconv")) { - Replaceall(tm, "$implicitconv", get_implicitconv_flag(n)); - } - Replaceall(tm, "$result", "c_result"); - Printv(w->code, tm, "\n", NIL); - Delete(tm); + Putc('O', parse_args); + Delete(mangle); + Delete(nonconst); } else { - Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, - "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), SwigType_namestr(c_classname), - SwigType_namestr(name)); - status = SWIG_ERROR; + Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, + "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0), + SwigType_namestr(c_classname), SwigType_namestr(name)); + status = SWIG_NOWRAP; + break; } } - - /* marshal outputs */ - for (p = l; p;) { - if ((tm = Getattr(p, "tmap:directorargout")) != 0) { - if (outputs > 1) { - Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++); - Replaceall(tm, "$input", "output"); - } else { - Replaceall(tm, "$input", "result"); - } - Replaceall(tm, "$result", Getattr(p, "name")); - Printv(w->code, tm, "\n", NIL); - p = Getattr(p, "tmap:directorargout:next"); - } else { - p = nextSibling(p); - } - } - - /* any existing helper functions to handle this? */ - if (allow_thread) { - Append(w->code, "}\n"); - thread_end_block(n, w->code); - } - - Delete(parse_args); - Delete(arglist); - Delete(cleanup); - Delete(outarg); + p = nextSibling(p); } - if (!is_void) { - if (!(ignored_method && !pure_virtual)) { - String *rettype = SwigType_str(return_type, 0); - if (!SwigType_isreference(return_type)) { - Printf(w->code, "return (%s) c_result;\n", rettype); - } else { - Printf(w->code, "return (%s) *c_result;\n", rettype); - } - Delete(rettype); - } + /* add the method name as a PyString */ + String *pyname = Getattr(n, "sym:name"); + + int allow_thread = threads_enable(n); + + if (allow_thread) { + thread_begin_block(n, w->code); + Append(w->code, "{\n"); } + /* wrap complex arguments to PyObjects */ + Printv(w->code, wrap_args, NIL); + + /* pass the method call on to the Python object */ + if (dirprot_mode() && !is_public(n)) { + Printf(w->code, "swig_set_inner(\"%s\", true);\n", name); + } + + + Append(w->code, "if (!swig_get_self()) {\n"); + Printf(w->code, " Swig::DirectorException::raise(\"'self' uninitialized, maybe you forgot to call %s.__init__.\");\n", classname); Append(w->code, "}\n"); + Append(w->code, "#if defined(SWIG_PYTHON_DIRECTOR_VTABLE)\n"); + Printf(w->code, "const size_t swig_method_index = %d;\n", director_method_index++); + Printf(w->code, "const char * const swig_method_name = \"%s\";\n", pyname); - // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method - String *inline_extra_method = NewString(""); - if (dirprot_mode() && !is_public(n) && !pure_virtual) { - Printv(inline_extra_method, declaration, NIL); - String *extra_method_name = NewStringf("%sSwigPublic", name); - Replaceall(inline_extra_method, name, extra_method_name); - Replaceall(inline_extra_method, ";\n", " {\n "); - if (!is_void) - Printf(inline_extra_method, "return "); - String *methodcall = Swig_method_call(super, l); - Printv(inline_extra_method, methodcall, ";\n }\n", NIL); - Delete(methodcall); - Delete(extra_method_name); + Append(w->code, "PyObject* method = swig_get_method(swig_method_index, swig_method_name);\n"); + if (Len(parse_args) > 0) { + if (use_parse || !modernargs) { + Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunction(method, (char *)\"(%s)\" %s);\n", parse_args, arglist); + } else { + Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunctionObjArgs(method %s, NULL);\n", arglist); + } + } else { + if (modernargs) { + Append(w->code, "swig::SwigVar_PyObject args = PyTuple_New(0);\n"); + Append(w->code, "swig::SwigVar_PyObject result = PyObject_Call(method, (PyObject*) args, NULL);\n"); + } else { + Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunction(method, NULL, NULL);\n"); + } + } + Append(w->code, "#else\n"); + if (Len(parse_args) > 0) { + if (use_parse || !modernargs) { + Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethod(swig_get_self(), (char *)\"%s\", (char *)\"(%s)\" %s);\n", + pyname, parse_args, arglist); + } else { + Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname); + Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name %s, NULL);\n", arglist); + } + } else { + if (!modernargs) { + Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethod(swig_get_self(), (char *) \"%s\", NULL);\n", pyname); + } else { + Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname); + Append(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name, NULL);\n"); + } + } + Append(w->code, "#endif\n"); + + if (dirprot_mode() && !is_public(n)) + Printf(w->code, "swig_set_inner(\"%s\", false);\n", name); + + /* exception handling */ + tm = Swig_typemap_lookup("director:except", n, "result", 0); + if (!tm) { + tm = Getattr(n, "feature:director:except"); + if (tm) + tm = Copy(tm); + } + Append(w->code, "if (!result) {\n"); + Append(w->code, " PyObject *error = PyErr_Occurred();\n"); + if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) { + Replaceall(tm, "$error", "error"); + Printv(w->code, Str(tm), "\n", NIL); + } else { + Append(w->code, " if (error) {\n"); + Printf(w->code, " Swig::DirectorMethodException::raise(\"Error detected when calling '%s.%s'\");\n", classname, pyname); + Append(w->code, " }\n"); + } + Append(w->code, "}\n"); + Delete(tm); + + /* + * Python method may return a simple object, or a tuple. + * for in/out aruments, we have to extract the appropriate PyObjects from the tuple, + * then marshal everything back to C/C++ (return value and output arguments). + * + */ + + /* marshal return value and other outputs (if any) from PyObject to C/C++ type */ + + String *cleanup = NewString(""); + String *outarg = NewString(""); + + if (outputs > 1) { + Wrapper_add_local(w, "output", "PyObject *output"); + Append(w->code, "if (!PyTuple_Check(result)) {\n"); + Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Python method %s.%sfailed to return a tuple.\");\n", classname, pyname); + Append(w->code, "}\n"); } - /* emit the director method */ - if (status == SWIG_OK) { - if (!Getattr(n, "defaultargs")) { - Wrapper_print(w, f_directors); - Printv(f_directors_h, declaration, NIL); - Printv(f_directors_h, inline_extra_method, NIL); + idx = 0; + + /* marshal return value */ + if (!is_void) { + /* this seems really silly. the node's type excludes + * qualifier/pointer/reference markers, which have to be retrieved + * from the decl field to construct return_type. but the typemap + * lookup routine uses the node's type, so we have to swap in and + * out the correct type. it's not just me, similar silliness also + * occurs in Language::cDeclaration(). + */ + Setattr(n, "type", return_type); + tm = Swig_typemap_lookup("directorout", n, "result", w); + Setattr(n, "type", type); + if (tm != 0) { + if (outputs > 1) { + Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++); + Replaceall(tm, "$input", "output"); + } else { + Replaceall(tm, "$input", "result"); + } + char temp[24]; + sprintf(temp, "%d", idx); + Replaceall(tm, "$argnum", temp); + + /* TODO check this */ + if (Getattr(n, "wrap:disown")) { + Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); + } else { + Replaceall(tm, "$disown", "0"); + } + if (Getattr(n, "tmap:directorout:implicitconv")) { + Replaceall(tm, "$implicitconv", get_implicitconv_flag(n)); + } + Replaceall(tm, "$result", "c_result"); + Printv(w->code, tm, "\n", NIL); + Delete(tm); + } else { + Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, + "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), SwigType_namestr(c_classname), + SwigType_namestr(name)); + status = SWIG_ERROR; } } - /* clean up */ - Delete(wrap_args); - Delete(return_type); - Delete(pclassname); - DelWrapper(w); - return status; + /* marshal outputs */ + for (p = l; p;) { + if ((tm = Getattr(p, "tmap:directorargout")) != 0) { + if (outputs > 1) { + Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++); + Replaceall(tm, "$input", "output"); + } else { + Replaceall(tm, "$input", "result"); + } + Replaceall(tm, "$result", Getattr(p, "name")); + Printv(w->code, tm, "\n", NIL); + p = Getattr(p, "tmap:directorargout:next"); + } else { + p = nextSibling(p); + } + } + + /* any existing helper functions to handle this? */ + if (allow_thread) { + Append(w->code, "}\n"); + thread_end_block(n, w->code); + } + + Delete(parse_args); + Delete(arglist); + Delete(cleanup); + Delete(outarg); + } + + if (!is_void) { + if (!(ignored_method && !pure_virtual)) { + String *rettype = SwigType_str(return_type, 0); + if (!SwigType_isreference(return_type)) { + Printf(w->code, "return (%s) c_result;\n", rettype); + } else { + Printf(w->code, "return (%s) *c_result;\n", rettype); + } + Delete(rettype); + } + } + + Append(w->code, "}\n"); + + // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method + String *inline_extra_method = NewString(""); + if (dirprot_mode() && !is_public(n) && !pure_virtual) { + Printv(inline_extra_method, declaration, NIL); + String *extra_method_name = NewStringf("%sSwigPublic", name); + Replaceall(inline_extra_method, name, extra_method_name); + Replaceall(inline_extra_method, ";\n", " {\n "); + if (!is_void) + Printf(inline_extra_method, "return "); + String *methodcall = Swig_method_call(super, l); + Printv(inline_extra_method, methodcall, ";\n }\n", NIL); + Delete(methodcall); + Delete(extra_method_name); + } + + /* emit the director method */ + if (status == SWIG_OK) { + if (!Getattr(n, "defaultargs")) { + Wrapper_print(w, f_directors); + Printv(f_directors_h, declaration, NIL); + Printv(f_directors_h, inline_extra_method, NIL); + } + } + + /* clean up */ + Delete(wrap_args); + Delete(return_type); + Delete(pclassname); + DelWrapper(w); + return status; } /* ----------------------------------------------------------------------------- From 3a86f2068ffca467f9aac0a06ac085cdb2af4e8d Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Mon, 20 Dec 2010 23:35:18 +0000 Subject: [PATCH 07/56] Added support for multiple inheritance. Not as hard as I feared. Apply operator features to both the operator name, and the renamed "__*__" method. That's the only way to hit all corners. Added support for %pythonnondynamic. I believe this implementation is more correct than the existing implementation, but I'm still waiting for an adjudication on the behavior of the python_nondynamic test. Current list of unsupported features that require minor tweaks to the test suite: - 'this' member variable is obsolete. - No support for reversible operator overloads (e.g., __radd__). You can still support this: a = MyString("foo") b = "bar" c = a + b ... but you can't do this: a = "foo" b = MyString("bar") c = a + b With the tweaks, the test suite now fails on python_nondynamic. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12353 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/builtin.swg | 30 ++++---- Lib/python/pyinit.swg | 6 ++ Lib/python/pyopers.swg | 4 +- Lib/python/pyrun.swg | 49 +++++++++++++ Source/Modules/python.cxx | 148 ++++++++++++++++++++++++++++---------- 5 files changed, 182 insertions(+), 55 deletions(-) diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index 7a5ad8664..9b385ddfd 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -115,6 +115,21 @@ wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \ return result; \ } +SWIGINTERN int +pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure) +{ + if (!closure) + return -1; + PyObject *tuple = PyTuple_New(1); + assert(tuple); + PyTuple_SET_ITEM(tuple, 0, val); + Py_XINCREF(val); + PyObject *result = ((PyCFunction) closure)(obj, tuple); + Py_DECREF(tuple); + Py_XDECREF(result); + return result ? 0 : -1; +} + #ifdef __cplusplus namespace { @@ -146,21 +161,6 @@ template void py_builtin_dealloc (PyObject *pyobj) (*pyobj->ob_type->tp_free)(pyobj); } -SWIGINTERN int -pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure) -{ - if (!closure) - return -1; - PyObject *tuple = PyTuple_New(1); - assert(tuple); - PyTuple_SET_ITEM(tuple, 0, val); - Py_XINCREF(val); - PyObject *result = ((PyCFunction) closure)(obj, tuple); - Py_DECREF(tuple); - Py_XDECREF(result); - return result ? 0 : -1; -} - } // namespace { #endif diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index 5ee13f34b..f873e3968 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -7,6 +7,8 @@ %init %{ #ifdef __cplusplus +#include + extern "C" { #endif @@ -338,7 +340,11 @@ SWIG_init(void) { #if defined(SWIGPYTHON_BUILTIN) PyTypeObject *builtin_pytype = 0; + PyObject *propargs = NULL, *propget = NULL, *propset = NULL, *propobj = NULL; + std::vector builtin_bases; swig_type_info *builtin_basetype = 0; + PyObject *base_tuple = NULL; + int i; SWIG_Python_builtin_imports(); #endif diff --git a/Lib/python/pyopers.swg b/Lib/python/pyopers.swg index 851524219..84058da96 100644 --- a/Lib/python/pyopers.swg +++ b/Lib/python/pyopers.swg @@ -6,8 +6,8 @@ #ifdef __cplusplus #if defined(SWIGPYTHON_BUILTIN) -#define %pybinoperator(pyname,oper,functp,slot) %rename(pyname) oper; %pythonmaybecall oper; %feature("pyslot", #slot, functype=#functp) oper; -#define %pycompare(pyname,oper,comptype) %rename(pyname) oper; %pythonmaybecall oper; %feature("pycompare", #comptype) oper; +#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; #else #define %pybinoperator(pyname,oper,functp,slot) %rename(pyname) oper; %pythonmaybecall oper #define %pycompare(pyname,oper,comptype) %pybinoperator(pyname,oper,,comptype) diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 96fdcf085..503e42711 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1628,6 +1628,55 @@ 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; + PyObject *descr; + descrsetfunc f; + int res = -1; + + if (!PyString_Check(name)) { +#ifdef Py_USING_UNICODE + if (PyUnicode_Check(name)) { + name = PyUnicode_AsEncodedString(name, NULL, NULL); + if (name == NULL) + return -1; + } + else +#endif + { + PyErr_Format(PyExc_TypeError, + "attribute name must be string, not '%.200s'", + name->ob_type->tp_name); + return -1; + } + } + else + Py_INCREF(name); + + if (tp->tp_dict == NULL) { + if (PyType_Ready(tp) < 0) + goto done; + } + + descr = _PyType_Lookup(tp, name); + f = NULL; + if (descr != NULL && PyType_HasFeature(descr->ob_type, Py_TPFLAGS_HAVE_CLASS)) + f = descr->ob_type->tp_descr_set; + if (f == NULL) + PyErr_Format(PyExc_AttributeError, + "'%.100s' object has no attribute '%.200s'", + tp->tp_name, PyString_AS_STRING(name)); + else + res = f(descr, obj, value); + +done: + Py_DECREF(name); + return res; +} + #ifdef __cplusplus #if 0 diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 1a4209092..a10ba2179 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -48,7 +48,6 @@ static String *f_shadow_imports = 0; static String *f_shadow_import_stmts = 0; static String *f_shadow_stubs = 0; static Hash *builtin_getset = 0; -static String *builtin_richcompare = 0; static String *methods; static String *class_name; @@ -572,7 +571,6 @@ public: f_directors_h = NewString(""); f_directors = NewString(""); builtin_getset = NewHash(); - builtin_richcompare = NewString(""); if (builtin) { f_builtins = NewString(""); @@ -1906,6 +1904,7 @@ public: String *iname = Getattr(n, "sym:name"); SwigType *d = Getattr(n, "type"); ParmList *l = Getattr(n, "parms"); + Node *parent = Swig_methodclass(n); int director_method = 0; @@ -2059,7 +2058,6 @@ public: if (constructor && num_arguments == 1 && num_required == 1) { if (Cmp(storage, "explicit") == 0) { - Node *parent = Swig_methodclass(n); if (GetFlag(parent, "feature:implicitconv")) { String *desc = NewStringf("SWIGTYPE%s", SwigType_manglestr(Getattr(n, "type"))); Printf(f->code, "if (SWIG_CheckImplicit(%s)) SWIG_fail;\n", desc); @@ -2097,7 +2095,7 @@ public: } /* Keyword argument handling */ - if (allow_kwargs) { + if (allow_kwargs && parse_from_tuple) { if (Len(pn)) { String *tmp = 0; String *name = pn; @@ -2380,7 +2378,6 @@ public: String *type = Getattr(n, "type"); //Node *classNode = Swig_methodclass(n); //Node *module = Getattr(classNode, "module"); - Node *parent = Swig_methodclass(n); Node *module = Getattr(parent, "module"); Node *target = Swig_directormap(module, type); if (target) @@ -2545,7 +2542,6 @@ public: Printv(f_wrappers, closure_decl, "\n\n", NIL); Append(closure_name, "_closure"); } - Node *parent = Swig_methodclass(n); Setattr(parent, feature_name, closure_name); Delete(feature_name); Delete(closure_name); @@ -2553,8 +2549,11 @@ public: /* Handle comparison operators for builtin types */ String *compare = Getattr(n, "feature:pycompare"); - if (compare) - Printf(builtin_richcompare, " case %s : result = %s(self, tuple); break;\n", compare, wrapper_name); + if (compare) { + Hash *richcompare = Getattr(parent, "richcompare"); + assert(richcompare); + Setattr(richcompare, compare, wrapper_name); + } Delete(self_parse); Delete(parse_args); @@ -2597,7 +2596,7 @@ public: Python dictionary. */ if (!have_globals) { - Printf(f_init, "\t PyDict_SetItemString(d,(char*)\"%s\", SWIG_globals());\n", global_name); + Printf(f_init, "\t PyDict_SetItemString(md,(char*)\"%s\", SWIG_globals());\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); @@ -2605,8 +2604,8 @@ public: } int assignable = is_assignable(n); - if (!builtin && (shadow) && !assignable && !in_class) - Printf(f_shadow_stubs, "%s = %s.%s\n", iname, global_name, iname); + if (!builtin && shadow && !assignable && !in_class) + Printf(f_shadow_stubs, "%s = %s.%s\n", iname, global_name, iname); String *getname = Swig_name_get(NSPACE_TODO, iname); String *setname = Swig_name_set(NSPACE_TODO, iname); @@ -2616,6 +2615,12 @@ public: /* Create a function for setting the value of the variable */ if (assignable) { Setattr(n, "wrap:name", varsetname); + if (builtin && in_class) { + String *method_def = NewStringf("%s_method_def", varsetname); + Printf(f_builtins, "static PyMethodDef %s = { const_cast(\"%s\"), (PyCFunction)%s, METH_VARARGS, \"\" };\n", method_def, name, varsetname); + Setattr(n, "builtin:setter", method_def); + Delete(method_def); + } Printf(setf->def, "SWIGINTERN int %s(PyObject *_val) {", varsetname); if ((tm = Swig_typemap_lookup("varin", n, name, 0))) { Replaceall(tm, "$source", "_val"); @@ -2647,6 +2652,12 @@ public: /* Create a function for getting the value of a variable */ Setattr(n, "wrap:name", vargetname); + if (builtin && in_class) { + String *method_def = NewStringf("%s_method_def", vargetname); + Printf(f_builtins, "static PyMethodDef %s = { const_cast(\"%s\"), (PyCFunction)%s, METH_NOARGS, \"\" };\n", method_def, name, vargetname); + Setattr(n, "builtin:getter", method_def); + Delete(method_def); + } int addfail = 0; Printf(getf->def, "SWIGINTERN PyObject *%s(void) {", vargetname); Wrapper_add_local(getf, "pyobj", "PyObject *pyobj = 0"); @@ -2670,7 +2681,9 @@ public: /* Now add this to the variable linking mechanism */ 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); Delete(vargetname); Delete(varsetname); Delete(getname); @@ -2991,7 +3004,7 @@ public: Setattr(n, "single_inh", "1"); return true; } - if (baselist && Len(baselist) == 1) { + //if (baselist && Len(baselist) == 1) { Iterator b = First(baselist); if (this->get_single_base(b.item)) { if (base) @@ -2999,7 +3012,7 @@ public: Setattr(n, "single_inh", "1"); return true; } - } + //} return false; } @@ -3030,11 +3043,38 @@ public: * classHandler() * ------------------------------------------------------------ */ - void builtin_pre_decl(Node *n, Node *base_node) { + void builtin_pre_decl(Node *n, Node *) { String *name = Getattr(n, "name"); String *rname = SwigType_namestr(name); Printf(f_init, tab4 "builtin_pytype = &PySwigBuiltin< %s >::pytype;\n", rname); Printf(f_init, tab4 "builtin_pytype->tp_new = PyType_GenericNew;\n"); + List *baselist = Getattr(n, "bases"); + if (baselist) { + for (Iterator b = First(baselist); b.item; b = Next(b)) { + String *bname = Getattr(b.item, "name"); + if (!bname || GetFlag(b.item, "feature:ignore")) + continue; + 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); + Delete(base_name); + Delete(base_mname); + } + } + Printv(f_init, " if (!builtin_bases.size())\n", NIL); + Printv(f_init, " builtin_bases.push_back(SwigPyObject_type());\n", NIL); + Printv(f_init, " builtin_pytype->tp_base = builtin_bases[0];\n", NIL); + Printv(f_init, " Py_INCREF((PyObject*) builtin_bases[0]);\n", NIL); + Printv(f_init, " base_tuple = PyTuple_New(builtin_bases.size());\n", NIL); + Printv(f_init, " for (i = 0; i < builtin_bases.size(); ++i) {\n", NIL); + Printv(f_init, " PyTuple_SET_ITEM(base_tuple, i, (PyObject*) builtin_bases[i]);\n", NIL); + Printv(f_init, " Py_INCREF((PyObject*) builtin_bases[i]);\n", NIL); + Printv(f_init, " }\n", NIL); + Printv(f_init, " builtin_bases.clear();\n", NIL); + /* if (base_node) { String *base_name = Copy(Getattr(base_node, "name")); SwigType_add_pointer(base_name); @@ -3047,8 +3087,8 @@ public: Delete(base_name); } else { Printv(f_init, tab4, "builtin_pytype->tp_base = SwigPyObject_type();\n", NIL); - //Printv(f_init, tab4, "builtin_pytype->tp_base = &PyBaseObject_Type;\n", NIL); } + */ Printf(f_init, tab4 "builtin_pytype->tp_dict = d = PyDict_New();\n"); Delete(rname); } @@ -3160,13 +3200,20 @@ public: Printf(f, " PyTuple_SET_ITEM(tuple, 0, other);\n"); Printf(f, " Py_XINCREF(other);\n"); Printf(f, " switch (op) {\n"); - Printv(f, builtin_richcompare, NIL); + + Hash *richcompare = Getattr(n, "richcompare"); + assert(richcompare); + for (Iterator i = First(richcompare); i.item; i = Next(i)) + Printf(f, " case %s : result = %s(self, tuple); break;\n", i.key, i.item); + Printf(f, " default : PyErr_Format(PyExc_TypeError, \"Cannot compare a(n) '%%s' to a(n) '%%s'\", self->ob_type->tp_name, other ? other->ob_type->tp_name : \"NIL\");\n"); Printf(f, " }\n"); Printf(f, " Py_DECREF(tuple);\n"); Printf(f, " return result;\n"); Printf(f, "}\n\n"); - Clear(builtin_richcompare); + + if (GetFlag(n, "feature:python:nondynamic")) + Setattr(n, "feature:tp_setattro", "SWIG_Python_NonDynamicSetAttr"); // Type object String *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES"); @@ -3241,7 +3288,6 @@ public: int oldclassic = classic; int oldmodern = modern; File *f_shadow_file = f_shadow; - bool single_inh = false; Node *base_node = NULL; if (shadow) { @@ -3269,8 +3315,7 @@ public: if (!addSymbol(class_name, n)) return SWIG_ERROR; - single_inh = builtin && get_single_base(n, &base_node); - if (builtin && !single_inh) { + if (builtin && !get_single_base(n, &base_node)) { Swig_warning(WARN_PYTHON_MULTIPLE_INH, Getfile(n), Getline(n), "Class '%s' ignored, because it has multiple inheritance, which is incompatible with the '-builtin' option.\n", real_classname); return SWIG_OK; @@ -3304,6 +3349,18 @@ public: } } + if (builtin) { + Hash *richcompare = NULL; + if (base_node) { + Hash *base_richcompare = Getattr(base_node, "richcompare"); + assert(base_richcompare); + richcompare = Copy(base_richcompare); + } else { + richcompare = NewHash(); + } + Setattr(n, "richcompare", richcompare); + } + /* dealing with abstract base class */ String *abcs = Getattr(n, "feature:python:abc"); if (py3 && abcs) { @@ -3313,7 +3370,7 @@ public: Printv(base_class, abcs, NIL); } - if (!single_inh) { + if (!builtin) { Printv(f_shadow, "class ", class_name, NIL); if (Len(base_class)) { @@ -3367,7 +3424,7 @@ public: /* Emit all of the members */ in_class = 1; - if (single_inh) { + if (builtin) { class_members = NewHash(); builtin_pre_decl(n, base_node); } @@ -3397,7 +3454,7 @@ public: /* Complete the class */ if (shadow) { /* Generate a class registration function */ - if (!single_inh) { + if (!builtin) { String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers) SwigType *smart = 0; if (smartptr) { @@ -3437,10 +3494,10 @@ public: Delete(realct); } if (!have_constructor) { - if (!single_inh) + if (!builtin) Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined", (Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL); - } else if (fastinit && !single_inh) { + } else if (fastinit && !builtin) { Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL); Printv(f_wrappers, " return SWIG_Python_InitShadowInstance(args);\n", "}\n\n", NIL); @@ -3448,7 +3505,7 @@ public: add_method(cname, cname, 0); Delete(cname); } - if (!have_repr && !single_inh) { + if (!have_repr && !builtin) { /* Supply a repr method for this class */ String *rname = SwigType_namestr(real_classname); if (new_repr) { @@ -3459,7 +3516,7 @@ public: Delete(rname); } - if (single_inh) { + if (builtin) { builtin_post_decl(f_builtins, n); String *rname = SwigType_namestr(real_classname); Printf(f_builtins, "template <> PyMethodDef PySwigBuiltin< %s >::methods[] = {\n", rname); @@ -3472,11 +3529,11 @@ public: } /* Now emit methods */ - if (!single_inh) + if (!builtin) Printv(f_shadow_file, f_shadow, NIL); /* Now the Ptr class */ - if (classptr && !single_inh) { + if (classptr && !builtin) { Printv(f_shadow_file, "\nclass ", class_name, "Ptr(", class_name, "):\n", tab4, "def __init__(self, this):\n", NIL); if (!modern) { Printv(f_shadow_file, @@ -3489,7 +3546,7 @@ public: } } - if (!single_inh) { + if (!builtin) { if (fastproxy) { List *shadow_list = Getattr(n, "shadow_methods"); for (int i = 0; i < Len(shadow_list); ++i) { @@ -3508,7 +3565,7 @@ public: Clear(f_shadow_stubs); } - if (single_inh) { + if (builtin) { Dump(f_shadow, f_builtins); Printf(f_builtins, " {NULL} // Sentinel\n};\n\n"); Delete(class_members); @@ -3573,15 +3630,14 @@ public: String *fullname = Swig_name_member(NULL, class_name, symname); String *wname = Swig_name_wrapper(fullname); Setattr(class_members, name, name); - String *pyflags = NewString("METH_VARARGS"); - Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", Char(name), wname, Char(pyflags)); + int allow_kwargs = check_kwargs(n); + Printf(f_shadow, " { \"%s\", (PyCFunction) %s, METH_VARARGS%s, \"\" },\n", + name, wname, allow_kwargs ? "|METH_KEYWORDS" : ""); Delete(name); Delete(fullname); Delete(wname); - Delete(pyflags); } } else if (shadow) { - int allow_kwargs = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; int fproxy = fastproxy; if (Strcmp(symname, "__repr__") == 0) { have_repr = 1; @@ -3595,6 +3651,7 @@ public: Delete(pycode); fproxy = 0; } else { + int allow_kwargs = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; String *parms = make_pyParmList(n, true, false, allow_kwargs); String *callParms = make_pyParmList(n, true, true, allow_kwargs); if (!have_addtofunc(n)) { @@ -3996,19 +4053,34 @@ public: add_method(setname, wrapsetname, 0); DelWrapper(f); } - if (!modern) { + if (!modern && !builtin) { if (assignable) { Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL); } Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL); } - if (!classic) { + if (!classic && !builtin) { if (!assignable) { Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL); } else { 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"); + if (getter) { + Printf(f_init, " propargs = PyTuple_New(%d);\n", setter ? 2 : 1); + Printf(f_init, " propget = PyCFunction_New(&%s, NULL);\n", getter); + Printf(f_init, " PyTuple_SET_ITEM(propargs, 0, propget);\n"); + if (setter) { + Printf(f_init, " propset = PyCFunction_New(&%s, NULL);\n", setter); + Printf(f_init, " PyTuple_SET_ITEM(propargs, 1, propset);\n"); + } + Printf(f_init, " propobj = PyType_Type.tp_call((PyObject*) &PyProperty_Type, propargs, NULL);\n"); + Printf(f_init, " Py_DECREF(propargs);\n"); + Printf(f_init, " PyDict_SetItemString(d, \"%s\", propobj);\n", symname); + Printf(f_init, " Py_DECREF(propobj);\n"); + } Delete(mname); Delete(getname); Delete(wrapgetname); From b77b64944b6befc15b984b5f22187e13c288672e Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Wed, 5 Jan 2011 08:35:28 +0000 Subject: [PATCH 08/56] Static member variables are working. Fixed some corner cases with protected members of director classes. Now dying in director_finalizer. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12371 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/builtin.swg | 241 ++++++++++++++++++-- Lib/python/pyinit.swg | 19 +- Lib/python/pyrun.swg | 41 +++- Lib/python/std_pair.i | 27 ++- Source/Modules/python.cxx | 451 ++++++++++++++++++++------------------ 5 files changed, 525 insertions(+), 254 deletions(-) diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index 9b385ddfd..de72a558e 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -1,3 +1,10 @@ +#define PYSWIG_UNARYFUNC_CLOSURE(wrapper) \ +SWIGINTERN PyObject* \ +wrapper##_closure (PyObject *a) \ +{ \ + return wrapper(a, NULL); \ +} + #define PYSWIG_BINARYFUNC_CLOSURE(wrapper) \ SWIGINTERN PyObject* \ wrapper##_closure (PyObject *a, PyObject *b) \ @@ -115,28 +122,13 @@ wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \ return result; \ } -SWIGINTERN int -pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure) -{ - if (!closure) - return -1; - PyObject *tuple = PyTuple_New(1); - assert(tuple); - PyTuple_SET_ITEM(tuple, 0, val); - Py_XINCREF(val); - PyObject *result = ((PyCFunction) closure)(obj, tuple); - Py_DECREF(tuple); - Py_XDECREF(result); - return result ? 0 : -1; -} - #ifdef __cplusplus namespace { -template struct PySwigBuiltin : public SwigPyObject { +template struct SwigPyBuiltin : public SwigPyObject { - typedef PySwigBuiltin<_Tp> this_type; + typedef SwigPyBuiltin<_Tp> this_type; typedef _Tp obj_type; typedef obj_type* pointer; typedef obj_type& reference; @@ -154,7 +146,7 @@ template struct PySwigBuiltin : public SwigPyObject { template void py_builtin_dealloc (PyObject *pyobj) { - typedef PySwigBuiltin<_Tp> builtin_type; + typedef SwigPyBuiltin<_Tp> builtin_type; builtin_type *obj = (builtin_type*) pyobj; if (obj->own) delete reinterpret_cast<_Tp*>(obj->ptr); @@ -164,3 +156,216 @@ template void py_builtin_dealloc (PyObject *pyobj) } // namespace { #endif + +SWIGRUNTIME int py_builtin_bad_init (PyObject *self, PyObject *args, PyObject *kwds) +{ + PyErr_Format(PyExc_TypeError, "Cannot create new instances of type '%.300s'", self->ob_type->tp_name); + return -1; +} + +SWIGRUNTIME void py_builtin_bad_dealloc (PyObject *pyobj) +{ + SwigPyObject *sobj = (SwigPyObject*) pyobj; + if (sobj->own) { + PyErr_Format(PyExc_TypeError, + "Swig detected a memory leak in type '%s': no callable destructor found.", + pyobj->ob_type->tp_name); + } +} + +typedef struct { + PyCFunction get; + PyCFunction set; +} SwigPyGetSet; + +SWIGRUNTIME PyObject* +pyswig_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; +} + +SWIGRUNTIME int +pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure) +{ + if (!closure) + return -1; + SwigPyGetSet *getset = (SwigPyGetSet*) closure; + if (!getset->set) + 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; +} + +SWIGRUNTIME 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; +} + +SWIGRUNTIME int +pyswig_static_setter_closure (PyObject *obj, PyObject *val, void *closure) +{ + if (!closure) + return -1; + SwigPyGetSet *getset = (SwigPyGetSet*) closure; + if (!getset->set) + 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; +} + +SWIGRUNTIME void +SwigPyStaticVar_dealloc(PyDescrObject *descr) +{ + _PyObject_GC_UNTRACK(descr); + Py_XDECREF(descr->d_type); + Py_XDECREF(descr->d_name); + PyObject_GC_Del(descr); +} + +SWIGRUNTIME PyObject * +SwigPyStaticVar_repr(PyGetSetDescrObject *descr) +{ + return PyString_FromFormat("", + PyString_AsString(descr->d_name), + descr->d_type->tp_name); +} + +SWIGRUNTIME int +SwigPyStaticVar_traverse(PyObject *self, visitproc visit, void *arg) +{ + PyDescrObject *descr = (PyDescrObject *)self; + Py_VISIT(descr->d_type); + return 0; +} + +SWIGRUNTIME PyObject * +SwigPyStaticVar_get (PyGetSetDescrObject *descr, PyObject *obj, PyObject *type) +{ + if (descr->d_getset->get != NULL) + return descr->d_getset->get(obj, descr->d_getset->closure); + PyErr_Format(PyExc_AttributeError, + "attribute '%.300s' of '%.100s' objects is not readable", + PyString_AsString(descr->d_name), + descr->d_type->tp_name); + return NULL; +} + +SWIGRUNTIME int +SwigPyStaticVar_set (PyGetSetDescrObject *descr, PyObject *obj, PyObject *value) +{ + int res; + + if (descr->d_getset->set != NULL) + return descr->d_getset->set(obj, value, descr->d_getset->closure); + PyErr_Format(PyExc_AttributeError, + "attribute '%.300s' of '%.100s' objects is not writable", + PyString_AsString(descr->d_name), + descr->d_type->tp_name); + return -1; +} + +SWIGRUNTIME PyTypeObject SwigPyStaticVar_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, + "swig_static_var_getset_descriptor", + sizeof(PyGetSetDescrObject), + 0, + (destructor)SwigPyStaticVar_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + (reprfunc)SwigPyStaticVar_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ + 0, /* tp_doc */ + SwigPyStaticVar_traverse, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + (descrgetfunc)SwigPyStaticVar_get, /* tp_descr_get */ + (descrsetfunc)SwigPyStaticVar_set, /* tp_descr_set */ +}; + +SWIGRUNTIME int +SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value) +{ + PyObject *attribute = _PyType_Lookup(type, name); + if (attribute != NULL) { + /* Implement descriptor functionality, if any */ + descrsetfunc local_set = attribute->ob_type->tp_descr_set; + if (local_set != NULL) + return local_set(attribute, (PyObject*) type, value); + PyErr_Format(PyExc_AttributeError, + "cannot modify read-only attribute '%.50s.%.400s'", + type->tp_name, PyString_AS_STRING(name)); + } else { + PyErr_Format(PyExc_AttributeError, + "type '%.50s' has no attribute '%.400s'", + type->tp_name, PyString_AS_STRING(name)); + } + + return -1; +} + +SWIGINTERN PyGetSetDescrObject* +SwigPyStaticVar_new_getset (PyTypeObject *type, PyGetSetDef *getset) +{ + PyGetSetDescrObject *descr = (PyGetSetDescrObject*) PyType_GenericAlloc(&SwigPyStaticVar_Type, 0); + assert(descr); + Py_XINCREF(type); + descr->d_type = type; + descr->d_name = PyString_InternFromString(getset->name); + descr->d_getset = getset; + if (descr->d_name == NULL) { + Py_DECREF(descr); + descr = NULL; + } + return descr; +} diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index f873e3968..3faef3f76 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -340,12 +340,25 @@ SWIG_init(void) { #if defined(SWIGPYTHON_BUILTIN) PyTypeObject *builtin_pytype = 0; - PyObject *propargs = NULL, *propget = NULL, *propset = NULL, *propobj = NULL; +#ifdef __cplusplus std::vector builtin_bases; +#endif swig_type_info *builtin_basetype = 0; - PyObject *base_tuple = NULL; + PyObject *tuple = NULL; + PyGetSetDescrObject *static_getset = NULL; + int i; + // 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); + assert(metatype); + Py_DECREF(metatype_args); + metatype->tp_setattro = (setattrofunc) &SwigPyObjectType_setattro; + assert(PyType_Ready(metatype) >= 0); + SWIG_Python_builtin_imports(); #endif @@ -361,6 +374,6 @@ SWIG_init(void) { SWIG_InitializeModule(0); SWIG_InstallConstants(d,swig_const_table); - + %} diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 503e42711..acffffd01 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -332,6 +332,9 @@ typedef struct { swig_type_info *ty; int own; PyObject *next; +#ifdef SWIGPYTHON_BUILTIN + PyObject *dict; +#endif } SwigPyObject; SWIGRUNTIME PyObject * @@ -384,19 +387,19 @@ SwigPyObject_repr(SwigPyObject *v, PyObject *args) const char *name = SWIG_TypePrettyName(v->ty); PyObject *repr = SWIG_Python_str_FromFormat("", name, v); if (v->next) { -#ifdef METH_NOARGS +# ifdef METH_NOARGS PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next); -#else +# else PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next, args); -#endif -#if PY_VERSION_HEX >= 0x03000000 +# endif +# if PY_VERSION_HEX >= 0x03000000 PyObject *joined = PyUnicode_Concat(repr, nrep); Py_DecRef(repr); Py_DecRef(nrep); repr = joined; -#else +# else PyString_ConcatAndDel(&repr,nrep); -#endif +# endif } return repr; } @@ -468,9 +471,8 @@ SwigPyObject_Check(PyObject *op) { #ifdef SWIGPYTHON_BUILTIN PyTypeObject *target_tp = SwigPyObject_type(); PyTypeObject *obj_tp; - for (obj_tp = op->ob_type; obj_tp; obj_tp = obj_tp->tp_base) - if (obj_tp == target_tp) - return 1; + if (PyType_IsSubtype(op->ob_type, target_tp)) + return 1; return (strcmp(op->ob_type->tp_name, "SwigPyObject") == 0); #else return (Py_TYPE(op) == SwigPyObject_type()) @@ -1080,6 +1082,7 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int if (ptr) *ptr = 0; return SWIG_OK; } + if (ty && ty->clientdata && ((SwigPyClientData*) ty->clientdata)->pytype) { PyTypeObject *target_tp = ((SwigPyClientData*) ty->clientdata)->pytype; PyTypeObject *obj_tp; @@ -1096,6 +1099,9 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int } } } + + int res = SWIG_ERROR; + SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj); if (own) *own = 0; @@ -1135,9 +1141,8 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int if (flags & SWIG_POINTER_DISOWN) { sobj->own = 0; } - return SWIG_OK; + res = SWIG_OK; } else { - int res = SWIG_ERROR; if (flags & SWIG_POINTER_IMPLICIT_CONV) { SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0; if (data && !data->implicitconv) { @@ -1173,8 +1178,8 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int } } } - return res; } + return res; } /* Convert a function ptr value */ @@ -1357,6 +1362,9 @@ SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) { newobj->ty = type; newobj->own = own; newobj->next = 0; +#ifdef SWIGPYTHON_BUILTIN + newobj->dict = 0; +#endif return (PyObject*) newobj; } return SWIG_Py_Void(); @@ -1388,10 +1396,19 @@ SWIG_Python_NewBuiltinObj(PyObject *self, void *ptr, swig_type_info *type, int f assert(clientdata->pytype); int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; SwigPyObject *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; + } newobj->ptr = ptr; newobj->own = own; newobj->ty = type; newobj->next = 0; +#ifdef SWIGPYTHON_BUILTIN + newobj->dict = 0; +#endif return 0; } diff --git a/Lib/python/std_pair.i b/Lib/python/std_pair.i index 4cc8fe5c2..49f381afb 100644 --- a/Lib/python/std_pair.i +++ b/Lib/python/std_pair.i @@ -161,13 +161,28 @@ SwigPython_std_pair_setitem (PyObject *a, Py_ssize_t b, PyObject *c) } +%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("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("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("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"; + %define %swig_pair_methods(pair...) -#if defined(SWIGPYTHON_BUILTIN) -%feature("sq_length") pair "SwigPython_std_pair_len"; -%feature("tp_repr") pair "SwigPython_std_pair_repr"; -%feature("sq_item") pair "SwigPython_std_pair_getitem"; -%feature("sq_ass_item") pair "SwigPython_std_pair_setitem"; -#else +#if !defined(SWIGPYTHON_BUILTIN) %extend { %pythoncode {def __len__(self): return 2 def __repr__(self): return str((self.first, self.second)) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index a10ba2179..edfb9c56e 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -33,6 +33,7 @@ static String *global_name = 0; static int shadow = 1; static int use_kw = 0; static int director_method_index = 0; +static int builtin = 0; static File *f_begin = 0; static File *f_runtime = 0; @@ -48,6 +49,9 @@ static String *f_shadow_imports = 0; static String *f_shadow_import_stmts = 0; static String *f_shadow_stubs = 0; static Hash *builtin_getset = 0; +static Hash *class_members = 0; +static File *f_builtins = 0; +static String *builtin_tp_init = 0; static String *methods; static String *class_name; @@ -60,12 +64,6 @@ static int no_header_file = 0; static int py3 = 0; -static Hash *class_members = 0; - -static int builtin = 0; -static File *f_builtins = 0; -static String *builtin_tp_init = 0; - /* C++ Support + Shadow Classes */ static int have_constructor; @@ -172,6 +170,9 @@ static String *getSlot(Node *n, const char *key) { static String *getClosure(String *functype, String *wrapper) { static const char *functypes[] = { + "unaryfunc", "PYSWIG_UNARYFUNC_CLOSURE", + "getiterfunc", "PYSWIG_UNARYFUNC_CLOSURE", + "iternextfunc", "PYSWIG_UNARYFUNC_CLOSURE", "binaryfunc", "PYSWIG_BINARYFUNC_CLOSURE", "ternaryfunc", "PYSWIG_TERNARYFUNC_CLOSURE", "lenfunc", "PYSWIG_LENFUNC_CLOSURE", @@ -571,10 +572,11 @@ public: f_directors_h = NewString(""); f_directors = NewString(""); builtin_getset = NewHash(); + class_members = NewHash(); if (builtin) { f_builtins = NewString(""); - Printf(f_builtins, "namespace {\n\n"); + Printf(f_builtins, "#ifdef __cplusplus\nnamespace {\n#endif\n\n"); } if (directorsEnabled()) { @@ -915,7 +917,7 @@ public: Printf(f_init, "#endif\n"); Printf(f_init, "}\n"); if (builtin) - Printf(f_builtins, "} // namespace {\n\n"); + Printv(f_builtins, "#ifdef __cplusplus\n} // namespace {\n#endif\n\n", NIL); Printf(f_wrappers, "#ifdef __cplusplus\n"); Printf(f_wrappers, "}\n"); @@ -1803,7 +1805,7 @@ public: int maxargs; - char const *wrap_return = (builtin_self && constructor) ? "int " : "PyObject *"; + bool return_int = (builtin_self && constructor); String *tmp = NewString(""); String *dispatch; const char *dispatch_code = funpack ? "return %s(self, argc, argv);" : "return %s(self, args);"; @@ -1820,7 +1822,7 @@ public: String *symname = Getattr(n, "sym:name"); String *wname = Swig_name_wrapper(symname); - Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL); + Printv(f->def, linkage, return_int ? "int " : "PyObject *", wname, "(PyObject *self, PyObject *args) {", NIL); Wrapper_add_local(f, "argc", "int argc"); Printf(tmp, "PyObject *argv[%d]", maxargs + 1); @@ -1865,7 +1867,7 @@ public: Append(f->code, "fail:\n"); Printf(f->code, "SWIG_SetErrorMsg(PyExc_NotImplementedError," "\"Wrong number or type of arguments for overloaded function '%s'.\\n\"" "\n\" Possible C/C++ prototypes are:\\n\"%s);\n", symname, protoTypes); - Printf(f->code, "return (%s) 0;\n", wrap_return); + Printf(f->code, "return %s;\n", return_int ? "-1" : "0"); Delete(protoTypes); } Printv(f->code, "}\n", NIL); @@ -1958,13 +1960,6 @@ public: if (slot) closure_decl = getClosure(Getattr(n, "feature:pyslot:functype"), wrapper_name); - /* - if (builtin_setter || builtin_getter) { - Clear(linkage); - Printv(linkage, "extern ", NIL); - } - */ - if (Getattr(n, "sym:overloaded")) { overname = Getattr(n, "sym:overname"); } else { @@ -2066,6 +2061,14 @@ public: } } + if (builtin_ctor && checkAttribute(n, "access", "protected")) { + String *tmp_none_comparison = Copy(none_comparison); + Replaceall(tmp_none_comparison, "$arg", "self"); + Printf(self_parse, "if (!(%s)) {\n", tmp_none_comparison); + Printv(self_parse, " SWIG_SetErrorMsg(PyExc_RuntimeError, \"accessing abstract class or protected constructor\");\n SWIG_fail;\n}\n", NIL); + Delete(tmp_none_comparison); + } + if (builtin_self && !builtin_ctor) Printf(self_parse, "%s = self;\n", funpack ? "swig_obj[0]" : "obj0"); @@ -2175,10 +2178,14 @@ public: Printv(f->locals, " char * kwnames[] = ", kwargs, ";\n", NIL); } - if (tuple_arguments > 0 && (use_parse || allow_kwargs || !modernargs)) { - Printf(parse_args, ":%s\"", iname); - Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL); - funpack = 0; + if (use_parse || allow_kwargs || !modernargs) { + if (builtin && in_class && tuple_arguments == 0) { + Printf(parse_args, " if (args && PyTuple_Check(args) && PyTuple_GET_SIZE(args) > 0) SWIG_fail;\n"); + } else { + Printf(parse_args, ":%s\"", iname); + Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL); + funpack = 0; + } } else { Clear(parse_args); if (funpack) { @@ -2513,6 +2520,18 @@ 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)) { + Setattr(class_members, iname, n); + if (!builtin_tp_init) + builtin_tp_init = Swig_name_wrapper(iname); + } + } + /* If this is a builtin type, create a PyGetSetDef entry for this member variable. */ if (builtin_getter) { Hash *h = Getattr(builtin_getset, name); @@ -2616,10 +2635,9 @@ public: if (assignable) { Setattr(n, "wrap:name", varsetname); if (builtin && in_class) { - String *method_def = NewStringf("%s_method_def", varsetname); - Printf(f_builtins, "static PyMethodDef %s = { const_cast(\"%s\"), (PyCFunction)%s, METH_VARARGS, \"\" };\n", method_def, name, varsetname); - Setattr(n, "builtin:setter", method_def); - Delete(method_def); + String *set_wrapper = Swig_name_wrapper(setname); + Setattr(n, "builtin:setter", set_wrapper); + Delete(set_wrapper); } Printf(setf->def, "SWIGINTERN int %s(PyObject *_val) {", varsetname); if ((tm = Swig_typemap_lookup("varin", n, name, 0))) { @@ -2653,10 +2671,9 @@ public: /* Create a function for getting the value of a variable */ Setattr(n, "wrap:name", vargetname); if (builtin && in_class) { - String *method_def = NewStringf("%s_method_def", vargetname); - Printf(f_builtins, "static PyMethodDef %s = { const_cast(\"%s\"), (PyCFunction)%s, METH_NOARGS, \"\" };\n", method_def, name, vargetname); - Setattr(n, "builtin:getter", method_def); - Delete(method_def); + String *get_wrapper = Swig_name_wrapper(getname); + Setattr(n, "builtin:getter", get_wrapper); + Delete(get_wrapper); } int addfail = 0; Printf(getf->def, "SWIGINTERN PyObject *%s(void) {", vargetname); @@ -2967,7 +2984,7 @@ public: shadow = oldshadow; if (shadow) { if (builtin) { - Printf(f_shadow, tab4, "{ \"disown\", (PyCFunction) Swig::Director::pyobj_disown< %s >, METH_NOARGS, \"\" },\n", real_classname); + Printf(f_shadow, tab4 "{ \"__disown__\", (PyCFunction) Swig::Director::pyobj_disown< %s >, METH_NOARGS, \"\" },\n", real_classname); } else { String *symname = Getattr(n, "sym:name"); String *mrename = Swig_name_disown(NSPACE_TODO, symname); //Getattr(n, "name")); @@ -3046,7 +3063,8 @@ public: void builtin_pre_decl(Node *n, Node *) { String *name = Getattr(n, "name"); String *rname = SwigType_namestr(name); - Printf(f_init, tab4 "builtin_pytype = &PySwigBuiltin< %s >::pytype;\n", rname); + Printf(f_init, tab4 "builtin_pytype = &SwigPyBuiltin< %s >::pytype;\n", rname); + Printf(f_init, tab4 "builtin_pytype->ob_type = metatype;\n"); Printf(f_init, tab4 "builtin_pytype->tp_new = PyType_GenericNew;\n"); List *baselist = Getattr(n, "bases"); if (baselist) { @@ -3068,66 +3086,75 @@ public: Printv(f_init, " builtin_bases.push_back(SwigPyObject_type());\n", NIL); Printv(f_init, " builtin_pytype->tp_base = builtin_bases[0];\n", NIL); Printv(f_init, " Py_INCREF((PyObject*) builtin_bases[0]);\n", NIL); - Printv(f_init, " base_tuple = PyTuple_New(builtin_bases.size());\n", NIL); + Printv(f_init, " tuple = PyTuple_New(builtin_bases.size());\n", NIL); Printv(f_init, " for (i = 0; i < builtin_bases.size(); ++i) {\n", NIL); - Printv(f_init, " PyTuple_SET_ITEM(base_tuple, i, (PyObject*) builtin_bases[i]);\n", NIL); + Printv(f_init, " PyTuple_SET_ITEM(tuple, i, (PyObject*) builtin_bases[i]);\n", NIL); Printv(f_init, " Py_INCREF((PyObject*) builtin_bases[i]);\n", NIL); Printv(f_init, " }\n", NIL); Printv(f_init, " builtin_bases.clear();\n", NIL); - /* - if (base_node) { - String *base_name = Copy(Getattr(base_node, "name")); - SwigType_add_pointer(base_name); - String *base_mname = SwigType_manglestr(base_name); - Printf(f_init, tab4 "builtin_basetype = SWIG_MangledTypeQuery(\"%s\");\n", base_mname); - Printf(f_init, tab4 "if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) {\n"); - Printf(f_init, tab8 "builtin_pytype->tp_base = ((SwigPyClientData*) builtin_basetype->clientdata)->pytype;\n"); - Printf(f_init, tab4 "}\n"); - Delete(base_mname); - Delete(base_name); - } else { - Printv(f_init, tab4, "builtin_pytype->tp_base = SwigPyObject_type();\n", NIL); - } - */ Printf(f_init, tab4 "builtin_pytype->tp_dict = d = PyDict_New();\n"); Delete(rname); } + virtual bool has_callable_dtor (Node *n, bool protected_ok = false) { + if (GetFlag(n, "private_dtor")) + return false; + if (!protected_ok && GetFlag(n, "protected_dtor")) + return false; + List *baselist = Getattr(n, "bases"); + if (!baselist || Len(baselist) == 0) + return true; + for (Iterator b = First(baselist); b.item; b = Next(b)) + if (!has_callable_dtor(b.item, true)) + return false; + return true; + } + void builtin_post_decl(File *f, Node *n) { String *name = Getattr(n, "name"); String *pname = Copy(name); SwigType_add_pointer(pname); String *symname = Getattr(n, "sym:name"); String *rname = SwigType_namestr(name); - String *mname = SwigType_manglestr(pname); String *templ = NewString(""); - Printf(templ, "PySwigBuiltin< %s >", rname); - char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : "0"; + Printf(templ, "SwigPyBuiltin< %s >", rname); + char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : Swig_directorclass(n) ? "0" : "py_builtin_bad_init"; - // Check for non-public destructor, in which case tp_dealloc should be "0" - // Any class that doesn't explicitly have a private/protected destructor - // has an implicit public destructor. + // 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 = NewString(""); - if (GetFlag(n, "private_dtor")) - Printv(tp_dealloc, "0", NIL); - else + if (has_callable_dtor(n)) Printf(tp_dealloc, "py_builtin_dealloc< %s >", rname); + else + Printv(tp_dealloc, "py_builtin_bad_dealloc", NIL); - Printf(f, "template <> PyGetSetDef PySwigBuiltin< %s >::getset[] = {\n", rname); + String *getset_def = NewString(""); + Printf(getset_def, "template <> PyGetSetDef SwigPyBuiltin< %s >::getset[] = {\n", rname); for (DohIterator member_iter = First(builtin_getset); member_iter.item; member_iter = Next(member_iter)) { - String *mname = member_iter.key; + String *memname = member_iter.key; Hash *mgetset = member_iter.item; String *getter = Getattr(mgetset, "getter"); String *setter = Getattr(mgetset, "setter"); - Printf(f, tab4 "{ const_cast(\"%s\"), (getter) %s, (setter) %s, const_cast(\"%s.%s\"), (void*) %s },\n", - mname, getter ? getter : "0", setter ? "pyswig_setter_closure" : "0", name, mname, setter ? setter : "0"); + const char *getter_closure = getter ? "pyswig_getter_closure" : "0"; + const char *setter_closure = getter ? "pyswig_setter_closure" : "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 = NewStringf("{ const_cast(\"%s\"), (getter) %s, (setter) %s, const_cast(\"%s.%s\"), (void*) &%s }\n", memname, getter_closure, setter_closure, name, memname, gspair); + if (GetFlag(mgetset, "static")) { + Printf(f, "static PyGetSetDef %s_def = %s;\n", gspair, entry); + Printf(f_init, "static_getset = SwigPyStaticVar_new_getset(metatype, &%s_def);\n", gspair); + Printf(f_init, "PyDict_SetItemString(d, static_getset->d_getset->name, (PyObject*) static_getset);\n", memname); Printf(f_init, "Py_DECREF(static_getset);\n"); + } else { + Printf(getset_def, " %s,\n", entry); + } + Delete(gspair); + Delete(entry); } - Printv(f, " {NULL} // Sentinel\n", NIL); - Printv(f, "};\n\n", NIL); - Clear(builtin_getset); + Printv(f, getset_def, " {NULL} // Sentinel\n", "};\n\n", NIL); // Number methods - Printf(f, "template <> PyNumberMethods PySwigBuiltin< %s >::number_methods = {\n", rname); + Printf(f, "template <> PyNumberMethods SwigPyBuiltin< %s >::number_methods = {\n", rname); 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")); @@ -3170,7 +3197,7 @@ public: Printf(f, "};\n\n"); // Sequence methods - Printf(f, "template <> PySequenceMethods PySwigBuiltin< %s >::sequence_methods = {\n", rname); + Printf(f, "template <> PySequenceMethods SwigPyBuiltin< %s >::sequence_methods = {\n", rname); 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")); @@ -3184,7 +3211,7 @@ public: Printf(f, "};\n\n"); // Mapping methods - Printf(f, "template <> PyMappingMethods PySwigBuiltin< %s >::mapping_methods = {\n", rname); + Printf(f, "template <> PyMappingMethods SwigPyBuiltin< %s >::mapping_methods = {\n", rname); 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")); @@ -3218,7 +3245,7 @@ public: // Type object String *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES"); // TODO: Add more flags based on slots - Printf(f, "template <> PyTypeObject PySwigBuiltin< %s >::pytype = {\n", rname); + Printf(f, "template <> PyTypeObject SwigPyBuiltin< %s >::pytype = {\n", rname); Printf(f, " PyObject_HEAD_INIT(NULL)\n"); Printf(f, " 0, /*ob_size*/\n"); Printf(f, " \"%s\", /*tp_name*/\n", symname); @@ -3254,8 +3281,8 @@ public: 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")); - Printf(f, " %s, /* tp_dictoffset */\n", getSlot(n, "feature:tp_dictoffset")); - Printf(f, " (initproc)%s, /* tp_init */\n", tp_init); + 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")); @@ -3277,7 +3304,6 @@ public: Delete(clientdata); Delete(templ); - Delete(mname); Delete(rname); Delete(pname); Delete(tp_dealloc); @@ -3350,14 +3376,14 @@ public: } if (builtin) { + Hash *base_richcompare = NULL; Hash *richcompare = NULL; - if (base_node) { - Hash *base_richcompare = Getattr(base_node, "richcompare"); - assert(base_richcompare); + if (base_node) + base_richcompare = Getattr(base_node, "richcompare"); + if (base_richcompare) richcompare = Copy(base_richcompare); - } else { + else richcompare = NewHash(); - } Setattr(n, "richcompare", richcompare); } @@ -3424,10 +3450,8 @@ public: /* Emit all of the members */ in_class = 1; - if (builtin) { - class_members = NewHash(); + if (builtin) builtin_pre_decl(n, base_node); - } /* Overide the shadow file so we can capture its methods */ f_shadow = NewString(""); @@ -3447,6 +3471,9 @@ public: Printv(none_comparison, "$arg != Py_None", NIL); } + if (builtin) + Setattr(n, "feature:unref", "1"); + Language::classHandler(n); in_class = 0; @@ -3519,7 +3546,7 @@ public: if (builtin) { builtin_post_decl(f_builtins, n); String *rname = SwigType_namestr(real_classname); - Printf(f_builtins, "template <> PyMethodDef PySwigBuiltin< %s >::methods[] = {\n", rname); + Printf(f_builtins, "template <> PyMethodDef SwigPyBuiltin< %s >::methods[] = {\n", rname); Delete(rname); } @@ -3557,19 +3584,18 @@ public: } Printf(f_shadow_file, "%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name); Printf(f_shadow_file, "%s_swigregister(%s)\n", class_name, class_name); - - shadow_indent = 0; - Printf(f_shadow_file, "%s\n", f_shadow_stubs); } + shadow_indent = 0; + Printf(f_shadow_file, "%s\n", f_shadow_stubs); Clear(f_shadow_stubs); } if (builtin) { Dump(f_shadow, f_builtins); Printf(f_builtins, " {NULL} // Sentinel\n};\n\n"); - Delete(class_members); - class_members = 0; + Clear(class_members); + Clear(builtin_getset); } classic = oldclassic; @@ -3617,27 +3643,28 @@ public: Language::memberfunctionHandler(n); shadow = oldshadow; - if (!Getattr(n, "sym:nextSibling")) { - if (builtin && in_class) { + if (builtin && in_class) { String *name = Getattr(n, "name"); // Can't use checkAttribute(n, "access", "public") because // "access" attr isn't set on %extend methods if (!checkAttribute(n, "access", "private") && - !checkAttribute(n, "access", "protected") && + //!checkAttribute(n, "access", "protected") && strncmp(Char(name), "operator ", 9) && - !Getattr(class_members, name)) { - String *fullname = Swig_name_member(NULL, class_name, symname); - String *wname = Swig_name_wrapper(fullname); - Setattr(class_members, name, name); - int allow_kwargs = check_kwargs(n); - Printf(f_shadow, " { \"%s\", (PyCFunction) %s, METH_VARARGS%s, \"\" },\n", - name, wname, allow_kwargs ? "|METH_KEYWORDS" : ""); - Delete(name); - Delete(fullname); - Delete(wname); + !Getattr(class_members, symname)) { + String *fullname = Swig_name_member(NULL, class_name, symname); + String *wname = Swig_name_wrapper(fullname); + Setattr(class_members, symname, n); + int allow_kwargs = check_kwargs(n); + Printf(f_shadow, " { \"%s\", (PyCFunction) %s, METH_VARARGS%s, \"\" },\n", + symname, wname, allow_kwargs ? "|METH_KEYWORDS" : ""); + Delete(fullname); + Delete(wname); } - } else if (shadow) { + } + + if (!Getattr(n, "sym:nextSibling")) { + if (shadow && !builtin) { int fproxy = fastproxy; if (Strcmp(symname, "__repr__") == 0) { have_repr = 1; @@ -3712,14 +3739,12 @@ public: } if (builtin && in_class) { - String *name = Getattr(n, "name"); - if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) { - String *fullname = Swig_name_member(NULL, class_name, name); + if (checkAttribute(n, "access", "public") && !Getattr(class_members, symname)) { + String *fullname = Swig_name_member(NULL, class_name, symname); String *wname = Swig_name_wrapper(fullname); - Setattr(class_members, name, name); + Setattr(class_members, symname, n); String *pyflags = NewString("METH_VARARGS|METH_STATIC"); - Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", Char(name), wname, Char(pyflags)); - Delete(name); + Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", symname, wname, pyflags); Delete(fullname); Delete(wname); Delete(pyflags); @@ -3803,108 +3828,100 @@ public: Swig_restore(n); if (!Getattr(n, "sym:nextSibling")) { - if (builtin && in_class) { - String *name = NewString("new"); - // Can't use checkAttribute(n, "access", "public") because - // "access" attr isn't set on %extend methods - if ((use_director || - (!checkAttribute(n, "access", "protected") && - !checkAttribute(n, "access", "private"))) && - !Getattr(class_members, name)) { - Setattr(class_members, name, name); - String *fullname = Swig_name_member(NULL, name, class_name); - if (!builtin_tp_init) - builtin_tp_init = Swig_name_wrapper(fullname); - Delete(fullname); - } - Delete(name); - } else if (shadow) { - int allow_kwargs = (check_kwargs(n) && (!Getattr(n, "sym:overloaded"))) ? 1 : 0; - int handled_as_init = 0; - if (!have_constructor) { - String *nname = Getattr(n, "sym:name"); - String *sname = Getattr(getCurrentClass(), "sym:name"); - String *cname = Swig_name_construct(NSPACE_TODO, sname); - handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0); - Delete(cname); - } - - if (!have_constructor && handled_as_init) { - if (Getattr(n, "feature:shadow")) { - String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); - String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); - Replaceall(pycode, "$action", pyaction); - Delete(pyaction); - Printv(f_shadow, pycode, "\n", NIL); - Delete(pycode); - } else { - String *pass_self = NewString(""); - Node *parent = Swig_methodclass(n); - String *classname = Swig_class_name(parent); - String *rclassname = Swig_class_name(getCurrentClass()); - assert(rclassname); - - - String *parms = make_pyParmList(n, true, false, allow_kwargs); - /* Pass 'self' only if using director */ - String *callParms = make_pyParmList(n, false, true, allow_kwargs); - - if (use_director) { - Insert(callParms, 0, "_self, "); - Printv(pass_self, tab8, NIL); - Printf(pass_self, "if self.__class__ == %s:\n", classname); - //Printv(pass_self, tab8, tab4, "args = (None,) + args\n", tab8, "else:\n", tab8, tab4, "args = (self,) + args\n", NIL); - Printv(pass_self, tab8, tab4, "_self = None\n", tab8, "else:\n", tab8, tab4, "_self = self\n", NIL); + if (shadow) { + int allow_kwargs = (check_kwargs(n) && (!Getattr(n, "sym:overloaded"))) ? 1 : 0; + int handled_as_init = 0; + if (!have_constructor) { + String *nname = Getattr(n, "sym:name"); + String *sname = Getattr(getCurrentClass(), "sym:name"); + String *cname = Swig_name_construct(NSPACE_TODO, sname); + handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0); + Delete(cname); } + + if (!have_constructor && handled_as_init) { + if (!builtin) { + if (Getattr(n, "feature:shadow")) { + String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); + String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); + Replaceall(pycode, "$action", pyaction); + Delete(pyaction); + Printv(f_shadow, pycode, "\n", NIL); + Delete(pycode); + } else { + String *pass_self = NewString(""); + Node *parent = Swig_methodclass(n); + String *classname = Swig_class_name(parent); + String *rclassname = Swig_class_name(getCurrentClass()); + assert(rclassname); + - Printv(f_shadow, tab4, "def __init__(", parms, ")", returnTypeAnnotation(n), ": \n", NIL); - if (have_docstring(n)) - Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL); - if (have_pythonprepend(n)) - Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); - Printv(f_shadow, pass_self, NIL); - if (fastinit) { - Printv(f_shadow, tab8, module, ".", class_name, "_swiginit(self,", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), ")\n", NIL); + String *parms = make_pyParmList(n, true, false, allow_kwargs); + /* Pass 'self' only if using director */ + String *callParms = make_pyParmList(n, false, true, allow_kwargs); + + if (use_director) { + Insert(callParms, 0, "_self, "); + Printv(pass_self, tab8, NIL); + Printf(pass_self, "if self.__class__ == %s:\n", classname); + //Printv(pass_self, tab8, tab4, "args = (None,) + args\n", tab8, "else:\n", tab8, tab4, "args = (self,) + args\n", NIL); + Printv(pass_self, tab8, tab4, "_self = None\n", tab8, "else:\n", tab8, tab4, "_self = self\n", NIL); + } + + Printv(f_shadow, tab4, "def __init__(", parms, ")", returnTypeAnnotation(n), ": \n", NIL); + if (have_docstring(n)) + Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL); + if (have_pythonprepend(n)) + Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); + Printv(f_shadow, pass_self, NIL); + if (fastinit) { + Printv(f_shadow, tab8, module, ".", class_name, "_swiginit(self,", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), ")\n", NIL); + } else { + Printv(f_shadow, + tab8, "this = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", + tab8, "try: self.this.append(this)\n", tab8, "except: self.this = this\n", NIL); + } + if (have_pythonappend(n)) + Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n\n", NIL); + Delete(pass_self); + } + have_constructor = 1; + } } else { - Printv(f_shadow, - tab8, "this = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", - tab8, "try: self.this.append(this)\n", tab8, "except: self.this = this\n", NIL); - } - if (have_pythonappend(n)) - Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n\n", NIL); - Delete(pass_self); - } - have_constructor = 1; - } else { - /* Hmmm. We seem to be creating a different constructor. We're just going to create a - function for it. */ + /* Hmmm. We seem to be creating a different constructor. We're just going to create a + function for it. */ + if (Getattr(n, "feature:shadow")) { + String *pycode = pythoncode(Getattr(n, "feature:shadow"), ""); + String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); + Replaceall(pycode, "$action", pyaction); + Delete(pyaction); + Printv(f_shadow_stubs, pycode, "\n", NIL); + Delete(pycode); + } else { + String *parms = make_pyParmList(n, false, false, allow_kwargs); + String *callParms = make_pyParmList(n, false, true, allow_kwargs); - if (Getattr(n, "feature:shadow")) { - String *pycode = pythoncode(Getattr(n, "feature:shadow"), ""); - String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); - Replaceall(pycode, "$action", pyaction); - Delete(pyaction); - Printv(f_shadow_stubs, pycode, "\n", NIL); - Delete(pycode); - } else { - String *parms = make_pyParmList(n, false, false, allow_kwargs); - String *callParms = make_pyParmList(n, false, true, allow_kwargs); - - Printv(f_shadow_stubs, "\ndef ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); - if (have_docstring(n)) - Printv(f_shadow_stubs, tab4, docstring(n, AUTODOC_CTOR, tab4), "\n", NIL); - if (have_pythonprepend(n)) - Printv(f_shadow_stubs, pythoncode(pythonprepend(n), tab4), "\n", NIL); - Printv(f_shadow_stubs, tab4, "val = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", NIL); + Printv(f_shadow_stubs, "\ndef ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); + if (have_docstring(n)) + Printv(f_shadow_stubs, tab4, docstring(n, AUTODOC_CTOR, tab4), "\n", NIL); + if (have_pythonprepend(n)) + Printv(f_shadow_stubs, pythoncode(pythonprepend(n), tab4), "\n", NIL); + String *subfunc = NULL; + if (builtin) + subfunc = Copy(Getattr(getCurrentClass(), "sym:name")); + else + subfunc = Swig_name_construct(NSPACE_TODO, symname); + Printv(f_shadow_stubs, tab4, "val = ", funcCall(subfunc, callParms), "\n", NIL); #ifdef USE_THISOWN - Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL); + Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL); #endif - if (have_pythonappend(n)) - Printv(f_shadow_stubs, pythoncode(pythonappend(n), tab4), "\n", NIL); - Printv(f_shadow_stubs, tab4, "return val\n", NIL); - } + if (have_pythonappend(n)) + Printv(f_shadow_stubs, pythoncode(pythonappend(n), tab4), "\n", NIL); + Printv(f_shadow_stubs, tab4, "return val\n", NIL); + Delete(subfunc); + } + } } - } } return SWIG_OK; } @@ -3915,8 +3932,10 @@ public: virtual int destructorHandler(Node *n) { if (builtin && in_class) { - if (checkAttribute(n, "access", "private") || checkAttribute(n, "access", "protected")) - SetFlag(Swig_methodclass(n), "private_dtor"); + if (checkAttribute(n, "access", "private")) + SetFlag(Swig_methodclass(n), "private_dtor"); + if (checkAttribute(n, "access", "protected")) + SetFlag(Swig_methodclass(n), "protected_dtor"); return SWIG_OK; } @@ -4019,7 +4038,7 @@ public: String *symname = Getattr(n, "sym:name"); if (shadow) { - if (GetFlag(n, "hasconsttype")) { + if (!builtin && GetFlag(n, "hasconsttype")) { String *mname = Swig_name_member(NSPACE_TODO, class_name, symname); Printf(f_shadow_stubs, "%s.%s = %s.%s.%s\n", class_name, symname, module, global_name, mname); Delete(mname); @@ -4068,19 +4087,21 @@ public: } String *getter = Getattr(n, "builtin:getter"); String *setter = Getattr(n, "builtin:setter"); - if (getter) { - Printf(f_init, " propargs = PyTuple_New(%d);\n", setter ? 2 : 1); - Printf(f_init, " propget = PyCFunction_New(&%s, NULL);\n", getter); - Printf(f_init, " PyTuple_SET_ITEM(propargs, 0, propget);\n"); - if (setter) { - Printf(f_init, " propset = PyCFunction_New(&%s, NULL);\n", setter); - Printf(f_init, " PyTuple_SET_ITEM(propargs, 1, propset);\n"); + Hash *h = NULL; + if (getter || setter) { + h = Getattr(builtin_getset, symname); + if (!h) { + h = NewHash(); + Setattr(h, "static", "1"); + Setattr(builtin_getset, symname, h); } - Printf(f_init, " propobj = PyType_Type.tp_call((PyObject*) &PyProperty_Type, propargs, NULL);\n"); - Printf(f_init, " Py_DECREF(propargs);\n"); - Printf(f_init, " PyDict_SetItemString(d, \"%s\", propobj);\n", symname); - Printf(f_init, " Py_DECREF(propobj);\n"); } + if (getter) + Setattr(h, "getter", getter); + if (setter) + Setattr(h, "setter", setter); + if (h) + Delete(h); Delete(mname); Delete(getname); Delete(wrapgetname); From 8ac54d1d5e579ea54f11c7ee1d2bbf472337a345 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Thu, 6 Jan 2011 00:09:25 +0000 Subject: [PATCH 09/56] Director issues should be mostly clean now. Refactored some type initialization out of SWIG_init. Use __all__ attribute of module to define public interface. This is necessary to make available symbols starting with '_'. Now dying on li_boost_shared_ptr. Looks like it's gonna be ugly. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12373 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/boost_shared_ptr.i | 34 ++++++++++++++++++ Lib/python/builtin.swg | 22 ++++++++++++ Lib/python/director.swg | 2 +- Lib/python/pyinit.swg | 24 +++++++++++-- Lib/python/pyrun.swg | 21 +++++++++++ Lib/python/pytypemaps.swg | 10 +++++- Source/Modules/python.cxx | 67 ++++++++++++++++++++++------------- 7 files changed, 152 insertions(+), 28 deletions(-) diff --git a/Lib/python/boost_shared_ptr.i b/Lib/python/boost_shared_ptr.i index e8c536026..85843b20a 100644 --- a/Lib/python/boost_shared_ptr.i +++ b/Lib/python/boost_shared_ptr.i @@ -39,6 +39,11 @@ %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } +%typemap(builtin_init, noblock=1) CONST TYPE { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); + %set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} + %typemap(varin) CONST TYPE { void *argp = 0; int newmem = 0; @@ -79,6 +84,10 @@ 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)); } +%typemap(builtin_init, fragment="SWIG_null_deleter") 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)); +} %typemap(varin) CONST TYPE * { void *argp = 0; @@ -123,6 +132,10 @@ 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)); } +%typemap(builtin_init, fragment="SWIG_null_deleter") 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_Python_NewBuiltinObj(self, %as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} %typemap(varin) CONST TYPE & { void *argp = 0; @@ -167,6 +180,10 @@ 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)); } +%typemap(builtin_init, fragment="SWIG_null_deleter") 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_Python_NewBuiltinObj(self, %as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} %typemap(varin) TYPE *CONST& %{ #error "varin typemap not implemented" @@ -189,6 +206,10 @@ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } +%typemap(builtin_init) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; + %set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} %typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { int newmem = 0; @@ -224,6 +245,10 @@ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } +%typemap(builtin_init) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; + %set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} %typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{ #error "varin typemap not implemented" @@ -252,6 +277,11 @@ %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); if ($owner) delete $1; } +%typemap(builtin_init) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 && *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; + %set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); + if ($owner) delete $1; +} %typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{ #error "varin typemap not implemented" @@ -276,6 +306,10 @@ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 && **$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0; %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } +%typemap(builtin_init) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 && **$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0; + %set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); +} %typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{ #error "varin typemap not implemented" diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index de72a558e..f0736c452 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -369,3 +369,25 @@ 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()); + 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) { + PyTuple_SET_ITEM(tuple, i, (PyObject*) bases[i]); + Py_INCREF((PyObject*) bases[i]); + } + type->tp_bases = tuple; +} + +#endif diff --git a/Lib/python/director.swg b/Lib/python/director.swg index 00ab9b03f..95dc991cd 100644 --- a/Lib/python/director.swg +++ b/Lib/python/director.swg @@ -467,7 +467,7 @@ namespace Swig { sobj->own = 0; Director *d = SWIG_DIRECTOR_CAST(reinterpret_cast<_Tp*>(sobj->ptr)); if (d) d->swig_disown(); - return SWIG_Py_Void(); + return PyWeakref_NewProxy(pyobj, NULL); } }; diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index 3faef3f76..dd0139b69 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -350,7 +350,6 @@ SWIG_init(void) { int i; // 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); @@ -359,6 +358,16 @@ SWIG_init(void) { metatype->tp_setattro = (setattrofunc) &SwigPyObjectType_setattro; assert(PyType_Ready(metatype) >= 0); + // 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 + }; + PyObject *thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def); + SWIG_Python_builtin_imports(); #endif @@ -371,9 +380,20 @@ SWIG_init(void) { m = Py_InitModule((char *) SWIG_name, SwigMethods); #endif md = d = PyModule_GetDict(m); - + SWIG_InitializeModule(0); SWIG_InstallConstants(d,swig_const_table); +#if defined(SWIGPYTHON_BUILTIN) + PyObject *public_interface = PyList_New(0); + PyObject *public_symbol = 0; + 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); + for (i = 0; swig_const_table[i].name != 0; ++i) + pyswig_add_public_symbol(public_interface, swig_const_table[i].name); +#endif + %} diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index acffffd01..935103334 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -71,12 +71,33 @@ SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) { /* Set a constant value */ +#if defined(SWIGPYTHON_BUILTIN) + +SWIGINTERN void +pyswig_add_public_symbol (PyObject *seq, const char *key) { + PyObject *s = PyString_InternFromString(key); + PyList_Append(seq, s); + Py_DECREF(s); +} + +SWIGINTERN void +SWIG_Python_SetConstant(PyObject *d, PyObject *public_interface, const char *name, PyObject *obj) { + PyDict_SetItemString(d, (char*) name, obj); + Py_DECREF(obj); + if (public_interface) + pyswig_add_public_symbol(public_interface, name); +} + +#else + SWIGINTERN void SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) { PyDict_SetItemString(d, (char*) name, obj); Py_DECREF(obj); } +#endif + /* Append a value to the result obj */ SWIGINTERN PyObject* diff --git a/Lib/python/pytypemaps.swg b/Lib/python/pytypemaps.swg index 0cc1e976c..3496324aa 100644 --- a/Lib/python/pytypemaps.swg +++ b/Lib/python/pytypemaps.swg @@ -51,7 +51,11 @@ #define SWIG_AppendOutput(result, obj) SWIG_Python_AppendOutput(result, obj) /* set constant */ -#define SWIG_SetConstant(name, obj) SWIG_Python_SetConstant(d, name,obj) +#if defined(SWIGPYTHON_BUILTIN) +#define SWIG_SetConstant(name, obj) SWIG_Python_SetConstant(d, d == md ? public_interface : NULL, name,obj) +#else +#define SWIG_SetConstant(name, obj) SWIG_Python_SetConstant(d, name,obj) +#endif /* raise */ #define SWIG_Raise(obj, type, desc) SWIG_Python_Raise(obj, type, desc) @@ -84,6 +88,10 @@ $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) { PyObject *robj = PyObject_CallMethod($result, (char *)"__deref__", NULL); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index edfb9c56e..7ea66f6f4 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -469,8 +469,10 @@ public: py3 = 1; Swig_mark_arg(i); } else if (strcmp(argv[i], "-builtin") == 0) { - builtin = 1; - Preprocessor_define("SWIGPYTHON_BUILTIN", 0); + if (CPlusPlus) { + builtin = 1; + Preprocessor_define("SWIGPYTHON_BUILTIN", 0); + } Swig_mark_arg(i); } @@ -2616,6 +2618,8 @@ 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); have_globals = 1; if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) { Printf(f_shadow_stubs, "%s = %s.%s\n", global_name, module, global_name); @@ -2698,9 +2702,11 @@ public: /* Now add this to the variable linking mechanism */ 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); + 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); + } Delete(vargetname); Delete(varsetname); Delete(getname); @@ -2984,7 +2990,9 @@ public: shadow = oldshadow; if (shadow) { if (builtin) { - Printf(f_shadow, tab4 "{ \"__disown__\", (PyCFunction) Swig::Director::pyobj_disown< %s >, METH_NOARGS, \"\" },\n", real_classname); + String *rname = SwigType_namestr(real_classname); + Printf(f_shadow, tab4 "{ \"__disown__\", (PyCFunction) Swig::Director::pyobj_disown< %s >, METH_NOARGS, \"\" },\n", rname); + Delete(rname); } else { String *symname = Getattr(n, "sym:name"); String *mrename = Swig_name_disown(NSPACE_TODO, symname); //Getattr(n, "name")); @@ -3060,9 +3068,19 @@ public: * classHandler() * ------------------------------------------------------------ */ + String* add_explicit_scope (String *s) { + if (!Strstr(s, "::")) { + String *ss = NewStringf("::%s", s); + Delete(s); + s = ss; + } + return s; + } + void builtin_pre_decl(Node *n, Node *) { String *name = Getattr(n, "name"); - String *rname = SwigType_namestr(name); + String *rname = add_explicit_scope(SwigType_namestr(name)); + Printf(f_init, "\n// type '%s'\n", rname); Printf(f_init, tab4 "builtin_pytype = &SwigPyBuiltin< %s >::pytype;\n", rname); Printf(f_init, tab4 "builtin_pytype->ob_type = metatype;\n"); Printf(f_init, tab4 "builtin_pytype->tp_new = PyType_GenericNew;\n"); @@ -3076,23 +3094,16 @@ public: 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, " 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); Delete(base_name); Delete(base_mname); } } - Printv(f_init, " if (!builtin_bases.size())\n", NIL); - Printv(f_init, " builtin_bases.push_back(SwigPyObject_type());\n", NIL); - Printv(f_init, " builtin_pytype->tp_base = builtin_bases[0];\n", NIL); - Printv(f_init, " Py_INCREF((PyObject*) builtin_bases[0]);\n", NIL); - Printv(f_init, " tuple = PyTuple_New(builtin_bases.size());\n", NIL); - Printv(f_init, " for (i = 0; i < builtin_bases.size(); ++i) {\n", NIL); - Printv(f_init, " PyTuple_SET_ITEM(tuple, i, (PyObject*) builtin_bases[i]);\n", NIL); - Printv(f_init, " Py_INCREF((PyObject*) builtin_bases[i]);\n", NIL); - Printv(f_init, " }\n", NIL); + Printv(f_init, " pyswig_builtin_init_bases(builtin_pytype, builtin_bases);\n", NIL); Printv(f_init, " builtin_bases.clear();\n", NIL); - Printf(f_init, tab4 "builtin_pytype->tp_dict = d = PyDict_New();\n"); + Printf(f_init, " builtin_pytype->tp_dict = d = PyDict_New();\n"); Delete(rname); } @@ -3115,7 +3126,7 @@ public: String *pname = Copy(name); SwigType_add_pointer(pname); String *symname = Getattr(n, "sym:name"); - String *rname = SwigType_namestr(name); + String *rname = add_explicit_scope(SwigType_namestr(name)); String *templ = NewString(""); Printf(templ, "SwigPyBuiltin< %s >", rname); char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : Swig_directorclass(n) ? "0" : "py_builtin_bad_init"; @@ -3131,6 +3142,11 @@ public: String *getset_def = NewString(""); Printf(getset_def, "template <> PyGetSetDef SwigPyBuiltin< %s >::getset[] = {\n", rname); + + // All objects have a 'thisown' attribute + Printv(f_init, "PyDict_SetItemString(d, \"thisown\", thisown_descr);\n", NIL); + + // Now, the rest of the attributes for (DohIterator member_iter = First(builtin_getset); member_iter.item; member_iter = Next(member_iter)) { String *memname = member_iter.key; Hash *mgetset = member_iter.item; @@ -3294,13 +3310,14 @@ public: Printf(f, "template <> SwigPyClientData %s::clientdata = {0, 0, 0, 0, 0, 0, &%s::pytype};\n\n", templ, templ); - Printv(f_init, " d = md;\n", NIL); Printv(f_init, " if (PyType_Ready(builtin_pytype) < 0) {\n", NIL); - Printf(f_init, " fprintf(stderr, \"Couldn't create type %s\");\n", symname); - Printv(f_init, " return;\n", NIL); + Printf(f_init, " PyErr_Format(PyExc_TypeError, \"Couldn't create type '.300%s'\");\n", symname); + Printv(f_init, " return;\n", NIL); 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); + Printv(f_init, " d = md;\n", NIL); Delete(clientdata); Delete(templ); @@ -3396,7 +3413,9 @@ public: Printv(base_class, abcs, NIL); } - if (!builtin) { + if (builtin) { + + } else { Printv(f_shadow, "class ", class_name, NIL); if (Len(base_class)) { @@ -3545,7 +3564,7 @@ public: if (builtin) { builtin_post_decl(f_builtins, n); - String *rname = SwigType_namestr(real_classname); + String *rname = add_explicit_scope(SwigType_namestr(real_classname)); Printf(f_builtins, "template <> PyMethodDef SwigPyBuiltin< %s >::methods[] = {\n", rname); Delete(rname); } From d4b8048e9ac7556dd78142afb8b508ca3585ca4f Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Wed, 12 Jan 2011 00:43:01 +0000 Subject: [PATCH 10/56] Stopped using template class SwigPyBuiltin, because it caused problems when two typedef-equivalent types are wrapped as separate classes. Now failing on refcount.cpptest. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12392 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/boost_shared_ptr.i | 338 ++++++++++++++++++++++++++--- Lib/python/builtin.swg | 33 ++- Lib/python/carrays.i | 44 ++++ Lib/python/pycontainer.swg | 2 +- Lib/python/pyopers.swg | 2 +- Lib/python/pyrun.swg | 120 ++++++----- Source/Modules/python.cxx | 388 +++++++++++++++++++--------------- 7 files changed, 642 insertions(+), 285 deletions(-) diff --git a/Lib/python/boost_shared_ptr.i b/Lib/python/boost_shared_ptr.i index 85843b20a..c527dd6b5 100644 --- a/Lib/python/boost_shared_ptr.i +++ b/Lib/python/boost_shared_ptr.i @@ -39,11 +39,6 @@ %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } -%typemap(builtin_init, noblock=1) CONST TYPE { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); - %set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); -} - %typemap(varin) CONST TYPE { void *argp = 0; int newmem = 0; @@ -80,14 +75,11 @@ $1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype); } } + %typemap(out, fragment="SWIG_null_deleter") 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)); } -%typemap(builtin_init, fragment="SWIG_null_deleter") 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)); -} %typemap(varin) CONST TYPE * { void *argp = 0; @@ -132,10 +124,6 @@ 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)); } -%typemap(builtin_init, fragment="SWIG_null_deleter") 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_Python_NewBuiltinObj(self, %as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); -} %typemap(varin) CONST TYPE & { void *argp = 0; @@ -180,10 +168,6 @@ 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)); } -%typemap(builtin_init, fragment="SWIG_null_deleter") 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_Python_NewBuiltinObj(self, %as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); -} %typemap(varin) TYPE *CONST& %{ #error "varin typemap not implemented" @@ -206,10 +190,6 @@ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } -%typemap(builtin_init) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; - %set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); -} %typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { int newmem = 0; @@ -245,10 +225,6 @@ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } -%typemap(builtin_init) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; - %set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); -} %typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{ #error "varin typemap not implemented" @@ -277,11 +253,6 @@ %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); if ($owner) delete $1; } -%typemap(builtin_init) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 && *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; - %set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); - if ($owner) delete $1; -} %typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{ #error "varin typemap not implemented" @@ -306,10 +277,6 @@ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 && **$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0; %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } -%typemap(builtin_init) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 && **$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0; - %set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); -} %typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{ #error "varin typemap not implemented" @@ -345,5 +312,308 @@ %template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; + + +// Separate out the code for builtin types, since it's pretty extensive. +// I feel compelled to point out that the functionality provided by +// smart pointers is utterly redundant when using builtin types. + +#if defined(SWIGPYTHON_BUILTIN) + +/* + +// plain value +%typemap(in) CONST TYPE (void *argp, int res = 0) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (!argp) { + %argument_nullref("$type", $symname, $argnum); + } else { + $1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get()); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + } +} +%typemap(out) CONST TYPE { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(TYPE *), SWIG_POINTER_OWN)); +} + +%typemap(varin) CONST TYPE { + void *argp = 0; + int newmem = 0; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + if (!argp) { + %argument_nullref("$type", $symname, $argnum); + } else { + $1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get()); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + } +} +%typemap(varout) CONST TYPE { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); + %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(TYPE *), SWIG_POINTER_OWN)); +} + +// plain pointer +%typemap(builtin_init, fragment="SWIG_null_deleter") TYPE *, 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(TYPE *), $owner | SWIG_POINTER_OWN)); +} + +%typemap(in) CONST TYPE * (void *argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), SHARED_PTR_DISOWN | %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast(tempshared.get(), $1_ltype); + } else { + smartarg = %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype); + } +} + +%typemap(out, fragment="SWIG_null_deleter") 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(TYPE *), $owner | SWIG_POINTER_OWN)); +} + +%typemap(varin) CONST TYPE * { + void *argp = 0; + int newmem = 0; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared; + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0; + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast(tempshared.get(), $1_ltype); + } else { + smartarg = %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype); + } +} +%typemap(varout, fragment="SWIG_null_deleter") 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(TYPE *), SWIG_POINTER_OWN)); +} + +%typemap(in) CONST TYPE & (void *argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (!argp) { %argument_nullref("$type", $symname, $argnum); } + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = %const_cast(tempshared.get(), $1_ltype); + } else { + $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 & { + 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(TYPE *), SWIG_POINTER_OWN)); +} + +%typemap(varin) CONST TYPE & { + void *argp = 0; + int newmem = 0; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared; + if (!argp) { %argument_nullref("$type", $symname, $argnum); } + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + $1 = *%const_cast(tempshared.get(), $1_ltype); + } else { + $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 & { + 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(TYPE *), SWIG_POINTER_OWN)); +} + +// plain pointer by reference +// Note: $disown not implemented by default as it will lead to a memory leak of the shared_ptr instance +%typemap(in) TYPE *CONST& (void *argp = 0, int res = 0, $*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), SHARED_PTR_DISOWN | %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem & SWIG_CAST_NEW_MEMORY) { + tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); + temp = %const_cast(tempshared.get(), $*1_ltype); + } else { + temp = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $*1_ltype); + } + $1 = &temp; +} +%typemap(out, fragment="SWIG_null_deleter") 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(TYPE *), SWIG_POINTER_OWN)); +} + +%typemap(varin) TYPE *CONST& %{ +#error "varin typemap not implemented" +%} +%typemap(varout) TYPE *CONST& %{ +#error "varout typemap not implemented" +%} + +// shared_ptr by value +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (void *argp, int res = 0) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (argp) $1 = *(%reinterpret_cast(argp, $<ype)); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $<ype); +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(TYPE *), SWIG_POINTER_OWN)); +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { + int newmem = 0; + void *argp = 0; + int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %variable_fail(res, "$type", "$name"); + } + $1 = argp ? *(%reinterpret_cast(argp, $<ype)) : SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE >(); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $<ype); +} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; + %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(TYPE *), SWIG_POINTER_OWN)); +} + +// shared_ptr by reference +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & (void *argp, int res = 0, $*1_ltype tempshared) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem & SWIG_CAST_NEW_MEMORY) { + if (argp) tempshared = *%reinterpret_cast(argp, $ltype); + delete %reinterpret_cast(argp, $ltype); + $1 = &tempshared; + } else { + $1 = (argp) ? %reinterpret_cast(argp, $ltype) : &tempshared; + } +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(TYPE *), SWIG_POINTER_OWN)); +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{ +#error "varin typemap not implemented" +%} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{ +#error "varout typemap not implemented" +%} + +// shared_ptr by pointer +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * (void *argp, int res = 0, $*1_ltype tempshared) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (newmem & SWIG_CAST_NEW_MEMORY) { + if (argp) tempshared = *%reinterpret_cast(argp, $ltype); + delete %reinterpret_cast(argp, $ltype); + $1 = &tempshared; + } else { + $1 = (argp) ? %reinterpret_cast(argp, $ltype) : &tempshared; + } +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 && *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(TYPE *), SWIG_POINTER_OWN)); + if ($owner) delete $1; +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{ +#error "varin typemap not implemented" +%} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{ +#error "varout typemap not implemented" +%} + +// shared_ptr by pointer reference +%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& (void *argp, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, $*1_ltype temp = 0) { + int newmem = 0; + res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); + if (!SWIG_IsOK(res)) { + %argument_fail(res, "$type", $symname, $argnum); + } + if (argp) tempshared = *%reinterpret_cast(argp, $*ltype); + if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $*ltype); + temp = &tempshared; + $1 = &temp; +} +%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& { + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 && **$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0; + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(TYPE *), SWIG_POINTER_OWN)); +} + +%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{ +#error "varin typemap not implemented" +%} +%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{ +#error "varout typemap not implemented" +%} + +// Typecheck typemaps +// Note: SWIG_ConvertPtr with void ** parameter set to 0 instead of using SWIG_ConvertPtrAndOwn, so that the casting +// function is not called thereby avoiding a possible smart pointer copy constructor call when casting up the inheritance chain. +%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) + TYPE CONST, + TYPE CONST &, + TYPE CONST *, + TYPE *CONST&, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *, + SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& { + int res = SWIG_ConvertPtr($input, 0, $descriptor(TYPE *), 0); + $1 = SWIG_CheckState(res); +} + +*/ + +%typemap(builtin_init, fragment="SWIG_null_deleter") 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)); +} + +#endif + %enddef diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index f0736c452..45b1a5d26 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -5,6 +5,16 @@ wrapper##_closure (PyObject *a) \ return wrapper(a, NULL); \ } +#define PYSWIG_INQUIRY_CLOSURE(wrapper) \ +SWIGINTERN int \ +wrapper##_closure (PyObject *a) \ +{ \ + PyObject *pyresult = wrapper(a, NULL); \ + int result = pyresult && PyObject_IsTrue(pyresult) ? 1 : 0; \ + Py_XDECREF(pyresult); \ + return result; \ +} + #define PYSWIG_BINARYFUNC_CLOSURE(wrapper) \ SWIGINTERN PyObject* \ wrapper##_closure (PyObject *a, PyObject *b) \ @@ -126,28 +136,9 @@ wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \ namespace { -template struct SwigPyBuiltin : public SwigPyObject { - - typedef SwigPyBuiltin<_Tp> this_type; - typedef _Tp obj_type; - typedef obj_type* pointer; - typedef obj_type& reference; - - static PyObject* richcompare (PyObject *self, PyObject *other, int op); - - static PyMethodDef methods[]; - static PyGetSetDef getset[]; - static PyNumberMethods number_methods; - static PySequenceMethods sequence_methods; - static PyMappingMethods mapping_methods; - static PyTypeObject pytype; - static SwigPyClientData clientdata; -}; - template void py_builtin_dealloc (PyObject *pyobj) { - typedef SwigPyBuiltin<_Tp> builtin_type; - builtin_type *obj = (builtin_type*) pyobj; + SwigPyObject *obj = (SwigPyObject*) pyobj; if (obj->own) delete reinterpret_cast<_Tp*>(obj->ptr); (*pyobj->ob_type->tp_free)(pyobj); @@ -168,7 +159,7 @@ SWIGRUNTIME void py_builtin_bad_dealloc (PyObject *pyobj) SwigPyObject *sobj = (SwigPyObject*) pyobj; if (sobj->own) { PyErr_Format(PyExc_TypeError, - "Swig detected a memory leak in type '%s': no callable destructor found.", + "Swig detected a memory leak in type '%.300s': no callable destructor found.", pyobj->ob_type->tp_name); } } diff --git a/Lib/python/carrays.i b/Lib/python/carrays.i index 8d6d44082..6a43637e6 100644 --- a/Lib/python/carrays.i +++ b/Lib/python/carrays.i @@ -1,5 +1,49 @@ %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__; + +%inline %{ +typedef struct NAME { + TYPE *el; +} NAME; +%} + +%extend NAME { + + NAME(size_t nelements) { + NAME *arr = %new_instance(NAME); + arr->el = %new_array(nelements, TYPE); + return arr; + } + + ~NAME() { + %delete_array(self->el); + %delete(self); + } + + TYPE __getitem__(size_t index) { + return self->el[index]; + } + + void __setitem__(size_t index, TYPE value) { + self->el[index] = value; + } + + TYPE * cast() { + return self->el; + } + + static NAME *frompointer(TYPE *t) { + return %reinterpret_cast(t, NAME *); + } +}; + +%types(NAME = TYPE); + +#else %array_class_wrap(TYPE,NAME,__getitem__,__setitem__) +#endif %enddef %include diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg index cd38eeee1..29d9b4dab 100644 --- a/Lib/python/pycontainer.swg +++ b/Lib/python/pycontainer.swg @@ -604,7 +604,7 @@ namespace swig %newobject __getslice__; #if defined(SWIGPYTHON_BUILTIN) - %feature("pyslot", "nb_nonzero", functype="unaryfunc") __nonzero__; + %feature("pyslot", "nb_nonzero", functype="inquiry") __nonzero__; %feature("pyslot", "sq_length", functype="lenfunc") __len__; #endif // SWIGPYTHON_BUILTIN diff --git a/Lib/python/pyopers.swg b/Lib/python/pyopers.swg index 84058da96..a51d87549 100644 --- a/Lib/python/pyopers.swg +++ b/Lib/python/pyopers.swg @@ -43,7 +43,7 @@ %feature("pyslot", "tp_call", functype="ternaryfunc") *::operator(); #if defined(SWIGPYTHON_BUILTIN) -%pybinoperator(__nonzero__, *::operator bool, unaryfunc, nb_nonzero); +%pybinoperator(__nonzero__, *::operator bool, inquiry, nb_nonzero); #else %feature("shadow") *::operator bool %{ def __nonzero__(self): diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 935103334..731e05d65 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1033,50 +1033,61 @@ SWIG_This(void) SWIGRUNTIME SwigPyObject * SWIG_Python_GetSwigThis(PyObject *pyobj) { - if (SwigPyObject_Check(pyobj)) { + if (SwigPyObject_Check(pyobj)) return (SwigPyObject *) pyobj; - } else { - PyObject *obj = 0; -#if (!defined(SWIG_PYTHON_SLOW_GETSET_THIS) && (PY_VERSION_HEX >= 0x02030000)) - if (PyInstance_Check(pyobj)) { - obj = _PyInstance_Lookup(pyobj, SWIG_This()); - } else { - PyObject **dictptr = _PyObject_GetDictPtr(pyobj); - if (dictptr != NULL) { - PyObject *dict = *dictptr; - obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0; - } else { -#ifdef PyWeakref_CheckProxy - if (PyWeakref_CheckProxy(pyobj)) { - PyObject *wobj = PyWeakref_GET_OBJECT(pyobj); - return wobj ? SWIG_Python_GetSwigThis(wobj) : 0; - } + +#ifdef SWIGPYTHON_BUILTIN +# ifdef PyWeakref_CheckProxy + if (PyWeakref_CheckProxy(pyobj)) { + pyobj = PyWeakref_GET_OBJECT(pyobj); + if (pyobj && SwigPyObject_Check(pyobj)) + return (SwigPyObject*) pyobj; + } +# endif + return NULL; #endif - obj = PyObject_GetAttr(pyobj,SWIG_This()); - if (obj) { - Py_DECREF(obj); - } else { - if (PyErr_Occurred()) PyErr_Clear(); - return 0; - } + + PyObject *obj = 0; + +#if (!defined(SWIG_PYTHON_SLOW_GETSET_THIS) && (PY_VERSION_HEX >= 0x02030000)) + if (PyInstance_Check(pyobj)) { + obj = _PyInstance_Lookup(pyobj, SWIG_This()); + } else { + PyObject **dictptr = _PyObject_GetDictPtr(pyobj); + if (dictptr != NULL) { + PyObject *dict = *dictptr; + obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0; + } else { +#ifdef PyWeakref_CheckProxy + if (PyWeakref_CheckProxy(pyobj)) { + PyObject *wobj = PyWeakref_GET_OBJECT(pyobj); + return wobj ? SWIG_Python_GetSwigThis(wobj) : 0; + } +#endif + obj = PyObject_GetAttr(pyobj,SWIG_This()); + if (obj) { + Py_DECREF(obj); + } else { + if (PyErr_Occurred()) PyErr_Clear(); + return 0; } } -#else - obj = PyObject_GetAttr(pyobj,SWIG_This()); - if (obj) { - Py_DECREF(obj); - } else { - if (PyErr_Occurred()) PyErr_Clear(); - return 0; - } -#endif - if (obj && !SwigPyObject_Check(obj)) { - /* a PyObject is called 'this', try to get the 'real this' - SwigPyObject from it */ - return SWIG_Python_GetSwigThis(obj); - } - return (SwigPyObject *)obj; } +#else + obj = PyObject_GetAttr(pyobj,SWIG_This()); + if (obj) { + Py_DECREF(obj); + } else { + if (PyErr_Occurred()) PyErr_Clear(); + return 0; + } +#endif + if (obj && !SwigPyObject_Check(obj)) { + /* a PyObject is called 'this', try to get the 'real this' + SwigPyObject from it */ + return SWIG_Python_GetSwigThis(obj); + } + return (SwigPyObject *)obj; } /* Acquire a pointer value */ @@ -1104,22 +1115,27 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int return SWIG_OK; } + /* if (ty && ty->clientdata && ((SwigPyClientData*) ty->clientdata)->pytype) { - PyTypeObject *target_tp = ((SwigPyClientData*) ty->clientdata)->pytype; - PyTypeObject *obj_tp; - for (obj_tp = obj->ob_type; obj_tp; obj_tp = obj_tp->tp_base) { - if (obj_tp == target_tp) { - SwigPyObject *sobj = (SwigPyObject*) obj; - if (own) - *own = *own | sobj->own; - if (flags & SWIG_POINTER_DISOWN) - sobj->own = 0; - if (ptr) - *ptr = sobj->ptr; - return SWIG_OK; - } + PyTypeObject *target_tp = ((SwigPyClientData*) ty->clientdata)->pytype; + SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj); + for (; sobj; sobj = (SwigPyObject*) sobj->next) { + if (!sobj->ty->clientdata) + continue; + PyTypeObject *candidate_tp = ((SwigPyClientData*) sobj->ty->clientdata)->pytype; + if (candidate_tp && PyType_IsSubtype(candidate_tp, target_tp)) { + if (own) + *own = *own | sobj->own; + if (flags & SWIG_POINTER_DISOWN) + sobj->own = 0; + if (ptr) + *ptr = sobj->ptr; + return SWIG_OK; } + } + return SWIG_ERROR; } + */ int res = SWIG_ERROR; diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 7ea66f6f4..45c03b509 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -52,6 +52,7 @@ static Hash *builtin_getset = 0; static Hash *class_members = 0; static File *f_builtins = 0; static String *builtin_tp_init = 0; +static String *builtin_methods = 0; static String *methods; static String *class_name; @@ -171,6 +172,7 @@ static String *getSlot(Node *n, const char *key) { static String *getClosure(String *functype, String *wrapper) { static const char *functypes[] = { "unaryfunc", "PYSWIG_UNARYFUNC_CLOSURE", + "inquiry", "PYSWIG_INQUIRY_CLOSURE", "getiterfunc", "PYSWIG_UNARYFUNC_CLOSURE", "iternextfunc", "PYSWIG_UNARYFUNC_CLOSURE", "binaryfunc", "PYSWIG_BINARYFUNC_CLOSURE", @@ -575,6 +577,7 @@ public: f_directors = NewString(""); builtin_getset = NewHash(); class_members = NewHash(); + builtin_methods = NewString(""); if (builtin) { f_builtins = NewString(""); @@ -906,6 +909,11 @@ public: Append(methods, "};\n"); Printf(f_wrappers, "%s\n", methods); + if (builtin) { + Printv(f_builtins, "#ifdef __cplusplus\n} // namespace {\n#endif\n\n", NIL); + Dump(f_builtins, f_wrappers); + } + SwigType_emit_type_table(f_runtime, f_wrappers); Append(const_code, "{0, 0, 0, 0.0, 0, 0}};\n"); @@ -918,8 +926,6 @@ public: Printf(f_init, " return;\n"); Printf(f_init, "#endif\n"); Printf(f_init, "}\n"); - if (builtin) - Printv(f_builtins, "#ifdef __cplusplus\n} // namespace {\n#endif\n\n", NIL); Printf(f_wrappers, "#ifdef __cplusplus\n"); Printf(f_wrappers, "}\n"); @@ -951,8 +957,8 @@ public: } Dump(f_wrappers, f_begin); - if (builtin) - Dump(f_builtins, f_begin); + //if (builtin) + //Dump(f_builtins, f_begin); Wrapper_pretty_print(f_init, f_begin); Delete(f_header); @@ -1802,12 +1808,11 @@ public: /* ------------------------------------------------------------ * dispatchFunction() * ------------------------------------------------------------ */ - void dispatchFunction(Node *n, String *linkage, int funpack = 0, bool builtin_self = false, bool constructor = false) { + void dispatchFunction(Node *n, String *linkage, int funpack = 0, bool return_int = false, bool add_self = false, bool addmeth = true) { /* Last node in overloaded chain */ int maxargs; - bool return_int = (builtin_self && constructor); String *tmp = NewString(""); String *dispatch; const char *dispatch_code = funpack ? "return %s(self, argc, argv);" : "return %s(self, args);"; @@ -1831,8 +1836,6 @@ public: Wrapper_add_local(f, "argv", tmp); if (!fastunpack) { - bool director_class = (getCurrentClass() && Swig_directorclass(getCurrentClass())); - bool add_self = builtin_self && (!constructor || director_class); Wrapper_add_local(f, "ii", "int ii"); if (maxargs - (add_self ? 1 : 0) > 0) Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n"); @@ -1875,7 +1878,7 @@ public: Printv(f->code, "}\n", NIL); Wrapper_print(f, f_wrappers); Node *p = Getattr(n, "sym:previousSibling"); - if (!builtin_self) + if (addmeth) add_method(symname, wname, 0, p); /* Create a shadow for this function (if enabled and not in a member function) */ @@ -1949,7 +1952,15 @@ public: Delete(cname); } bool builtin_self = builtin && in_class && (constructor || (l && Getattr(l, "self"))); - bool builtin_ctor = builtin_self && constructor; + bool builtin_ctor = false; + if (builtin_self && constructor) { + String *class_mname = Getattr(getCurrentClass(), "sym:name"); + String *mrename = Swig_name_construct(getNSpace(), class_mname); + if (Cmp(iname, mrename)) + builtin_self = false; + else + builtin_ctor = true; + } bool director_class = (getCurrentClass() && Swig_directorclass(getCurrentClass())); bool builtin_getter = (builtin && GetFlag(n, "memberget")); bool builtin_setter = (builtin && GetFlag(n, "memberset") && !builtin_getter); @@ -1994,7 +2005,7 @@ public: /* Get number of required and total arguments */ tuple_arguments = num_arguments = emit_num_arguments(l); tuple_required = num_required = emit_num_required(l); - if (builtin_self && (!constructor || (constructor && director_class))) { + if (builtin_self && (!builtin_ctor || (builtin_ctor && director_class))) { --tuple_arguments; --tuple_required; } @@ -2493,7 +2504,7 @@ public: DelWrapper(f); f = NewWrapper(); Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL); - Wrapper_add_local(f, "resultobj", constructor && builtin_self ? "int resultobj" : "PyObject *resultobj"); + Wrapper_add_local(f, "resultobj", builtin_ctor ? "int resultobj" : "PyObject *resultobj"); Wrapper_add_local(f, "varargs", "PyObject *varargs"); Wrapper_add_local(f, "newargs", "PyObject *newargs"); int first_arg = builtin_self ? 1 : 0; @@ -2518,7 +2529,10 @@ public: } } else { if (!Getattr(n, "sym:nextSibling")) { - dispatchFunction(n, linkage, funpack, builtin_self, constructor); + dispatchFunction(n, linkage, funpack, + builtin_ctor, // return_int + builtin_self && (!builtin_ctor || director_class), // add_self + !builtin_self); // addmeth } } @@ -2991,7 +3005,7 @@ public: if (shadow) { if (builtin) { String *rname = SwigType_namestr(real_classname); - Printf(f_shadow, tab4 "{ \"__disown__\", (PyCFunction) Swig::Director::pyobj_disown< %s >, METH_NOARGS, \"\" },\n", rname); + Printf(builtin_methods, tab4 "{ \"__disown__\", (PyCFunction) Swig::Director::pyobj_disown< %s >, METH_NOARGS, \"\" },\n", rname); Delete(rname); } else { String *symname = Getattr(n, "sym:name"); @@ -3019,28 +3033,6 @@ public: * classDeclaration() * ------------------------------------------------------------ */ - virtual bool get_single_base(Node *n, Node **base = NULL) { - if (base) - *base = NULL; - if (Getattr(n, "single_inh")) - return true; - List *baselist = Getattr(n, "bases"); - if (!baselist || Len(baselist) == 0) { - Setattr(n, "single_inh", "1"); - return true; - } - //if (baselist && Len(baselist) == 1) { - Iterator b = First(baselist); - if (this->get_single_base(b.item)) { - if (base) - *base = b.item; - Setattr(n, "single_inh", "1"); - return true; - } - //} - return false; - } - virtual int classDeclaration(Node *n) { if (shadow && !Getattr(n, "feature:onlychildren")) { Node *mod = Getattr(n, "module"); @@ -3068,43 +3060,26 @@ public: * classHandler() * ------------------------------------------------------------ */ - String* add_explicit_scope (String *s) { - if (!Strstr(s, "::")) { - String *ss = NewStringf("::%s", s); - Delete(s); - s = ss; - } - return s; + String* add_explicit_scope (String *s) { + if (!Strstr(s, "::")) { + String *ss = NewStringf("::%s", s); + Delete(s); + s = ss; } + return s; + } - void builtin_pre_decl(Node *n, Node *) { + void builtin_pre_decl(Node *n) { String *name = Getattr(n, "name"); String *rname = add_explicit_scope(SwigType_namestr(name)); + String *mname = SwigType_manglestr(rname); + Printf(f_init, "\n// type '%s'\n", rname); - Printf(f_init, tab4 "builtin_pytype = &SwigPyBuiltin< %s >::pytype;\n", rname); - Printf(f_init, tab4 "builtin_pytype->ob_type = metatype;\n"); - Printf(f_init, tab4 "builtin_pytype->tp_new = PyType_GenericNew;\n"); - List *baselist = Getattr(n, "bases"); - if (baselist) { - for (Iterator b = First(baselist); b.item; b = Next(b)) { - String *bname = Getattr(b.item, "name"); - if (!bname || GetFlag(b.item, "feature:ignore")) - continue; - 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); - Delete(base_name); - Delete(base_mname); - } - } - Printv(f_init, " pyswig_builtin_init_bases(builtin_pytype, builtin_bases);\n", NIL); - Printv(f_init, " builtin_bases.clear();\n", NIL); + Printf(f_init, " builtin_pytype = (PyTypeObject*) &SwigPyBuiltin_%s_type;\n", mname); Printf(f_init, " builtin_pytype->tp_dict = d = PyDict_New();\n"); + Delete(rname); + Delete(mname); } virtual bool has_callable_dtor (Node *n, bool protected_ok = false) { @@ -3127,21 +3102,44 @@ public: SwigType_add_pointer(pname); String *symname = Getattr(n, "sym:name"); String *rname = add_explicit_scope(SwigType_namestr(name)); - String *templ = NewString(""); - Printf(templ, "SwigPyBuiltin< %s >", rname); - char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : Swig_directorclass(n) ? "0" : "py_builtin_bad_init"; + String *mname = SwigType_manglestr(rname); + String *templ = NewStringf("SwigPyBuiltin_%s", mname); + + Printf(f_init, tab4 "builtin_pytype->ob_type = metatype;\n"); + Printf(f_init, tab4 "builtin_pytype->tp_new = PyType_GenericNew;\n"); + List *baselist = Getattr(n, "bases"); + if (baselist) { + for (Iterator b = First(baselist); b.item; b = Next(b)) { + String *bname = Getattr(b.item, "name"); + if (!bname || GetFlag(b.item, "feature:ignore")) + continue; + 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); + Delete(base_name); + Delete(base_mname); + } + } + Printv(f_init, " pyswig_builtin_init_bases(builtin_pytype, builtin_bases);\n", NIL); + Printv(f_init, " builtin_bases.clear();\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 = NewString(""); - if (has_callable_dtor(n)) - Printf(tp_dealloc, "py_builtin_dealloc< %s >", rname); - else + if (has_callable_dtor(n)) { + String *smartptr = Getattr(n, "feature:smartptr"); + Printf(tp_dealloc, "py_builtin_dealloc< %s >", smartptr ? smartptr : rname); + } else { Printv(tp_dealloc, "py_builtin_bad_dealloc", NIL); + } String *getset_def = NewString(""); - Printf(getset_def, "template <> PyGetSetDef SwigPyBuiltin< %s >::getset[] = {\n", rname); + Printf(getset_def, "SWIGINTERN PyGetSetDef %s_getset[] = {\n", templ); // All objects have a 'thisown' attribute Printv(f_init, "PyDict_SetItemString(d, \"thisown\", thisown_descr);\n", NIL); @@ -3158,19 +3156,100 @@ public: Printf(f, "static SwigPyGetSet %s = { %s, %s };\n", gspair, getter ? getter : "0", setter ? setter : "0"); String *entry = NewStringf("{ const_cast(\"%s\"), (getter) %s, (setter) %s, const_cast(\"%s.%s\"), (void*) &%s }\n", memname, getter_closure, setter_closure, name, memname, gspair); if (GetFlag(mgetset, "static")) { - Printf(f, "static PyGetSetDef %s_def = %s;\n", gspair, entry); - Printf(f_init, "static_getset = SwigPyStaticVar_new_getset(metatype, &%s_def);\n", gspair); - Printf(f_init, "PyDict_SetItemString(d, static_getset->d_getset->name, (PyObject*) static_getset);\n", memname); Printf(f_init, "Py_DECREF(static_getset);\n"); + Printf(f, "static PyGetSetDef %s_def = %s;\n", gspair, entry); + Printf(f_init, "static_getset = SwigPyStaticVar_new_getset(metatype, &%s_def);\n", gspair); + Printf(f_init, "PyDict_SetItemString(d, static_getset->d_getset->name, (PyObject*) static_getset);\n", memname); Printf(f_init, "Py_DECREF(static_getset);\n"); } else { - Printf(getset_def, " %s,\n", entry); + Printf(getset_def, " %s,\n", entry); } Delete(gspair); Delete(entry); } Printv(f, getset_def, " {NULL} // Sentinel\n", "};\n\n", NIL); - // Number methods - Printf(f, "template <> PyNumberMethods SwigPyBuiltin< %s >::number_methods = {\n", rname); + // Rich compare function + Hash *richcompare = Getattr(n, "richcompare"); + assert(richcompare); + Printf(f, "SWIGINTERN PyObject*\n"); + Printf(f, "%s_richcompare (PyObject *self, PyObject *other, int op)\n", templ); + Printf(f, "{\n"); + Printf(f, " PyObject *result = NULL;\n"); + Printf(f, " PyObject *tuple = PyTuple_New(1);\n"); + Printf(f, " assert(tuple);\n"); + Printf(f, " PyTuple_SET_ITEM(tuple, 0, other);\n"); + Printf(f, " Py_XINCREF(other);\n"); + Printf(f, " switch (op) {\n"); + for (Iterator i = First(richcompare); i.item; i = Next(i)) + Printf(f, " case %s : result = %s(self, tuple); break;\n", i.key, i.item); + Printv(f, " default : PyErr_Format(PyExc_TypeError, \"Cannot compare a(n) '%s' to a(n) '%s'\",", NIL); + Printv(f, " self->ob_type->tp_name, other ? other->ob_type->tp_name : \"NULL\");\n", NIL); + Printf(f, " }\n"); + Printf(f, " Py_DECREF(tuple);\n"); + Printf(f, " return result;\n"); + Printf(f, "}\n\n"); + + // Methods + Printf(f, "SWIGINTERN PyMethodDef %s_methods[] = {\n", templ); + Dump(builtin_methods, f); + Printf(f, " {NULL} // Sentinel\n};\n\n"); + + // No instance dict for nondynamic objects + if (GetFlag(n, "feature:python:nondynamic")) + Setattr(n, "feature: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 *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES"); + + Printf(f, "static PyHeapTypeObject %s_type = {\n", templ); + + // PyTypeObject ht_type + //Printf(f, "template <> PyTypeObject %s::pytype = {\n", templ); + Printf(f, " {\n"); + Printf(f, " PyObject_HEAD_INIT(NULL)\n"); + Printf(f, " 0, /*ob_size*/\n"); + 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")); + 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")); + Printf(f, " &%s_type.as_buffer, /*tp_as_buffer*/\n", templ); + Printf(f, " %s, /*tp_flags*/\n", tp_flags); + 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")); + 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")); + 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")); @@ -3210,10 +3289,19 @@ public: 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")); - Printf(f, "};\n\n"); + Printf(f, " },\n"); - // Sequence methods - Printf(f, "template <> PySequenceMethods SwigPyBuiltin< %s >::sequence_methods = {\n", rname); + // 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")); + 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")); @@ -3224,94 +3312,39 @@ public: 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, "};\n\n"); + Printf(f, " },\n"); - // Mapping methods - Printf(f, "template <> PyMappingMethods SwigPyBuiltin< %s >::mapping_methods = {\n", rname); - 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")); - Printf(f, "};\n\n"); + // PyBufferProcs as_buffer; + Printf(f, " {\n"); + 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, " },\n"); - // Rich compare function - Printf(f, "template <> PyObject*\n"); - Printf(f, "%s::richcompare (PyObject *self, PyObject *other, int op)\n", templ); - Printf(f, "{\n"); - Printf(f, " PyObject *result = NULL;\n"); - Printf(f, " PyObject *tuple = PyTuple_New(1);\n"); - Printf(f, " assert(tuple);\n"); - Printf(f, " PyTuple_SET_ITEM(tuple, 0, other);\n"); - Printf(f, " Py_XINCREF(other);\n"); - Printf(f, " switch (op) {\n"); - - Hash *richcompare = Getattr(n, "richcompare"); - assert(richcompare); - for (Iterator i = First(richcompare); i.item; i = Next(i)) - Printf(f, " case %s : result = %s(self, tuple); break;\n", i.key, i.item); - - Printf(f, " default : PyErr_Format(PyExc_TypeError, \"Cannot compare a(n) '%%s' to a(n) '%%s'\", self->ob_type->tp_name, other ? other->ob_type->tp_name : \"NIL\");\n"); - Printf(f, " }\n"); - Printf(f, " Py_DECREF(tuple);\n"); - Printf(f, " return result;\n"); - Printf(f, "}\n\n"); - - if (GetFlag(n, "feature:python:nondynamic")) - Setattr(n, "feature:tp_setattro", "SWIG_Python_NonDynamicSetAttr"); - - // Type object - String *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES"); - // TODO: Add more flags based on slots - Printf(f, "template <> PyTypeObject SwigPyBuiltin< %s >::pytype = {\n", rname); - Printf(f, " PyObject_HEAD_INIT(NULL)\n"); - Printf(f, " 0, /*ob_size*/\n"); - Printf(f, " \"%s\", /*tp_name*/\n", symname); - Printf(f, " sizeof(%s), /*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")); - Printf(f, " &%s::number_methods, /*tp_as_number*/\n", templ); - Printf(f, " &%s::sequence_methods, /*tp_as_sequence*/\n", templ); - Printf(f, " &%s::mapping_methods, /*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")); - Printf(f, " %s, /*tp_as_buffer*/\n", getSlot(n, "feature:tp_as_buffer")); - Printf(f, " %s, /*tp_flags*/\n", tp_flags); - 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")); - 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")); + // 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, "};\n\n"); String *clientdata = NewString(""); - Printf(clientdata, "&%s::clientdata", templ); + Printf(clientdata, "&%s_clientdata", templ); SwigType_remember_clientdata(pname, clientdata); - Printf(f, "template <> SwigPyClientData %s::clientdata = {0, 0, 0, 0, 0, 0, &%s::pytype};\n\n", templ, templ); + String *smartptr = Getattr(n, "feature:smartptr"); + if (smartptr) { + SwigType *spt = Swig_cparse_type(smartptr); + SwigType *smart = SwigType_typedef_resolve_all(spt); + SwigType_add_pointer(smart); + SwigType_remember_clientdata(smart, clientdata); + Delete(spt); + Delete(smart); + } + + Printf(f, "SWIGINTERN SwigPyClientData %s_clientdata = {0, 0, 0, 0, 0, 0, (PyTypeObject*) &%s_type};\n\n", templ, templ); Printv(f_init, " if (PyType_Ready(builtin_pytype) < 0) {\n", NIL); - Printf(f_init, " PyErr_Format(PyExc_TypeError, \"Couldn't create type '.300%s'\");\n", symname); + Printf(f_init, " PyErr_SetString(PyExc_TypeError, \"Couldn't create type '%s'\");\n", symname); Printv(f_init, " return;\n", NIL); Printv(f_init, " }\n", NIL); Printv(f_init, " Py_INCREF(builtin_pytype);\n", NIL); @@ -3320,9 +3353,10 @@ public: Printv(f_init, " d = md;\n", NIL); Delete(clientdata); - Delete(templ); Delete(rname); Delete(pname); + Delete(mname); + Delete(templ); Delete(tp_dealloc); Delete(tp_flags); } @@ -3358,10 +3392,12 @@ public: if (!addSymbol(class_name, n)) return SWIG_ERROR; - if (builtin && !get_single_base(n, &base_node)) { - Swig_warning(WARN_PYTHON_MULTIPLE_INH, Getfile(n), Getline(n), - "Class '%s' ignored, because it has multiple inheritance, which is incompatible with the '-builtin' option.\n", real_classname); - return SWIG_OK; + if (builtin) { + List *baselist = Getattr(n, "bases"); + if (baselist && Len(baselist) > 0) { + Iterator b = First(baselist); + base_node = b.item; + } } shadow_indent = (String *) tab4; @@ -3470,7 +3506,7 @@ public: in_class = 1; if (builtin) - builtin_pre_decl(n, base_node); + builtin_pre_decl(n); /* Overide the shadow file so we can capture its methods */ f_shadow = NewString(""); @@ -3562,12 +3598,8 @@ public: Delete(rname); } - if (builtin) { + if (builtin) builtin_post_decl(f_builtins, n); - String *rname = add_explicit_scope(SwigType_namestr(real_classname)); - Printf(f_builtins, "template <> PyMethodDef SwigPyBuiltin< %s >::methods[] = {\n", rname); - Delete(rname); - } if (builtin_tp_init) { Delete(builtin_tp_init); @@ -3611,10 +3643,12 @@ public: } if (builtin) { - Dump(f_shadow, f_builtins); - Printf(f_builtins, " {NULL} // Sentinel\n};\n\n"); + //Dump(f_shadow, f_builtins); + //Printf(f_builtins, " {NULL} // Sentinel\n};\n\n"); + //Dump(builtin_methods, f_builtins); Clear(class_members); Clear(builtin_getset); + Clear(builtin_methods); } classic = oldclassic; @@ -3675,7 +3709,7 @@ public: String *wname = Swig_name_wrapper(fullname); Setattr(class_members, symname, n); int allow_kwargs = check_kwargs(n); - Printf(f_shadow, " { \"%s\", (PyCFunction) %s, METH_VARARGS%s, \"\" },\n", + Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_VARARGS%s, \"\" },\n", symname, wname, allow_kwargs ? "|METH_KEYWORDS" : ""); Delete(fullname); Delete(wname); @@ -3763,7 +3797,7 @@ public: String *wname = Swig_name_wrapper(fullname); Setattr(class_members, symname, n); String *pyflags = NewString("METH_VARARGS|METH_STATIC"); - Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", symname, wname, pyflags); + Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", symname, wname, pyflags); Delete(fullname); Delete(wname); Delete(pyflags); @@ -3926,9 +3960,11 @@ public: if (have_pythonprepend(n)) Printv(f_shadow_stubs, pythoncode(pythonprepend(n), tab4), "\n", NIL); String *subfunc = NULL; + /* if (builtin) subfunc = Copy(Getattr(getCurrentClass(), "sym:name")); else + */ subfunc = Swig_name_construct(NSPACE_TODO, symname); Printv(f_shadow_stubs, tab4, "val = ", funcCall(subfunc, callParms), "\n", NIL); #ifdef USE_THISOWN From 288c37f5bf17df431dbdaa23f4a0c41229a9868f Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Sun, 30 Jan 2011 03:17:28 +0000 Subject: [PATCH 11/56] Regressions pass! With a few tweaks for unsupported features, primarily: - Throwing wrapped types as exceptions is unsupported. - Reverse comparison operators (e.g., __radd__) aren't supported. Rationalized destructors. Finished std::map implementation. Required fixes to typecheck for SWIGTYPE* const&. Need a little special handling of the swig_type_info for SwigPyObject when multiple modules are loaded. Fall back to SwigPyObject_richcompare if there's no operator overload. "memberget" and "memberset" attrs are applied strangely; work around them. Added 'this' attribute. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12415 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/boost_shared_ptr.i | 288 ------------------- Lib/python/builtin.swg | 51 ++-- Lib/python/pyclasses.swg | 3 + Lib/python/pyinit.swg | 40 ++- Lib/python/pyiterators.swg | 17 +- Lib/python/pyrun.swg | 12 + Lib/python/pytypemaps.swg | 7 +- Lib/python/std_map.i | 7 +- Source/Modules/python.cxx | 501 ++++++++++++++++++---------------- 9 files changed, 352 insertions(+), 574 deletions(-) diff --git a/Lib/python/boost_shared_ptr.i b/Lib/python/boost_shared_ptr.i index c527dd6b5..129bd9965 100644 --- a/Lib/python/boost_shared_ptr.i +++ b/Lib/python/boost_shared_ptr.i @@ -320,294 +320,6 @@ #if defined(SWIGPYTHON_BUILTIN) -/* - -// plain value -%typemap(in) CONST TYPE (void *argp, int res = 0) { - int newmem = 0; - res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); - if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); - } - if (!argp) { - %argument_nullref("$type", $symname, $argnum); - } else { - $1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get()); - if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); - } -} -%typemap(out) CONST TYPE { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); - %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(TYPE *), SWIG_POINTER_OWN)); -} - -%typemap(varin) CONST TYPE { - void *argp = 0; - int newmem = 0; - int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); - if (!SWIG_IsOK(res)) { - %variable_fail(res, "$type", "$name"); - } - if (!argp) { - %argument_nullref("$type", $symname, $argnum); - } else { - $1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get()); - if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); - } -} -%typemap(varout) CONST TYPE { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); - %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(TYPE *), SWIG_POINTER_OWN)); -} - -// plain pointer -%typemap(builtin_init, fragment="SWIG_null_deleter") TYPE *, 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(TYPE *), $owner | SWIG_POINTER_OWN)); -} - -%typemap(in) CONST TYPE * (void *argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) { - int newmem = 0; - res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), SHARED_PTR_DISOWN | %convertptr_flags, &newmem); - if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); - } - if (newmem & SWIG_CAST_NEW_MEMORY) { - tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); - delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); - $1 = %const_cast(tempshared.get(), $1_ltype); - } else { - smartarg = %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); - $1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype); - } -} - -%typemap(out, fragment="SWIG_null_deleter") 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(TYPE *), $owner | SWIG_POINTER_OWN)); -} - -%typemap(varin) CONST TYPE * { - void *argp = 0; - int newmem = 0; - int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); - if (!SWIG_IsOK(res)) { - %variable_fail(res, "$type", "$name"); - } - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared; - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0; - if (newmem & SWIG_CAST_NEW_MEMORY) { - tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); - delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); - $1 = %const_cast(tempshared.get(), $1_ltype); - } else { - smartarg = %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); - $1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype); - } -} -%typemap(varout, fragment="SWIG_null_deleter") 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(TYPE *), SWIG_POINTER_OWN)); -} - -%typemap(in) CONST TYPE & (void *argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { - int newmem = 0; - res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); - if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); - } - if (!argp) { %argument_nullref("$type", $symname, $argnum); } - if (newmem & SWIG_CAST_NEW_MEMORY) { - tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); - delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); - $1 = %const_cast(tempshared.get(), $1_ltype); - } else { - $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 & { - 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(TYPE *), SWIG_POINTER_OWN)); -} - -%typemap(varin) CONST TYPE & { - void *argp = 0; - int newmem = 0; - int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); - if (!SWIG_IsOK(res)) { - %variable_fail(res, "$type", "$name"); - } - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared; - if (!argp) { %argument_nullref("$type", $symname, $argnum); } - if (newmem & SWIG_CAST_NEW_MEMORY) { - tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); - delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); - $1 = *%const_cast(tempshared.get(), $1_ltype); - } else { - $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 & { - 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(TYPE *), SWIG_POINTER_OWN)); -} - -// plain pointer by reference -// Note: $disown not implemented by default as it will lead to a memory leak of the shared_ptr instance -%typemap(in) TYPE *CONST& (void *argp = 0, int res = 0, $*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { - int newmem = 0; - res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), SHARED_PTR_DISOWN | %convertptr_flags, &newmem); - if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); - } - if (newmem & SWIG_CAST_NEW_MEMORY) { - tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); - delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *); - temp = %const_cast(tempshared.get(), $*1_ltype); - } else { - temp = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $*1_ltype); - } - $1 = &temp; -} -%typemap(out, fragment="SWIG_null_deleter") 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(TYPE *), SWIG_POINTER_OWN)); -} - -%typemap(varin) TYPE *CONST& %{ -#error "varin typemap not implemented" -%} -%typemap(varout) TYPE *CONST& %{ -#error "varout typemap not implemented" -%} - -// shared_ptr by value -%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (void *argp, int res = 0) { - int newmem = 0; - res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); - if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); - } - if (argp) $1 = *(%reinterpret_cast(argp, $<ype)); - if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $<ype); -} -%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; - %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(TYPE *), SWIG_POINTER_OWN)); -} - -%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { - int newmem = 0; - void *argp = 0; - int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); - if (!SWIG_IsOK(res)) { - %variable_fail(res, "$type", "$name"); - } - $1 = argp ? *(%reinterpret_cast(argp, $<ype)) : SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE >(); - if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $<ype); -} -%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0; - %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(TYPE *), SWIG_POINTER_OWN)); -} - -// shared_ptr by reference -%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & (void *argp, int res = 0, $*1_ltype tempshared) { - int newmem = 0; - res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); - if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); - } - if (newmem & SWIG_CAST_NEW_MEMORY) { - if (argp) tempshared = *%reinterpret_cast(argp, $ltype); - delete %reinterpret_cast(argp, $ltype); - $1 = &tempshared; - } else { - $1 = (argp) ? %reinterpret_cast(argp, $ltype) : &tempshared; - } -} -%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; - %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(TYPE *), SWIG_POINTER_OWN)); -} - -%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{ -#error "varin typemap not implemented" -%} -%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{ -#error "varout typemap not implemented" -%} - -// shared_ptr by pointer -%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * (void *argp, int res = 0, $*1_ltype tempshared) { - int newmem = 0; - res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); - if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); - } - if (newmem & SWIG_CAST_NEW_MEMORY) { - if (argp) tempshared = *%reinterpret_cast(argp, $ltype); - delete %reinterpret_cast(argp, $ltype); - $1 = &tempshared; - } else { - $1 = (argp) ? %reinterpret_cast(argp, $ltype) : &tempshared; - } -} -%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 && *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0; - %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(TYPE *), SWIG_POINTER_OWN)); - if ($owner) delete $1; -} - -%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{ -#error "varin typemap not implemented" -%} -%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{ -#error "varout typemap not implemented" -%} - -// shared_ptr by pointer reference -%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& (void *argp, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, $*1_ltype temp = 0) { - int newmem = 0; - res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(TYPE *), %convertptr_flags, &newmem); - if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); - } - if (argp) tempshared = *%reinterpret_cast(argp, $*ltype); - if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $*ltype); - temp = &tempshared; - $1 = &temp; -} -%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& { - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 && **$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0; - %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(TYPE *), SWIG_POINTER_OWN)); -} - -%typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{ -#error "varin typemap not implemented" -%} -%typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{ -#error "varout typemap not implemented" -%} - -// Typecheck typemaps -// Note: SWIG_ConvertPtr with void ** parameter set to 0 instead of using SWIG_ConvertPtrAndOwn, so that the casting -// function is not called thereby avoiding a possible smart pointer copy constructor call when casting up the inheritance chain. -%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) - TYPE CONST, - TYPE CONST &, - TYPE CONST *, - TYPE *CONST&, - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &, - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *, - SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& { - int res = SWIG_ConvertPtr($input, 0, $descriptor(TYPE *), 0); - $1 = SWIG_CheckState(res); -} - -*/ - %typemap(builtin_init, fragment="SWIG_null_deleter") 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 45b1a5d26..15eaf1d9b 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -5,6 +5,17 @@ wrapper##_closure (PyObject *a) \ return wrapper(a, NULL); \ } +#define PYSWIG_DESTRUCTOR_CLOSURE(wrapper) \ +SWIGINTERN void \ +wrapper##_closure (PyObject *a) \ +{ \ + SwigPyObject *sobj = (SwigPyObject*) a; \ + if (sobj->own) { \ + PyObject *o = wrapper(a, NULL); \ + Py_XDECREF(o); \ + } \ +} + #define PYSWIG_INQUIRY_CLOSURE(wrapper) \ SWIGINTERN int \ wrapper##_closure (PyObject *a) \ @@ -132,22 +143,6 @@ wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \ return result; \ } -#ifdef __cplusplus - -namespace { - -template void py_builtin_dealloc (PyObject *pyobj) -{ - SwigPyObject *obj = (SwigPyObject*) pyobj; - if (obj->own) - delete reinterpret_cast<_Tp*>(obj->ptr); - (*pyobj->ob_type->tp_free)(pyobj); -} - -} // namespace { - -#endif - SWIGRUNTIME int py_builtin_bad_init (PyObject *self, PyObject *args, PyObject *kwds) { PyErr_Format(PyExc_TypeError, "Cannot create new instances of type '%.300s'", self->ob_type->tp_name); @@ -187,11 +182,15 @@ pyswig_getter_closure (PyObject *obj, void *closure) SWIGRUNTIME int pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure) { - if (!closure) + if (!closure) { + PyErr_Format(PyExc_TypeError, "Missing getset closure"); return -1; + } SwigPyGetSet *getset = (SwigPyGetSet*) closure; - if (!getset->set) + if (!getset->set) { + PyErr_Format(PyExc_TypeError, "Illegal member variable assignment in type '%.300s'", obj->ob_type->tp_name); return -1; + } PyObject *tuple = PyTuple_New(1); assert(tuple); PyTuple_SET_ITEM(tuple, 0, val); @@ -220,11 +219,15 @@ pyswig_static_getter_closure (PyObject *obj, void *closure) SWIGRUNTIME int pyswig_static_setter_closure (PyObject *obj, PyObject *val, void *closure) { - if (!closure) + if (!closure) { + PyErr_Format(PyExc_TypeError, "Missing getset closure"); return -1; + } SwigPyGetSet *getset = (SwigPyGetSet*) closure; - if (!getset->set) + 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); @@ -381,4 +384,12 @@ pyswig_builtin_init_bases (PyTypeObject *type, std::vector& bases type->tp_bases = tuple; } +SWIGINTERN PyObject* +pyswig_this_closure (PyObject *self, void *closure) +{ + PyObject *result = (PyObject*) SWIG_Python_GetSwigThis(self); + Py_XINCREF(result); + return result; +} + #endif diff --git a/Lib/python/pyclasses.swg b/Lib/python/pyclasses.swg index 65f6dec47..b73ebdbb8 100644 --- a/Lib/python/pyclasses.swg +++ b/Lib/python/pyclasses.swg @@ -43,6 +43,9 @@ namespace swig { %apply PyObject * {SwigPtr_PyObject}; %apply PyObject * const& {SwigPtr_PyObject const&}; + %typemap(typecheck,precedence=SWIG_TYPECHECK_SWIGOBJECT,noblock=1) SwigPtr_PyObject const& "$1 = ($input != 0);"; + + /* For output */ %typemap(out,noblock=1) SwigPtr_PyObject { $result = (PyObject *)$1; diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index dd0139b69..bc19c33fb 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -358,17 +358,8 @@ SWIG_init(void) { metatype->tp_setattro = (setattrofunc) &SwigPyObjectType_setattro; assert(PyType_Ready(metatype) >= 0); - // 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 - }; - PyObject *thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def); - SWIG_Python_builtin_imports(); + #endif /* Fix SwigMethods to carry the callback ptrs when needed */ @@ -382,9 +373,33 @@ SWIG_init(void) { md = d = PyModule_GetDict(m); SWIG_InitializeModule(0); - SWIG_InstallConstants(d,swig_const_table); -#if defined(SWIGPYTHON_BUILTIN) +#ifdef SWIGPYTHON_BUILTIN + static SwigPyClientData SwigPyObject_clientdata = {0}; + SwigPyObject_stype = SWIG_MangledTypeQuery("_p_SwigPyObject"); + assert(SwigPyObject_stype); + SwigPyClientData *cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; + if (!cd) { + SwigPyObject_stype->clientdata = &SwigPyObject_clientdata; + SwigPyObject_clientdata.pytype = _PySwigObject_type(); + } + + // All objects have a 'this' attribute + static PyGetSetDef this_getset_def = { + const_cast("this"), pyswig_this_closure, NULL, NULL, NULL + }; + PyObject *this_descr = PyDescr_NewGetSet(SwigPyObject_type(), &this_getset_def); + + // 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 + }; + PyObject *thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def); + PyObject *public_interface = PyList_New(0); PyObject *public_symbol = 0; PyDict_SetItemString(md, "__all__", public_interface); @@ -395,5 +410,6 @@ SWIG_init(void) { pyswig_add_public_symbol(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 d5ca73ec8..6ff2ef3ee 100644 --- a/Lib/python/pyiterators.swg +++ b/Lib/python/pyiterators.swg @@ -128,6 +128,13 @@ namespace swig { return desc; } }; + + inline PyObject* make_output_iterator_builtin (PyObject *pyself) + { + Py_INCREF(pyself); + return pyself; + } + } } @@ -304,7 +311,7 @@ namespace swig { } template - inline PyObject* make_output_iterator_builtin (PyObject *pyself) + inline PyObject* make_output_iterator_builtin_T (PyObject *pyself) { SwigPyObject *builtin_obj = (SwigPyObject*) pyself; Sequence *seq = reinterpret_cast< Sequence * >(builtin_obj->ptr); @@ -314,12 +321,6 @@ namespace swig { return SWIG_NewPointerObj(iter, SWIGTYPE_p_swig__SwigPyIterator, SWIG_POINTER_OWN); } - template <> - inline PyObject* make_output_iterator_builtin (PyObject *pyself) - { - Py_INCREF(pyself); - return pyself; - } } } @@ -349,7 +350,7 @@ namespace swig %nodirector SwigPyIterator; #if defined(SWIGPYTHON_BUILTIN) - %feature("tp_iter") SwigPyIterator "&swig::make_output_iterator_builtin"; + %feature("tp_iter") SwigPyIterator "&swig::make_output_iterator_builtin"; %feature("pyslot", "tp_iternext", functype="iternextfunc") SwigPyIterator::__next__; #else %extend SwigPyIterator { diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 731e05d65..aa3c6d24a 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -481,11 +481,23 @@ SwigPyObject_richcompare(SwigPyObject *v, SwigPyObject *w, int op) SWIGRUNTIME PyTypeObject* _PySwigObject_type(void); +#ifdef SWIGPYTHON_BUILTIN +static swig_type_info *SwigPyObject_stype = 0; +SWIGRUNTIME PyTypeObject* +SwigPyObject_type(void) { + assert(SwigPyObject_stype); + SwigPyClientData *cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; + assert(cd); + assert(cd->pytype); + return cd->pytype; +} +#else SWIGRUNTIME PyTypeObject* SwigPyObject_type(void) { static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigObject_type(); return type; } +#endif SWIGRUNTIMEINLINE int SwigPyObject_Check(PyObject *op) { diff --git a/Lib/python/pytypemaps.swg b/Lib/python/pytypemaps.swg index 3496324aa..119bf0e1e 100644 --- a/Lib/python/pytypemaps.swg +++ b/Lib/python/pytypemaps.swg @@ -68,6 +68,12 @@ * Python extra typemaps / typemap overrides * ------------------------------------------------------------ */ +%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) SWIGTYPE *const& { + void *vptr = 0; + int res = SWIG_ConvertPtr($input, &vptr, $*descriptor, 0); + $1 = SWIG_CheckState(res); +} + /* Get the address of the 'python self' object */ %typemap(in,numinputs=0,noblock=1) PyObject **PYTHON_SELF { @@ -103,7 +109,6 @@ } } - /* ------------------------------------------------------------- * Output typemap for the __init__ method of a built-in type. * ------------------------------------------------------------ */ diff --git a/Lib/python/std_map.i b/Lib/python/std_map.i index 8f06a97d9..8dcb90fe5 100644 --- a/Lib/python/std_map.i +++ b/Lib/python/std_map.i @@ -158,7 +158,7 @@ #if defined(SWIGPYTHON_BUILTIN) %feature("pyslot", "mp_length", functype="lenfunc") __len__; %feature("pyslot", "mp_subscript", functype="binaryfunc") __getitem__; - %feature("tp_iter") Map "&swig::make_output_key_iterator_builtin< Map >"; + %feature("pyslot", "tp_iter", functype="getiterfunc") key_iterator; %extend { %newobject iterkeys(PyObject **PYTHON_SELF); @@ -288,20 +288,21 @@ #if defined(SWIGPYTHON_BUILTIN) %feature("pyslot", "mp_ass_subscript", functype="objobjargproc") __setitem__; +#endif %extend { // This will be called through the mp_ass_subscript slot to delete an entry. void __setitem__(const key_type& key) { self->erase(key); } - } -#endif + } %extend { void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) { (*self)[key] = x; } } + %enddef diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 45c03b509..9f1b1d0e6 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -53,6 +53,7 @@ static Hash *class_members = 0; static File *f_builtins = 0; static String *builtin_tp_init = 0; static String *builtin_methods = 0; +static String *builtin_default_unref = 0; static String *methods; static String *class_name; @@ -172,6 +173,7 @@ static String *getSlot(Node *n, const char *key) { static String *getClosure(String *functype, String *wrapper) { static const char *functypes[] = { "unaryfunc", "PYSWIG_UNARYFUNC_CLOSURE", + "destructor", "PYSWIG_DESTRUCTOR_CLOSURE", "inquiry", "PYSWIG_INQUIRY_CLOSURE", "getiterfunc", "PYSWIG_UNARYFUNC_CLOSURE", "iternextfunc", "PYSWIG_UNARYFUNC_CLOSURE", @@ -213,7 +215,8 @@ public: * Thread Implementation * ------------------------------------------------------------ */ int threads_enable(Node *n) const { return threads && !GetFlagAttr(n, "feature:nothread"); - } int initialize_threads(String *f_init) { + } + int initialize_threads(String *f_init) { if (!threads) { return SWIG_OK; } @@ -271,6 +274,7 @@ public: } } + /* ------------------------------------------------------------ * main() * ------------------------------------------------------------ */ @@ -578,6 +582,7 @@ public: builtin_getset = NewHash(); class_members = NewHash(); builtin_methods = NewString(""); + builtin_default_unref = NewString("delete $self;"); if (builtin) { f_builtins = NewString(""); @@ -896,6 +901,12 @@ public: /* the method exported for replacement of new.instancemethod in Python 3 */ add_pyinstancemethod_new(); + if (builtin) { + String *s = NewString("p.SwigPyObject"); + SwigType_remember(s); + Delete(s); + } + /* emit code */ Language::top(n); @@ -1808,7 +1819,7 @@ public: /* ------------------------------------------------------------ * dispatchFunction() * ------------------------------------------------------------ */ - void dispatchFunction(Node *n, String *linkage, int funpack = 0, bool return_int = false, bool add_self = false, bool addmeth = true) { + void dispatchFunction(Node *n, String *linkage, int funpack = 0, bool return_int = false, bool add_self = false, bool addmeth = true) { /* Last node in overloaded chain */ int maxargs; @@ -1954,12 +1965,12 @@ public: bool builtin_self = builtin && in_class && (constructor || (l && Getattr(l, "self"))); bool builtin_ctor = false; if (builtin_self && constructor) { - String *class_mname = Getattr(getCurrentClass(), "sym:name"); - String *mrename = Swig_name_construct(getNSpace(), class_mname); - if (Cmp(iname, mrename)) - builtin_self = false; - else - builtin_ctor = true; + String *class_mname = Getattr(getCurrentClass(), "sym:name"); + String *mrename = Swig_name_construct(getNSpace(), class_mname); + if (Cmp(iname, mrename)) + builtin_self = false; + else + builtin_ctor = true; } bool director_class = (getCurrentClass() && Swig_directorclass(getCurrentClass())); bool builtin_getter = (builtin && GetFlag(n, "memberget")); @@ -2075,11 +2086,11 @@ public: } if (builtin_ctor && checkAttribute(n, "access", "protected")) { - String *tmp_none_comparison = Copy(none_comparison); - Replaceall(tmp_none_comparison, "$arg", "self"); - Printf(self_parse, "if (!(%s)) {\n", tmp_none_comparison); - Printv(self_parse, " SWIG_SetErrorMsg(PyExc_RuntimeError, \"accessing abstract class or protected constructor\");\n SWIG_fail;\n}\n", NIL); - Delete(tmp_none_comparison); + String *tmp_none_comparison = Copy(none_comparison); + Replaceall(tmp_none_comparison, "$arg", "self"); + Printf(self_parse, "if (!(%s)) {\n", tmp_none_comparison); + Printv(self_parse, " SWIG_SetErrorMsg(PyExc_RuntimeError, \"accessing abstract class or protected constructor\");\n SWIG_fail;\n}\n", NIL); + Delete(tmp_none_comparison); } if (builtin_self && !builtin_ctor) @@ -2192,13 +2203,13 @@ public: } if (use_parse || allow_kwargs || !modernargs) { - if (builtin && in_class && tuple_arguments == 0) { - Printf(parse_args, " if (args && PyTuple_Check(args) && PyTuple_GET_SIZE(args) > 0) SWIG_fail;\n"); - } else { - Printf(parse_args, ":%s\"", iname); - Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL); - funpack = 0; - } + if (builtin && in_class && tuple_arguments == 0) { + Printf(parse_args, " if (args && PyTuple_Check(args) && PyTuple_GET_SIZE(args) > 0) SWIG_fail;\n"); + } else { + Printf(parse_args, ":%s\"", iname); + Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL); + funpack = 0; + } } else { Clear(parse_args); if (funpack) { @@ -2507,9 +2518,8 @@ public: Wrapper_add_local(f, "resultobj", builtin_ctor ? "int resultobj" : "PyObject *resultobj"); Wrapper_add_local(f, "varargs", "PyObject *varargs"); Wrapper_add_local(f, "newargs", "PyObject *newargs"); - int first_arg = builtin_self ? 1 : 0; - Printf(f->code, "newargs = PyTuple_GetSlice(args,%d,%d);\n", first_arg, first_arg + num_arguments); - Printf(f->code, "varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args)+1);\n", first_arg + num_arguments); + 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); Append(f->code, "Py_XDECREF(newargs);\n"); Append(f->code, "Py_XDECREF(varargs);\n"); @@ -2529,23 +2539,21 @@ public: } } else { if (!Getattr(n, "sym:nextSibling")) { - dispatchFunction(n, linkage, funpack, - builtin_ctor, // return_int - builtin_self && (!builtin_ctor || director_class), // add_self - !builtin_self); // addmeth + dispatchFunction(n, linkage, funpack, builtin_ctor, // return_int + builtin_self && (!builtin_ctor || director_class), // add_self + !builtin_self); // addmeth } } // 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)) { - Setattr(class_members, iname, n); - if (!builtin_tp_init) - builtin_tp_init = Swig_name_wrapper(iname); - } + // 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)) { + Setattr(class_members, iname, n); + if (!builtin_tp_init) + builtin_tp_init = Swig_name_wrapper(iname); + } } /* If this is a builtin type, create a PyGetSetDef entry for this member variable. */ @@ -2557,6 +2565,7 @@ public: Delete(h); } Setattr(h, "getter", wrapper_name); + Delattr(n, "memberget"); } if (builtin_setter) { Hash *h = Getattr(builtin_getset, name); @@ -2566,6 +2575,7 @@ public: Delete(h); } Setattr(h, "setter", wrapper_name); + Delattr(n, "memberset"); } /* Handle builtin operator overloads */ @@ -2585,9 +2595,9 @@ public: /* Handle comparison operators for builtin types */ String *compare = Getattr(n, "feature:pycompare"); if (compare) { - Hash *richcompare = Getattr(parent, "richcompare"); - assert(richcompare); - Setattr(richcompare, compare, wrapper_name); + Hash *richcompare = Getattr(parent, "richcompare"); + assert(richcompare); + Setattr(richcompare, compare, wrapper_name); } Delete(self_parse); @@ -2642,7 +2652,7 @@ public: int assignable = is_assignable(n); if (!builtin && shadow && !assignable && !in_class) - Printf(f_shadow_stubs, "%s = %s.%s\n", iname, global_name, iname); + Printf(f_shadow_stubs, "%s = %s.%s\n", iname, global_name, iname); String *getname = Swig_name_get(NSPACE_TODO, iname); String *setname = Swig_name_set(NSPACE_TODO, iname); @@ -2653,9 +2663,9 @@ public: if (assignable) { Setattr(n, "wrap:name", varsetname); if (builtin && in_class) { - String *set_wrapper = Swig_name_wrapper(setname); - Setattr(n, "builtin:setter", set_wrapper); - Delete(set_wrapper); + String *set_wrapper = Swig_name_wrapper(setname); + Setattr(n, "builtin:setter", set_wrapper); + Delete(set_wrapper); } Printf(setf->def, "SWIGINTERN int %s(PyObject *_val) {", varsetname); if ((tm = Swig_typemap_lookup("varin", n, name, 0))) { @@ -2717,8 +2727,7 @@ public: /* Now add this to the variable linking mechanism */ 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 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); } Delete(vargetname); @@ -3060,7 +3069,7 @@ public: * classHandler() * ------------------------------------------------------------ */ - String* add_explicit_scope (String *s) { + String *add_explicit_scope(String *s) { if (!Strstr(s, "::")) { String *ss = NewStringf("::%s", s); Delete(s); @@ -3082,20 +3091,6 @@ public: Delete(mname); } - virtual bool has_callable_dtor (Node *n, bool protected_ok = false) { - if (GetFlag(n, "private_dtor")) - return false; - if (!protected_ok && GetFlag(n, "protected_dtor")) - return false; - List *baselist = Getattr(n, "bases"); - if (!baselist || Len(baselist) == 0) - return true; - for (Iterator b = First(baselist); b.item; b = Next(b)) - if (!has_callable_dtor(b.item, true)) - return false; - return true; - } - void builtin_post_decl(File *f, Node *n) { String *name = Getattr(n, "name"); String *pname = Copy(name); @@ -3103,6 +3098,7 @@ public: String *symname = Getattr(n, "sym:name"); String *rname = add_explicit_scope(SwigType_namestr(name)); String *mname = SwigType_manglestr(rname); + String *pmname = SwigType_manglestr(pname); String *templ = NewStringf("SwigPyBuiltin_%s", mname); Printf(f_init, tab4 "builtin_pytype->ob_type = metatype;\n"); @@ -3130,18 +3126,19 @@ public: // 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 = NewString(""); - if (has_callable_dtor(n)) { - String *smartptr = Getattr(n, "feature:smartptr"); - Printf(tp_dealloc, "py_builtin_dealloc< %s >", smartptr ? smartptr : rname); + String *tp_dealloc = Getattr(n, "feature:tp_dealloc"); + if (tp_dealloc) { + Printf(f, "PYSWIG_DESTRUCTOR_CLOSURE(%s);\n", tp_dealloc); + tp_dealloc = NewStringf("%s_closure", tp_dealloc); } else { - Printv(tp_dealloc, "py_builtin_bad_dealloc", NIL); + tp_dealloc = NewString("py_builtin_bad_dealloc"); } String *getset_def = NewString(""); Printf(getset_def, "SWIGINTERN PyGetSetDef %s_getset[] = {\n", templ); - // All objects have a 'thisown' attribute + // All objects have 'this' and 'thisown' attributes + Printv(f_init, "PyDict_SetItemString(d, \"this\", this_descr);\n", NIL); Printv(f_init, "PyDict_SetItemString(d, \"thisown\", thisown_descr);\n", NIL); // Now, the rest of the attributes @@ -3151,14 +3148,17 @@ public: String *getter = Getattr(mgetset, "getter"); String *setter = Getattr(mgetset, "setter"); const char *getter_closure = getter ? "pyswig_getter_closure" : "0"; - const char *setter_closure = getter ? "pyswig_setter_closure" : "0"; + const char *setter_closure = setter ? "pyswig_setter_closure" : "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 = NewStringf("{ const_cast(\"%s\"), (getter) %s, (setter) %s, const_cast(\"%s.%s\"), (void*) &%s }\n", memname, getter_closure, setter_closure, name, memname, gspair); + String *entry = + NewStringf("{ const_cast(\"%s\"), (getter) %s, (setter) %s, const_cast(\"%s.%s\"), (void*) &%s }\n", memname, getter_closure, + setter_closure, name, memname, gspair); if (GetFlag(mgetset, "static")) { Printf(f, "static PyGetSetDef %s_def = %s;\n", gspair, entry); Printf(f_init, "static_getset = SwigPyStaticVar_new_getset(metatype, &%s_def);\n", gspair); - Printf(f_init, "PyDict_SetItemString(d, static_getset->d_getset->name, (PyObject*) static_getset);\n", memname); Printf(f_init, "Py_DECREF(static_getset);\n"); + Printf(f_init, "PyDict_SetItemString(d, static_getset->d_getset->name, (PyObject*) static_getset);\n", memname); + Printf(f_init, "Py_DECREF(static_getset);\n"); } else { Printf(getset_def, " %s,\n", entry); } @@ -3181,9 +3181,16 @@ public: Printf(f, " switch (op) {\n"); for (Iterator i = First(richcompare); i.item; i = Next(i)) Printf(f, " case %s : result = %s(self, tuple); break;\n", i.key, i.item); - Printv(f, " default : PyErr_Format(PyExc_TypeError, \"Cannot compare a(n) '%s' to a(n) '%s'\",", NIL); - Printv(f, " self->ob_type->tp_name, other ? other->ob_type->tp_name : \"NULL\");\n", NIL); + Printv(f, " default : break;\n", NIL); Printf(f, " }\n"); + Printv(f, " if (result == NULL) {\n", NIL); + Printv(f, " if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) {\n", NIL); + Printv(f, " result = SwigPyObject_richcompare((SwigPyObject*) self, (SwigPyObject*) other, op);\n", NIL); + Printv(f, " } else {\n", NIL); + Printv(f, " result = Py_NotImplemented;\n", NIL); + Printv(f, " Py_INCREF(result);\n", NIL); + Printv(f, " }\n", NIL); + Printv(f, " }\n", NIL); Printf(f, " Py_DECREF(tuple);\n"); Printf(f, " return result;\n"); Printf(f, "}\n\n"); @@ -3195,7 +3202,7 @@ public: // No instance dict for nondynamic objects if (GetFlag(n, "feature:python:nondynamic")) - Setattr(n, "feature:tp_setattro", "SWIG_Python_NonDynamicSetAttr"); + Setattr(n, "feature: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 *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES"); @@ -3317,7 +3324,7 @@ public: // PyBufferProcs as_buffer; Printf(f, " {\n"); 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, " (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, " },\n"); @@ -3329,19 +3336,29 @@ public: String *clientdata = NewString(""); Printf(clientdata, "&%s_clientdata", templ); - SwigType_remember_clientdata(pname, clientdata); + //SwigType_remember_clientdata(pname, clientdata); + SwigType_remember_mangleddata(pmname, clientdata); String *smartptr = Getattr(n, "feature:smartptr"); if (smartptr) { SwigType *spt = Swig_cparse_type(smartptr); SwigType *smart = SwigType_typedef_resolve_all(spt); SwigType_add_pointer(smart); - SwigType_remember_clientdata(smart, clientdata); + String *smart_pmname = SwigType_manglestr(smart); + //SwigType_remember_clientdata(smart, clientdata); + SwigType_remember_mangleddata(smart_pmname, clientdata); Delete(spt); Delete(smart); + Delete(smart_pmname); } - Printf(f, "SWIGINTERN SwigPyClientData %s_clientdata = {0, 0, 0, 0, 0, 0, (PyTypeObject*) &%s_type};\n\n", templ, templ); + String *clientdata_klass = NewString("0"); + if (GetFlag(n, "feature:implicitconv")) { + Clear(clientdata_klass); + Printf(clientdata_klass, "(PyObject*) &%s_type", templ); + } + + Printf(f, "SWIGINTERN SwigPyClientData %s_clientdata = {%s, 0, 0, 0, 0, 0, (PyTypeObject*) &%s_type};\n\n", templ, clientdata_klass, templ); Printv(f_init, " if (PyType_Ready(builtin_pytype) < 0) {\n", NIL); Printf(f_init, " PyErr_SetString(PyExc_TypeError, \"Couldn't create type '%s'\");\n", symname); @@ -3356,9 +3373,11 @@ public: Delete(rname); Delete(pname); Delete(mname); + Delete(pmname); Delete(templ); Delete(tp_dealloc); Delete(tp_flags); + Delete(clientdata_klass); } virtual int classHandler(Node *n) { @@ -3429,15 +3448,15 @@ public: } if (builtin) { - Hash *base_richcompare = NULL; - Hash *richcompare = NULL; - if (base_node) - base_richcompare = Getattr(base_node, "richcompare"); - if (base_richcompare) - richcompare = Copy(base_richcompare); - else - richcompare = NewHash(); - Setattr(n, "richcompare", richcompare); + Hash *base_richcompare = NULL; + Hash *richcompare = NULL; + if (base_node) + base_richcompare = Getattr(base_node, "richcompare"); + if (base_richcompare) + richcompare = Copy(base_richcompare); + else + richcompare = NewHash(); + Setattr(n, "richcompare", richcompare); } /* dealing with abstract base class */ @@ -3450,7 +3469,7 @@ public: } if (builtin) { - + } else { Printv(f_shadow, "class ", class_name, NIL); @@ -3526,9 +3545,6 @@ public: Printv(none_comparison, "$arg != Py_None", NIL); } - if (builtin) - Setattr(n, "feature:unref", "1"); - Language::classHandler(n); in_class = 0; @@ -3536,24 +3552,24 @@ public: /* Complete the class */ if (shadow) { /* Generate a class registration function */ - if (!builtin) { - String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers) - SwigType *smart = 0; - if (smartptr) { - SwigType *cpt = Swig_cparse_type(smartptr); - if (cpt) { - smart = SwigType_typedef_resolve_all(cpt); - Delete(cpt); - } else { - // TODO: report line number of where the feature comes from - Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, real_classname); - } + String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers) + SwigType *smart = 0; + if (smartptr) { + SwigType *cpt = Swig_cparse_type(smartptr); + if (cpt) { + smart = SwigType_typedef_resolve_all(cpt); + Delete(cpt); + } else { + // TODO: report line number of where the feature comes from + Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, real_classname); } - SwigType *ct = Copy(smart ? smart : real_classname); - SwigType_add_pointer(ct); - SwigType *realct = Copy(real_classname); - SwigType_add_pointer(realct); - SwigType_remember(realct); + } + SwigType *ct = Copy(smart ? smart : real_classname); + SwigType_add_pointer(ct); + SwigType *realct = Copy(real_classname); + SwigType_add_pointer(realct); + SwigType_remember(realct); + if (!builtin) { Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL); Printv(f_wrappers, " PyObject *obj;\n", NIL); if (modernargs) { @@ -3570,11 +3586,11 @@ public: " SWIG_TypeNewClientData(SWIGTYPE", SwigType_manglestr(ct), ", SWIG_NewClientData(obj));\n", " return SWIG_Py_Void();\n", "}\n\n", NIL); String *cname = NewStringf("%s_swigregister", class_name); add_method(cname, cname, 0); - Delete(smart); Delete(cname); - Delete(ct); - Delete(realct); } + Delete(smart); + Delete(ct); + Delete(realct); if (!have_constructor) { if (!builtin) Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined", @@ -3636,7 +3652,7 @@ public: Printf(f_shadow_file, "%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name); Printf(f_shadow_file, "%s_swigregister(%s)\n", class_name, class_name); } - + shadow_indent = 0; Printf(f_shadow_file, "%s\n", f_shadow_stubs); Clear(f_shadow_stubs); @@ -3697,27 +3713,21 @@ public: shadow = oldshadow; if (builtin && in_class) { - String *name = Getattr(n, "name"); - - // Can't use checkAttribute(n, "access", "public") because - // "access" attr isn't set on %extend methods - if (!checkAttribute(n, "access", "private") && - //!checkAttribute(n, "access", "protected") && - strncmp(Char(name), "operator ", 9) && - !Getattr(class_members, symname)) { - String *fullname = Swig_name_member(NULL, class_name, symname); - String *wname = Swig_name_wrapper(fullname); - Setattr(class_members, symname, n); - int allow_kwargs = check_kwargs(n); - Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_VARARGS%s, \"\" },\n", - symname, wname, allow_kwargs ? "|METH_KEYWORDS" : ""); - Delete(fullname); - Delete(wname); - } + // Can't use checkAttribute(n, "access", "public") because + // "access" attr isn't set on %extend methods + if (!checkAttribute(n, "access", "private") && strncmp(Char(symname), "operator ", 9) && !Getattr(class_members, symname)) { + String *fullname = Swig_name_member(NULL, class_name, symname); + String *wname = Swig_name_wrapper(fullname); + Setattr(class_members, symname, n); + int allow_kwargs = check_kwargs(n); + Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_VARARGS%s, \"\" },\n", symname, wname, allow_kwargs ? "|METH_KEYWORDS" : ""); + Delete(fullname); + Delete(wname); + } } if (!Getattr(n, "sym:nextSibling")) { - if (shadow && !builtin) { + if (shadow && !builtin) { int fproxy = fastproxy; if (Strcmp(symname, "__repr__") == 0) { have_repr = 1; @@ -3787,12 +3797,9 @@ public: Swig_restore(n); } - if (Getattr(n, "sym:nextSibling")) { - return SWIG_OK; - } - if (builtin && in_class) { - if (checkAttribute(n, "access", "public") && !Getattr(class_members, symname)) { + if ((GetFlagAttr(n, "feature:extend") || checkAttribute(n, "access", "public")) + && !Getattr(class_members, symname)) { String *fullname = Swig_name_member(NULL, class_name, symname); String *wname = Swig_name_wrapper(fullname); Setattr(class_members, symname, n); @@ -3802,7 +3809,14 @@ public: Delete(wname); Delete(pyflags); } - } else if (shadow) { + return SWIG_OK; + } + + if (Getattr(n, "sym:nextSibling")) { + return SWIG_OK; + } + + if (shadow) { if (!classic && !Getattr(n, "feature:python:callback") && have_addtofunc(n)) { int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; String *parms = make_pyParmList(n, false, false, kw); @@ -3881,102 +3895,102 @@ public: Swig_restore(n); if (!Getattr(n, "sym:nextSibling")) { - if (shadow) { - int allow_kwargs = (check_kwargs(n) && (!Getattr(n, "sym:overloaded"))) ? 1 : 0; - int handled_as_init = 0; - if (!have_constructor) { - String *nname = Getattr(n, "sym:name"); - String *sname = Getattr(getCurrentClass(), "sym:name"); - String *cname = Swig_name_construct(NSPACE_TODO, sname); - handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0); - Delete(cname); - } - - if (!have_constructor && handled_as_init) { - if (!builtin) { - if (Getattr(n, "feature:shadow")) { - String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); - String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); - Replaceall(pycode, "$action", pyaction); - Delete(pyaction); - Printv(f_shadow, pycode, "\n", NIL); - Delete(pycode); - } else { - String *pass_self = NewString(""); - Node *parent = Swig_methodclass(n); - String *classname = Swig_class_name(parent); - String *rclassname = Swig_class_name(getCurrentClass()); - assert(rclassname); - - - String *parms = make_pyParmList(n, true, false, allow_kwargs); - /* Pass 'self' only if using director */ - String *callParms = make_pyParmList(n, false, true, allow_kwargs); - - if (use_director) { - Insert(callParms, 0, "_self, "); - Printv(pass_self, tab8, NIL); - Printf(pass_self, "if self.__class__ == %s:\n", classname); - //Printv(pass_self, tab8, tab4, "args = (None,) + args\n", tab8, "else:\n", tab8, tab4, "args = (self,) + args\n", NIL); - Printv(pass_self, tab8, tab4, "_self = None\n", tab8, "else:\n", tab8, tab4, "_self = self\n", NIL); - } - - Printv(f_shadow, tab4, "def __init__(", parms, ")", returnTypeAnnotation(n), ": \n", NIL); - if (have_docstring(n)) - Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL); - if (have_pythonprepend(n)) - Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); - Printv(f_shadow, pass_self, NIL); - if (fastinit) { - Printv(f_shadow, tab8, module, ".", class_name, "_swiginit(self,", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), ")\n", NIL); - } else { - Printv(f_shadow, - tab8, "this = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", - tab8, "try: self.this.append(this)\n", tab8, "except: self.this = this\n", NIL); - } - if (have_pythonappend(n)) - Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n\n", NIL); - Delete(pass_self); - } - have_constructor = 1; - } - } else { - /* Hmmm. We seem to be creating a different constructor. We're just going to create a - function for it. */ - if (Getattr(n, "feature:shadow")) { - String *pycode = pythoncode(Getattr(n, "feature:shadow"), ""); - String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); - Replaceall(pycode, "$action", pyaction); - Delete(pyaction); - Printv(f_shadow_stubs, pycode, "\n", NIL); - Delete(pycode); - } else { - String *parms = make_pyParmList(n, false, false, allow_kwargs); - String *callParms = make_pyParmList(n, false, true, allow_kwargs); - - Printv(f_shadow_stubs, "\ndef ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); - if (have_docstring(n)) - Printv(f_shadow_stubs, tab4, docstring(n, AUTODOC_CTOR, tab4), "\n", NIL); - if (have_pythonprepend(n)) - Printv(f_shadow_stubs, pythoncode(pythonprepend(n), tab4), "\n", NIL); - String *subfunc = NULL; - /* - if (builtin) - subfunc = Copy(Getattr(getCurrentClass(), "sym:name")); - else - */ - subfunc = Swig_name_construct(NSPACE_TODO, symname); - Printv(f_shadow_stubs, tab4, "val = ", funcCall(subfunc, callParms), "\n", NIL); -#ifdef USE_THISOWN - Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL); -#endif - if (have_pythonappend(n)) - Printv(f_shadow_stubs, pythoncode(pythonappend(n), tab4), "\n", NIL); - Printv(f_shadow_stubs, tab4, "return val\n", NIL); - Delete(subfunc); - } - } + if (shadow) { + int allow_kwargs = (check_kwargs(n) && (!Getattr(n, "sym:overloaded"))) ? 1 : 0; + int handled_as_init = 0; + if (!have_constructor) { + String *nname = Getattr(n, "sym:name"); + String *sname = Getattr(getCurrentClass(), "sym:name"); + String *cname = Swig_name_construct(NSPACE_TODO, sname); + handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0); + Delete(cname); } + + if (!have_constructor && handled_as_init) { + if (!builtin) { + if (Getattr(n, "feature:shadow")) { + String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); + String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); + Replaceall(pycode, "$action", pyaction); + Delete(pyaction); + Printv(f_shadow, pycode, "\n", NIL); + Delete(pycode); + } else { + String *pass_self = NewString(""); + Node *parent = Swig_methodclass(n); + String *classname = Swig_class_name(parent); + String *rclassname = Swig_class_name(getCurrentClass()); + assert(rclassname); + + + String *parms = make_pyParmList(n, true, false, allow_kwargs); + /* Pass 'self' only if using director */ + String *callParms = make_pyParmList(n, false, true, allow_kwargs); + + if (use_director) { + Insert(callParms, 0, "_self, "); + Printv(pass_self, tab8, NIL); + Printf(pass_self, "if self.__class__ == %s:\n", classname); + //Printv(pass_self, tab8, tab4, "args = (None,) + args\n", tab8, "else:\n", tab8, tab4, "args = (self,) + args\n", NIL); + Printv(pass_self, tab8, tab4, "_self = None\n", tab8, "else:\n", tab8, tab4, "_self = self\n", NIL); + } + + Printv(f_shadow, tab4, "def __init__(", parms, ")", returnTypeAnnotation(n), ": \n", NIL); + if (have_docstring(n)) + Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL); + if (have_pythonprepend(n)) + Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL); + Printv(f_shadow, pass_self, NIL); + if (fastinit) { + Printv(f_shadow, tab8, module, ".", class_name, "_swiginit(self,", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), ")\n", NIL); + } else { + Printv(f_shadow, + tab8, "this = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", + tab8, "try: self.this.append(this)\n", tab8, "except: self.this = this\n", NIL); + } + if (have_pythonappend(n)) + Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n\n", NIL); + Delete(pass_self); + } + have_constructor = 1; + } + } else { + /* Hmmm. We seem to be creating a different constructor. We're just going to create a + function for it. */ + if (Getattr(n, "feature:shadow")) { + String *pycode = pythoncode(Getattr(n, "feature:shadow"), ""); + String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); + Replaceall(pycode, "$action", pyaction); + Delete(pyaction); + Printv(f_shadow_stubs, pycode, "\n", NIL); + Delete(pycode); + } else { + String *parms = make_pyParmList(n, false, false, allow_kwargs); + String *callParms = make_pyParmList(n, false, true, allow_kwargs); + + Printv(f_shadow_stubs, "\ndef ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); + if (have_docstring(n)) + Printv(f_shadow_stubs, tab4, docstring(n, AUTODOC_CTOR, tab4), "\n", NIL); + if (have_pythonprepend(n)) + Printv(f_shadow_stubs, pythoncode(pythonprepend(n), tab4), "\n", NIL); + String *subfunc = NULL; + /* + if (builtin) + subfunc = Copy(Getattr(getCurrentClass(), "sym:name")); + else + */ + subfunc = Swig_name_construct(NSPACE_TODO, symname); + Printv(f_shadow_stubs, tab4, "val = ", funcCall(subfunc, callParms), "\n", NIL); +#ifdef USE_THISOWN + Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL); +#endif + if (have_pythonappend(n)) + Printv(f_shadow_stubs, pythoncode(pythonappend(n), tab4), "\n", NIL); + Printv(f_shadow_stubs, tab4, "return val\n", NIL); + Delete(subfunc); + } + } + } } return SWIG_OK; } @@ -3987,11 +4001,14 @@ public: virtual int destructorHandler(Node *n) { if (builtin && in_class) { - if (checkAttribute(n, "access", "private")) - SetFlag(Swig_methodclass(n), "private_dtor"); - if (checkAttribute(n, "access", "protected")) - SetFlag(Swig_methodclass(n), "protected_dtor"); - return SWIG_OK; + Node *cls = Swig_methodclass(n); + if (!Getattr(cls, "feature:tp_dealloc")) { + String *dealloc = Swig_name_destroy(NSPACE_TODO, Getattr(cls, "sym:name")); + String *wdealloc = Swig_name_wrapper(dealloc); + Setattr(cls, "feature:tp_dealloc", wdealloc); + Delete(wdealloc); + Delete(dealloc); + } } String *symname = Getattr(n, "sym:name"); @@ -4144,19 +4161,19 @@ public: String *setter = Getattr(n, "builtin:setter"); Hash *h = NULL; if (getter || setter) { - h = Getattr(builtin_getset, symname); - if (!h) { - h = NewHash(); - Setattr(h, "static", "1"); - Setattr(builtin_getset, symname, h); - } + h = Getattr(builtin_getset, symname); + if (!h) { + h = NewHash(); + Setattr(h, "static", "1"); + Setattr(builtin_getset, symname, h); + } } if (getter) - Setattr(h, "getter", getter); + Setattr(h, "getter", getter); if (setter) - Setattr(h, "setter", setter); + Setattr(h, "setter", setter); if (h) - Delete(h); + Delete(h); Delete(mname); Delete(getname); Delete(wrapgetname); From 002598680e62b4dd505149f0d724b56450b62466 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Sun, 30 Jan 2011 04:13:58 +0000 Subject: [PATCH 12/56] This commit contains all changes to the regression tests which are necessitated by the -builtin option. Notes on individual tests follow. grouping_runme.py : 'cvar' syntax for class variables is obsolete. li_std_string_extra_runme.py : li_std_wstring_runme.py : Reverse binary operators (e.g., __radd__) are not supported. threads_exception_runme.py : director_exception_runme.py : exception_order_runme.py : Throwing wrapped objects as exceptions is not supported. default_constructor_runme.py : Redundant functional interface (e.g., 'module.new_Foo()' for 'module.Foo()') is not provided. python_nondynamic_runme.py : I believe that this test script doesn't actually test the %pythonnondynamic feature correctly, and I believe that the feature itself is implemented incorrectly. With the -builtin option, %pythonnondynamic *is* implemented correctly, and I have modified the test script to exercise it correctly. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12416 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../python/default_constructor_runme.py | 122 +++++++++++++----- .../python/director_exception_runme.py | 18 +-- .../python/exception_order_runme.py | 16 ++- Examples/test-suite/python/grouping_runme.py | 1 + .../python/li_std_string_extra_runme.py | 12 +- .../test-suite/python/li_std_wstring_runme.py | 12 +- .../python/python_nondynamic_runme.py | 6 +- .../python/threads_exception_runme.py | 4 +- 8 files changed, 134 insertions(+), 57 deletions(-) diff --git a/Examples/test-suite/python/default_constructor_runme.py b/Examples/test-suite/python/default_constructor_runme.py index 334eaa8af..60771c177 100644 --- a/Examples/test-suite/python/default_constructor_runme.py +++ b/Examples/test-suite/python/default_constructor_runme.py @@ -2,78 +2,123 @@ import _default_constructor dc = _default_constructor -a = dc.new_A() -dc.delete_A(a) +# Old static syntax not supported +#a = dc.new_A() +#dc.delete_A(a) +a = dc.A() +del a -aa = dc.new_AA() -dc.delete_AA(aa) +# Old static syntax not supported +#aa = dc.new_AA() +#dc.delete_AA(aa) +aa = dc.AA() +del aa try: - b = dc.new_B() + # Old static syntax not supported + #b = dc.new_B() + b = dc.B() print "Whoa. new_BB created." except: pass -del_b = dc.delete_B +# Old static syntax not supported. +# Swig builtin types have no tp_del entry (only tp_dealloc). +#del_b = dc.delete_B try: - bb = dc.new_BB(); + # Old static syntax not supported. + #bb = dc.new_BB(); + bb = dc.BB() print "Whoa. new_BB created." except: pass -del_bb = dc.delete_BB +# Old static syntax not supported. +# Swig builtin types have no tp_del entry (only tp_dealloc). +#del_bb = dc.delete_BB try: - c = dc.new_C() + # Old static syntax not supported + #c = dc.new_C() + c = dc.C() print "Whoa. new_C created." except: pass -del_c = dc.delete_C +# Old static syntax not supported. +# Swig builtin types have no tp_del entry (only tp_dealloc). +#del_c = dc.delete_C -cc = dc.new_CC() -dc.delete_CC(cc) +# Old static syntax not supported. +#cc = dc.new_CC() +#dc.delete_CC(cc) +cc = dc.CC() +del cc try: - d = dc.new_D(); + # Old static syntax not supported. + #d = dc.new_D(); + d = dc.D() print "Whoa. new_D created" except: pass -del_d = dc.delete_D +# Old static syntax not supported. +# Swig builtin types have no tp_del entry (only tp_dealloc). +#del_d = dc.delete_D try: - dd = dc.new_DD() + # Old static syntax not supported. + #dd = dc.new_DD() + dd = dc.DD() print "Whoa. new_DD created" except: pass -dd = dc.delete_DD +# Old static syntax not supported. +# Swig builtin types have no tp_del entry (only tp_dealloc). +#dd = dc.delete_DD try: - ad = dc.new_AD() + # Old static syntax not supported. + #ad = dc.new_AD() + ad = dc.AD() print "Whoa. new_AD created" except: pass -del_ad = dc.delete_AD +# Old static syntax not supported. +# Swig builtin types have no tp_del entry (only tp_dealloc). +#del_ad = dc.delete_AD -e = dc.new_E() -dc.delete_E(e) +# Old static syntax not supported. +#e = dc.new_E() +#dc.delete_E(e) +e = dc.E() +del e -ee = dc.new_EE() -dc.delete_EE(ee) +# Old static syntax not supported. +#ee = dc.new_EE() +#dc.delete_EE(ee) +ee = dc.EE() +del ee try: - eb = dc.new_EB() + # Old static syntax not supported. + #eb = dc.new_EB() + eb = dc.EB() print "Whoa. new_EB created" except: pass -del_eb = dc.delete_EB +# Old static syntax not supported. +# Swig builtin types have no tp_del entry (only tp_dealloc). +#del_eb = dc.delete_EB -f = dc.new_F() +# Old static syntax not supported. +#f = dc.new_F() +f = dc.F() try: del_f = dc.delete_F @@ -81,18 +126,27 @@ try: except AttributeError: pass -dc.F_destroy(f) +# Old static syntax not supported. +#dc.F_destroy(f) +f.destroy() + +# Old static syntax not supported. +#ff = dc.new_FFF() +ff = dc.FFF() -ff = dc.new_FFF() try: del_ff = dc.delete_FFF print "Whoa. delete_FFF created" except AttributeError: pass -dc.F_destroy(ff) +# Old static syntax not supported. +#dc.F_destroy(ff) +ff.destroy() -g = dc.new_G() +# Old static syntax not supported. +#g = dc.new_G() +g = dc.G() try: del_g = dc.delete_G @@ -100,11 +154,13 @@ try: except AttributeError: pass -dc.G_destroy(g) - -gg = dc.new_GG() -dc.delete_GG(gg) +dc.G.destroy(g) +# Old static syntax not supported. +#gg = dc.new_GG() +#dc.delete_GG(gg) +gg = dc.GG() +del gg import default_constructor hh = default_constructor.HH(1,1) diff --git a/Examples/test-suite/python/director_exception_runme.py b/Examples/test-suite/python/director_exception_runme.py index 82be1289b..6fb72da29 100644 --- a/Examples/test-suite/python/director_exception_runme.py +++ b/Examples/test-suite/python/director_exception_runme.py @@ -66,12 +66,14 @@ except MyException, e: if not ok: raise RuntimeError -try: - raise Exception2() -except Exception2: - pass +# Throwing builtin classes as exceptions not supported +#try: +# raise Exception2() +#except Exception2: +# pass -try: - raise Exception1() -except Exception1: - pass +# Throwing builtin classes as exceptions not supported +#try: +# raise Exception1() +#except Exception1: +# pass diff --git a/Examples/test-suite/python/exception_order_runme.py b/Examples/test-suite/python/exception_order_runme.py index 0b0b1c08d..4d74b9e7d 100644 --- a/Examples/test-suite/python/exception_order_runme.py +++ b/Examples/test-suite/python/exception_order_runme.py @@ -8,14 +8,18 @@ try: except E1,e: pass except: - raise RuntimeError, "bad exception order" + # Throwing builtin classes as exceptions not supported + #raise RuntimeError, "bad exception order" + pass try: a.bar() except E2,e: pass except: - raise RuntimeError, "bad exception order" + # Throwing builtin classes as exceptions not supported + #raise RuntimeError, "bad exception order" + pass try: a.foobar() @@ -31,11 +35,15 @@ try: except E1,e: pass except: - raise RuntimeError, "bad exception order" + # Throwing builtin classes as exceptions not supported + #raise RuntimeError, "bad exception order" + pass try: a.barfoo(2) except E2,e: pass except: - raise RuntimeError, "bad exception order" + # Throwing builtin classes as exceptions not supported + #raise RuntimeError, "bad exception order" + pass diff --git a/Examples/test-suite/python/grouping_runme.py b/Examples/test-suite/python/grouping_runme.py index 13f8c8c92..36f9b38de 100644 --- a/Examples/test-suite/python/grouping_runme.py +++ b/Examples/test-suite/python/grouping_runme.py @@ -11,3 +11,4 @@ if x != -37: raise RuntimeError grouping.cvar.test3 = 42 +grouping.test3 = 42 diff --git a/Examples/test-suite/python/li_std_string_extra_runme.py b/Examples/test-suite/python/li_std_string_extra_runme.py index cef5921b0..26ed05251 100644 --- a/Examples/test-suite/python/li_std_string_extra_runme.py +++ b/Examples/test-suite/python/li_std_string_extra_runme.py @@ -54,12 +54,14 @@ if a + b != "hello world": if a + " world" != "hello world": raise RuntimeError, "bad string mapping" -if "hello" + b != "hello world": - raise RuntimeError, "bad string mapping" +# Reverse operators not supported in builtin types +#if "hello" + b != "hello world": +# raise RuntimeError, "bad string mapping" -c = "hello" + b -if c.find_last_of("l") != 9: - raise RuntimeError, "bad string mapping" +# Reverse operators not supported in builtin types +#c = "hello" + b +#if c.find_last_of("l") != 9: +# raise RuntimeError, "bad string mapping" s = "hello world" diff --git a/Examples/test-suite/python/li_std_wstring_runme.py b/Examples/test-suite/python/li_std_wstring_runme.py index a4b9d3ee2..5605f0c92 100644 --- a/Examples/test-suite/python/li_std_wstring_runme.py +++ b/Examples/test-suite/python/li_std_wstring_runme.py @@ -53,12 +53,14 @@ if a + b != "hello world": if a + " world" != "hello world": raise RuntimeError, "bad string mapping" -if "hello" + b != "hello world": - raise RuntimeError, "bad string mapping" +# With -builtin option, no reverse binary operators +#if "hello" + b != "hello world": +# raise RuntimeError, "bad string mapping" -c = "hello" + b -if c.find_last_of("l") != 9: - raise RuntimeError, "bad string mapping" +# With -builtin option, no reverse binary operators +#c = "hello" + b +#if c.find_last_of("l") != 9: +# raise RuntimeError, "bad string mapping" s = "hello world" diff --git a/Examples/test-suite/python/python_nondynamic_runme.py b/Examples/test-suite/python/python_nondynamic_runme.py index 27755db9c..74d0aef0b 100644 --- a/Examples/test-suite/python/python_nondynamic_runme.py +++ b/Examples/test-suite/python/python_nondynamic_runme.py @@ -24,7 +24,11 @@ class B(python_nondynamic.A): bb = B() -bb.c = 3 + +# This is questionable. Trying to set B.c? That's not what it does. +# Should fail, I think, but it doesn't. +#bb.c = 3 + try: bb.d = 2 err = 0 diff --git a/Examples/test-suite/python/threads_exception_runme.py b/Examples/test-suite/python/threads_exception_runme.py index 9fbc6a9b2..bc48cbef5 100644 --- a/Examples/test-suite/python/threads_exception_runme.py +++ b/Examples/test-suite/python/threads_exception_runme.py @@ -19,7 +19,9 @@ except RuntimeError,e: raise RuntimeError try: - t.hosed() +# Throwing builtin classes as exceptions not supported +# t.hosed() + pass except threads_exception.Exc,e: if e.code != 42: raise RuntimeError From eb669d66c06b2b71dae56c94df7e6bb6f32e132f Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Sun, 30 Jan 2011 05:41:51 +0000 Subject: [PATCH 13/56] typecheck SWIGTYPE *const& has been fixed in Lib/typemaps/swigtype.swg, so remove the override here. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12418 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pytypemaps.swg | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Lib/python/pytypemaps.swg b/Lib/python/pytypemaps.swg index 119bf0e1e..aad9bacd7 100644 --- a/Lib/python/pytypemaps.swg +++ b/Lib/python/pytypemaps.swg @@ -68,12 +68,6 @@ * Python extra typemaps / typemap overrides * ------------------------------------------------------------ */ -%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) SWIGTYPE *const& { - void *vptr = 0; - int res = SWIG_ConvertPtr($input, &vptr, $*descriptor, 0); - $1 = SWIG_CheckState(res); -} - /* Get the address of the 'python self' object */ %typemap(in,numinputs=0,noblock=1) PyObject **PYTHON_SELF { From 00b5fa9c475d447dae5668bfba978f3085c6a4ac Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Wed, 2 Feb 2011 10:28:46 +0000 Subject: [PATCH 14/56] Now passes regressions with '-O -builtin'. Almost all changes are to accomodate -fastunpack. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12423 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/builtin.swg | 39 +++++++ Source/Modules/python.cxx | 214 +++++++++++++++++++++++++++----------- 2 files changed, 190 insertions(+), 63 deletions(-) diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index 15eaf1d9b..7894240e3 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -108,6 +108,16 @@ wrapper##_closure (PyObject *a, Py_ssize_t b) \ return result; \ } +#define PYSWIG_FUNPACK_SSIZEARGFUNC_CLOSURE(wrapper) \ +SWIGINTERN PyObject* \ +wrapper##_closure (PyObject *a, Py_ssize_t b) \ +{ \ + PyObject *arg = _PyLong_FromSsize_t(b); \ + PyObject *result = wrapper(a, arg); \ + Py_DECREF(arg); \ + return result; \ +} + #define PYSWIG_SSIZEOBJARGPROC_CLOSURE(wrapper) \ SWIGINTERN int \ wrapper##_closure (PyObject *a, Py_ssize_t b, PyObject *c) \ @@ -179,6 +189,18 @@ pyswig_getter_closure (PyObject *obj, void *closure) return result; } +SWIGRUNTIME PyObject* +pyswig_funpack_getter_closure (PyObject *obj, void *closure) +{ + if (!closure) + return SWIG_Py_Void(); + SwigPyGetSet *getset = (SwigPyGetSet*) closure; + if (!getset->get) + return SWIG_Py_Void(); + PyObject *result = (*getset->get)(obj, NULL); + return result; +} + SWIGRUNTIME int pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure) { @@ -201,6 +223,23 @@ pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure) return result ? 0 : -1; } +SWIGRUNTIME int +pyswig_funpack_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 member variable assignment in type '%.300s'", obj->ob_type->tp_name); + return -1; + } + PyObject *result = (*getset->set)(obj, val); + Py_XDECREF(result); + return result ? 0 : -1; +} + SWIGRUNTIME PyObject* pyswig_static_getter_closure (PyObject *obj, void *closure) { diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 9f1b1d0e6..8df00fae8 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -170,7 +170,7 @@ static String *getSlot(Node *n, const char *key) { return val ? val : slot_default; } -static String *getClosure(String *functype, String *wrapper) { +static String *getClosure(String *functype, String *wrapper, int funpack = 0) { static const char *functypes[] = { "unaryfunc", "PYSWIG_UNARYFUNC_CLOSURE", "destructor", "PYSWIG_DESTRUCTOR_CLOSURE", @@ -188,13 +188,36 @@ static String *getClosure(String *functype, String *wrapper) { NULL }; + static const char *funpack_functypes[] = { + "unaryfunc", "PYSWIG_UNARYFUNC_CLOSURE", + "destructor", "PYSWIG_DESTRUCTOR_CLOSURE", + "inquiry", "PYSWIG_INQUIRY_CLOSURE", + "getiterfunc", "PYSWIG_UNARYFUNC_CLOSURE", + "iternextfunc", "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", + NULL + }; + if (!functype) return NULL; char *c = Char(functype); int i; - for (i = 0; functypes[i] != NULL; i += 2) { - if (!strcmp(c, functypes[i])) - return NewStringf("%s(%s)", functypes[i + 1], wrapper); + if (funpack) { + for (i = 0; funpack_functypes[i] != NULL; i += 2) { + if (!strcmp(c, funpack_functypes[i])) + return NewStringf("%s(%s)", funpack_functypes[i + 1], wrapper); + } + } else { + for (i = 0; functypes[i] != NULL; i += 2) { + if (!strcmp(c, functypes[i])) + return NewStringf("%s(%s)", functypes[i + 1], wrapper); + } } return NULL; } @@ -1784,9 +1807,19 @@ public: * add_method() * ------------------------------------------------------------ */ - void add_method(String *name, String *function, int kw, Node *n = 0, int = 0, int = -1, int = -1) { + void add_method(String *name, String *function, int kw, Node *n = 0, int funpack= 0, int num_required= -1, int num_arguments = -1) { if (!kw) { - Printf(methods, "\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function); + if (n && funpack) { + if (num_required == 0 && num_arguments == 0) { + Printf(methods, "\t { (char *)\"%s\", (PyCFunction)%s, METH_NOARGS, ", name, function); + } else if (num_required == 1 && num_arguments == 1) { + Printf(methods, "\t { (char *)\"%s\", (PyCFunction)%s, METH_O, ", name, function); + } else { + Printf(methods, "\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function); + } + } else { + Printf(methods, "\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function); + } } else { Printf(methods, "\t { (char *)\"%s\", (PyCFunction) %s, METH_VARARGS | METH_KEYWORDS, ", name, function); } @@ -1819,9 +1852,11 @@ public: /* ------------------------------------------------------------ * dispatchFunction() * ------------------------------------------------------------ */ - void dispatchFunction(Node *n, String *linkage, int funpack = 0, bool return_int = false, bool add_self = false, bool addmeth = true) { + void dispatchFunction(Node *n, String *linkage, int funpack = 0, bool builtin_self = false, bool builtin_ctor = false, bool director_class = false) { /* Last node in overloaded chain */ + bool add_self = builtin_self && (!builtin_ctor || director_class); + int maxargs; String *tmp = NewString(""); @@ -1840,7 +1875,7 @@ public: String *symname = Getattr(n, "sym:name"); String *wname = Swig_name_wrapper(symname); - Printv(f->def, linkage, return_int ? "int " : "PyObject *", wname, "(PyObject *self, PyObject *args) {", NIL); + Printv(f->def, linkage, builtin_ctor ? "int " : "PyObject *", wname, "(PyObject *self, PyObject *args) {", NIL); Wrapper_add_local(f, "argc", "int argc"); Printf(tmp, "PyObject *argv[%d]", maxargs + 1); @@ -1860,8 +1895,11 @@ public: Append(f->code, "argc++;\n"); } else { String *iname = Getattr(n, "sym:name"); - Printf(f->code, "if (!(argc = SWIG_Python_UnpackTuple(args,\"%s\",0,%d,argv))) SWIG_fail;\n", iname, maxargs); - Append(f->code, "--argc;\n"); + Printf(f->code, "if (!(argc = SWIG_Python_UnpackTuple(args,\"%s\",0,%d,argv%s))) SWIG_fail;\n", iname, maxargs, add_self ? "+1" : ""); + if (add_self) + Append(f->code, "argv[0] = self;\n"); + else + Append(f->code, "--argc;\n"); } Replaceall(dispatch, "$args", "self,args"); @@ -1883,13 +1921,13 @@ public: Append(f->code, "fail:\n"); Printf(f->code, "SWIG_SetErrorMsg(PyExc_NotImplementedError," "\"Wrong number or type of arguments for overloaded function '%s'.\\n\"" "\n\" Possible C/C++ prototypes are:\\n\"%s);\n", symname, protoTypes); - Printf(f->code, "return %s;\n", return_int ? "-1" : "0"); + Printf(f->code, "return %s;\n", builtin_ctor ? "-1" : "0"); Delete(protoTypes); } Printv(f->code, "}\n", NIL); Wrapper_print(f, f_wrappers); Node *p = Getattr(n, "sym:previousSibling"); - if (addmeth) + if (!builtin_self) add_method(symname, wname, 0, p); /* Create a shadow for this function (if enabled and not in a member function) */ @@ -1906,6 +1944,24 @@ public: * functionWrapper() * ------------------------------------------------------------ */ + /* + A note about argument marshalling with built-in types. + There are three distinct cases for member (non-static) methods: + + 1) An ordinary member function. In this case, the first param in + the param list is 'this'. For builtin types, 'this' is taken from + the first argument to the wrapper (usually called 'self); it's not + extracted from the second argument (which is usually a tuple). + + 2) A constructor for a non-director class. In this case, the + param list doesn't contain an entry for 'this', but the first ('self') + argument to the wrapper *does* contain the newly-allocated, + uninitialized object. + + 3) A constructor for a director class. In this case, the param + list contains a 'self' param, which comes from the first argument + to the wrapper function. + */ const char *get_implicitconv_flag(Node *klass) { int conv = 0; @@ -1973,16 +2029,13 @@ public: builtin_ctor = true; } bool director_class = (getCurrentClass() && Swig_directorclass(getCurrentClass())); + bool add_self = builtin_self && (!builtin_ctor || director_class); bool builtin_getter = (builtin && GetFlag(n, "memberget")); bool builtin_setter = (builtin && GetFlag(n, "memberset") && !builtin_getter); char const *self_param = builtin_self ? "self" : "SWIGUNUSEDPARM(self)"; char const *wrap_return = builtin_ctor ? "int " : "PyObject *"; String *linkage = NewString("SWIGINTERN "); String *wrapper_name = Swig_name_wrapper(iname); - String *slot = Getattr(n, "feature:pyslot"); - String *closure_decl = NULL; - if (slot) - closure_decl = getClosure(Getattr(n, "feature:pyslot:functype"), wrapper_name); if (Getattr(n, "sym:overloaded")) { overname = Getattr(n, "sym:overname"); @@ -2016,7 +2069,7 @@ public: /* Get number of required and total arguments */ tuple_arguments = num_arguments = emit_num_arguments(l); tuple_required = num_required = emit_num_required(l); - if (builtin_self && (!builtin_ctor || (builtin_ctor && director_class))) { + if (add_self) { --tuple_arguments; --tuple_required; } @@ -2029,7 +2082,7 @@ public: Append(wname, overname); } - if (!allow_kwargs || Getattr(n, "sym:overloaded")) { + if (!allow_kwargs || overname) { if (!varargs) { Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL); } else { @@ -2056,8 +2109,15 @@ public: } int funpack = modernargs && fastunpack && !varargs && !allow_kwargs; - int noargs = funpack && (num_required == 0 && num_arguments == 0); - int onearg = funpack && (num_required == 1 && num_arguments == 1); + int noargs = funpack && (tuple_required == 0 && tuple_arguments == 0); + 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"); + } /* Generate code for argument marshalling */ if (funpack) { @@ -2093,16 +2153,10 @@ public: Delete(tmp_none_comparison); } - if (builtin_self && !builtin_ctor) - Printf(self_parse, "%s = self;\n", funpack ? "swig_obj[0]" : "obj0"); - - if (builtin_ctor && director_class) - Printv(self_parse, funpack ? "swig_obj[1]" : "obj1", " = self;\n", NIL); - int use_parse = 0; Append(kwargs, "{"); for (i = 0, p = l; i < num_arguments; i++) { - bool parse_from_tuple = (i > 0 || !builtin_self || (builtin_ctor && !director_class)); + bool parse_from_tuple = (i > 0 || !add_self); while (checkAttribute(p, "tmap:in:numinputs", "0")) { p = Getattr(p, "tmap:in:next"); } @@ -2110,8 +2164,10 @@ public: SwigType *pt = Getattr(p, "type"); String *pn = Getattr(p, "name"); String *ln = Getattr(p, "lname"); - if (funpack) - sprintf(source, "swig_obj[%d]", builtin_ctor ? i + 1 : i); + if (!parse_from_tuple) + sprintf(source, "self"); + else if (funpack) + sprintf(source, "swig_obj[%d]", add_self && !overname ? i - 1 : i); else sprintf(source, "obj%d", builtin_ctor ? i + 1 : i); @@ -2141,7 +2197,9 @@ public: if ((tm = Getattr(p, "tmap:in"))) { String *parse = Getattr(p, "tmap:in:parse"); if (!parse) { - if (funpack) { + if (builtin_self) { + Replaceall(tm, "$self", "self"); + } else if (funpack) { Replaceall(tm, "$self", "swig_obj[0]"); } else { Replaceall(tm, "$self", "obj0"); @@ -2167,14 +2225,11 @@ public: Setattr(p, "implicitconv", convflag); } - bool parse_from_tuple = (i > 0 || !builtin_self || (builtin_ctor && !director_class)); - if (parse_from_tuple) Putc('O', parse_args); - if (!funpack) { + if (!funpack && parse_from_tuple) { Wrapper_add_localv(f, source, "PyObject *", source, "= 0", NIL); - if (parse_from_tuple) - Printf(arglist, "&%s", source); + Printf(arglist, "&%s", source); } if (i >= num_required) Printv(get_pointers, "if (", source, ") {\n", NIL); @@ -2227,13 +2282,13 @@ public: } else { Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL); } - if (onearg) { + if (onearg && !builtin_ctor) { Printf(parse_args, "if (!args) SWIG_fail;\n"); - Printf(parse_args, "swig_obj[0] = args;\n"); + Append(parse_args, "swig_obj[0] = args;\n"); } else if (!noargs) { - Printf(parse_args, "if (!SWIG_Python_UnpackTuple(args,\"%s\",%d,%d,swig_obj)) SWIG_fail;\n", iname, num_required, num_arguments); + Printf(parse_args, "if (!SWIG_Python_UnpackTuple(args,\"%s\",%d,%d,swig_obj)) SWIG_fail;\n", iname, tuple_required, tuple_arguments); } else if (noargs) { - Printf(parse_args, "if (!SWIG_Python_UnpackTuple(args,\"%s\",%d,%d,0)) SWIG_fail;\n", iname, num_required, num_arguments); + Printf(parse_args, "if (!SWIG_Python_UnpackTuple(args,\"%s\",%d,%d,0)) SWIG_fail;\n", iname, tuple_required, tuple_arguments); } } } else if (tuple_arguments > 0) { @@ -2334,9 +2389,11 @@ public: } Wrapper_add_local(f, "upcall", "bool upcall = false"); if (funpack) { - Append(f->code, "upcall = (director && (director->swig_get_self()==swig_obj[0]));\n"); + const char *self_parm = builtin_self ? "self" : "swig_obj[0]"; + Printf(f->code, "upcall = (director && (director->swig_get_self()==%s));\n", self_parm); } else { - Append(f->code, "upcall = (director && (director->swig_get_self()==obj0));\n"); + const char *self_parm = builtin_self ? "self" : "obj0"; + Printf(f->code, "upcall = (director && (director->swig_get_self()==%s));\n", self_parm); } } @@ -2377,7 +2434,9 @@ public: } if (tm) { - if (funpack) { + if (builtin_self) { + Replaceall(tm, "$self", "self"); + } else if (funpack) { Replaceall(tm, "$self", "swig_obj[0]"); } else { Replaceall(tm, "$self", "obj0"); @@ -2501,7 +2560,9 @@ public: Replaceall(f->code, "$symname", iname); Replaceall(f->code, "$result", "resultobj"); - if (funpack) { + if (builtin_self) { + Replaceall(f->code, "$self", "self"); + } else if (funpack) { Replaceall(f->code, "$self", "swig_obj[0]"); } else { Replaceall(f->code, "$self", "obj0"); @@ -2539,9 +2600,7 @@ public: } } else { if (!Getattr(n, "sym:nextSibling")) { - dispatchFunction(n, linkage, funpack, builtin_ctor, // return_int - builtin_self && (!builtin_ctor || director_class), // add_self - !builtin_self); // addmeth + dispatchFunction(n, linkage, funpack, builtin_self, builtin_ctor, director_class); } } @@ -2579,13 +2638,16 @@ public: } /* Handle builtin operator overloads */ + String *slot = Getattr(n, "feature:pyslot"); if (slot) { + String *closure_decl = getClosure(Getattr(n, "feature:pyslot:functype"), wrapper_name, overname ? 0 : funpack); String *feature_name = NewStringf("feature:%s", slot); String *closure_name = Copy(wrapper_name); if (closure_decl) { if (!Getattr(n, "sym:overloaded") || !Getattr(n, "sym:nextSibling")) Printv(f_wrappers, closure_decl, "\n\n", NIL); Append(closure_name, "_closure"); + Delete(closure_decl); } Setattr(parent, feature_name, closure_name); Delete(feature_name); @@ -2611,8 +2673,6 @@ public: Delete(wname); DelWrapper(f); Delete(wrapper_name); - if (closure_decl) - Delete(closure_decl); return SWIG_OK; } @@ -3100,6 +3160,7 @@ public: String *mname = SwigType_manglestr(rname); String *pmname = SwigType_manglestr(pname); String *templ = NewStringf("SwigPyBuiltin_%s", mname); + int funpack = modernargs && fastunpack; Printf(f_init, tab4 "builtin_pytype->ob_type = metatype;\n"); Printf(f_init, tab4 "builtin_pytype->tp_new = PyType_GenericNew;\n"); @@ -3147,8 +3208,8 @@ public: Hash *mgetset = member_iter.item; String *getter = Getattr(mgetset, "getter"); String *setter = Getattr(mgetset, "setter"); - const char *getter_closure = getter ? "pyswig_getter_closure" : "0"; - const char *setter_closure = setter ? "pyswig_setter_closure" : "0"; + 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"; 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 = @@ -3174,13 +3235,15 @@ public: Printf(f, "%s_richcompare (PyObject *self, PyObject *other, int op)\n", templ); Printf(f, "{\n"); Printf(f, " PyObject *result = NULL;\n"); - Printf(f, " PyObject *tuple = PyTuple_New(1);\n"); - Printf(f, " assert(tuple);\n"); - Printf(f, " PyTuple_SET_ITEM(tuple, 0, other);\n"); - Printf(f, " Py_XINCREF(other);\n"); + if (!funpack) { + Printf(f, " PyObject *tuple = PyTuple_New(1);\n"); + Printf(f, " assert(tuple);\n"); + Printf(f, " PyTuple_SET_ITEM(tuple, 0, other);\n"); + Printf(f, " Py_XINCREF(other);\n"); + } Printf(f, " switch (op) {\n"); for (Iterator i = First(richcompare); i.item; i = Next(i)) - Printf(f, " case %s : result = %s(self, tuple); break;\n", i.key, i.item); + Printf(f, " case %s : result = %s(self, %s); break;\n", i.key, i.item, funpack ? "other" : "tuple"); Printv(f, " default : break;\n", NIL); Printf(f, " }\n"); Printv(f, " if (result == NULL) {\n", NIL); @@ -3191,7 +3254,8 @@ public: Printv(f, " Py_INCREF(result);\n", NIL); Printv(f, " }\n", NIL); Printv(f, " }\n", NIL); - Printf(f, " Py_DECREF(tuple);\n"); + if (!funpack) + Printf(f, " Py_DECREF(tuple);\n"); Printf(f, " return result;\n"); Printf(f, "}\n\n"); @@ -3705,6 +3769,9 @@ public: String *symname = Getattr(n, "sym:name"); int oldshadow; + if (builtin) + Swig_save("builtin_memberfunc", n, "noargs", "onearg", NIL); + /* Create the default member function */ oldshadow = shadow; /* Disable shadowing when wrapping member functions */ if (shadow) @@ -3719,13 +3786,23 @@ public: String *fullname = Swig_name_member(NULL, class_name, symname); String *wname = Swig_name_wrapper(fullname); Setattr(class_members, symname, n); - int allow_kwargs = check_kwargs(n); - Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_VARARGS%s, \"\" },\n", symname, wname, allow_kwargs ? "|METH_KEYWORDS" : ""); + 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); + } else { + Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_VARARGS, \"\" },\n", symname, wname); + } Delete(fullname); Delete(wname); } } + if (builtin) + Swig_restore(n); + if (!Getattr(n, "sym:nextSibling")) { if (shadow && !builtin) { int fproxy = fastproxy; @@ -3782,6 +3859,7 @@ public: return SWIG_OK; } + /* ------------------------------------------------------------ * staticmemberfunctionHandler() * ------------------------------------------------------------ */ @@ -3803,7 +3881,14 @@ public: String *fullname = Swig_name_member(NULL, class_name, symname); String *wname = Swig_name_wrapper(fullname); Setattr(class_members, symname, n); - String *pyflags = NewString("METH_VARARGS|METH_STATIC"); + int funpack = modernargs && fastunpack && !Getattr(n, "sym:overloaded"); + String *pyflags = NewString("METH_STATIC|"); + if (funpack && GetFlagAttr(n, "noargs")) + Append(pyflags, "METH_NOARGS"); + else if (funpack && GetFlagAttr(n, "onearg")) + Append(pyflags, "METH_O"); + else + Append(pyflags, "METH_VARARGS"); Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", symname, wname, pyflags); Delete(fullname); Delete(wname); @@ -4132,16 +4217,19 @@ public: DelWrapper(f); int assignable = is_assignable(n); if (assignable) { + int funpack = modernargs && fastunpack; Wrapper *f = NewWrapper(); Printv(f->def, "SWIGINTERN PyObject *", wrapsetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); - Wrapper_add_local(f, "value", "PyObject *value"); Wrapper_add_local(f, "res", "int res"); - Append(f->code, "if (!PyArg_ParseTuple(args,(char *)\"O:set\",&value)) return NULL;\n"); - Printv(f->code, "res = ", varsetname, "(value);\n", NIL); + if (!funpack) { + Wrapper_add_local(f, "value", "PyObject *value"); + Append(f->code, "if (!PyArg_ParseTuple(args,(char *)\"O:set\",&value)) return NULL;\n"); + } + Printf(f->code, "res = %s(%s);\n", varsetname, funpack ? "args" : "value"); Append(f->code, "return !res ? SWIG_Py_Void() : NULL;\n"); Append(f->code, "}\n"); Wrapper_print(f, f_wrappers); - add_method(setname, wrapsetname, 0); + add_method(setname, wrapsetname, 0, 0, funpack, 1, 1); DelWrapper(f); } if (!modern && !builtin) { From 62fef1bf99a5fd9fd2adad2ae299b64eebf9f0a3 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Thu, 3 Feb 2011 07:21:37 +0000 Subject: [PATCH 15/56] python3 support; passes all regressions. Adding argcargvtest_runme3.py, because 2to3 can't handle it. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12425 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../test-suite/python/argcargvtest_runme3.py | 27 +++++++++++ Lib/python/builtin.swg | 46 ++++++++++++++++--- Lib/python/pycontainer.swg | 24 ++++++++-- Lib/python/pyhead.swg | 6 +++ Lib/python/pyrun.swg | 10 ++-- Source/Modules/python.cxx | 43 +++++++++++++++++ 6 files changed, 143 insertions(+), 13 deletions(-) create mode 100644 Examples/test-suite/python/argcargvtest_runme3.py diff --git a/Examples/test-suite/python/argcargvtest_runme3.py b/Examples/test-suite/python/argcargvtest_runme3.py new file mode 100644 index 000000000..047ea9551 --- /dev/null +++ b/Examples/test-suite/python/argcargvtest_runme3.py @@ -0,0 +1,27 @@ +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/Lib/python/builtin.swg b/Lib/python/builtin.swg index 7894240e3..bba988dd4 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -289,9 +289,15 @@ SwigPyStaticVar_dealloc(PyDescrObject *descr) SWIGRUNTIME PyObject * SwigPyStaticVar_repr(PyGetSetDescrObject *descr) { - return PyString_FromFormat("", - PyString_AsString(descr->d_name), - descr->d_type->tp_name); +#if PY_VERSION_HEX >= 0x03000000 + 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 } SWIGRUNTIME int @@ -307,10 +313,15 @@ SwigPyStaticVar_get (PyGetSetDescrObject *descr, PyObject *obj, PyObject *type) { if (descr->d_getset->get != NULL) return descr->d_getset->get(obj, descr->d_getset->closure); +#if PY_VERSION_HEX >= 0x03000000 + PyErr_Format(PyExc_AttributeError, + "attribute '%.300U' of '%.100s' objects is not readable", + descr->d_name, descr->d_type->tp_name); +#else PyErr_Format(PyExc_AttributeError, "attribute '%.300s' of '%.100s' objects is not readable", - PyString_AsString(descr->d_name), - descr->d_type->tp_name); + PyString_AsString(descr->d_name), descr->d_type->tp_name); +#endif return NULL; } @@ -321,16 +332,27 @@ SwigPyStaticVar_set (PyGetSetDescrObject *descr, PyObject *obj, PyObject *value) if (descr->d_getset->set != NULL) return descr->d_getset->set(obj, value, descr->d_getset->closure); +#if PY_VERSION_HEX >= 0x03000000 + PyErr_Format(PyExc_AttributeError, + "attribute '%.300U' of '%.100s' objects is not writable", + descr->d_name, + descr->d_type->tp_name); +#else PyErr_Format(PyExc_AttributeError, "attribute '%.300s' of '%.100s' objects is not writable", PyString_AsString(descr->d_name), descr->d_type->tp_name); +#endif return -1; } SWIGRUNTIME PyTypeObject SwigPyStaticVar_Type = { +#if PY_VERSION_HEX >= 0x03000000 + PyVarObject_HEAD_INIT(&PyType_Type, 0) +#else PyObject_HEAD_INIT(&PyType_Type) 0, +#endif "swig_static_var_getset_descriptor", sizeof(PyGetSetDescrObject), 0, @@ -349,7 +371,7 @@ SWIGRUNTIME PyTypeObject SwigPyStaticVar_Type = { PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_HAVE_CLASS, /* tp_flags */ 0, /* tp_doc */ SwigPyStaticVar_traverse, /* tp_traverse */ 0, /* tp_clear */ @@ -375,13 +397,25 @@ SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value) descrsetfunc local_set = attribute->ob_type->tp_descr_set; if (local_set != NULL) return local_set(attribute, (PyObject*) type, value); +#if PY_VERSION_HEX >= 0x03000000 + PyErr_Format(PyExc_AttributeError, + "cannot modify read-only attribute '%.50s.%.400U'", + type->tp_name, name); +#else PyErr_Format(PyExc_AttributeError, "cannot modify read-only attribute '%.50s.%.400s'", type->tp_name, PyString_AS_STRING(name)); +#endif } else { +#if PY_VERSION_HEX >= 0x03000000 + PyErr_Format(PyExc_AttributeError, + "type '%.50s' has no attribute '%.400U'", + type->tp_name, name); +#else PyErr_Format(PyExc_AttributeError, "type '%.50s' has no attribute '%.400s'", type->tp_name, PyString_AS_STRING(name)); +#endif } return -1; diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg index 29d9b4dab..4878f66c7 100644 --- a/Lib/python/pycontainer.swg +++ b/Lib/python/pycontainer.swg @@ -634,10 +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", "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__; #endif // SWIGPYTHON_BUILTIN %extend { @@ -651,6 +653,9 @@ namespace swig /* typemap for slice object support */ %typemap(in) PySliceObject* { + if (!PySlice_Check($input)) { + %argument_fail(SWIG_TypeError, "$type", $symname, $argnum); + } $1 = (PySliceObject *) $input; } %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) PySliceObject* { @@ -699,6 +704,17 @@ namespace swig swig::setslice(self, i, j, v); } + void __setitem__(PySliceObject *slice) + throw (std::out_of_range) { + Py_ssize_t i, j, step; + if( !PySlice_Check(slice) ) { + SWIG_Error(SWIG_TypeError, "Slice object expected."); + return; + } + PySlice_GetIndices(slice, self->size(), &i, &j, &step); + swig::delslice(self, i,j); + } + void __delitem__(PySliceObject *slice) throw (std::out_of_range) { Py_ssize_t i, j, step; diff --git a/Lib/python/pyhead.swg b/Lib/python/pyhead.swg index 2edbf631f..c7f897f78 100644 --- a/Lib/python/pyhead.swg +++ b/Lib/python/pyhead.swg @@ -5,7 +5,13 @@ #define PyInt_Check(x) PyLong_Check(x) #define PyInt_AsLong(x) PyLong_AsLong(x) #define PyInt_FromLong(x) PyLong_FromLong(x) +#define PyString_FromString(x) PyUnicode_FromString(x) #define PyString_Format(fmt, args) PyUnicode_Format(fmt, args) +#define PyString_InternFromString(key) PyUnicode_InternFromString(key) +#define PyString_Check(name) PyUnicode_Check(name) +#define Py_TPFLAGS_HAVE_CLASS Py_TPFLAGS_BASETYPE +#define PyString_AS_STRING(x) PyUnicode_AS_STRING(x) +#define _PyLong_FromSsize_t(x) PyLong_FromSsize_t(x) #endif diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index aa3c6d24a..f1857fe27 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1729,12 +1729,16 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) descr = _PyType_Lookup(tp, name); f = NULL; - if (descr != NULL && PyType_HasFeature(descr->ob_type, Py_TPFLAGS_HAVE_CLASS)) + if (descr != NULL) f = descr->ob_type->tp_descr_set; if (f == NULL) PyErr_Format(PyExc_AttributeError, - "'%.100s' object has no attribute '%.200s'", - tp->tp_name, PyString_AS_STRING(name)); +#if PY_VERSION_HEX >= 0x03000000 + "'%.100s' object has no attribute '%.200U'", +#else + "'%.100s' object has no attribute '%.200S'", +#endif + tp->tp_name, name); else res = f(descr, obj, value); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 8df00fae8..16385d798 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -3162,7 +3162,11 @@ public: String *templ = NewStringf("SwigPyBuiltin_%s", mname); 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"); + Printv(f_init, "#else\n", NIL); Printf(f_init, tab4 "builtin_pytype->ob_type = metatype;\n"); + Printv(f_init, "#endif\n", NIL); Printf(f_init, tab4 "builtin_pytype->tp_new = PyType_GenericNew;\n"); List *baselist = Getattr(n, "bases"); if (baselist) { @@ -3270,14 +3274,19 @@ public: char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : Swig_directorclass(n) ? "0" : "py_builtin_bad_init"; 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"); + 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")); @@ -3296,7 +3305,11 @@ public: Printf(f, " %s, /*tp_getattro*/\n", getSlot(n, "feature:tp_getattro")); Printf(f, " %s, /*tp_setattro*/\n", getSlot(n, "feature:tp_setattro")); 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); + Printv(f, "#else\n", NIL); Printf(f, " %s, /*tp_flags*/\n", 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")); @@ -3324,7 +3337,9 @@ public: 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")); + Printv(f, "#if PY_VERSION_HEX < 0x03000000\n", NIL); Printf(f, " (binaryfunc) %s, // nb_divide;\n", getSlot(n, "feature:nb_divide")); + 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")); @@ -3338,16 +3353,26 @@ public: 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")); + Printv(f, "#if PY_VERSION_HEX < 0x03000000\n", NIL); Printf(f, " (coercion) %s, // nb_coerce;\n", getSlot(n, "feature:nb_coerce")); + Printv(f, "#endif\n", NIL); Printf(f, " (unaryfunc) %s, // nb_int;\n", getSlot(n, "feature:nb_int")); + Printv(f, "#if PY_VERSION_HEX >= 0x03000000\n", NIL); + Printf(f, " (void*) %s, // nb_reserved;\n", getSlot(n, "feature:nb_reserved")); + Printv(f, "#else\n", NIL); Printf(f, " (unaryfunc) %s, // nb_long;\n", getSlot(n, "feature:nb_long")); + Printv(f, "#endif\n", NIL); Printf(f, " (unaryfunc) %s, // nb_float;\n", getSlot(n, "feature:nb_float")); + 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")); + 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")); + Printv(f, "#if PY_VERSION_HEX < 0x03000000\n", NIL); Printf(f, " (binaryfunc) %s, // nb_inplace_divide;\n", getSlot(n, "feature:nb_inplace_divide")); + 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")); @@ -3377,9 +3402,17 @@ public: 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")); + 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")); + Printv(f, "#endif\n", NIL); Printf(f, " (ssizeobjargproc) %s, // sq_ass_item\n", getSlot(n, "feature: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")); + 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")); @@ -3387,10 +3420,15 @@ public: // 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")); + 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")); + Printv(f, "#endif\n", NIL); Printf(f, " },\n"); // PyObject *ht_name, *ht_slots @@ -3426,7 +3464,11 @@ public: Printv(f_init, " if (PyType_Ready(builtin_pytype) < 0) {\n", NIL); Printf(f_init, " PyErr_SetString(PyExc_TypeError, \"Couldn't create type '%s'\");\n", symname); + Printv(f_init, "#if PY_VERSION_HEX >= 0x03000000\n", NIL); + Printv(f_init, " return NULL;\n", NIL); + Printv(f_init, "#else\n", NIL); Printv(f_init, " return;\n", NIL); + Printv(f_init, "#endif\n", NIL); 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); @@ -3441,6 +3483,7 @@ public: Delete(templ); Delete(tp_dealloc); Delete(tp_flags); + Delete(py3_tp_flags); Delete(clientdata_klass); } From cd93c7362efc6214c659a7d91807b39b3b14cb47 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Thu, 3 Feb 2011 18:10:39 +0000 Subject: [PATCH 16/56] Applied patch #3171793 to fix -fvirtual. Mostly disabled python_abstractbase, since builtin types can't inherit from pure-python ABC's. Duck typing still works. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12426 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../test-suite/python/python_abstractbase_runme3.py | 13 +++++++------ Source/Modules/allocate.cxx | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Examples/test-suite/python/python_abstractbase_runme3.py b/Examples/test-suite/python/python_abstractbase_runme3.py index e34777558..4874f6859 100644 --- a/Examples/test-suite/python/python_abstractbase_runme3.py +++ b/Examples/test-suite/python/python_abstractbase_runme3.py @@ -1,8 +1,9 @@ from python_abstractbase import * from collections import * -assert issubclass(Mapii, MutableMapping) -assert issubclass(Multimapii, MutableMapping) -assert issubclass(IntSet, MutableSet) -assert issubclass(IntMultiset, MutableSet) -assert issubclass(IntVector, MutableSequence) -assert issubclass(IntList, MutableSequence) +# Builtin types can't inherit from pure-python abstract bases +#assert issubclass(Mapii, MutableMapping) +#assert issubclass(Multimapii, MutableMapping) +#assert issubclass(IntSet, MutableSet) +#assert issubclass(IntMultiset, MutableSet) +#assert issubclass(IntVector, MutableSequence) +#assert issubclass(IntList, MutableSequence) diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx index 31f7c20ae..1a62f5d69 100644 --- a/Source/Modules/allocate.cxx +++ b/Source/Modules/allocate.cxx @@ -216,7 +216,7 @@ class Allocate:public Dispatcher { if (!most_base_covariant_type) { // Eliminate the derived virtual method. - if (virtual_elimination_mode) + if (virtual_elimination_mode && !this_wrapping_protected_members) if (both_have_public_access) if (!is_non_public_base(inclass, b)) if (!Swig_symbol_isoverloaded(n)) { From 460ac6206a64a17626b7582d19274b47395929be Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Wed, 9 Feb 2011 07:26:07 +0000 Subject: [PATCH 17/56] A place to write and run performance tests. The variants we're most interested in are: 'baseline' -- swig run without any special flags 'optimized' -- swig run with -O flag 'builtin' -- swig run with -builtin flag git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12442 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/python/Makefile | 40 ++++ Examples/python/constructor/Makefile | 21 ++ Examples/python/constructor/Simple.i | 8 + .../python/constructor/Simple_baseline.py | 86 ++++++++ Examples/python/constructor/Simple_builtin.py | 81 +++++++ .../python/constructor/Simple_optimized.py | 93 ++++++++ Examples/python/constructor/runme.py | 17 ++ Examples/python/constructor/runme_baseline.py | 11 + Examples/python/constructor/runme_builtin.py | 11 + .../python/constructor/runme_optimized.py | 11 + Examples/python/deep_hierarchy/Makefile | 23 ++ Examples/python/deep_hierarchy/Simple.i | 52 +++++ .../python/deep_hierarchy/Simple_baseline.py | 205 ++++++++++++++++++ .../python/deep_hierarchy/Simple_builtin.py | 88 ++++++++ .../python/deep_hierarchy/Simple_optimized.py | 156 +++++++++++++ Examples/python/deep_hierarchy/runme.py | 17 ++ .../python/deep_hierarchy/runme_baseline.py | 11 + .../python/deep_hierarchy/runme_builtin.py | 11 + .../python/deep_hierarchy/runme_optimized.py | 11 + Examples/python/func/Makefile | 23 ++ Examples/python/func/Simple.i | 8 + Examples/python/func/Simple_baseline.py | 86 ++++++++ Examples/python/func/Simple_builtin.py | 81 +++++++ Examples/python/func/Simple_optimized.py | 93 ++++++++ Examples/python/func/runme.py | 17 ++ Examples/python/func/runme_baseline.py | 11 + Examples/python/func/runme_builtin.py | 11 + Examples/python/func/runme_optimized.py | 11 + 28 files changed, 1294 insertions(+) create mode 100644 Examples/python/Makefile create mode 100644 Examples/python/constructor/Makefile create mode 100644 Examples/python/constructor/Simple.i create mode 100644 Examples/python/constructor/Simple_baseline.py create mode 100644 Examples/python/constructor/Simple_builtin.py create mode 100644 Examples/python/constructor/Simple_optimized.py create mode 100644 Examples/python/constructor/runme.py create mode 100644 Examples/python/constructor/runme_baseline.py create mode 100644 Examples/python/constructor/runme_builtin.py create mode 100644 Examples/python/constructor/runme_optimized.py create mode 100644 Examples/python/deep_hierarchy/Makefile create mode 100644 Examples/python/deep_hierarchy/Simple.i create mode 100644 Examples/python/deep_hierarchy/Simple_baseline.py create mode 100644 Examples/python/deep_hierarchy/Simple_builtin.py create mode 100644 Examples/python/deep_hierarchy/Simple_optimized.py create mode 100644 Examples/python/deep_hierarchy/runme.py create mode 100644 Examples/python/deep_hierarchy/runme_baseline.py create mode 100644 Examples/python/deep_hierarchy/runme_builtin.py create mode 100644 Examples/python/deep_hierarchy/runme_optimized.py create mode 100644 Examples/python/func/Makefile create mode 100644 Examples/python/func/Simple.i create mode 100644 Examples/python/func/Simple_baseline.py create mode 100644 Examples/python/func/Simple_builtin.py create mode 100644 Examples/python/func/Simple_optimized.py create mode 100644 Examples/python/func/runme.py create mode 100644 Examples/python/func/runme_baseline.py create mode 100644 Examples/python/func/runme_builtin.py create mode 100644 Examples/python/func/runme_optimized.py diff --git a/Examples/python/Makefile b/Examples/python/Makefile new file mode 100644 index 000000000..c1b4a69c6 --- /dev/null +++ b/Examples/python/Makefile @@ -0,0 +1,40 @@ +ifeq (,$(PY3)) + PYTHON_INCLUDE= $(DEFS) -I/usr/include/python2.6 -I/usr/lib/python2.6/config + PYTHON_LIB = + PYTHON = python + PYSCRIPT = runme.py +else + PYTHON_INCLUDE= $(DEFS) -I/home/szager/include/python3.1 + PYTHON_LIB = + PYTHON = python3 + PYSCRIPT = runme3.py +endif + +SUBDIRS := constructor func deep_hierarchy + +default : all + +.PHONY : $(SUBDIRS) all clean + +all : $(SUBDIRS) + @for subdir in $(SUBDIRS); do \ + echo Running $$subdir test... ; \ + echo -------------------------------------------------------------------------------- ; \ + cd $$subdir; \ + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(PYTHON) $(PYSCRIPT); \ + cd ..; \ + done + +$(SUBDIRS) : + $(MAKE) -C $@ + @echo Running $$subdir test... + @echo -------------------------------------------------------------------------------- + cd $@ && env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(PYTHON) $(PYSCRIPT) + +%-clean : + $(MAKE) -s -C $* clean + +$(SUBDIRS:%=%-check) : + $(MAKE) -C $* check + +clean : $(SUBDIRS:%=%-clean) diff --git a/Examples/python/constructor/Makefile b/Examples/python/constructor/Makefile new file mode 100644 index 000000000..48449875c --- /dev/null +++ b/Examples/python/constructor/Makefile @@ -0,0 +1,21 @@ +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = +TARGET = Simple +INTERFACE = Simple.i + +all : + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ + TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ + TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ + TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp + +static : + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static + +clean : + $(MAKE) -f $(TOP)/Makefile python_clean + rm -f $(TARGET).py diff --git a/Examples/python/constructor/Simple.i b/Examples/python/constructor/Simple.i new file mode 100644 index 000000000..d642d15bf --- /dev/null +++ b/Examples/python/constructor/Simple.i @@ -0,0 +1,8 @@ +%inline %{ +class MyClass { +public: + MyClass () {} + ~MyClass () {} + void func () {} +}; +%} diff --git a/Examples/python/constructor/Simple_baseline.py b/Examples/python/constructor/Simple_baseline.py new file mode 100644 index 000000000..7e401b403 --- /dev/null +++ b/Examples/python/constructor/Simple_baseline.py @@ -0,0 +1,86 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. +# This file is compatible with both classic and new-style classes. + +from sys import version_info +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_baseline', [dirname(__file__)]) + except ImportError: + import _Simple_baseline + return _Simple_baseline + if fp is not None: + try: + _mod = imp.load_module('_Simple_baseline', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_baseline = swig_import_helper() + del swig_import_helper +else: + import _Simple_baseline +del version_info +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +class MyClass(_object): + __swig_setmethods__ = {} + __setattr__ = lambda self, name, value: _swig_setattr(self, MyClass, name, value) + __swig_getmethods__ = {} + __getattr__ = lambda self, name: _swig_getattr(self, MyClass, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_MyClass() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_MyClass + __del__ = lambda self : None; + def func(self): return _Simple_baseline.MyClass_func(self) +MyClass_swigregister = _Simple_baseline.MyClass_swigregister +MyClass_swigregister(MyClass) + + + diff --git a/Examples/python/constructor/Simple_builtin.py b/Examples/python/constructor/Simple_builtin.py new file mode 100644 index 000000000..4ecd8a63e --- /dev/null +++ b/Examples/python/constructor/Simple_builtin.py @@ -0,0 +1,81 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. + +from sys import version_info +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_builtin', [dirname(__file__)]) + except ImportError: + import _Simple_builtin + return _Simple_builtin + if fp is not None: + try: + _mod = imp.load_module('_Simple_builtin', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_builtin = swig_import_helper() + del swig_import_helper +else: + import _Simple_builtin +del version_info +from _Simple_builtin import * +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + + + + diff --git a/Examples/python/constructor/Simple_optimized.py b/Examples/python/constructor/Simple_optimized.py new file mode 100644 index 000000000..0bf42ced3 --- /dev/null +++ b/Examples/python/constructor/Simple_optimized.py @@ -0,0 +1,93 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. + +from sys import version_info +if version_info >= (3,0,0): + new_instancemethod = lambda func, inst, cls: _Simple_optimized.SWIG_PyInstanceMethod_New(func) +else: + from new import instancemethod as new_instancemethod +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_optimized', [dirname(__file__)]) + except ImportError: + import _Simple_optimized + return _Simple_optimized + if fp is not None: + try: + _mod = imp.load_module('_Simple_optimized', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_optimized = swig_import_helper() + del swig_import_helper +else: + import _Simple_optimized +del version_info +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + +class MyClass(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.MyClass_swiginit(self,_Simple_optimized.new_MyClass()) + __swig_destroy__ = _Simple_optimized.delete_MyClass +MyClass.func = new_instancemethod(_Simple_optimized.MyClass_func,None,MyClass) +MyClass_swigregister = _Simple_optimized.MyClass_swigregister +MyClass_swigregister(MyClass) + + + diff --git a/Examples/python/constructor/runme.py b/Examples/python/constructor/runme.py new file mode 100644 index 000000000..7e50aff16 --- /dev/null +++ b/Examples/python/constructor/runme.py @@ -0,0 +1,17 @@ +#!/usr/bin/env + +import sys +from subprocess import * + +proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + +proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + +proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + diff --git a/Examples/python/constructor/runme_baseline.py b/Examples/python/constructor/runme_baseline.py new file mode 100644 index 000000000..0eb284ccc --- /dev/null +++ b/Examples/python/constructor/runme_baseline.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_baseline +import time + +t1 = time.clock() +for i in range(1000000) : + x = Simple_baseline.MyClass() + #x.func() +t2 = time.clock() +print "Simple_baseline took %f seconds" % (t2 - t1) diff --git a/Examples/python/constructor/runme_builtin.py b/Examples/python/constructor/runme_builtin.py new file mode 100644 index 000000000..47ce37864 --- /dev/null +++ b/Examples/python/constructor/runme_builtin.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_builtin +import time + +t1 = time.clock() +for i in range(1000000) : + x = Simple_builtin.MyClass() + #x.func() +t2 = time.clock() +print "Simple_builtin took %f seconds" % (t2 - t1) diff --git a/Examples/python/constructor/runme_optimized.py b/Examples/python/constructor/runme_optimized.py new file mode 100644 index 000000000..0c0ed220f --- /dev/null +++ b/Examples/python/constructor/runme_optimized.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_optimized +import time + +t1 = time.clock() +for i in range(1000000) : + x = Simple_optimized.MyClass() + #x.func() +t2 = time.clock() +print "Simple_optimized took %f seconds" % (t2 - t1) diff --git a/Examples/python/deep_hierarchy/Makefile b/Examples/python/deep_hierarchy/Makefile new file mode 100644 index 000000000..0df09d908 --- /dev/null +++ b/Examples/python/deep_hierarchy/Makefile @@ -0,0 +1,23 @@ +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = +TARGET = Simple +INTERFACE = Simple.i + +default : all + +all : + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ + TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ + TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ + TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp + +static : + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static + +clean : + $(MAKE) -f $(TOP)/Makefile python_clean + rm -f $(TARGET).py diff --git a/Examples/python/deep_hierarchy/Simple.i b/Examples/python/deep_hierarchy/Simple.i new file mode 100644 index 000000000..b4f43ec3e --- /dev/null +++ b/Examples/python/deep_hierarchy/Simple.i @@ -0,0 +1,52 @@ +%inline %{ + +class A { +public: + A () {} + ~A () {} + void func () {} +}; + +class B : public A { +public: + B () {} + ~B () {} +}; + +class C : public B { +public: + C () {} + ~C () {} +}; + +class D : public C { +public: + D () {} + ~D () {} +}; + +class E : public D { +public: + E () {} + ~E () {} +}; + +class F : public E { +public: + F () {} + ~F () {} +}; + +class G : public F { +public: + G () {} + ~G () {} +}; + +class H : public G { +public: + H () {} + ~H () {} +}; + +%} diff --git a/Examples/python/deep_hierarchy/Simple_baseline.py b/Examples/python/deep_hierarchy/Simple_baseline.py new file mode 100644 index 000000000..ed91fd14d --- /dev/null +++ b/Examples/python/deep_hierarchy/Simple_baseline.py @@ -0,0 +1,205 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. +# This file is compatible with both classic and new-style classes. + +from sys import version_info +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_baseline', [dirname(__file__)]) + except ImportError: + import _Simple_baseline + return _Simple_baseline + if fp is not None: + try: + _mod = imp.load_module('_Simple_baseline', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_baseline = swig_import_helper() + del swig_import_helper +else: + import _Simple_baseline +del version_info +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +class A(_object): + __swig_setmethods__ = {} + __setattr__ = lambda self, name, value: _swig_setattr(self, A, name, value) + __swig_getmethods__ = {} + __getattr__ = lambda self, name: _swig_getattr(self, A, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_A() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_A + __del__ = lambda self : None; + def func(self): return _Simple_baseline.A_func(self) +A_swigregister = _Simple_baseline.A_swigregister +A_swigregister(A) + +class B(A): + __swig_setmethods__ = {} + for _s in [A]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, B, name, value) + __swig_getmethods__ = {} + for _s in [A]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, B, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_B() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_B + __del__ = lambda self : None; +B_swigregister = _Simple_baseline.B_swigregister +B_swigregister(B) + +class C(B): + __swig_setmethods__ = {} + for _s in [B]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, C, name, value) + __swig_getmethods__ = {} + for _s in [B]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, C, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_C() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_C + __del__ = lambda self : None; +C_swigregister = _Simple_baseline.C_swigregister +C_swigregister(C) + +class D(C): + __swig_setmethods__ = {} + for _s in [C]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, D, name, value) + __swig_getmethods__ = {} + for _s in [C]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, D, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_D() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_D + __del__ = lambda self : None; +D_swigregister = _Simple_baseline.D_swigregister +D_swigregister(D) + +class E(D): + __swig_setmethods__ = {} + for _s in [D]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, E, name, value) + __swig_getmethods__ = {} + for _s in [D]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, E, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_E() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_E + __del__ = lambda self : None; +E_swigregister = _Simple_baseline.E_swigregister +E_swigregister(E) + +class F(E): + __swig_setmethods__ = {} + for _s in [E]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, F, name, value) + __swig_getmethods__ = {} + for _s in [E]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, F, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_F() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_F + __del__ = lambda self : None; +F_swigregister = _Simple_baseline.F_swigregister +F_swigregister(F) + +class G(F): + __swig_setmethods__ = {} + for _s in [F]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, G, name, value) + __swig_getmethods__ = {} + for _s in [F]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, G, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_G() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_G + __del__ = lambda self : None; +G_swigregister = _Simple_baseline.G_swigregister +G_swigregister(G) + +class H(G): + __swig_setmethods__ = {} + for _s in [G]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, H, name, value) + __swig_getmethods__ = {} + for _s in [G]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, H, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_H() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_H + __del__ = lambda self : None; +H_swigregister = _Simple_baseline.H_swigregister +H_swigregister(H) + + + diff --git a/Examples/python/deep_hierarchy/Simple_builtin.py b/Examples/python/deep_hierarchy/Simple_builtin.py new file mode 100644 index 000000000..6572f16bc --- /dev/null +++ b/Examples/python/deep_hierarchy/Simple_builtin.py @@ -0,0 +1,88 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. + +from sys import version_info +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_builtin', [dirname(__file__)]) + except ImportError: + import _Simple_builtin + return _Simple_builtin + if fp is not None: + try: + _mod = imp.load_module('_Simple_builtin', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_builtin = swig_import_helper() + del swig_import_helper +else: + import _Simple_builtin +del version_info +from _Simple_builtin import * +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + + + + + + + + + + + diff --git a/Examples/python/deep_hierarchy/Simple_optimized.py b/Examples/python/deep_hierarchy/Simple_optimized.py new file mode 100644 index 000000000..3cfcda3b1 --- /dev/null +++ b/Examples/python/deep_hierarchy/Simple_optimized.py @@ -0,0 +1,156 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. + +from sys import version_info +if version_info >= (3,0,0): + new_instancemethod = lambda func, inst, cls: _Simple_optimized.SWIG_PyInstanceMethod_New(func) +else: + from new import instancemethod as new_instancemethod +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_optimized', [dirname(__file__)]) + except ImportError: + import _Simple_optimized + return _Simple_optimized + if fp is not None: + try: + _mod = imp.load_module('_Simple_optimized', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_optimized = swig_import_helper() + del swig_import_helper +else: + import _Simple_optimized +del version_info +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + +class A(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.A_swiginit(self,_Simple_optimized.new_A()) + __swig_destroy__ = _Simple_optimized.delete_A +A.func = new_instancemethod(_Simple_optimized.A_func,None,A) +A_swigregister = _Simple_optimized.A_swigregister +A_swigregister(A) + +class B(A): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.B_swiginit(self,_Simple_optimized.new_B()) + __swig_destroy__ = _Simple_optimized.delete_B +B_swigregister = _Simple_optimized.B_swigregister +B_swigregister(B) + +class C(B): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.C_swiginit(self,_Simple_optimized.new_C()) + __swig_destroy__ = _Simple_optimized.delete_C +C_swigregister = _Simple_optimized.C_swigregister +C_swigregister(C) + +class D(C): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.D_swiginit(self,_Simple_optimized.new_D()) + __swig_destroy__ = _Simple_optimized.delete_D +D_swigregister = _Simple_optimized.D_swigregister +D_swigregister(D) + +class E(D): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.E_swiginit(self,_Simple_optimized.new_E()) + __swig_destroy__ = _Simple_optimized.delete_E +E_swigregister = _Simple_optimized.E_swigregister +E_swigregister(E) + +class F(E): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.F_swiginit(self,_Simple_optimized.new_F()) + __swig_destroy__ = _Simple_optimized.delete_F +F_swigregister = _Simple_optimized.F_swigregister +F_swigregister(F) + +class G(F): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.G_swiginit(self,_Simple_optimized.new_G()) + __swig_destroy__ = _Simple_optimized.delete_G +G_swigregister = _Simple_optimized.G_swigregister +G_swigregister(G) + +class H(G): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.H_swiginit(self,_Simple_optimized.new_H()) + __swig_destroy__ = _Simple_optimized.delete_H +H_swigregister = _Simple_optimized.H_swigregister +H_swigregister(H) + + + diff --git a/Examples/python/deep_hierarchy/runme.py b/Examples/python/deep_hierarchy/runme.py new file mode 100644 index 000000000..7e50aff16 --- /dev/null +++ b/Examples/python/deep_hierarchy/runme.py @@ -0,0 +1,17 @@ +#!/usr/bin/env + +import sys +from subprocess import * + +proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + +proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + +proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + diff --git a/Examples/python/deep_hierarchy/runme_baseline.py b/Examples/python/deep_hierarchy/runme_baseline.py new file mode 100644 index 000000000..584b9fb97 --- /dev/null +++ b/Examples/python/deep_hierarchy/runme_baseline.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_baseline +import time + +t1 = time.clock() +x = Simple_baseline.H() +for i in range(10000000) : + x.func() +t2 = time.clock() +print "Simple_baseline took %f seconds" % (t2 - t1) diff --git a/Examples/python/deep_hierarchy/runme_builtin.py b/Examples/python/deep_hierarchy/runme_builtin.py new file mode 100644 index 000000000..a095ed223 --- /dev/null +++ b/Examples/python/deep_hierarchy/runme_builtin.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_builtin +import time + +t1 = time.clock() +x = Simple_builtin.H() +for i in range(10000000) : + x.func() +t2 = time.clock() +print "Simple_builtin took %f seconds" % (t2 - t1) diff --git a/Examples/python/deep_hierarchy/runme_optimized.py b/Examples/python/deep_hierarchy/runme_optimized.py new file mode 100644 index 000000000..c6f20463d --- /dev/null +++ b/Examples/python/deep_hierarchy/runme_optimized.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_optimized +import time + +t1 = time.clock() +x = Simple_optimized.H() +for i in range(10000000) : + x.func() +t2 = time.clock() +print "Simple_optimized took %f seconds" % (t2 - t1) diff --git a/Examples/python/func/Makefile b/Examples/python/func/Makefile new file mode 100644 index 000000000..0df09d908 --- /dev/null +++ b/Examples/python/func/Makefile @@ -0,0 +1,23 @@ +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = +TARGET = Simple +INTERFACE = Simple.i + +default : all + +all : + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ + TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ + TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ + TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp + +static : + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static + +clean : + $(MAKE) -f $(TOP)/Makefile python_clean + rm -f $(TARGET).py diff --git a/Examples/python/func/Simple.i b/Examples/python/func/Simple.i new file mode 100644 index 000000000..d642d15bf --- /dev/null +++ b/Examples/python/func/Simple.i @@ -0,0 +1,8 @@ +%inline %{ +class MyClass { +public: + MyClass () {} + ~MyClass () {} + void func () {} +}; +%} diff --git a/Examples/python/func/Simple_baseline.py b/Examples/python/func/Simple_baseline.py new file mode 100644 index 000000000..7e401b403 --- /dev/null +++ b/Examples/python/func/Simple_baseline.py @@ -0,0 +1,86 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. +# This file is compatible with both classic and new-style classes. + +from sys import version_info +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_baseline', [dirname(__file__)]) + except ImportError: + import _Simple_baseline + return _Simple_baseline + if fp is not None: + try: + _mod = imp.load_module('_Simple_baseline', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_baseline = swig_import_helper() + del swig_import_helper +else: + import _Simple_baseline +del version_info +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +class MyClass(_object): + __swig_setmethods__ = {} + __setattr__ = lambda self, name, value: _swig_setattr(self, MyClass, name, value) + __swig_getmethods__ = {} + __getattr__ = lambda self, name: _swig_getattr(self, MyClass, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_MyClass() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_MyClass + __del__ = lambda self : None; + def func(self): return _Simple_baseline.MyClass_func(self) +MyClass_swigregister = _Simple_baseline.MyClass_swigregister +MyClass_swigregister(MyClass) + + + diff --git a/Examples/python/func/Simple_builtin.py b/Examples/python/func/Simple_builtin.py new file mode 100644 index 000000000..4ecd8a63e --- /dev/null +++ b/Examples/python/func/Simple_builtin.py @@ -0,0 +1,81 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. + +from sys import version_info +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_builtin', [dirname(__file__)]) + except ImportError: + import _Simple_builtin + return _Simple_builtin + if fp is not None: + try: + _mod = imp.load_module('_Simple_builtin', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_builtin = swig_import_helper() + del swig_import_helper +else: + import _Simple_builtin +del version_info +from _Simple_builtin import * +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + + + + diff --git a/Examples/python/func/Simple_optimized.py b/Examples/python/func/Simple_optimized.py new file mode 100644 index 000000000..0bf42ced3 --- /dev/null +++ b/Examples/python/func/Simple_optimized.py @@ -0,0 +1,93 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. + +from sys import version_info +if version_info >= (3,0,0): + new_instancemethod = lambda func, inst, cls: _Simple_optimized.SWIG_PyInstanceMethod_New(func) +else: + from new import instancemethod as new_instancemethod +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_optimized', [dirname(__file__)]) + except ImportError: + import _Simple_optimized + return _Simple_optimized + if fp is not None: + try: + _mod = imp.load_module('_Simple_optimized', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_optimized = swig_import_helper() + del swig_import_helper +else: + import _Simple_optimized +del version_info +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + +class MyClass(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.MyClass_swiginit(self,_Simple_optimized.new_MyClass()) + __swig_destroy__ = _Simple_optimized.delete_MyClass +MyClass.func = new_instancemethod(_Simple_optimized.MyClass_func,None,MyClass) +MyClass_swigregister = _Simple_optimized.MyClass_swigregister +MyClass_swigregister(MyClass) + + + diff --git a/Examples/python/func/runme.py b/Examples/python/func/runme.py new file mode 100644 index 000000000..7e50aff16 --- /dev/null +++ b/Examples/python/func/runme.py @@ -0,0 +1,17 @@ +#!/usr/bin/env + +import sys +from subprocess import * + +proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + +proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + +proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + diff --git a/Examples/python/func/runme_baseline.py b/Examples/python/func/runme_baseline.py new file mode 100644 index 000000000..6966fd904 --- /dev/null +++ b/Examples/python/func/runme_baseline.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_baseline +import time + +t1 = time.clock() +x = Simple_baseline.MyClass() +for i in range(10000000) : + x.func() +t2 = time.clock() +print "Simple_baseline took %f seconds" % (t2 - t1) diff --git a/Examples/python/func/runme_builtin.py b/Examples/python/func/runme_builtin.py new file mode 100644 index 000000000..ca2f88ac8 --- /dev/null +++ b/Examples/python/func/runme_builtin.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_builtin +import time + +t1 = time.clock() +x = Simple_builtin.MyClass() +for i in range(10000000) : + x.func() +t2 = time.clock() +print "Simple_builtin took %f seconds" % (t2 - t1) diff --git a/Examples/python/func/runme_optimized.py b/Examples/python/func/runme_optimized.py new file mode 100644 index 000000000..fe10eb376 --- /dev/null +++ b/Examples/python/func/runme_optimized.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_optimized +import time + +t1 = time.clock() +x = Simple_optimized.MyClass() +for i in range(10000000) : + x.func() +t2 = time.clock() +print "Simple_optimized took %f seconds" % (t2 - t1) From f39c09e12d444bd6f9e974d3608c2c2f02455891 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Wed, 9 Feb 2011 07:28:54 +0000 Subject: [PATCH 18/56] Whoops; bad import git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12443 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/python/Makefile | 40 ---- Examples/python/constructor/Makefile | 21 -- Examples/python/constructor/Simple.i | 8 - .../python/constructor/Simple_baseline.py | 86 -------- Examples/python/constructor/Simple_builtin.py | 81 ------- .../python/constructor/Simple_optimized.py | 93 -------- Examples/python/constructor/runme.py | 17 -- Examples/python/constructor/runme_baseline.py | 11 - Examples/python/constructor/runme_builtin.py | 11 - .../python/constructor/runme_optimized.py | 11 - Examples/python/deep_hierarchy/Makefile | 23 -- Examples/python/deep_hierarchy/Simple.i | 52 ----- .../python/deep_hierarchy/Simple_baseline.py | 205 ------------------ .../python/deep_hierarchy/Simple_builtin.py | 88 -------- .../python/deep_hierarchy/Simple_optimized.py | 156 ------------- Examples/python/deep_hierarchy/runme.py | 17 -- .../python/deep_hierarchy/runme_baseline.py | 11 - .../python/deep_hierarchy/runme_builtin.py | 11 - .../python/deep_hierarchy/runme_optimized.py | 11 - Examples/python/func/Makefile | 23 -- Examples/python/func/Simple.i | 8 - Examples/python/func/Simple_baseline.py | 86 -------- Examples/python/func/Simple_builtin.py | 81 ------- Examples/python/func/Simple_optimized.py | 93 -------- Examples/python/func/runme.py | 17 -- Examples/python/func/runme_baseline.py | 11 - Examples/python/func/runme_builtin.py | 11 - Examples/python/func/runme_optimized.py | 11 - 28 files changed, 1294 deletions(-) delete mode 100644 Examples/python/Makefile delete mode 100644 Examples/python/constructor/Makefile delete mode 100644 Examples/python/constructor/Simple.i delete mode 100644 Examples/python/constructor/Simple_baseline.py delete mode 100644 Examples/python/constructor/Simple_builtin.py delete mode 100644 Examples/python/constructor/Simple_optimized.py delete mode 100644 Examples/python/constructor/runme.py delete mode 100644 Examples/python/constructor/runme_baseline.py delete mode 100644 Examples/python/constructor/runme_builtin.py delete mode 100644 Examples/python/constructor/runme_optimized.py delete mode 100644 Examples/python/deep_hierarchy/Makefile delete mode 100644 Examples/python/deep_hierarchy/Simple.i delete mode 100644 Examples/python/deep_hierarchy/Simple_baseline.py delete mode 100644 Examples/python/deep_hierarchy/Simple_builtin.py delete mode 100644 Examples/python/deep_hierarchy/Simple_optimized.py delete mode 100644 Examples/python/deep_hierarchy/runme.py delete mode 100644 Examples/python/deep_hierarchy/runme_baseline.py delete mode 100644 Examples/python/deep_hierarchy/runme_builtin.py delete mode 100644 Examples/python/deep_hierarchy/runme_optimized.py delete mode 100644 Examples/python/func/Makefile delete mode 100644 Examples/python/func/Simple.i delete mode 100644 Examples/python/func/Simple_baseline.py delete mode 100644 Examples/python/func/Simple_builtin.py delete mode 100644 Examples/python/func/Simple_optimized.py delete mode 100644 Examples/python/func/runme.py delete mode 100644 Examples/python/func/runme_baseline.py delete mode 100644 Examples/python/func/runme_builtin.py delete mode 100644 Examples/python/func/runme_optimized.py diff --git a/Examples/python/Makefile b/Examples/python/Makefile deleted file mode 100644 index c1b4a69c6..000000000 --- a/Examples/python/Makefile +++ /dev/null @@ -1,40 +0,0 @@ -ifeq (,$(PY3)) - PYTHON_INCLUDE= $(DEFS) -I/usr/include/python2.6 -I/usr/lib/python2.6/config - PYTHON_LIB = - PYTHON = python - PYSCRIPT = runme.py -else - PYTHON_INCLUDE= $(DEFS) -I/home/szager/include/python3.1 - PYTHON_LIB = - PYTHON = python3 - PYSCRIPT = runme3.py -endif - -SUBDIRS := constructor func deep_hierarchy - -default : all - -.PHONY : $(SUBDIRS) all clean - -all : $(SUBDIRS) - @for subdir in $(SUBDIRS); do \ - echo Running $$subdir test... ; \ - echo -------------------------------------------------------------------------------- ; \ - cd $$subdir; \ - env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(PYTHON) $(PYSCRIPT); \ - cd ..; \ - done - -$(SUBDIRS) : - $(MAKE) -C $@ - @echo Running $$subdir test... - @echo -------------------------------------------------------------------------------- - cd $@ && env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(PYTHON) $(PYSCRIPT) - -%-clean : - $(MAKE) -s -C $* clean - -$(SUBDIRS:%=%-check) : - $(MAKE) -C $* check - -clean : $(SUBDIRS:%=%-clean) diff --git a/Examples/python/constructor/Makefile b/Examples/python/constructor/Makefile deleted file mode 100644 index 48449875c..000000000 --- a/Examples/python/constructor/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../preinst-swig -CXXSRCS = -TARGET = Simple -INTERFACE = Simple.i - -all : - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ - TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ - TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ - TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp - -static : - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static - -clean : - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py diff --git a/Examples/python/constructor/Simple.i b/Examples/python/constructor/Simple.i deleted file mode 100644 index d642d15bf..000000000 --- a/Examples/python/constructor/Simple.i +++ /dev/null @@ -1,8 +0,0 @@ -%inline %{ -class MyClass { -public: - MyClass () {} - ~MyClass () {} - void func () {} -}; -%} diff --git a/Examples/python/constructor/Simple_baseline.py b/Examples/python/constructor/Simple_baseline.py deleted file mode 100644 index 7e401b403..000000000 --- a/Examples/python/constructor/Simple_baseline.py +++ /dev/null @@ -1,86 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. -# This file is compatible with both classic and new-style classes. - -from sys import version_info -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_baseline', [dirname(__file__)]) - except ImportError: - import _Simple_baseline - return _Simple_baseline - if fp is not None: - try: - _mod = imp.load_module('_Simple_baseline', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_baseline = swig_import_helper() - del swig_import_helper -else: - import _Simple_baseline -del version_info -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -class MyClass(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, MyClass, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, MyClass, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_MyClass() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_MyClass - __del__ = lambda self : None; - def func(self): return _Simple_baseline.MyClass_func(self) -MyClass_swigregister = _Simple_baseline.MyClass_swigregister -MyClass_swigregister(MyClass) - - - diff --git a/Examples/python/constructor/Simple_builtin.py b/Examples/python/constructor/Simple_builtin.py deleted file mode 100644 index 4ecd8a63e..000000000 --- a/Examples/python/constructor/Simple_builtin.py +++ /dev/null @@ -1,81 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. - -from sys import version_info -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_builtin', [dirname(__file__)]) - except ImportError: - import _Simple_builtin - return _Simple_builtin - if fp is not None: - try: - _mod = imp.load_module('_Simple_builtin', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_builtin = swig_import_helper() - del swig_import_helper -else: - import _Simple_builtin -del version_info -from _Simple_builtin import * -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -def _swig_setattr_nondynamic_method(set): - def set_attr(self,name,value): - if (name == "thisown"): return self.this.own(value) - if hasattr(self,name) or (name == "this"): - set(self,name,value) - else: - raise AttributeError("You cannot add attributes to %s" % self) - return set_attr - - - - - diff --git a/Examples/python/constructor/Simple_optimized.py b/Examples/python/constructor/Simple_optimized.py deleted file mode 100644 index 0bf42ced3..000000000 --- a/Examples/python/constructor/Simple_optimized.py +++ /dev/null @@ -1,93 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. - -from sys import version_info -if version_info >= (3,0,0): - new_instancemethod = lambda func, inst, cls: _Simple_optimized.SWIG_PyInstanceMethod_New(func) -else: - from new import instancemethod as new_instancemethod -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_optimized', [dirname(__file__)]) - except ImportError: - import _Simple_optimized - return _Simple_optimized - if fp is not None: - try: - _mod = imp.load_module('_Simple_optimized', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_optimized = swig_import_helper() - del swig_import_helper -else: - import _Simple_optimized -del version_info -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -def _swig_setattr_nondynamic_method(set): - def set_attr(self,name,value): - if (name == "thisown"): return self.this.own(value) - if hasattr(self,name) or (name == "this"): - set(self,name,value) - else: - raise AttributeError("You cannot add attributes to %s" % self) - return set_attr - - -class MyClass(object): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.MyClass_swiginit(self,_Simple_optimized.new_MyClass()) - __swig_destroy__ = _Simple_optimized.delete_MyClass -MyClass.func = new_instancemethod(_Simple_optimized.MyClass_func,None,MyClass) -MyClass_swigregister = _Simple_optimized.MyClass_swigregister -MyClass_swigregister(MyClass) - - - diff --git a/Examples/python/constructor/runme.py b/Examples/python/constructor/runme.py deleted file mode 100644 index 7e50aff16..000000000 --- a/Examples/python/constructor/runme.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env - -import sys -from subprocess import * - -proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout - -proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout - -proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout - diff --git a/Examples/python/constructor/runme_baseline.py b/Examples/python/constructor/runme_baseline.py deleted file mode 100644 index 0eb284ccc..000000000 --- a/Examples/python/constructor/runme_baseline.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_baseline -import time - -t1 = time.clock() -for i in range(1000000) : - x = Simple_baseline.MyClass() - #x.func() -t2 = time.clock() -print "Simple_baseline took %f seconds" % (t2 - t1) diff --git a/Examples/python/constructor/runme_builtin.py b/Examples/python/constructor/runme_builtin.py deleted file mode 100644 index 47ce37864..000000000 --- a/Examples/python/constructor/runme_builtin.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_builtin -import time - -t1 = time.clock() -for i in range(1000000) : - x = Simple_builtin.MyClass() - #x.func() -t2 = time.clock() -print "Simple_builtin took %f seconds" % (t2 - t1) diff --git a/Examples/python/constructor/runme_optimized.py b/Examples/python/constructor/runme_optimized.py deleted file mode 100644 index 0c0ed220f..000000000 --- a/Examples/python/constructor/runme_optimized.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_optimized -import time - -t1 = time.clock() -for i in range(1000000) : - x = Simple_optimized.MyClass() - #x.func() -t2 = time.clock() -print "Simple_optimized took %f seconds" % (t2 - t1) diff --git a/Examples/python/deep_hierarchy/Makefile b/Examples/python/deep_hierarchy/Makefile deleted file mode 100644 index 0df09d908..000000000 --- a/Examples/python/deep_hierarchy/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../preinst-swig -CXXSRCS = -TARGET = Simple -INTERFACE = Simple.i - -default : all - -all : - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ - TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ - TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ - TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp - -static : - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static - -clean : - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py diff --git a/Examples/python/deep_hierarchy/Simple.i b/Examples/python/deep_hierarchy/Simple.i deleted file mode 100644 index b4f43ec3e..000000000 --- a/Examples/python/deep_hierarchy/Simple.i +++ /dev/null @@ -1,52 +0,0 @@ -%inline %{ - -class A { -public: - A () {} - ~A () {} - void func () {} -}; - -class B : public A { -public: - B () {} - ~B () {} -}; - -class C : public B { -public: - C () {} - ~C () {} -}; - -class D : public C { -public: - D () {} - ~D () {} -}; - -class E : public D { -public: - E () {} - ~E () {} -}; - -class F : public E { -public: - F () {} - ~F () {} -}; - -class G : public F { -public: - G () {} - ~G () {} -}; - -class H : public G { -public: - H () {} - ~H () {} -}; - -%} diff --git a/Examples/python/deep_hierarchy/Simple_baseline.py b/Examples/python/deep_hierarchy/Simple_baseline.py deleted file mode 100644 index ed91fd14d..000000000 --- a/Examples/python/deep_hierarchy/Simple_baseline.py +++ /dev/null @@ -1,205 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. -# This file is compatible with both classic and new-style classes. - -from sys import version_info -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_baseline', [dirname(__file__)]) - except ImportError: - import _Simple_baseline - return _Simple_baseline - if fp is not None: - try: - _mod = imp.load_module('_Simple_baseline', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_baseline = swig_import_helper() - del swig_import_helper -else: - import _Simple_baseline -del version_info -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -class A(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, A, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, A, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_A() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_A - __del__ = lambda self : None; - def func(self): return _Simple_baseline.A_func(self) -A_swigregister = _Simple_baseline.A_swigregister -A_swigregister(A) - -class B(A): - __swig_setmethods__ = {} - for _s in [A]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, B, name, value) - __swig_getmethods__ = {} - for _s in [A]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, B, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_B() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_B - __del__ = lambda self : None; -B_swigregister = _Simple_baseline.B_swigregister -B_swigregister(B) - -class C(B): - __swig_setmethods__ = {} - for _s in [B]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, C, name, value) - __swig_getmethods__ = {} - for _s in [B]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, C, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_C() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_C - __del__ = lambda self : None; -C_swigregister = _Simple_baseline.C_swigregister -C_swigregister(C) - -class D(C): - __swig_setmethods__ = {} - for _s in [C]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, D, name, value) - __swig_getmethods__ = {} - for _s in [C]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, D, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_D() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_D - __del__ = lambda self : None; -D_swigregister = _Simple_baseline.D_swigregister -D_swigregister(D) - -class E(D): - __swig_setmethods__ = {} - for _s in [D]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, E, name, value) - __swig_getmethods__ = {} - for _s in [D]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, E, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_E() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_E - __del__ = lambda self : None; -E_swigregister = _Simple_baseline.E_swigregister -E_swigregister(E) - -class F(E): - __swig_setmethods__ = {} - for _s in [E]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, F, name, value) - __swig_getmethods__ = {} - for _s in [E]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, F, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_F() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_F - __del__ = lambda self : None; -F_swigregister = _Simple_baseline.F_swigregister -F_swigregister(F) - -class G(F): - __swig_setmethods__ = {} - for _s in [F]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, G, name, value) - __swig_getmethods__ = {} - for _s in [F]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, G, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_G() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_G - __del__ = lambda self : None; -G_swigregister = _Simple_baseline.G_swigregister -G_swigregister(G) - -class H(G): - __swig_setmethods__ = {} - for _s in [G]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, H, name, value) - __swig_getmethods__ = {} - for _s in [G]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, H, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_H() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_H - __del__ = lambda self : None; -H_swigregister = _Simple_baseline.H_swigregister -H_swigregister(H) - - - diff --git a/Examples/python/deep_hierarchy/Simple_builtin.py b/Examples/python/deep_hierarchy/Simple_builtin.py deleted file mode 100644 index 6572f16bc..000000000 --- a/Examples/python/deep_hierarchy/Simple_builtin.py +++ /dev/null @@ -1,88 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. - -from sys import version_info -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_builtin', [dirname(__file__)]) - except ImportError: - import _Simple_builtin - return _Simple_builtin - if fp is not None: - try: - _mod = imp.load_module('_Simple_builtin', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_builtin = swig_import_helper() - del swig_import_helper -else: - import _Simple_builtin -del version_info -from _Simple_builtin import * -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -def _swig_setattr_nondynamic_method(set): - def set_attr(self,name,value): - if (name == "thisown"): return self.this.own(value) - if hasattr(self,name) or (name == "this"): - set(self,name,value) - else: - raise AttributeError("You cannot add attributes to %s" % self) - return set_attr - - - - - - - - - - - - diff --git a/Examples/python/deep_hierarchy/Simple_optimized.py b/Examples/python/deep_hierarchy/Simple_optimized.py deleted file mode 100644 index 3cfcda3b1..000000000 --- a/Examples/python/deep_hierarchy/Simple_optimized.py +++ /dev/null @@ -1,156 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. - -from sys import version_info -if version_info >= (3,0,0): - new_instancemethod = lambda func, inst, cls: _Simple_optimized.SWIG_PyInstanceMethod_New(func) -else: - from new import instancemethod as new_instancemethod -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_optimized', [dirname(__file__)]) - except ImportError: - import _Simple_optimized - return _Simple_optimized - if fp is not None: - try: - _mod = imp.load_module('_Simple_optimized', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_optimized = swig_import_helper() - del swig_import_helper -else: - import _Simple_optimized -del version_info -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -def _swig_setattr_nondynamic_method(set): - def set_attr(self,name,value): - if (name == "thisown"): return self.this.own(value) - if hasattr(self,name) or (name == "this"): - set(self,name,value) - else: - raise AttributeError("You cannot add attributes to %s" % self) - return set_attr - - -class A(object): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.A_swiginit(self,_Simple_optimized.new_A()) - __swig_destroy__ = _Simple_optimized.delete_A -A.func = new_instancemethod(_Simple_optimized.A_func,None,A) -A_swigregister = _Simple_optimized.A_swigregister -A_swigregister(A) - -class B(A): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.B_swiginit(self,_Simple_optimized.new_B()) - __swig_destroy__ = _Simple_optimized.delete_B -B_swigregister = _Simple_optimized.B_swigregister -B_swigregister(B) - -class C(B): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.C_swiginit(self,_Simple_optimized.new_C()) - __swig_destroy__ = _Simple_optimized.delete_C -C_swigregister = _Simple_optimized.C_swigregister -C_swigregister(C) - -class D(C): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.D_swiginit(self,_Simple_optimized.new_D()) - __swig_destroy__ = _Simple_optimized.delete_D -D_swigregister = _Simple_optimized.D_swigregister -D_swigregister(D) - -class E(D): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.E_swiginit(self,_Simple_optimized.new_E()) - __swig_destroy__ = _Simple_optimized.delete_E -E_swigregister = _Simple_optimized.E_swigregister -E_swigregister(E) - -class F(E): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.F_swiginit(self,_Simple_optimized.new_F()) - __swig_destroy__ = _Simple_optimized.delete_F -F_swigregister = _Simple_optimized.F_swigregister -F_swigregister(F) - -class G(F): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.G_swiginit(self,_Simple_optimized.new_G()) - __swig_destroy__ = _Simple_optimized.delete_G -G_swigregister = _Simple_optimized.G_swigregister -G_swigregister(G) - -class H(G): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.H_swiginit(self,_Simple_optimized.new_H()) - __swig_destroy__ = _Simple_optimized.delete_H -H_swigregister = _Simple_optimized.H_swigregister -H_swigregister(H) - - - diff --git a/Examples/python/deep_hierarchy/runme.py b/Examples/python/deep_hierarchy/runme.py deleted file mode 100644 index 7e50aff16..000000000 --- a/Examples/python/deep_hierarchy/runme.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env - -import sys -from subprocess import * - -proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout - -proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout - -proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout - diff --git a/Examples/python/deep_hierarchy/runme_baseline.py b/Examples/python/deep_hierarchy/runme_baseline.py deleted file mode 100644 index 584b9fb97..000000000 --- a/Examples/python/deep_hierarchy/runme_baseline.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_baseline -import time - -t1 = time.clock() -x = Simple_baseline.H() -for i in range(10000000) : - x.func() -t2 = time.clock() -print "Simple_baseline took %f seconds" % (t2 - t1) diff --git a/Examples/python/deep_hierarchy/runme_builtin.py b/Examples/python/deep_hierarchy/runme_builtin.py deleted file mode 100644 index a095ed223..000000000 --- a/Examples/python/deep_hierarchy/runme_builtin.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_builtin -import time - -t1 = time.clock() -x = Simple_builtin.H() -for i in range(10000000) : - x.func() -t2 = time.clock() -print "Simple_builtin took %f seconds" % (t2 - t1) diff --git a/Examples/python/deep_hierarchy/runme_optimized.py b/Examples/python/deep_hierarchy/runme_optimized.py deleted file mode 100644 index c6f20463d..000000000 --- a/Examples/python/deep_hierarchy/runme_optimized.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_optimized -import time - -t1 = time.clock() -x = Simple_optimized.H() -for i in range(10000000) : - x.func() -t2 = time.clock() -print "Simple_optimized took %f seconds" % (t2 - t1) diff --git a/Examples/python/func/Makefile b/Examples/python/func/Makefile deleted file mode 100644 index 0df09d908..000000000 --- a/Examples/python/func/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -TOP = ../../.. -SWIG = $(TOP)/../preinst-swig -CXXSRCS = -TARGET = Simple -INTERFACE = Simple.i - -default : all - -all : - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ - TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ - TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ - TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp - -static : - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static - -clean : - $(MAKE) -f $(TOP)/Makefile python_clean - rm -f $(TARGET).py diff --git a/Examples/python/func/Simple.i b/Examples/python/func/Simple.i deleted file mode 100644 index d642d15bf..000000000 --- a/Examples/python/func/Simple.i +++ /dev/null @@ -1,8 +0,0 @@ -%inline %{ -class MyClass { -public: - MyClass () {} - ~MyClass () {} - void func () {} -}; -%} diff --git a/Examples/python/func/Simple_baseline.py b/Examples/python/func/Simple_baseline.py deleted file mode 100644 index 7e401b403..000000000 --- a/Examples/python/func/Simple_baseline.py +++ /dev/null @@ -1,86 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. -# This file is compatible with both classic and new-style classes. - -from sys import version_info -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_baseline', [dirname(__file__)]) - except ImportError: - import _Simple_baseline - return _Simple_baseline - if fp is not None: - try: - _mod = imp.load_module('_Simple_baseline', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_baseline = swig_import_helper() - del swig_import_helper -else: - import _Simple_baseline -del version_info -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -class MyClass(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, MyClass, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, MyClass, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_MyClass() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_MyClass - __del__ = lambda self : None; - def func(self): return _Simple_baseline.MyClass_func(self) -MyClass_swigregister = _Simple_baseline.MyClass_swigregister -MyClass_swigregister(MyClass) - - - diff --git a/Examples/python/func/Simple_builtin.py b/Examples/python/func/Simple_builtin.py deleted file mode 100644 index 4ecd8a63e..000000000 --- a/Examples/python/func/Simple_builtin.py +++ /dev/null @@ -1,81 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. - -from sys import version_info -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_builtin', [dirname(__file__)]) - except ImportError: - import _Simple_builtin - return _Simple_builtin - if fp is not None: - try: - _mod = imp.load_module('_Simple_builtin', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_builtin = swig_import_helper() - del swig_import_helper -else: - import _Simple_builtin -del version_info -from _Simple_builtin import * -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -def _swig_setattr_nondynamic_method(set): - def set_attr(self,name,value): - if (name == "thisown"): return self.this.own(value) - if hasattr(self,name) or (name == "this"): - set(self,name,value) - else: - raise AttributeError("You cannot add attributes to %s" % self) - return set_attr - - - - - diff --git a/Examples/python/func/Simple_optimized.py b/Examples/python/func/Simple_optimized.py deleted file mode 100644 index 0bf42ced3..000000000 --- a/Examples/python/func/Simple_optimized.py +++ /dev/null @@ -1,93 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. - -from sys import version_info -if version_info >= (3,0,0): - new_instancemethod = lambda func, inst, cls: _Simple_optimized.SWIG_PyInstanceMethod_New(func) -else: - from new import instancemethod as new_instancemethod -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_optimized', [dirname(__file__)]) - except ImportError: - import _Simple_optimized - return _Simple_optimized - if fp is not None: - try: - _mod = imp.load_module('_Simple_optimized', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_optimized = swig_import_helper() - del swig_import_helper -else: - import _Simple_optimized -del version_info -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -def _swig_setattr_nondynamic_method(set): - def set_attr(self,name,value): - if (name == "thisown"): return self.this.own(value) - if hasattr(self,name) or (name == "this"): - set(self,name,value) - else: - raise AttributeError("You cannot add attributes to %s" % self) - return set_attr - - -class MyClass(object): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.MyClass_swiginit(self,_Simple_optimized.new_MyClass()) - __swig_destroy__ = _Simple_optimized.delete_MyClass -MyClass.func = new_instancemethod(_Simple_optimized.MyClass_func,None,MyClass) -MyClass_swigregister = _Simple_optimized.MyClass_swigregister -MyClass_swigregister(MyClass) - - - diff --git a/Examples/python/func/runme.py b/Examples/python/func/runme.py deleted file mode 100644 index 7e50aff16..000000000 --- a/Examples/python/func/runme.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env - -import sys -from subprocess import * - -proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout - -proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout - -proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout - diff --git a/Examples/python/func/runme_baseline.py b/Examples/python/func/runme_baseline.py deleted file mode 100644 index 6966fd904..000000000 --- a/Examples/python/func/runme_baseline.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_baseline -import time - -t1 = time.clock() -x = Simple_baseline.MyClass() -for i in range(10000000) : - x.func() -t2 = time.clock() -print "Simple_baseline took %f seconds" % (t2 - t1) diff --git a/Examples/python/func/runme_builtin.py b/Examples/python/func/runme_builtin.py deleted file mode 100644 index ca2f88ac8..000000000 --- a/Examples/python/func/runme_builtin.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_builtin -import time - -t1 = time.clock() -x = Simple_builtin.MyClass() -for i in range(10000000) : - x.func() -t2 = time.clock() -print "Simple_builtin took %f seconds" % (t2 - t1) diff --git a/Examples/python/func/runme_optimized.py b/Examples/python/func/runme_optimized.py deleted file mode 100644 index fe10eb376..000000000 --- a/Examples/python/func/runme_optimized.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_optimized -import time - -t1 = time.clock() -x = Simple_optimized.MyClass() -for i in range(10000000) : - x.func() -t2 = time.clock() -print "Simple_optimized took %f seconds" % (t2 - t1) From 25be33dcd479870fa444fe33403b9bc55086decc Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Wed, 9 Feb 2011 07:31:08 +0000 Subject: [PATCH 19/56] A collection of performance tests. The variants we're most interested in are: - swig run without any special parameters - swig run with -O - swig run with -builtin git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12444 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/python/performance/Makefile | 40 ++++ .../python/performance/constructor/Makefile | 21 ++ .../python/performance/constructor/Simple.i | 8 + .../constructor/Simple_baseline.py | 86 ++++++++ .../performance/constructor/Simple_builtin.py | 81 +++++++ .../constructor/Simple_optimized.py | 93 ++++++++ .../python/performance/constructor/runme.py | 17 ++ .../performance/constructor/runme_baseline.py | 11 + .../performance/constructor/runme_builtin.py | 11 + .../constructor/runme_optimized.py | 11 + .../performance/deep_hierarchy/Makefile | 23 ++ .../performance/deep_hierarchy/Simple.i | 52 +++++ .../deep_hierarchy/Simple_baseline.py | 205 ++++++++++++++++++ .../deep_hierarchy/Simple_builtin.py | 88 ++++++++ .../deep_hierarchy/Simple_optimized.py | 156 +++++++++++++ .../performance/deep_hierarchy/runme.py | 17 ++ .../deep_hierarchy/runme_baseline.py | 11 + .../deep_hierarchy/runme_builtin.py | 11 + .../deep_hierarchy/runme_optimized.py | 11 + Examples/python/performance/func/Makefile | 23 ++ Examples/python/performance/func/Simple.i | 8 + .../performance/func/Simple_baseline.py | 86 ++++++++ .../python/performance/func/Simple_builtin.py | 81 +++++++ .../performance/func/Simple_optimized.py | 93 ++++++++ Examples/python/performance/func/runme.py | 17 ++ .../python/performance/func/runme_baseline.py | 11 + .../python/performance/func/runme_builtin.py | 11 + .../performance/func/runme_optimized.py | 11 + 28 files changed, 1294 insertions(+) create mode 100644 Examples/python/performance/Makefile create mode 100644 Examples/python/performance/constructor/Makefile create mode 100644 Examples/python/performance/constructor/Simple.i create mode 100644 Examples/python/performance/constructor/Simple_baseline.py create mode 100644 Examples/python/performance/constructor/Simple_builtin.py create mode 100644 Examples/python/performance/constructor/Simple_optimized.py create mode 100644 Examples/python/performance/constructor/runme.py create mode 100644 Examples/python/performance/constructor/runme_baseline.py create mode 100644 Examples/python/performance/constructor/runme_builtin.py create mode 100644 Examples/python/performance/constructor/runme_optimized.py create mode 100644 Examples/python/performance/deep_hierarchy/Makefile create mode 100644 Examples/python/performance/deep_hierarchy/Simple.i create mode 100644 Examples/python/performance/deep_hierarchy/Simple_baseline.py create mode 100644 Examples/python/performance/deep_hierarchy/Simple_builtin.py create mode 100644 Examples/python/performance/deep_hierarchy/Simple_optimized.py create mode 100644 Examples/python/performance/deep_hierarchy/runme.py create mode 100644 Examples/python/performance/deep_hierarchy/runme_baseline.py create mode 100644 Examples/python/performance/deep_hierarchy/runme_builtin.py create mode 100644 Examples/python/performance/deep_hierarchy/runme_optimized.py create mode 100644 Examples/python/performance/func/Makefile create mode 100644 Examples/python/performance/func/Simple.i create mode 100644 Examples/python/performance/func/Simple_baseline.py create mode 100644 Examples/python/performance/func/Simple_builtin.py create mode 100644 Examples/python/performance/func/Simple_optimized.py create mode 100644 Examples/python/performance/func/runme.py create mode 100644 Examples/python/performance/func/runme_baseline.py create mode 100644 Examples/python/performance/func/runme_builtin.py create mode 100644 Examples/python/performance/func/runme_optimized.py diff --git a/Examples/python/performance/Makefile b/Examples/python/performance/Makefile new file mode 100644 index 000000000..c1b4a69c6 --- /dev/null +++ b/Examples/python/performance/Makefile @@ -0,0 +1,40 @@ +ifeq (,$(PY3)) + PYTHON_INCLUDE= $(DEFS) -I/usr/include/python2.6 -I/usr/lib/python2.6/config + PYTHON_LIB = + PYTHON = python + PYSCRIPT = runme.py +else + PYTHON_INCLUDE= $(DEFS) -I/home/szager/include/python3.1 + PYTHON_LIB = + PYTHON = python3 + PYSCRIPT = runme3.py +endif + +SUBDIRS := constructor func deep_hierarchy + +default : all + +.PHONY : $(SUBDIRS) all clean + +all : $(SUBDIRS) + @for subdir in $(SUBDIRS); do \ + echo Running $$subdir test... ; \ + echo -------------------------------------------------------------------------------- ; \ + cd $$subdir; \ + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(PYTHON) $(PYSCRIPT); \ + cd ..; \ + done + +$(SUBDIRS) : + $(MAKE) -C $@ + @echo Running $$subdir test... + @echo -------------------------------------------------------------------------------- + cd $@ && env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(PYTHON) $(PYSCRIPT) + +%-clean : + $(MAKE) -s -C $* clean + +$(SUBDIRS:%=%-check) : + $(MAKE) -C $* check + +clean : $(SUBDIRS:%=%-clean) diff --git a/Examples/python/performance/constructor/Makefile b/Examples/python/performance/constructor/Makefile new file mode 100644 index 000000000..48449875c --- /dev/null +++ b/Examples/python/performance/constructor/Makefile @@ -0,0 +1,21 @@ +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = +TARGET = Simple +INTERFACE = Simple.i + +all : + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ + TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ + TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ + TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp + +static : + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static + +clean : + $(MAKE) -f $(TOP)/Makefile python_clean + rm -f $(TARGET).py diff --git a/Examples/python/performance/constructor/Simple.i b/Examples/python/performance/constructor/Simple.i new file mode 100644 index 000000000..d642d15bf --- /dev/null +++ b/Examples/python/performance/constructor/Simple.i @@ -0,0 +1,8 @@ +%inline %{ +class MyClass { +public: + MyClass () {} + ~MyClass () {} + void func () {} +}; +%} diff --git a/Examples/python/performance/constructor/Simple_baseline.py b/Examples/python/performance/constructor/Simple_baseline.py new file mode 100644 index 000000000..7e401b403 --- /dev/null +++ b/Examples/python/performance/constructor/Simple_baseline.py @@ -0,0 +1,86 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. +# This file is compatible with both classic and new-style classes. + +from sys import version_info +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_baseline', [dirname(__file__)]) + except ImportError: + import _Simple_baseline + return _Simple_baseline + if fp is not None: + try: + _mod = imp.load_module('_Simple_baseline', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_baseline = swig_import_helper() + del swig_import_helper +else: + import _Simple_baseline +del version_info +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +class MyClass(_object): + __swig_setmethods__ = {} + __setattr__ = lambda self, name, value: _swig_setattr(self, MyClass, name, value) + __swig_getmethods__ = {} + __getattr__ = lambda self, name: _swig_getattr(self, MyClass, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_MyClass() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_MyClass + __del__ = lambda self : None; + def func(self): return _Simple_baseline.MyClass_func(self) +MyClass_swigregister = _Simple_baseline.MyClass_swigregister +MyClass_swigregister(MyClass) + + + diff --git a/Examples/python/performance/constructor/Simple_builtin.py b/Examples/python/performance/constructor/Simple_builtin.py new file mode 100644 index 000000000..4ecd8a63e --- /dev/null +++ b/Examples/python/performance/constructor/Simple_builtin.py @@ -0,0 +1,81 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. + +from sys import version_info +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_builtin', [dirname(__file__)]) + except ImportError: + import _Simple_builtin + return _Simple_builtin + if fp is not None: + try: + _mod = imp.load_module('_Simple_builtin', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_builtin = swig_import_helper() + del swig_import_helper +else: + import _Simple_builtin +del version_info +from _Simple_builtin import * +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + + + + diff --git a/Examples/python/performance/constructor/Simple_optimized.py b/Examples/python/performance/constructor/Simple_optimized.py new file mode 100644 index 000000000..0bf42ced3 --- /dev/null +++ b/Examples/python/performance/constructor/Simple_optimized.py @@ -0,0 +1,93 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. + +from sys import version_info +if version_info >= (3,0,0): + new_instancemethod = lambda func, inst, cls: _Simple_optimized.SWIG_PyInstanceMethod_New(func) +else: + from new import instancemethod as new_instancemethod +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_optimized', [dirname(__file__)]) + except ImportError: + import _Simple_optimized + return _Simple_optimized + if fp is not None: + try: + _mod = imp.load_module('_Simple_optimized', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_optimized = swig_import_helper() + del swig_import_helper +else: + import _Simple_optimized +del version_info +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + +class MyClass(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.MyClass_swiginit(self,_Simple_optimized.new_MyClass()) + __swig_destroy__ = _Simple_optimized.delete_MyClass +MyClass.func = new_instancemethod(_Simple_optimized.MyClass_func,None,MyClass) +MyClass_swigregister = _Simple_optimized.MyClass_swigregister +MyClass_swigregister(MyClass) + + + diff --git a/Examples/python/performance/constructor/runme.py b/Examples/python/performance/constructor/runme.py new file mode 100644 index 000000000..7e50aff16 --- /dev/null +++ b/Examples/python/performance/constructor/runme.py @@ -0,0 +1,17 @@ +#!/usr/bin/env + +import sys +from subprocess import * + +proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + +proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + +proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + diff --git a/Examples/python/performance/constructor/runme_baseline.py b/Examples/python/performance/constructor/runme_baseline.py new file mode 100644 index 000000000..0eb284ccc --- /dev/null +++ b/Examples/python/performance/constructor/runme_baseline.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_baseline +import time + +t1 = time.clock() +for i in range(1000000) : + x = Simple_baseline.MyClass() + #x.func() +t2 = time.clock() +print "Simple_baseline took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/constructor/runme_builtin.py b/Examples/python/performance/constructor/runme_builtin.py new file mode 100644 index 000000000..47ce37864 --- /dev/null +++ b/Examples/python/performance/constructor/runme_builtin.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_builtin +import time + +t1 = time.clock() +for i in range(1000000) : + x = Simple_builtin.MyClass() + #x.func() +t2 = time.clock() +print "Simple_builtin took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/constructor/runme_optimized.py b/Examples/python/performance/constructor/runme_optimized.py new file mode 100644 index 000000000..0c0ed220f --- /dev/null +++ b/Examples/python/performance/constructor/runme_optimized.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_optimized +import time + +t1 = time.clock() +for i in range(1000000) : + x = Simple_optimized.MyClass() + #x.func() +t2 = time.clock() +print "Simple_optimized took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/deep_hierarchy/Makefile b/Examples/python/performance/deep_hierarchy/Makefile new file mode 100644 index 000000000..0df09d908 --- /dev/null +++ b/Examples/python/performance/deep_hierarchy/Makefile @@ -0,0 +1,23 @@ +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = +TARGET = Simple +INTERFACE = Simple.i + +default : all + +all : + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ + TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ + TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ + TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp + +static : + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static + +clean : + $(MAKE) -f $(TOP)/Makefile python_clean + rm -f $(TARGET).py diff --git a/Examples/python/performance/deep_hierarchy/Simple.i b/Examples/python/performance/deep_hierarchy/Simple.i new file mode 100644 index 000000000..b4f43ec3e --- /dev/null +++ b/Examples/python/performance/deep_hierarchy/Simple.i @@ -0,0 +1,52 @@ +%inline %{ + +class A { +public: + A () {} + ~A () {} + void func () {} +}; + +class B : public A { +public: + B () {} + ~B () {} +}; + +class C : public B { +public: + C () {} + ~C () {} +}; + +class D : public C { +public: + D () {} + ~D () {} +}; + +class E : public D { +public: + E () {} + ~E () {} +}; + +class F : public E { +public: + F () {} + ~F () {} +}; + +class G : public F { +public: + G () {} + ~G () {} +}; + +class H : public G { +public: + H () {} + ~H () {} +}; + +%} diff --git a/Examples/python/performance/deep_hierarchy/Simple_baseline.py b/Examples/python/performance/deep_hierarchy/Simple_baseline.py new file mode 100644 index 000000000..ed91fd14d --- /dev/null +++ b/Examples/python/performance/deep_hierarchy/Simple_baseline.py @@ -0,0 +1,205 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. +# This file is compatible with both classic and new-style classes. + +from sys import version_info +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_baseline', [dirname(__file__)]) + except ImportError: + import _Simple_baseline + return _Simple_baseline + if fp is not None: + try: + _mod = imp.load_module('_Simple_baseline', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_baseline = swig_import_helper() + del swig_import_helper +else: + import _Simple_baseline +del version_info +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +class A(_object): + __swig_setmethods__ = {} + __setattr__ = lambda self, name, value: _swig_setattr(self, A, name, value) + __swig_getmethods__ = {} + __getattr__ = lambda self, name: _swig_getattr(self, A, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_A() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_A + __del__ = lambda self : None; + def func(self): return _Simple_baseline.A_func(self) +A_swigregister = _Simple_baseline.A_swigregister +A_swigregister(A) + +class B(A): + __swig_setmethods__ = {} + for _s in [A]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, B, name, value) + __swig_getmethods__ = {} + for _s in [A]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, B, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_B() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_B + __del__ = lambda self : None; +B_swigregister = _Simple_baseline.B_swigregister +B_swigregister(B) + +class C(B): + __swig_setmethods__ = {} + for _s in [B]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, C, name, value) + __swig_getmethods__ = {} + for _s in [B]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, C, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_C() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_C + __del__ = lambda self : None; +C_swigregister = _Simple_baseline.C_swigregister +C_swigregister(C) + +class D(C): + __swig_setmethods__ = {} + for _s in [C]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, D, name, value) + __swig_getmethods__ = {} + for _s in [C]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, D, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_D() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_D + __del__ = lambda self : None; +D_swigregister = _Simple_baseline.D_swigregister +D_swigregister(D) + +class E(D): + __swig_setmethods__ = {} + for _s in [D]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, E, name, value) + __swig_getmethods__ = {} + for _s in [D]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, E, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_E() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_E + __del__ = lambda self : None; +E_swigregister = _Simple_baseline.E_swigregister +E_swigregister(E) + +class F(E): + __swig_setmethods__ = {} + for _s in [E]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, F, name, value) + __swig_getmethods__ = {} + for _s in [E]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, F, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_F() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_F + __del__ = lambda self : None; +F_swigregister = _Simple_baseline.F_swigregister +F_swigregister(F) + +class G(F): + __swig_setmethods__ = {} + for _s in [F]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, G, name, value) + __swig_getmethods__ = {} + for _s in [F]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, G, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_G() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_G + __del__ = lambda self : None; +G_swigregister = _Simple_baseline.G_swigregister +G_swigregister(G) + +class H(G): + __swig_setmethods__ = {} + for _s in [G]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, H, name, value) + __swig_getmethods__ = {} + for _s in [G]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, H, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_H() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_H + __del__ = lambda self : None; +H_swigregister = _Simple_baseline.H_swigregister +H_swigregister(H) + + + diff --git a/Examples/python/performance/deep_hierarchy/Simple_builtin.py b/Examples/python/performance/deep_hierarchy/Simple_builtin.py new file mode 100644 index 000000000..6572f16bc --- /dev/null +++ b/Examples/python/performance/deep_hierarchy/Simple_builtin.py @@ -0,0 +1,88 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. + +from sys import version_info +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_builtin', [dirname(__file__)]) + except ImportError: + import _Simple_builtin + return _Simple_builtin + if fp is not None: + try: + _mod = imp.load_module('_Simple_builtin', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_builtin = swig_import_helper() + del swig_import_helper +else: + import _Simple_builtin +del version_info +from _Simple_builtin import * +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + + + + + + + + + + + diff --git a/Examples/python/performance/deep_hierarchy/Simple_optimized.py b/Examples/python/performance/deep_hierarchy/Simple_optimized.py new file mode 100644 index 000000000..3cfcda3b1 --- /dev/null +++ b/Examples/python/performance/deep_hierarchy/Simple_optimized.py @@ -0,0 +1,156 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. + +from sys import version_info +if version_info >= (3,0,0): + new_instancemethod = lambda func, inst, cls: _Simple_optimized.SWIG_PyInstanceMethod_New(func) +else: + from new import instancemethod as new_instancemethod +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_optimized', [dirname(__file__)]) + except ImportError: + import _Simple_optimized + return _Simple_optimized + if fp is not None: + try: + _mod = imp.load_module('_Simple_optimized', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_optimized = swig_import_helper() + del swig_import_helper +else: + import _Simple_optimized +del version_info +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + +class A(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.A_swiginit(self,_Simple_optimized.new_A()) + __swig_destroy__ = _Simple_optimized.delete_A +A.func = new_instancemethod(_Simple_optimized.A_func,None,A) +A_swigregister = _Simple_optimized.A_swigregister +A_swigregister(A) + +class B(A): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.B_swiginit(self,_Simple_optimized.new_B()) + __swig_destroy__ = _Simple_optimized.delete_B +B_swigregister = _Simple_optimized.B_swigregister +B_swigregister(B) + +class C(B): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.C_swiginit(self,_Simple_optimized.new_C()) + __swig_destroy__ = _Simple_optimized.delete_C +C_swigregister = _Simple_optimized.C_swigregister +C_swigregister(C) + +class D(C): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.D_swiginit(self,_Simple_optimized.new_D()) + __swig_destroy__ = _Simple_optimized.delete_D +D_swigregister = _Simple_optimized.D_swigregister +D_swigregister(D) + +class E(D): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.E_swiginit(self,_Simple_optimized.new_E()) + __swig_destroy__ = _Simple_optimized.delete_E +E_swigregister = _Simple_optimized.E_swigregister +E_swigregister(E) + +class F(E): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.F_swiginit(self,_Simple_optimized.new_F()) + __swig_destroy__ = _Simple_optimized.delete_F +F_swigregister = _Simple_optimized.F_swigregister +F_swigregister(F) + +class G(F): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.G_swiginit(self,_Simple_optimized.new_G()) + __swig_destroy__ = _Simple_optimized.delete_G +G_swigregister = _Simple_optimized.G_swigregister +G_swigregister(G) + +class H(G): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.H_swiginit(self,_Simple_optimized.new_H()) + __swig_destroy__ = _Simple_optimized.delete_H +H_swigregister = _Simple_optimized.H_swigregister +H_swigregister(H) + + + diff --git a/Examples/python/performance/deep_hierarchy/runme.py b/Examples/python/performance/deep_hierarchy/runme.py new file mode 100644 index 000000000..7e50aff16 --- /dev/null +++ b/Examples/python/performance/deep_hierarchy/runme.py @@ -0,0 +1,17 @@ +#!/usr/bin/env + +import sys +from subprocess import * + +proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + +proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + +proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + diff --git a/Examples/python/performance/deep_hierarchy/runme_baseline.py b/Examples/python/performance/deep_hierarchy/runme_baseline.py new file mode 100644 index 000000000..584b9fb97 --- /dev/null +++ b/Examples/python/performance/deep_hierarchy/runme_baseline.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_baseline +import time + +t1 = time.clock() +x = Simple_baseline.H() +for i in range(10000000) : + x.func() +t2 = time.clock() +print "Simple_baseline took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/deep_hierarchy/runme_builtin.py b/Examples/python/performance/deep_hierarchy/runme_builtin.py new file mode 100644 index 000000000..a095ed223 --- /dev/null +++ b/Examples/python/performance/deep_hierarchy/runme_builtin.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_builtin +import time + +t1 = time.clock() +x = Simple_builtin.H() +for i in range(10000000) : + x.func() +t2 = time.clock() +print "Simple_builtin took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/deep_hierarchy/runme_optimized.py b/Examples/python/performance/deep_hierarchy/runme_optimized.py new file mode 100644 index 000000000..c6f20463d --- /dev/null +++ b/Examples/python/performance/deep_hierarchy/runme_optimized.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_optimized +import time + +t1 = time.clock() +x = Simple_optimized.H() +for i in range(10000000) : + x.func() +t2 = time.clock() +print "Simple_optimized took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/func/Makefile b/Examples/python/performance/func/Makefile new file mode 100644 index 000000000..0df09d908 --- /dev/null +++ b/Examples/python/performance/func/Makefile @@ -0,0 +1,23 @@ +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = +TARGET = Simple +INTERFACE = Simple.i + +default : all + +all : + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ + TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ + TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ + TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp + +static : + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static + +clean : + $(MAKE) -f $(TOP)/Makefile python_clean + rm -f $(TARGET).py diff --git a/Examples/python/performance/func/Simple.i b/Examples/python/performance/func/Simple.i new file mode 100644 index 000000000..d642d15bf --- /dev/null +++ b/Examples/python/performance/func/Simple.i @@ -0,0 +1,8 @@ +%inline %{ +class MyClass { +public: + MyClass () {} + ~MyClass () {} + void func () {} +}; +%} diff --git a/Examples/python/performance/func/Simple_baseline.py b/Examples/python/performance/func/Simple_baseline.py new file mode 100644 index 000000000..7e401b403 --- /dev/null +++ b/Examples/python/performance/func/Simple_baseline.py @@ -0,0 +1,86 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. +# This file is compatible with both classic and new-style classes. + +from sys import version_info +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_baseline', [dirname(__file__)]) + except ImportError: + import _Simple_baseline + return _Simple_baseline + if fp is not None: + try: + _mod = imp.load_module('_Simple_baseline', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_baseline = swig_import_helper() + del swig_import_helper +else: + import _Simple_baseline +del version_info +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +class MyClass(_object): + __swig_setmethods__ = {} + __setattr__ = lambda self, name, value: _swig_setattr(self, MyClass, name, value) + __swig_getmethods__ = {} + __getattr__ = lambda self, name: _swig_getattr(self, MyClass, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_MyClass() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_MyClass + __del__ = lambda self : None; + def func(self): return _Simple_baseline.MyClass_func(self) +MyClass_swigregister = _Simple_baseline.MyClass_swigregister +MyClass_swigregister(MyClass) + + + diff --git a/Examples/python/performance/func/Simple_builtin.py b/Examples/python/performance/func/Simple_builtin.py new file mode 100644 index 000000000..4ecd8a63e --- /dev/null +++ b/Examples/python/performance/func/Simple_builtin.py @@ -0,0 +1,81 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. + +from sys import version_info +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_builtin', [dirname(__file__)]) + except ImportError: + import _Simple_builtin + return _Simple_builtin + if fp is not None: + try: + _mod = imp.load_module('_Simple_builtin', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_builtin = swig_import_helper() + del swig_import_helper +else: + import _Simple_builtin +del version_info +from _Simple_builtin import * +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + + + + diff --git a/Examples/python/performance/func/Simple_optimized.py b/Examples/python/performance/func/Simple_optimized.py new file mode 100644 index 000000000..0bf42ced3 --- /dev/null +++ b/Examples/python/performance/func/Simple_optimized.py @@ -0,0 +1,93 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. + +from sys import version_info +if version_info >= (3,0,0): + new_instancemethod = lambda func, inst, cls: _Simple_optimized.SWIG_PyInstanceMethod_New(func) +else: + from new import instancemethod as new_instancemethod +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_optimized', [dirname(__file__)]) + except ImportError: + import _Simple_optimized + return _Simple_optimized + if fp is not None: + try: + _mod = imp.load_module('_Simple_optimized', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_optimized = swig_import_helper() + del swig_import_helper +else: + import _Simple_optimized +del version_info +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + +class MyClass(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.MyClass_swiginit(self,_Simple_optimized.new_MyClass()) + __swig_destroy__ = _Simple_optimized.delete_MyClass +MyClass.func = new_instancemethod(_Simple_optimized.MyClass_func,None,MyClass) +MyClass_swigregister = _Simple_optimized.MyClass_swigregister +MyClass_swigregister(MyClass) + + + diff --git a/Examples/python/performance/func/runme.py b/Examples/python/performance/func/runme.py new file mode 100644 index 000000000..7e50aff16 --- /dev/null +++ b/Examples/python/performance/func/runme.py @@ -0,0 +1,17 @@ +#!/usr/bin/env + +import sys +from subprocess import * + +proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + +proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + +proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + diff --git a/Examples/python/performance/func/runme_baseline.py b/Examples/python/performance/func/runme_baseline.py new file mode 100644 index 000000000..6966fd904 --- /dev/null +++ b/Examples/python/performance/func/runme_baseline.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_baseline +import time + +t1 = time.clock() +x = Simple_baseline.MyClass() +for i in range(10000000) : + x.func() +t2 = time.clock() +print "Simple_baseline took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/func/runme_builtin.py b/Examples/python/performance/func/runme_builtin.py new file mode 100644 index 000000000..ca2f88ac8 --- /dev/null +++ b/Examples/python/performance/func/runme_builtin.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_builtin +import time + +t1 = time.clock() +x = Simple_builtin.MyClass() +for i in range(10000000) : + x.func() +t2 = time.clock() +print "Simple_builtin took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/func/runme_optimized.py b/Examples/python/performance/func/runme_optimized.py new file mode 100644 index 000000000..fe10eb376 --- /dev/null +++ b/Examples/python/performance/func/runme_optimized.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_optimized +import time + +t1 = time.clock() +x = Simple_optimized.MyClass() +for i in range(10000000) : + x.func() +t2 = time.clock() +print "Simple_optimized took %f seconds" % (t2 - t1) From 6fa3033971fdffc77fcdd6edd6e5c7e0378507ce Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Wed, 9 Feb 2011 07:35:56 +0000 Subject: [PATCH 20/56] Makefile tweaks git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12445 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/python/performance/Makefile | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Examples/python/performance/Makefile b/Examples/python/performance/Makefile index c1b4a69c6..0a2dabaa9 100644 --- a/Examples/python/performance/Makefile +++ b/Examples/python/performance/Makefile @@ -14,9 +14,7 @@ SUBDIRS := constructor func deep_hierarchy default : all -.PHONY : $(SUBDIRS) all clean - -all : $(SUBDIRS) +all : $(SUBDIRS:%=%-build) @for subdir in $(SUBDIRS); do \ echo Running $$subdir test... ; \ echo -------------------------------------------------------------------------------- ; \ @@ -31,10 +29,10 @@ $(SUBDIRS) : @echo -------------------------------------------------------------------------------- cd $@ && env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(PYTHON) $(PYSCRIPT) +%-build : + $(MAKE) -C $* + %-clean : $(MAKE) -s -C $* clean -$(SUBDIRS:%=%-check) : - $(MAKE) -C $* check - clean : $(SUBDIRS:%=%-clean) From b5889b8b0fca55583acc8da3067ca7867778de7c Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Wed, 9 Feb 2011 08:59:09 +0000 Subject: [PATCH 21/56] Unicode fixes for python3. Added a few more closure types. Guard against operator overloads outside of a class declaration. Incorporate fix for patch #3171793. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12446 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/builtin.swg | 31 ++++++++++++++++++++++ Lib/python/pyhead.swg | 3 ++- Lib/python/pyrun.swg | 41 ++++++++++++++--------------- Source/Modules/allocate.cxx | 2 +- Source/Modules/python.cxx | 52 +++++++++++++++++++++---------------- 5 files changed, 83 insertions(+), 46 deletions(-) diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index bba988dd4..b662acbb7 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -153,6 +153,37 @@ wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \ return result; \ } +#define PYSWIG_REPRFUNC_CLOSURE(wrapper) \ +SWIGINTERN PyObject* \ +wrapper##_closure (PyObject *a) \ +{ \ + return wrapper(a, NULL); \ +} + +#define PYSWIG_HASHFUNC_CLOSURE(wrapper) \ +SWIGINTERN long \ +wrapper##_closure (PyObject *a) \ +{ \ + PyObject *pyresult = wrapper(a, NULL); \ + if (!pyresult || !PyLong_Check(pyresult)) \ + return -1; \ + long result = PyLong_AsLong(pyresult); \ + Py_DECREF(pyresult); \ + return result; \ +} + +#define PYSWIG_ITERNEXT_CLOSURE(wrapper) \ +SWIGINTERN PyObject* \ +wrapper##_closure (PyObject *a) \ +{ \ + PyObject *result = wrapper(a, NULL); \ + if (result && result == Py_None) { \ + Py_DECREF(result); \ + result = NULL; \ + } \ + return result; \ +} + SWIGRUNTIME int py_builtin_bad_init (PyObject *self, PyObject *args, PyObject *kwds) { PyErr_Format(PyExc_TypeError, "Cannot create new instances of type '%.300s'", self->ob_type->tp_name); diff --git a/Lib/python/pyhead.swg b/Lib/python/pyhead.swg index c7f897f78..98ffa8d63 100644 --- a/Lib/python/pyhead.swg +++ b/Lib/python/pyhead.swg @@ -5,10 +5,11 @@ #define PyInt_Check(x) PyLong_Check(x) #define PyInt_AsLong(x) PyLong_AsLong(x) #define PyInt_FromLong(x) PyLong_FromLong(x) +#define PyString_Check(name) PyBytes_Check(name) #define PyString_FromString(x) PyUnicode_FromString(x) #define PyString_Format(fmt, args) PyUnicode_Format(fmt, args) +#define PyString_AsString(str) PyBytes_AsString(str) #define PyString_InternFromString(key) PyUnicode_InternFromString(key) -#define PyString_Check(name) PyUnicode_Check(name) #define Py_TPFLAGS_HAVE_CLASS Py_TPFLAGS_BASETYPE #define PyString_AS_STRING(x) PyUnicode_AS_STRING(x) #define _PyLong_FromSsize_t(x) PyLong_FromSsize_t(x) diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index f1857fe27..57b3d1780 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1703,24 +1703,22 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) descrsetfunc f; int res = -1; - if (!PyString_Check(name)) { #ifdef Py_USING_UNICODE - if (PyUnicode_Check(name)) { - name = PyUnicode_AsEncodedString(name, NULL, NULL); - if (name == NULL) - return -1; - } - else + if (PyString_Check(name)) { + name = PyUnicode_Decode(PyString_AsString(name), PyBytes_Size(name), NULL, NULL); + if (name == NULL) + return -1; + } else if (!PyUnicode_Check(name)) { +#else + if (!PyString_Check(name)) { #endif - { - PyErr_Format(PyExc_TypeError, - "attribute name must be string, not '%.200s'", - name->ob_type->tp_name); - return -1; - } - } - else + PyErr_Format(PyExc_TypeError, + "attribute name must be string, not '%.200s'", + name->ob_type->tp_name); + return -1; + } else { Py_INCREF(name); + } if (tp->tp_dict == NULL) { if (PyType_Ready(tp) < 0) @@ -1731,21 +1729,22 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) f = NULL; if (descr != NULL) f = descr->ob_type->tp_descr_set; - if (f == NULL) + if (f == NULL) { PyErr_Format(PyExc_AttributeError, -#if PY_VERSION_HEX >= 0x03000000 +#ifdef Py_USING_UNICODE "'%.100s' object has no attribute '%.200U'", #else "'%.100s' object has no attribute '%.200S'", #endif tp->tp_name, name); - else + } else { res = f(descr, obj, value); - -done: + } + + done: Py_DECREF(name); return res; -} + } #ifdef __cplusplus diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx index 1a62f5d69..110a92939 100644 --- a/Source/Modules/allocate.cxx +++ b/Source/Modules/allocate.cxx @@ -216,7 +216,7 @@ class Allocate:public Dispatcher { if (!most_base_covariant_type) { // Eliminate the derived virtual method. - if (virtual_elimination_mode && !this_wrapping_protected_members) + if (virtual_elimination_mode && !is_member_director(n)) if (both_have_public_access) if (!is_non_public_base(inclass, b)) if (!Swig_symbol_isoverloaded(n)) { diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 16385d798..9eaaa1f9d 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -176,7 +176,6 @@ static String *getClosure(String *functype, String *wrapper, int funpack = 0) { "destructor", "PYSWIG_DESTRUCTOR_CLOSURE", "inquiry", "PYSWIG_INQUIRY_CLOSURE", "getiterfunc", "PYSWIG_UNARYFUNC_CLOSURE", - "iternextfunc", "PYSWIG_UNARYFUNC_CLOSURE", "binaryfunc", "PYSWIG_BINARYFUNC_CLOSURE", "ternaryfunc", "PYSWIG_TERNARYFUNC_CLOSURE", "lenfunc", "PYSWIG_LENFUNC_CLOSURE", @@ -185,6 +184,9 @@ static String *getClosure(String *functype, String *wrapper, int funpack = 0) { "ssizeobjargproc", "PYSWIG_SSIZEOBJARGPROC_CLOSURE", "ssizessizeobjargproc", "PYSWIG_SSIZESSIZEOBJARGPROC_CLOSURE", "objobjargproc", "PYSWIG_OBJOBJARGPROC_CLOSURE", + "reprfunc", "PYSWIG_REPRFUNC_CLOSURE", + "hashfunc", "PYSWIG_HASHFUNC_CLOSURE", + "iternextfunc", "PYSWIG_ITERNEXT_CLOSURE", NULL }; @@ -193,7 +195,6 @@ static String *getClosure(String *functype, String *wrapper, int funpack = 0) { "destructor", "PYSWIG_DESTRUCTOR_CLOSURE", "inquiry", "PYSWIG_INQUIRY_CLOSURE", "getiterfunc", "PYSWIG_UNARYFUNC_CLOSURE", - "iternextfunc", "PYSWIG_UNARYFUNC_CLOSURE", "ternaryfunc", "PYSWIG_TERNARYFUNC_CLOSURE", "lenfunc", "PYSWIG_LENFUNC_CLOSURE", "ssizeargfunc", "PYSWIG_FUNPACK_SSIZEARGFUNC_CLOSURE", @@ -201,6 +202,9 @@ static String *getClosure(String *functype, String *wrapper, int funpack = 0) { "ssizeobjargproc", "PYSWIG_SSIZEOBJARGPROC_CLOSURE", "ssizessizeobjargproc", "PYSWIG_SSIZESSIZEOBJARGPROC_CLOSURE", "objobjargproc", "PYSWIG_OBJOBJARGPROC_CLOSURE", + "reprfunc", "PYSWIG_REPRFUNC_CLOSURE", + "hashfunc", "PYSWIG_HASHFUNC_CLOSURE", + "iternextfunc", "PYSWIG_ITERNEXT_CLOSURE", NULL }; @@ -2637,29 +2641,31 @@ public: Delattr(n, "memberset"); } - /* Handle builtin operator overloads */ - String *slot = Getattr(n, "feature:pyslot"); - if (slot) { - String *closure_decl = getClosure(Getattr(n, "feature:pyslot:functype"), wrapper_name, overname ? 0 : funpack); - String *feature_name = NewStringf("feature:%s", slot); - String *closure_name = Copy(wrapper_name); - if (closure_decl) { - if (!Getattr(n, "sym:overloaded") || !Getattr(n, "sym:nextSibling")) - Printv(f_wrappers, closure_decl, "\n\n", NIL); - Append(closure_name, "_closure"); - Delete(closure_decl); + if (in_class && builtin) { + /* Handle operator overloads overloads for builtin types */ + String *slot = Getattr(n, "feature:pyslot"); + if (slot) { + String *closure_decl = getClosure(Getattr(n, "feature:pyslot:functype"), wrapper_name, overname ? 0 : funpack); + String *feature_name = NewStringf("feature:%s", slot); + String *closure_name = Copy(wrapper_name); + if (closure_decl) { + if (!Getattr(n, "sym:overloaded") || !Getattr(n, "sym:nextSibling")) + Printv(f_wrappers, closure_decl, "\n\n", NIL); + Append(closure_name, "_closure"); + Delete(closure_decl); + } + Setattr(parent, feature_name, closure_name); + Delete(feature_name); + Delete(closure_name); } - Setattr(parent, feature_name, closure_name); - Delete(feature_name); - Delete(closure_name); - } - /* Handle comparison operators for builtin types */ - String *compare = Getattr(n, "feature:pycompare"); - if (compare) { - Hash *richcompare = Getattr(parent, "richcompare"); - assert(richcompare); - Setattr(richcompare, compare, wrapper_name); + /* Handle comparison operators for builtin types */ + String *compare = Getattr(n, "feature:pycompare"); + if (compare) { + Hash *richcompare = Getattr(parent, "richcompare"); + assert(richcompare); + Setattr(richcompare, compare, wrapper_name); + } } Delete(self_parse); From 011049ffe2c2b7e6d69d2a1f2225ea610a3025bf Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Thu, 10 Feb 2011 05:04:12 +0000 Subject: [PATCH 22/56] Another macro define for unicode. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12447 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pyhead.swg | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/python/pyhead.swg b/Lib/python/pyhead.swg index 98ffa8d63..2ce0fb194 100644 --- a/Lib/python/pyhead.swg +++ b/Lib/python/pyhead.swg @@ -9,6 +9,7 @@ #define PyString_FromString(x) PyUnicode_FromString(x) #define PyString_Format(fmt, args) PyUnicode_Format(fmt, args) #define PyString_AsString(str) PyBytes_AsString(str) +#define PyString_Size(str) PyBytes_Size(str) #define PyString_InternFromString(key) PyUnicode_InternFromString(key) #define Py_TPFLAGS_HAVE_CLASS Py_TPFLAGS_BASETYPE #define PyString_AS_STRING(x) PyUnicode_AS_STRING(x) From 5db5f109c77ad194a044695060e4a5ae628e123e Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Thu, 10 Feb 2011 05:05:14 +0000 Subject: [PATCH 23/56] python3 won't let you declare an 'except' clause for a non-throwable type, even if the clause is never executed. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12448 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../python/exception_order_runme.py | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Examples/test-suite/python/exception_order_runme.py b/Examples/test-suite/python/exception_order_runme.py index 4d74b9e7d..cd9144a98 100644 --- a/Examples/test-suite/python/exception_order_runme.py +++ b/Examples/test-suite/python/exception_order_runme.py @@ -5,20 +5,20 @@ a = A() try: a.foo() -except E1,e: - pass +# Throwing builtin classes as exceptions not supported +#except E1,e: +# pass except: - # Throwing builtin classes as exceptions not supported - #raise RuntimeError, "bad exception order" +# raise RuntimeError, "bad exception order" pass try: a.bar() -except E2,e: - pass +# Throwing builtin classes as exceptions not supported +#except E2,e: +# pass except: - # Throwing builtin classes as exceptions not supported - #raise RuntimeError, "bad exception order" +# raise RuntimeError, "bad exception order" pass try: @@ -32,18 +32,18 @@ except RuntimeError,e: try: a.barfoo(1) -except E1,e: - pass +# Throwing builtin classes as exceptions not supported +#except E1,e: +# pass except: - # Throwing builtin classes as exceptions not supported - #raise RuntimeError, "bad exception order" +# raise RuntimeError, "bad exception order" pass try: a.barfoo(2) -except E2,e: - pass +# Throwing builtin classes as exceptions not supported +#except E2,e: +# pass except: - # Throwing builtin classes as exceptions not supported - #raise RuntimeError, "bad exception order" +# raise RuntimeError, "bad exception order" pass From e5bf6419b2441044796b8efbfa39355a38fd152e Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Thu, 10 Feb 2011 05:15:03 +0000 Subject: [PATCH 24/56] Test operator overloads with deep hierarchy. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12449 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../performance/hierarchy_operator/Makefile | 23 + .../performance/hierarchy_operator/Simple.i | 53 + .../hierarchy_operator/Simple_baseline.py | 206 + .../hierarchy_operator/Simple_builtin.py | 88 + .../hierarchy_operator/Simple_optimized.py | 157 + .../hierarchy_operator/Simple_wrap.cxx | 6456 +++++++++++++++++ .../performance/hierarchy_operator/runme.py | 17 + .../hierarchy_operator/runme_baseline.py | 11 + .../hierarchy_operator/runme_builtin.py | 11 + .../hierarchy_operator/runme_optimized.py | 11 + 10 files changed, 7033 insertions(+) create mode 100644 Examples/python/performance/hierarchy_operator/Makefile create mode 100644 Examples/python/performance/hierarchy_operator/Simple.i create mode 100644 Examples/python/performance/hierarchy_operator/Simple_baseline.py create mode 100644 Examples/python/performance/hierarchy_operator/Simple_builtin.py create mode 100644 Examples/python/performance/hierarchy_operator/Simple_optimized.py create mode 100644 Examples/python/performance/hierarchy_operator/Simple_wrap.cxx create mode 100644 Examples/python/performance/hierarchy_operator/runme.py create mode 100644 Examples/python/performance/hierarchy_operator/runme_baseline.py create mode 100644 Examples/python/performance/hierarchy_operator/runme_builtin.py create mode 100644 Examples/python/performance/hierarchy_operator/runme_optimized.py diff --git a/Examples/python/performance/hierarchy_operator/Makefile b/Examples/python/performance/hierarchy_operator/Makefile new file mode 100644 index 000000000..0df09d908 --- /dev/null +++ b/Examples/python/performance/hierarchy_operator/Makefile @@ -0,0 +1,23 @@ +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = +TARGET = Simple +INTERFACE = Simple.i + +default : all + +all : + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ + TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ + TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ + TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp + +static : + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static + +clean : + $(MAKE) -f $(TOP)/Makefile python_clean + rm -f $(TARGET).py diff --git a/Examples/python/performance/hierarchy_operator/Simple.i b/Examples/python/performance/hierarchy_operator/Simple.i new file mode 100644 index 000000000..b26bcf31d --- /dev/null +++ b/Examples/python/performance/hierarchy_operator/Simple.i @@ -0,0 +1,53 @@ +%inline %{ + +class A { +public: + A () {} + ~A () {} + void func () {} + A& operator+= (int i) { return *this; } +}; + +class B : public A { +public: + B () {} + ~B () {} +}; + +class C : public B { +public: + C () {} + ~C () {} +}; + +class D : public C { +public: + D () {} + ~D () {} +}; + +class E : public D { +public: + E () {} + ~E () {} +}; + +class F : public E { +public: + F () {} + ~F () {} +}; + +class G : public F { +public: + G () {} + ~G () {} +}; + +class H : public G { +public: + H () {} + ~H () {} +}; + +%} diff --git a/Examples/python/performance/hierarchy_operator/Simple_baseline.py b/Examples/python/performance/hierarchy_operator/Simple_baseline.py new file mode 100644 index 000000000..ab5dc8594 --- /dev/null +++ b/Examples/python/performance/hierarchy_operator/Simple_baseline.py @@ -0,0 +1,206 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. +# This file is compatible with both classic and new-style classes. + +from sys import version_info +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_baseline', [dirname(__file__)]) + except ImportError: + import _Simple_baseline + return _Simple_baseline + if fp is not None: + try: + _mod = imp.load_module('_Simple_baseline', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_baseline = swig_import_helper() + del swig_import_helper +else: + import _Simple_baseline +del version_info +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +class A(_object): + __swig_setmethods__ = {} + __setattr__ = lambda self, name, value: _swig_setattr(self, A, name, value) + __swig_getmethods__ = {} + __getattr__ = lambda self, name: _swig_getattr(self, A, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_A() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_A + __del__ = lambda self : None; + def func(self): return _Simple_baseline.A_func(self) + def __iadd__(self, *args): return _Simple_baseline.A___iadd__(self, *args) +A_swigregister = _Simple_baseline.A_swigregister +A_swigregister(A) + +class B(A): + __swig_setmethods__ = {} + for _s in [A]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, B, name, value) + __swig_getmethods__ = {} + for _s in [A]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, B, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_B() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_B + __del__ = lambda self : None; +B_swigregister = _Simple_baseline.B_swigregister +B_swigregister(B) + +class C(B): + __swig_setmethods__ = {} + for _s in [B]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, C, name, value) + __swig_getmethods__ = {} + for _s in [B]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, C, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_C() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_C + __del__ = lambda self : None; +C_swigregister = _Simple_baseline.C_swigregister +C_swigregister(C) + +class D(C): + __swig_setmethods__ = {} + for _s in [C]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, D, name, value) + __swig_getmethods__ = {} + for _s in [C]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, D, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_D() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_D + __del__ = lambda self : None; +D_swigregister = _Simple_baseline.D_swigregister +D_swigregister(D) + +class E(D): + __swig_setmethods__ = {} + for _s in [D]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, E, name, value) + __swig_getmethods__ = {} + for _s in [D]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, E, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_E() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_E + __del__ = lambda self : None; +E_swigregister = _Simple_baseline.E_swigregister +E_swigregister(E) + +class F(E): + __swig_setmethods__ = {} + for _s in [E]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, F, name, value) + __swig_getmethods__ = {} + for _s in [E]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, F, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_F() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_F + __del__ = lambda self : None; +F_swigregister = _Simple_baseline.F_swigregister +F_swigregister(F) + +class G(F): + __swig_setmethods__ = {} + for _s in [F]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, G, name, value) + __swig_getmethods__ = {} + for _s in [F]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, G, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_G() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_G + __del__ = lambda self : None; +G_swigregister = _Simple_baseline.G_swigregister +G_swigregister(G) + +class H(G): + __swig_setmethods__ = {} + for _s in [G]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) + __setattr__ = lambda self, name, value: _swig_setattr(self, H, name, value) + __swig_getmethods__ = {} + for _s in [G]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) + __getattr__ = lambda self, name: _swig_getattr(self, H, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_H() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_H + __del__ = lambda self : None; +H_swigregister = _Simple_baseline.H_swigregister +H_swigregister(H) + + + diff --git a/Examples/python/performance/hierarchy_operator/Simple_builtin.py b/Examples/python/performance/hierarchy_operator/Simple_builtin.py new file mode 100644 index 000000000..6572f16bc --- /dev/null +++ b/Examples/python/performance/hierarchy_operator/Simple_builtin.py @@ -0,0 +1,88 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. + +from sys import version_info +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_builtin', [dirname(__file__)]) + except ImportError: + import _Simple_builtin + return _Simple_builtin + if fp is not None: + try: + _mod = imp.load_module('_Simple_builtin', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_builtin = swig_import_helper() + del swig_import_helper +else: + import _Simple_builtin +del version_info +from _Simple_builtin import * +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + + + + + + + + + + + diff --git a/Examples/python/performance/hierarchy_operator/Simple_optimized.py b/Examples/python/performance/hierarchy_operator/Simple_optimized.py new file mode 100644 index 000000000..0e824ea40 --- /dev/null +++ b/Examples/python/performance/hierarchy_operator/Simple_optimized.py @@ -0,0 +1,157 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. + +from sys import version_info +if version_info >= (3,0,0): + new_instancemethod = lambda func, inst, cls: _Simple_optimized.SWIG_PyInstanceMethod_New(func) +else: + from new import instancemethod as new_instancemethod +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_optimized', [dirname(__file__)]) + except ImportError: + import _Simple_optimized + return _Simple_optimized + if fp is not None: + try: + _mod = imp.load_module('_Simple_optimized', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_optimized = swig_import_helper() + del swig_import_helper +else: + import _Simple_optimized +del version_info +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + +class A(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.A_swiginit(self,_Simple_optimized.new_A()) + __swig_destroy__ = _Simple_optimized.delete_A +A.func = new_instancemethod(_Simple_optimized.A_func,None,A) +A.__iadd__ = new_instancemethod(_Simple_optimized.A___iadd__,None,A) +A_swigregister = _Simple_optimized.A_swigregister +A_swigregister(A) + +class B(A): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.B_swiginit(self,_Simple_optimized.new_B()) + __swig_destroy__ = _Simple_optimized.delete_B +B_swigregister = _Simple_optimized.B_swigregister +B_swigregister(B) + +class C(B): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.C_swiginit(self,_Simple_optimized.new_C()) + __swig_destroy__ = _Simple_optimized.delete_C +C_swigregister = _Simple_optimized.C_swigregister +C_swigregister(C) + +class D(C): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.D_swiginit(self,_Simple_optimized.new_D()) + __swig_destroy__ = _Simple_optimized.delete_D +D_swigregister = _Simple_optimized.D_swigregister +D_swigregister(D) + +class E(D): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.E_swiginit(self,_Simple_optimized.new_E()) + __swig_destroy__ = _Simple_optimized.delete_E +E_swigregister = _Simple_optimized.E_swigregister +E_swigregister(E) + +class F(E): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.F_swiginit(self,_Simple_optimized.new_F()) + __swig_destroy__ = _Simple_optimized.delete_F +F_swigregister = _Simple_optimized.F_swigregister +F_swigregister(F) + +class G(F): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.G_swiginit(self,_Simple_optimized.new_G()) + __swig_destroy__ = _Simple_optimized.delete_G +G_swigregister = _Simple_optimized.G_swigregister +G_swigregister(G) + +class H(G): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.H_swiginit(self,_Simple_optimized.new_H()) + __swig_destroy__ = _Simple_optimized.delete_H +H_swigregister = _Simple_optimized.H_swigregister +H_swigregister(H) + + + diff --git a/Examples/python/performance/hierarchy_operator/Simple_wrap.cxx b/Examples/python/performance/hierarchy_operator/Simple_wrap.cxx new file mode 100644 index 000000000..0b1c79bed --- /dev/null +++ b/Examples/python/performance/hierarchy_operator/Simple_wrap.cxx @@ -0,0 +1,6456 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 2.0.2 + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + +#define SWIGPYTHON +#define SWIG_PYTHON_NO_BUILD_NONE +#define SWIG_PYTHON_DIRECTOR_NO_VTABLE +#define SWIGPYTHON_BUILTIN + + +#ifdef __cplusplus +/* SwigValueWrapper is described in swig.swg */ +template class SwigValueWrapper { + struct SwigMovePointer { + T *ptr; + SwigMovePointer(T *p) : ptr(p) { } + ~SwigMovePointer() { delete ptr; } + SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; } + } pointer; + SwigValueWrapper& operator=(const SwigValueWrapper& rhs); + SwigValueWrapper(const SwigValueWrapper& rhs); +public: + SwigValueWrapper() : pointer(0) { } + SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; } + operator T&() const { return *pointer.ptr; } + T *operator&() { return pointer.ptr; } +}; + +template T SwigValueInit() { + return T(); +} +#endif + +/* ----------------------------------------------------------------------------- + * This section contains generic SWIG labels for method/variable + * declarations/attributes, and other compiler dependent labels. + * ----------------------------------------------------------------------------- */ + +/* template workaround for compilers that cannot correctly implement the C++ standard */ +#ifndef SWIGTEMPLATEDISAMBIGUATOR +# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) +# define SWIGTEMPLATEDISAMBIGUATOR template +# elif defined(__HP_aCC) +/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ +/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ +# define SWIGTEMPLATEDISAMBIGUATOR template +# else +# define SWIGTEMPLATEDISAMBIGUATOR +# endif +#endif + +/* inline attribute */ +#ifndef SWIGINLINE +# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) +# define SWIGINLINE inline +# else +# define SWIGINLINE +# endif +#endif + +/* attribute recognised by some compilers to avoid 'unused' warnings */ +#ifndef SWIGUNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define SWIGUNUSED __attribute__ ((__unused__)) +# else +# define SWIGUNUSED +# endif +# elif defined(__ICC) +# define SWIGUNUSED __attribute__ ((__unused__)) +# else +# define SWIGUNUSED +# endif +#endif + +#ifndef SWIG_MSC_UNSUPPRESS_4505 +# if defined(_MSC_VER) +# pragma warning(disable : 4505) /* unreferenced local function has been removed */ +# endif +#endif + +#ifndef SWIGUNUSEDPARM +# ifdef __cplusplus +# define SWIGUNUSEDPARM(p) +# else +# define SWIGUNUSEDPARM(p) p SWIGUNUSED +# endif +#endif + +/* internal SWIG method */ +#ifndef SWIGINTERN +# define SWIGINTERN static SWIGUNUSED +#endif + +/* internal inline SWIG method */ +#ifndef SWIGINTERNINLINE +# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE +#endif + +/* exporting methods */ +#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) +# ifndef GCC_HASCLASSVISIBILITY +# define GCC_HASCLASSVISIBILITY +# endif +#endif + +#ifndef SWIGEXPORT +# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# if defined(STATIC_LINKED) +# define SWIGEXPORT +# else +# define SWIGEXPORT __declspec(dllexport) +# endif +# else +# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) +# define SWIGEXPORT __attribute__ ((visibility("default"))) +# else +# define SWIGEXPORT +# endif +# endif +#endif + +/* calling conventions for Windows */ +#ifndef SWIGSTDCALL +# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# define SWIGSTDCALL __stdcall +# else +# define SWIGSTDCALL +# endif +#endif + +/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ +#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) +# define _CRT_SECURE_NO_DEPRECATE +#endif + +/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ +#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) +# define _SCL_SECURE_NO_DEPRECATE +#endif + + + +/* Python.h has to appear first */ +#include + +/* ----------------------------------------------------------------------------- + * swigrun.swg + * + * This file contains generic C API SWIG runtime support for pointer + * type checking. + * ----------------------------------------------------------------------------- */ + +/* This should only be incremented when either the layout of swig_type_info changes, + or for whatever reason, the runtime changes incompatibly */ +#define SWIG_RUNTIME_VERSION "4" + +/* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ +#ifdef SWIG_TYPE_TABLE +# define SWIG_QUOTE_STRING(x) #x +# define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) +# define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) +#else +# define SWIG_TYPE_TABLE_NAME +#endif + +/* + You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for + creating a static or dynamic library from the SWIG runtime code. + In 99.9% of the cases, SWIG just needs to declare them as 'static'. + + But only do this if strictly necessary, ie, if you have problems + with your compiler or suchlike. +*/ + +#ifndef SWIGRUNTIME +# define SWIGRUNTIME SWIGINTERN +#endif + +#ifndef SWIGRUNTIMEINLINE +# define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE +#endif + +/* Generic buffer size */ +#ifndef SWIG_BUFFER_SIZE +# define SWIG_BUFFER_SIZE 1024 +#endif + +/* Flags for pointer conversions */ +#define SWIG_POINTER_DISOWN 0x1 +#define SWIG_CAST_NEW_MEMORY 0x2 + +/* Flags for new pointer objects */ +#define SWIG_POINTER_OWN 0x1 + + +/* + Flags/methods for returning states. + + The SWIG conversion methods, as ConvertPtr, return an integer + that tells if the conversion was successful or not. And if not, + an error code can be returned (see swigerrors.swg for the codes). + + Use the following macros/flags to set or process the returning + states. + + In old versions of SWIG, code such as the following was usually written: + + if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) { + // success code + } else { + //fail code + } + + Now you can be more explicit: + + int res = SWIG_ConvertPtr(obj,vptr,ty.flags); + if (SWIG_IsOK(res)) { + // success code + } else { + // fail code + } + + which is the same really, but now you can also do + + Type *ptr; + int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags); + if (SWIG_IsOK(res)) { + // success code + if (SWIG_IsNewObj(res) { + ... + delete *ptr; + } else { + ... + } + } else { + // fail code + } + + I.e., now SWIG_ConvertPtr can return new objects and you can + identify the case and take care of the deallocation. Of course that + also requires SWIG_ConvertPtr to return new result values, such as + + int SWIG_ConvertPtr(obj, ptr,...) { + if () { + if () { + *ptr = ; + return SWIG_NEWOBJ; + } else { + *ptr = ; + return SWIG_OLDOBJ; + } + } else { + return SWIG_BADOBJ; + } + } + + Of course, returning the plain '0(success)/-1(fail)' still works, but you can be + more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the + SWIG errors code. + + Finally, if the SWIG_CASTRANK_MODE is enabled, the result code + allows to return the 'cast rank', for example, if you have this + + int food(double) + int fooi(int); + + and you call + + food(1) // cast rank '1' (1 -> 1.0) + fooi(1) // cast rank '0' + + just use the SWIG_AddCast()/SWIG_CheckState() +*/ + +#define SWIG_OK (0) +#define SWIG_ERROR (-1) +#define SWIG_IsOK(r) (r >= 0) +#define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError) + +/* The CastRankLimit says how many bits are used for the cast rank */ +#define SWIG_CASTRANKLIMIT (1 << 8) +/* The NewMask denotes the object was created (using new/malloc) */ +#define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1) +/* The TmpMask is for in/out typemaps that use temporal objects */ +#define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1) +/* Simple returning values */ +#define SWIG_BADOBJ (SWIG_ERROR) +#define SWIG_OLDOBJ (SWIG_OK) +#define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK) +#define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK) +/* Check, add and del mask methods */ +#define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r) +#define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r) +#define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK)) +#define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r) +#define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r) +#define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK)) + +/* Cast-Rank Mode */ +#if defined(SWIG_CASTRANK_MODE) +# ifndef SWIG_TypeRank +# define SWIG_TypeRank unsigned long +# endif +# ifndef SWIG_MAXCASTRANK /* Default cast allowed */ +# define SWIG_MAXCASTRANK (2) +# endif +# define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) +# define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) +SWIGINTERNINLINE int SWIG_AddCast(int r) { + return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; +} +SWIGINTERNINLINE int SWIG_CheckState(int r) { + return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; +} +#else /* no cast-rank mode */ +# define SWIG_AddCast +# define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) +#endif + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void *(*swig_converter_func)(void *, int *); +typedef struct swig_type_info *(*swig_dycast_func)(void **); + +/* Structure to store information on one type */ +typedef struct swig_type_info { + const char *name; /* mangled name of this type */ + const char *str; /* human readable name of this type */ + swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ + struct swig_cast_info *cast; /* linked list of types that can cast into this type */ + void *clientdata; /* language specific type data */ + int owndata; /* flag if the structure owns the clientdata */ +} swig_type_info; + +/* Structure to store a type and conversion function used for casting */ +typedef struct swig_cast_info { + swig_type_info *type; /* pointer to type that is equivalent to this type */ + swig_converter_func converter; /* function to cast the void pointers */ + struct swig_cast_info *next; /* pointer to next cast in linked list */ + struct swig_cast_info *prev; /* pointer to the previous cast */ +} swig_cast_info; + +/* Structure used to store module information + * Each module generates one structure like this, and the runtime collects + * all of these structures and stores them in a circularly linked list.*/ +typedef struct swig_module_info { + swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ + size_t size; /* Number of types in this module */ + struct swig_module_info *next; /* Pointer to next element in circularly linked list */ + swig_type_info **type_initial; /* Array of initially generated type structures */ + swig_cast_info **cast_initial; /* Array of initially generated casting structures */ + void *clientdata; /* Language specific module data */ +} swig_module_info; + +/* + Compare two type names skipping the space characters, therefore + "char*" == "char *" and "Class" == "Class", etc. + + Return 0 when the two name types are equivalent, as in + strncmp, but skipping ' '. +*/ +SWIGRUNTIME int +SWIG_TypeNameComp(const char *f1, const char *l1, + const char *f2, const char *l2) { + for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { + while ((*f1 == ' ') && (f1 != l1)) ++f1; + while ((*f2 == ' ') && (f2 != l2)) ++f2; + if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1; + } + return (int)((l1 - f1) - (l2 - f2)); +} + +/* + Check type equivalence in a name list like ||... + Return 0 if not equal, 1 if equal +*/ +SWIGRUNTIME int +SWIG_TypeEquiv(const char *nb, const char *tb) { + int equiv = 0; + const char* te = tb + strlen(tb); + const char* ne = nb; + while (!equiv && *ne) { + for (nb = ne; *ne; ++ne) { + if (*ne == '|') break; + } + equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0; + if (*ne) ++ne; + } + return equiv; +} + +/* + Check type equivalence in a name list like ||... + Return 0 if equal, -1 if nb < tb, 1 if nb > tb +*/ +SWIGRUNTIME int +SWIG_TypeCompare(const char *nb, const char *tb) { + int equiv = 0; + const char* te = tb + strlen(tb); + const char* ne = nb; + while (!equiv && *ne) { + for (nb = ne; *ne; ++ne) { + if (*ne == '|') break; + } + equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0; + if (*ne) ++ne; + } + return equiv; +} + + +/* + Check the typename +*/ +SWIGRUNTIME swig_cast_info * +SWIG_TypeCheck(const char *c, swig_type_info *ty) { + if (ty) { + swig_cast_info *iter = ty->cast; + while (iter) { + if (strcmp(iter->type->name, c) == 0) { + if (iter == ty->cast) + return iter; + /* Move iter to the top of the linked list */ + iter->prev->next = iter->next; + if (iter->next) + iter->next->prev = iter->prev; + iter->next = ty->cast; + iter->prev = 0; + if (ty->cast) ty->cast->prev = iter; + ty->cast = iter; + return iter; + } + iter = iter->next; + } + } + return 0; +} + +/* + Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison +*/ +SWIGRUNTIME swig_cast_info * +SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *ty) { + if (ty) { + swig_cast_info *iter = ty->cast; + while (iter) { + if (iter->type == from) { + if (iter == ty->cast) + return iter; + /* Move iter to the top of the linked list */ + iter->prev->next = iter->next; + if (iter->next) + iter->next->prev = iter->prev; + iter->next = ty->cast; + iter->prev = 0; + if (ty->cast) ty->cast->prev = iter; + ty->cast = iter; + return iter; + } + iter = iter->next; + } + } + return 0; +} + +/* + Cast a pointer up an inheritance hierarchy +*/ +SWIGRUNTIMEINLINE void * +SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { + return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); +} + +/* + Dynamic pointer casting. Down an inheritance hierarchy +*/ +SWIGRUNTIME swig_type_info * +SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { + swig_type_info *lastty = ty; + if (!ty || !ty->dcast) return ty; + while (ty && (ty->dcast)) { + ty = (*ty->dcast)(ptr); + if (ty) lastty = ty; + } + return lastty; +} + +/* + Return the name associated with this type +*/ +SWIGRUNTIMEINLINE const char * +SWIG_TypeName(const swig_type_info *ty) { + return ty->name; +} + +/* + Return the pretty name associated with this type, + that is an unmangled type name in a form presentable to the user. +*/ +SWIGRUNTIME const char * +SWIG_TypePrettyName(const swig_type_info *type) { + /* The "str" field contains the equivalent pretty names of the + type, separated by vertical-bar characters. We choose + to print the last name, as it is often (?) the most + specific. */ + if (!type) return NULL; + if (type->str != NULL) { + const char *last_name = type->str; + const char *s; + for (s = type->str; *s; s++) + if (*s == '|') last_name = s+1; + return last_name; + } + else + return type->name; +} + +/* + Set the clientdata field for a type +*/ +SWIGRUNTIME void +SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { + swig_cast_info *cast = ti->cast; + /* if (ti->clientdata == clientdata) return; */ + ti->clientdata = clientdata; + + while (cast) { + if (!cast->converter) { + swig_type_info *tc = cast->type; + if (!tc->clientdata) { + SWIG_TypeClientData(tc, clientdata); + } + } + cast = cast->next; + } +} +SWIGRUNTIME void +SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { + SWIG_TypeClientData(ti, clientdata); + ti->owndata = 1; +} + +/* + Search for a swig_type_info structure only by mangled name + Search is a O(log #types) + + We start searching at module start, and finish searching when start == end. + Note: if start == end at the beginning of the function, we go all the way around + the circular list. +*/ +SWIGRUNTIME swig_type_info * +SWIG_MangledTypeQueryModule(swig_module_info *start, + swig_module_info *end, + const char *name) { + swig_module_info *iter = start; + do { + if (iter->size) { + register size_t l = 0; + register size_t r = iter->size - 1; + do { + /* since l+r >= 0, we can (>> 1) instead (/ 2) */ + register size_t i = (l + r) >> 1; + const char *iname = iter->types[i]->name; + if (iname) { + register int compare = strcmp(name, iname); + if (compare == 0) { + return iter->types[i]; + } else if (compare < 0) { + if (i) { + r = i - 1; + } else { + break; + } + } else if (compare > 0) { + l = i + 1; + } + } else { + break; /* should never happen */ + } + } while (l <= r); + } + iter = iter->next; + } while (iter != end); + return 0; +} + +/* + Search for a swig_type_info structure for either a mangled name or a human readable name. + It first searches the mangled names of the types, which is a O(log #types) + If a type is not found it then searches the human readable names, which is O(#types). + + We start searching at module start, and finish searching when start == end. + Note: if start == end at the beginning of the function, we go all the way around + the circular list. +*/ +SWIGRUNTIME swig_type_info * +SWIG_TypeQueryModule(swig_module_info *start, + swig_module_info *end, + const char *name) { + /* STEP 1: Search the name field using binary search */ + swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); + if (ret) { + return ret; + } else { + /* STEP 2: If the type hasn't been found, do a complete search + of the str field (the human readable name) */ + swig_module_info *iter = start; + do { + register size_t i = 0; + for (; i < iter->size; ++i) { + if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) + return iter->types[i]; + } + iter = iter->next; + } while (iter != end); + } + + /* neither found a match */ + return 0; +} + +/* + Pack binary data into a string +*/ +SWIGRUNTIME char * +SWIG_PackData(char *c, void *ptr, size_t sz) { + static const char hex[17] = "0123456789abcdef"; + register const unsigned char *u = (unsigned char *) ptr; + register const unsigned char *eu = u + sz; + for (; u != eu; ++u) { + register unsigned char uu = *u; + *(c++) = hex[(uu & 0xf0) >> 4]; + *(c++) = hex[uu & 0xf]; + } + return c; +} + +/* + Unpack binary data from a string +*/ +SWIGRUNTIME const char * +SWIG_UnpackData(const char *c, void *ptr, size_t sz) { + register unsigned char *u = (unsigned char *) ptr; + register const unsigned char *eu = u + sz; + for (; u != eu; ++u) { + register char d = *(c++); + register unsigned char uu; + if ((d >= '0') && (d <= '9')) + uu = ((d - '0') << 4); + else if ((d >= 'a') && (d <= 'f')) + uu = ((d - ('a'-10)) << 4); + else + return (char *) 0; + d = *(c++); + if ((d >= '0') && (d <= '9')) + uu |= (d - '0'); + else if ((d >= 'a') && (d <= 'f')) + uu |= (d - ('a'-10)); + else + return (char *) 0; + *u = uu; + } + return c; +} + +/* + Pack 'void *' into a string buffer. +*/ +SWIGRUNTIME char * +SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) { + char *r = buff; + if ((2*sizeof(void *) + 2) > bsz) return 0; + *(r++) = '_'; + r = SWIG_PackData(r,&ptr,sizeof(void *)); + if (strlen(name) + 1 > (bsz - (r - buff))) return 0; + strcpy(r,name); + return buff; +} + +SWIGRUNTIME const char * +SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) { + if (*c != '_') { + if (strcmp(c,"NULL") == 0) { + *ptr = (void *) 0; + return name; + } else { + return 0; + } + } + return SWIG_UnpackData(++c,ptr,sizeof(void *)); +} + +SWIGRUNTIME char * +SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) { + char *r = buff; + size_t lname = (name ? strlen(name) : 0); + if ((2*sz + 2 + lname) > bsz) return 0; + *(r++) = '_'; + r = SWIG_PackData(r,ptr,sz); + if (lname) { + strncpy(r,name,lname+1); + } else { + *r = 0; + } + return buff; +} + +SWIGRUNTIME const char * +SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { + if (*c != '_') { + if (strcmp(c,"NULL") == 0) { + memset(ptr,0,sz); + return name; + } else { + return 0; + } + } + return SWIG_UnpackData(++c,ptr,sz); +} + +#ifdef __cplusplus +} +#endif + +/* Errors in SWIG */ +#define SWIG_UnknownError -1 +#define SWIG_IOError -2 +#define SWIG_RuntimeError -3 +#define SWIG_IndexError -4 +#define SWIG_TypeError -5 +#define SWIG_DivisionByZero -6 +#define SWIG_OverflowError -7 +#define SWIG_SyntaxError -8 +#define SWIG_ValueError -9 +#define SWIG_SystemError -10 +#define SWIG_AttributeError -11 +#define SWIG_MemoryError -12 +#define SWIG_NullReferenceError -13 + + + +/* Compatibility macros for Python 3 */ +#if PY_VERSION_HEX >= 0x03000000 + +#define PyClass_Check(obj) PyObject_IsInstance(obj, (PyObject *)&PyType_Type) +#define PyInt_Check(x) PyLong_Check(x) +#define PyInt_AsLong(x) PyLong_AsLong(x) +#define PyInt_FromLong(x) PyLong_FromLong(x) +#define PyString_Check(name) PyBytes_Check(name) +#define PyString_FromString(x) PyUnicode_FromString(x) +#define PyString_Format(fmt, args) PyUnicode_Format(fmt, args) +#define PyString_AsString(str) PyBytes_AsString(str) +#define PyString_Size(str) PyBytes_Size(str) +#define PyString_InternFromString(key) PyUnicode_InternFromString(key) +#define Py_TPFLAGS_HAVE_CLASS Py_TPFLAGS_BASETYPE +#define PyString_AS_STRING(x) PyUnicode_AS_STRING(x) +#define _PyLong_FromSsize_t(x) PyLong_FromSsize_t(x) + +#endif + +#ifndef Py_TYPE +# define Py_TYPE(op) ((op)->ob_type) +#endif + +/* SWIG APIs for compatibility of both Python 2 & 3 */ + +#if PY_VERSION_HEX >= 0x03000000 +# define SWIG_Python_str_FromFormat PyUnicode_FromFormat +#else +# define SWIG_Python_str_FromFormat PyString_FromFormat +#endif + + +/* Warning: This function will allocate a new string in Python 3, + * so please call SWIG_Python_str_DelForPy3(x) to free the space. + */ +SWIGINTERN char* +SWIG_Python_str_AsChar(PyObject *str) +{ +#if PY_VERSION_HEX >= 0x03000000 + char *cstr; + char *newstr; + Py_ssize_t len; + str = PyUnicode_AsUTF8String(str); + PyBytes_AsStringAndSize(str, &cstr, &len); + newstr = (char *) malloc(len+1); + memcpy(newstr, cstr, len+1); + Py_XDECREF(str); + return newstr; +#else + return PyString_AsString(str); +#endif +} + +#if PY_VERSION_HEX >= 0x03000000 +# define SWIG_Python_str_DelForPy3(x) free( (void*) (x) ) +#else +# define SWIG_Python_str_DelForPy3(x) +#endif + + +SWIGINTERN PyObject* +SWIG_Python_str_FromChar(const char *c) +{ +#if PY_VERSION_HEX >= 0x03000000 + return PyUnicode_FromString(c); +#else + return PyString_FromString(c); +#endif +} + +/* Add PyOS_snprintf for old Pythons */ +#if PY_VERSION_HEX < 0x02020000 +# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) +# define PyOS_snprintf _snprintf +# else +# define PyOS_snprintf snprintf +# endif +#endif + +/* A crude PyString_FromFormat implementation for old Pythons */ +#if PY_VERSION_HEX < 0x02020000 + +#ifndef SWIG_PYBUFFER_SIZE +# define SWIG_PYBUFFER_SIZE 1024 +#endif + +static PyObject * +PyString_FromFormat(const char *fmt, ...) { + va_list ap; + char buf[SWIG_PYBUFFER_SIZE * 2]; + int res; + va_start(ap, fmt); + res = vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + return (res < 0 || res >= (int)sizeof(buf)) ? 0 : PyString_FromString(buf); +} +#endif + +/* Add PyObject_Del for old Pythons */ +#if PY_VERSION_HEX < 0x01060000 +# define PyObject_Del(op) PyMem_DEL((op)) +#endif +#ifndef PyObject_DEL +# define PyObject_DEL PyObject_Del +#endif + +/* A crude PyExc_StopIteration exception for old Pythons */ +#if PY_VERSION_HEX < 0x02020000 +# ifndef PyExc_StopIteration +# define PyExc_StopIteration PyExc_RuntimeError +# endif +# ifndef PyObject_GenericGetAttr +# define PyObject_GenericGetAttr 0 +# endif +#endif + +/* Py_NotImplemented is defined in 2.1 and up. */ +#if PY_VERSION_HEX < 0x02010000 +# ifndef Py_NotImplemented +# define Py_NotImplemented PyExc_RuntimeError +# endif +#endif + +/* A crude PyString_AsStringAndSize implementation for old Pythons */ +#if PY_VERSION_HEX < 0x02010000 +# ifndef PyString_AsStringAndSize +# define PyString_AsStringAndSize(obj, s, len) {*s = PyString_AsString(obj); *len = *s ? strlen(*s) : 0;} +# endif +#endif + +/* PySequence_Size for old Pythons */ +#if PY_VERSION_HEX < 0x02000000 +# ifndef PySequence_Size +# define PySequence_Size PySequence_Length +# endif +#endif + +/* PyBool_FromLong for old Pythons */ +#if PY_VERSION_HEX < 0x02030000 +static +PyObject *PyBool_FromLong(long ok) +{ + PyObject *result = ok ? Py_True : Py_False; + Py_INCREF(result); + return result; +} +#endif + +/* Py_ssize_t for old Pythons */ +/* This code is as recommended by: */ +/* http://www.python.org/dev/peps/pep-0353/#conversion-guidelines */ +#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) +typedef int Py_ssize_t; +# define PY_SSIZE_T_MAX INT_MAX +# define PY_SSIZE_T_MIN INT_MIN +#endif + +/* ----------------------------------------------------------------------------- + * error manipulation + * ----------------------------------------------------------------------------- */ + +SWIGRUNTIME PyObject* +SWIG_Python_ErrorType(int code) { + PyObject* type = 0; + switch(code) { + case SWIG_MemoryError: + type = PyExc_MemoryError; + break; + case SWIG_IOError: + type = PyExc_IOError; + break; + case SWIG_RuntimeError: + type = PyExc_RuntimeError; + break; + case SWIG_IndexError: + type = PyExc_IndexError; + break; + case SWIG_TypeError: + type = PyExc_TypeError; + break; + case SWIG_DivisionByZero: + type = PyExc_ZeroDivisionError; + break; + case SWIG_OverflowError: + type = PyExc_OverflowError; + break; + case SWIG_SyntaxError: + type = PyExc_SyntaxError; + break; + case SWIG_ValueError: + type = PyExc_ValueError; + break; + case SWIG_SystemError: + type = PyExc_SystemError; + break; + case SWIG_AttributeError: + type = PyExc_AttributeError; + break; + default: + type = PyExc_RuntimeError; + } + return type; +} + + +SWIGRUNTIME void +SWIG_Python_AddErrorMsg(const char* mesg) +{ + PyObject *type = 0; + PyObject *value = 0; + PyObject *traceback = 0; + + if (PyErr_Occurred()) PyErr_Fetch(&type, &value, &traceback); + if (value) { + char *tmp; + PyObject *old_str = PyObject_Str(value); + PyErr_Clear(); + Py_XINCREF(type); + + PyErr_Format(type, "%s %s", tmp = SWIG_Python_str_AsChar(old_str), mesg); + SWIG_Python_str_DelForPy3(tmp); + Py_DECREF(old_str); + Py_DECREF(value); + } else { + PyErr_SetString(PyExc_RuntimeError, mesg); + } +} + +#if defined(SWIG_PYTHON_NO_THREADS) +# if defined(SWIG_PYTHON_THREADS) +# undef SWIG_PYTHON_THREADS +# endif +#endif +#if defined(SWIG_PYTHON_THREADS) /* Threading support is enabled */ +# if !defined(SWIG_PYTHON_USE_GIL) && !defined(SWIG_PYTHON_NO_USE_GIL) +# if (PY_VERSION_HEX >= 0x02030000) /* For 2.3 or later, use the PyGILState calls */ +# define SWIG_PYTHON_USE_GIL +# endif +# endif +# if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */ +# ifndef SWIG_PYTHON_INITIALIZE_THREADS +# define SWIG_PYTHON_INITIALIZE_THREADS PyEval_InitThreads() +# endif +# ifdef __cplusplus /* C++ code */ + class SWIG_Python_Thread_Block { + bool status; + PyGILState_STATE state; + public: + void end() { if (status) { PyGILState_Release(state); status = false;} } + SWIG_Python_Thread_Block() : status(true), state(PyGILState_Ensure()) {} + ~SWIG_Python_Thread_Block() { end(); } + }; + class SWIG_Python_Thread_Allow { + bool status; + PyThreadState *save; + public: + void end() { if (status) { PyEval_RestoreThread(save); status = false; }} + SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {} + ~SWIG_Python_Thread_Allow() { end(); } + }; +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK SWIG_Python_Thread_Block _swig_thread_block +# define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end() +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW SWIG_Python_Thread_Allow _swig_thread_allow +# define SWIG_PYTHON_THREAD_END_ALLOW _swig_thread_allow.end() +# else /* C code */ +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK PyGILState_STATE _swig_thread_block = PyGILState_Ensure() +# define SWIG_PYTHON_THREAD_END_BLOCK PyGILState_Release(_swig_thread_block) +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW PyThreadState *_swig_thread_allow = PyEval_SaveThread() +# define SWIG_PYTHON_THREAD_END_ALLOW PyEval_RestoreThread(_swig_thread_allow) +# endif +# else /* Old thread way, not implemented, user must provide it */ +# if !defined(SWIG_PYTHON_INITIALIZE_THREADS) +# define SWIG_PYTHON_INITIALIZE_THREADS +# endif +# if !defined(SWIG_PYTHON_THREAD_BEGIN_BLOCK) +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK +# endif +# if !defined(SWIG_PYTHON_THREAD_END_BLOCK) +# define SWIG_PYTHON_THREAD_END_BLOCK +# endif +# if !defined(SWIG_PYTHON_THREAD_BEGIN_ALLOW) +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW +# endif +# if !defined(SWIG_PYTHON_THREAD_END_ALLOW) +# define SWIG_PYTHON_THREAD_END_ALLOW +# endif +# endif +#else /* No thread support */ +# define SWIG_PYTHON_INITIALIZE_THREADS +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK +# define SWIG_PYTHON_THREAD_END_BLOCK +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW +# define SWIG_PYTHON_THREAD_END_ALLOW +#endif + +/* ----------------------------------------------------------------------------- + * Python API portion that goes into the runtime + * ----------------------------------------------------------------------------- */ + +#ifdef __cplusplus +extern "C" { +#if 0 +} /* cc-mode */ +#endif +#endif + +/* ----------------------------------------------------------------------------- + * Constant declarations + * ----------------------------------------------------------------------------- */ + +/* Constant Types */ +#define SWIG_PY_POINTER 4 +#define SWIG_PY_BINARY 5 + +/* Constant information structure */ +typedef struct swig_const_info { + int type; + char *name; + long lvalue; + double dvalue; + void *pvalue; + swig_type_info **ptype; +} swig_const_info; + + +/* ----------------------------------------------------------------------------- + * Wrapper of PyInstanceMethod_New() used in Python 3 + * It is exported to the generated module, used for -fastproxy + * ----------------------------------------------------------------------------- */ +SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *self, PyObject *func) +{ +#if PY_VERSION_HEX >= 0x03000000 + return PyInstanceMethod_New(func); +#else + return NULL; +#endif +} + +#ifdef __cplusplus +#if 0 +{ /* cc-mode */ +#endif +} +#endif + + +/* ----------------------------------------------------------------------------- + * pyrun.swg + * + * This file contains the runtime support for Python modules + * and includes code for managing global variables and pointer + * type checking. + * + * ----------------------------------------------------------------------------- */ + +/* Common SWIG API */ + +/* for raw pointers */ +#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) +#define SWIG_CheckImplicit(ty) SWIG_Python_CheckImplicit(ty) +#define SWIG_AcquirePtr(ptr, src) SWIG_Python_AcquirePtr(ptr, src) +#define swig_owntype int + +/* for raw packed data */ +#define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) +#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) + +/* for class or struct pointers */ +#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags) +#define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags) + +/* 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) + +/* for C++ member pointers, ie, member methods */ +#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) +#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) + + +/* Runtime API */ + +#define SWIG_GetModule(clientdata) SWIG_Python_GetModule() +#define SWIG_SetModule(clientdata, pointer) SWIG_Python_SetModule(pointer) +#define SWIG_NewClientData(obj) SwigPyClientData_New(obj) + +#define SWIG_SetErrorObj SWIG_Python_SetErrorObj +#define SWIG_SetErrorMsg SWIG_Python_SetErrorMsg +#define SWIG_ErrorType(code) SWIG_Python_ErrorType(code) +#define SWIG_Error(code, msg) SWIG_Python_SetErrorMsg(SWIG_ErrorType(code), msg) +#define SWIG_fail goto fail + + +/* Runtime API implementation */ + +/* Error manipulation */ + +SWIGINTERN void +SWIG_Python_SetErrorObj(PyObject *errtype, PyObject *obj) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetObject(errtype, obj); + Py_DECREF(obj); + SWIG_PYTHON_THREAD_END_BLOCK; +} + +SWIGINTERN void +SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetString(errtype, (char *) msg); + SWIG_PYTHON_THREAD_END_BLOCK; +} + +#define SWIG_Python_Raise(obj, type, desc) SWIG_Python_SetErrorObj(SWIG_Python_ExceptionType(desc), obj) + +/* Set a constant value */ + +#if defined(SWIGPYTHON_BUILTIN) + +SWIGINTERN void +pyswig_add_public_symbol (PyObject *seq, const char *key) { + PyObject *s = PyString_InternFromString(key); + PyList_Append(seq, s); + Py_DECREF(s); +} + +SWIGINTERN void +SWIG_Python_SetConstant(PyObject *d, PyObject *public_interface, const char *name, PyObject *obj) { + PyDict_SetItemString(d, (char*) name, obj); + Py_DECREF(obj); + if (public_interface) + pyswig_add_public_symbol(public_interface, name); +} + +#else + +SWIGINTERN void +SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) { + PyDict_SetItemString(d, (char*) name, obj); + Py_DECREF(obj); +} + +#endif + +/* Append a value to the result obj */ + +SWIGINTERN PyObject* +SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) { +#if !defined(SWIG_PYTHON_OUTPUT_TUPLE) + if (!result) { + result = obj; + } else if (result == Py_None) { + Py_DECREF(result); + result = obj; + } else { + if (!PyList_Check(result)) { + PyObject *o2 = result; + result = PyList_New(1); + PyList_SetItem(result, 0, o2); + } + PyList_Append(result,obj); + Py_DECREF(obj); + } + return result; +#else + PyObject* o2; + PyObject* o3; + if (!result) { + result = obj; + } else if (result == Py_None) { + Py_DECREF(result); + result = obj; + } else { + if (!PyTuple_Check(result)) { + o2 = result; + result = PyTuple_New(1); + PyTuple_SET_ITEM(result, 0, o2); + } + o3 = PyTuple_New(1); + PyTuple_SET_ITEM(o3, 0, obj); + o2 = result; + result = PySequence_Concat(o2, o3); + Py_DECREF(o2); + Py_DECREF(o3); + } + return result; +#endif +} + +/* Unpack the argument tuple */ + +SWIGINTERN int +SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, PyObject **objs) +{ + if (!args) { + if (!min && !max) { + return 1; + } else { + PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got none", + name, (min == max ? "" : "at least "), (int)min); + return 0; + } + } + if (!PyTuple_Check(args)) { + PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple"); + return 0; + } else { + register Py_ssize_t l = PyTuple_GET_SIZE(args); + if (l < min) { + PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", + name, (min == max ? "" : "at least "), (int)min, (int)l); + return 0; + } else if (l > max) { + PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", + name, (min == max ? "" : "at most "), (int)max, (int)l); + return 0; + } else { + register int i; + for (i = 0; i < l; ++i) { + objs[i] = PyTuple_GET_ITEM(args, i); + } + for (; l < max; ++l) { + objs[l] = 0; + } + return i + 1; + } + } +} + +/* A functor is a function object with one single object argument */ +#if PY_VERSION_HEX >= 0x02020000 +#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunctionObjArgs(functor, obj, NULL); +#else +#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunction(functor, "O", obj); +#endif + +/* + Helper for static pointer initialization for both C and C++ code, for example + static PyObject *SWIG_STATIC_POINTER(MyVar) = NewSomething(...); +*/ +#ifdef __cplusplus +#define SWIG_STATIC_POINTER(var) var +#else +#define SWIG_STATIC_POINTER(var) var = 0; if (!var) var +#endif + +/* ----------------------------------------------------------------------------- + * Pointer declarations + * ----------------------------------------------------------------------------- */ + +/* Flags for new pointer objects */ +#define SWIG_POINTER_NOSHADOW (SWIG_POINTER_OWN << 1) +#define SWIG_POINTER_NEW (SWIG_POINTER_NOSHADOW | SWIG_POINTER_OWN) + +#define SWIG_POINTER_IMPLICIT_CONV (SWIG_POINTER_DISOWN << 1) + +#ifdef __cplusplus +extern "C" { +#if 0 +} /* cc-mode */ +#endif +#endif + +/* How to access Py_None */ +#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# ifndef SWIG_PYTHON_NO_BUILD_NONE +# ifndef SWIG_PYTHON_BUILD_NONE +# define SWIG_PYTHON_BUILD_NONE +# endif +# endif +#endif + +#ifdef SWIG_PYTHON_BUILD_NONE +# ifdef Py_None +# undef Py_None +# define Py_None SWIG_Py_None() +# endif +SWIGRUNTIMEINLINE PyObject * +_SWIG_Py_None(void) +{ + PyObject *none = Py_BuildValue((char*)""); + Py_DECREF(none); + return none; +} +SWIGRUNTIME PyObject * +SWIG_Py_None(void) +{ + static PyObject *SWIG_STATIC_POINTER(none) = _SWIG_Py_None(); + return none; +} +#endif + +/* The python void return value */ + +SWIGRUNTIMEINLINE PyObject * +SWIG_Py_Void(void) +{ + PyObject *none = Py_None; + Py_INCREF(none); + return none; +} + +/* SwigPyClientData */ + +typedef struct { + PyObject *klass; + PyObject *newraw; + PyObject *newargs; + PyObject *destroy; + int delargs; + int implicitconv; + PyTypeObject *pytype; +} SwigPyClientData; + +SWIGRUNTIMEINLINE int +SWIG_Python_CheckImplicit(swig_type_info *ty) +{ + SwigPyClientData *data = (SwigPyClientData *)ty->clientdata; + return data ? data->implicitconv : 0; +} + +SWIGRUNTIMEINLINE PyObject * +SWIG_Python_ExceptionType(swig_type_info *desc) { + SwigPyClientData *data = desc ? (SwigPyClientData *) desc->clientdata : 0; + PyObject *klass = data ? data->klass : 0; + return (klass ? klass : PyExc_RuntimeError); +} + + +SWIGRUNTIME SwigPyClientData * +SwigPyClientData_New(PyObject* obj) +{ + if (!obj) { + return 0; + } else { + SwigPyClientData *data = (SwigPyClientData *)malloc(sizeof(SwigPyClientData)); + /* the klass element */ + data->klass = obj; + Py_INCREF(data->klass); + /* the newraw method and newargs arguments used to create a new raw instance */ + if (PyClass_Check(obj)) { + data->newraw = 0; + data->newargs = obj; + Py_INCREF(obj); + } else { +#if (PY_VERSION_HEX < 0x02020000) + data->newraw = 0; +#else + data->newraw = PyObject_GetAttrString(data->klass, (char *)"__new__"); +#endif + if (data->newraw) { + Py_INCREF(data->newraw); + data->newargs = PyTuple_New(1); + PyTuple_SetItem(data->newargs, 0, obj); + } else { + data->newargs = obj; + } + Py_INCREF(data->newargs); + } + /* the destroy method, aka as the C++ delete method */ + data->destroy = PyObject_GetAttrString(data->klass, (char *)"__swig_destroy__"); + if (PyErr_Occurred()) { + PyErr_Clear(); + data->destroy = 0; + } + if (data->destroy) { + int flags; + Py_INCREF(data->destroy); + flags = PyCFunction_GET_FLAGS(data->destroy); +#ifdef METH_O + data->delargs = !(flags & (METH_O)); +#else + data->delargs = 0; +#endif + } else { + data->delargs = 0; + } + data->implicitconv = 0; + data->pytype = 0; + return data; + } +} + +SWIGRUNTIME void +SwigPyClientData_Del(SwigPyClientData* data) +{ + Py_XDECREF(data->newraw); + Py_XDECREF(data->newargs); + Py_XDECREF(data->destroy); +} + +/* =============== SwigPyObject =====================*/ + +typedef struct { + PyObject_HEAD + void *ptr; + swig_type_info *ty; + int own; + PyObject *next; +#ifdef SWIGPYTHON_BUILTIN + PyObject *dict; +#endif +} SwigPyObject; + +SWIGRUNTIME PyObject * +SwigPyObject_long(SwigPyObject *v) +{ + return PyLong_FromVoidPtr(v->ptr); +} + +SWIGRUNTIME PyObject * +SwigPyObject_format(const char* fmt, SwigPyObject *v) +{ + PyObject *res = NULL; + PyObject *args = PyTuple_New(1); + if (args) { + if (PyTuple_SetItem(args, 0, SwigPyObject_long(v)) == 0) { + PyObject *ofmt = SWIG_Python_str_FromChar(fmt); + if (ofmt) { +#if PY_VERSION_HEX >= 0x03000000 + res = PyUnicode_Format(ofmt,args); +#else + res = PyString_Format(ofmt,args); +#endif + Py_DECREF(ofmt); + } + Py_DECREF(args); + } + } + return res; +} + +SWIGRUNTIME PyObject * +SwigPyObject_oct(SwigPyObject *v) +{ + return SwigPyObject_format("%o",v); +} + +SWIGRUNTIME PyObject * +SwigPyObject_hex(SwigPyObject *v) +{ + return SwigPyObject_format("%x",v); +} + +SWIGRUNTIME PyObject * +#ifdef METH_NOARGS +SwigPyObject_repr(SwigPyObject *v) +#else +SwigPyObject_repr(SwigPyObject *v, PyObject *args) +#endif +{ + const char *name = SWIG_TypePrettyName(v->ty); + PyObject *repr = SWIG_Python_str_FromFormat("", name, v); + if (v->next) { +# ifdef METH_NOARGS + PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next); +# else + PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next, args); +# endif +# if PY_VERSION_HEX >= 0x03000000 + PyObject *joined = PyUnicode_Concat(repr, nrep); + Py_DecRef(repr); + Py_DecRef(nrep); + repr = joined; +# else + PyString_ConcatAndDel(&repr,nrep); +# endif + } + return repr; +} + +SWIGRUNTIME int +SwigPyObject_print(SwigPyObject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) +{ + char *str; +#ifdef METH_NOARGS + PyObject *repr = SwigPyObject_repr(v); +#else + PyObject *repr = SwigPyObject_repr(v, NULL); +#endif + if (repr) { + str = SWIG_Python_str_AsChar(repr); + fputs(str, fp); + SWIG_Python_str_DelForPy3(str); + Py_DECREF(repr); + return 0; + } else { + return 1; + } +} + +SWIGRUNTIME PyObject * +SwigPyObject_str(SwigPyObject *v) +{ + char result[SWIG_BUFFER_SIZE]; + return SWIG_PackVoidPtr(result, v->ptr, v->ty->name, sizeof(result)) ? + SWIG_Python_str_FromChar(result) : 0; +} + +SWIGRUNTIME int +SwigPyObject_compare(SwigPyObject *v, SwigPyObject *w) +{ + void *i = v->ptr; + void *j = w->ptr; + return (i < j) ? -1 : ((i > j) ? 1 : 0); +} + +/* Added for Python 3.x, would it also be useful for Python 2.x? */ +SWIGRUNTIME PyObject* +SwigPyObject_richcompare(SwigPyObject *v, SwigPyObject *w, int op) +{ + PyObject* res; + if( op != Py_EQ && op != Py_NE ) { + Py_INCREF(Py_NotImplemented); + return Py_NotImplemented; + } + if( (SwigPyObject_compare(v, w)==0) == (op == Py_EQ) ) + res = Py_True; + else + res = Py_False; + Py_INCREF(res); + return res; +} + + +SWIGRUNTIME PyTypeObject* _PySwigObject_type(void); + +#ifdef SWIGPYTHON_BUILTIN +static swig_type_info *SwigPyObject_stype = 0; +SWIGRUNTIME PyTypeObject* +SwigPyObject_type(void) { + assert(SwigPyObject_stype); + SwigPyClientData *cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; + assert(cd); + assert(cd->pytype); + return cd->pytype; +} +#else +SWIGRUNTIME PyTypeObject* +SwigPyObject_type(void) { + static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigObject_type(); + return type; +} +#endif + +SWIGRUNTIMEINLINE int +SwigPyObject_Check(PyObject *op) { +#ifdef SWIGPYTHON_BUILTIN + PyTypeObject *target_tp = SwigPyObject_type(); + PyTypeObject *obj_tp; + if (PyType_IsSubtype(op->ob_type, target_tp)) + return 1; + return (strcmp(op->ob_type->tp_name, "SwigPyObject") == 0); +#else + return (Py_TYPE(op) == SwigPyObject_type()) + || (strcmp(Py_TYPE(op)->tp_name,"SwigPyObject") == 0); +#endif +} + +SWIGRUNTIME PyObject * +SwigPyObject_New(void *ptr, swig_type_info *ty, int own); + +SWIGRUNTIME void +SwigPyObject_dealloc(PyObject *v) +{ + SwigPyObject *sobj = (SwigPyObject *) v; + PyObject *next = sobj->next; + if (sobj->own == SWIG_POINTER_OWN) { + swig_type_info *ty = sobj->ty; + SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0; + PyObject *destroy = data ? data->destroy : 0; + if (destroy) { + /* destroy is always a VARARGS method */ + PyObject *res; + if (data->delargs) { + /* we need to create a temporary object to carry the destroy operation */ + PyObject *tmp = SwigPyObject_New(sobj->ptr, ty, 0); + res = SWIG_Python_CallFunctor(destroy, tmp); + Py_DECREF(tmp); + } else { + PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); + PyObject *mself = PyCFunction_GET_SELF(destroy); + res = ((*meth)(mself, v)); + } + Py_XDECREF(res); + } +#if !defined(SWIG_PYTHON_SILENT_MEMLEAK) + else { + const char *name = SWIG_TypePrettyName(ty); + printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown")); + } +#endif + } + Py_XDECREF(next); + PyObject_DEL(v); +} + +SWIGRUNTIME PyObject* +SwigPyObject_append(PyObject* v, PyObject* next) +{ + SwigPyObject *sobj = (SwigPyObject *) v; +#ifndef METH_O + PyObject *tmp = 0; + if (!PyArg_ParseTuple(next,(char *)"O:append", &tmp)) return NULL; + next = tmp; +#endif + if (!SwigPyObject_Check(next)) { + return NULL; + } + sobj->next = next; + Py_INCREF(next); + return SWIG_Py_Void(); +} + +SWIGRUNTIME PyObject* +#ifdef METH_NOARGS +SwigPyObject_next(PyObject* v) +#else +SwigPyObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) +#endif +{ + SwigPyObject *sobj = (SwigPyObject *) v; + if (sobj->next) { + Py_INCREF(sobj->next); + return sobj->next; + } else { + return SWIG_Py_Void(); + } +} + +SWIGINTERN PyObject* +#ifdef METH_NOARGS +SwigPyObject_disown(PyObject *v) +#else +SwigPyObject_disown(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) +#endif +{ + SwigPyObject *sobj = (SwigPyObject *)v; + sobj->own = 0; + return SWIG_Py_Void(); +} + +SWIGINTERN PyObject* +#ifdef METH_NOARGS +SwigPyObject_acquire(PyObject *v) +#else +SwigPyObject_acquire(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) +#endif +{ + SwigPyObject *sobj = (SwigPyObject *)v; + sobj->own = SWIG_POINTER_OWN; + return SWIG_Py_Void(); +} + +SWIGINTERN PyObject* +SwigPyObject_own(PyObject *v, PyObject *args) +{ + PyObject *val = 0; +#if (PY_VERSION_HEX < 0x02020000) + if (!PyArg_ParseTuple(args,(char *)"|O:own",&val)) +#else + if (!PyArg_UnpackTuple(args, (char *)"own", 0, 1, &val)) +#endif + { + return NULL; + } + else + { + SwigPyObject *sobj = (SwigPyObject *)v; + PyObject *obj = PyBool_FromLong(sobj->own); + if (val) { +#ifdef METH_NOARGS + if (PyObject_IsTrue(val)) { + SwigPyObject_acquire(v); + } else { + SwigPyObject_disown(v); + } +#else + if (PyObject_IsTrue(val)) { + SwigPyObject_acquire(v,args); + } else { + SwigPyObject_disown(v,args); + } +#endif + } + return obj; + } +} + +#ifdef METH_O +static PyMethodDef +swigobject_methods[] = { + {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_NOARGS, (char *)"releases ownership of the pointer"}, + {(char *)"acquire", (PyCFunction)SwigPyObject_acquire, METH_NOARGS, (char *)"aquires ownership of the pointer"}, + {(char *)"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, + {(char *)"append", (PyCFunction)SwigPyObject_append, METH_O, (char *)"appends another 'this' object"}, + {(char *)"next", (PyCFunction)SwigPyObject_next, METH_NOARGS, (char *)"returns the next 'this' object"}, + {(char *)"__repr__",(PyCFunction)SwigPyObject_repr, METH_NOARGS, (char *)"returns object representation"}, + {0, 0, 0, 0} +}; +#else +static PyMethodDef +swigobject_methods[] = { + {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_VARARGS, (char *)"releases ownership of the pointer"}, + {(char *)"acquire", (PyCFunction)SwigPyObject_acquire, METH_VARARGS, (char *)"aquires ownership of the pointer"}, + {(char *)"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, + {(char *)"append", (PyCFunction)SwigPyObject_append, METH_VARARGS, (char *)"appends another 'this' object"}, + {(char *)"next", (PyCFunction)SwigPyObject_next, METH_VARARGS, (char *)"returns the next 'this' object"}, + {(char *)"__repr__",(PyCFunction)SwigPyObject_repr, METH_VARARGS, (char *)"returns object representation"}, + {0, 0, 0, 0} +}; +#endif + +#if PY_VERSION_HEX < 0x02020000 +SWIGINTERN PyObject * +SwigPyObject_getattr(SwigPyObject *sobj,char *name) +{ + return Py_FindMethod(swigobject_methods, (PyObject *)sobj, name); +} +#endif + +SWIGRUNTIME PyTypeObject* +_PySwigObject_type(void) { + static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer"; + + static PyNumberMethods SwigPyObject_as_number = { + (binaryfunc)0, /*nb_add*/ + (binaryfunc)0, /*nb_subtract*/ + (binaryfunc)0, /*nb_multiply*/ + /* nb_divide removed in Python 3 */ +#if PY_VERSION_HEX < 0x03000000 + (binaryfunc)0, /*nb_divide*/ +#endif + (binaryfunc)0, /*nb_remainder*/ + (binaryfunc)0, /*nb_divmod*/ + (ternaryfunc)0,/*nb_power*/ + (unaryfunc)0, /*nb_negative*/ + (unaryfunc)0, /*nb_positive*/ + (unaryfunc)0, /*nb_absolute*/ + (inquiry)0, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ +#if PY_VERSION_HEX < 0x03000000 + 0, /*nb_coerce*/ +#endif + (unaryfunc)SwigPyObject_long, /*nb_int*/ +#if PY_VERSION_HEX < 0x03000000 + (unaryfunc)SwigPyObject_long, /*nb_long*/ +#else + 0, /*nb_reserved*/ +#endif + (unaryfunc)0, /*nb_float*/ +#if PY_VERSION_HEX < 0x03000000 + (unaryfunc)SwigPyObject_oct, /*nb_oct*/ + (unaryfunc)SwigPyObject_hex, /*nb_hex*/ +#endif +#if PY_VERSION_HEX >= 0x03000000 /* 3.0 */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index, nb_inplace_divide removed */ +#elif PY_VERSION_HEX >= 0x02050000 /* 2.5.0 */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index */ +#elif PY_VERSION_HEX >= 0x02020000 /* 2.2.0 */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_true_divide */ +#elif PY_VERSION_HEX >= 0x02000000 /* 2.0.0 */ + 0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_or */ +#endif + }; + + static PyTypeObject swigpyobject_type; + static int type_init = 0; + if (!type_init) { + const PyTypeObject tmp + = { + /* PyObject header changed in Python 3 */ +#if PY_VERSION_HEX >= 0x03000000 + PyVarObject_HEAD_INIT(&PyType_Type, 0) +#else + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ +#endif + (char *)"SwigPyObject", /* tp_name */ + sizeof(SwigPyObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)SwigPyObject_dealloc, /* tp_dealloc */ + (printfunc)SwigPyObject_print, /* tp_print */ +#if PY_VERSION_HEX < 0x02020000 + (getattrfunc)SwigPyObject_getattr, /* tp_getattr */ +#else + (getattrfunc)0, /* tp_getattr */ +#endif + (setattrfunc)0, /* tp_setattr */ +#if PY_VERSION_HEX >= 0x03000000 + 0, /* tp_reserved in 3.0.1, tp_compare in 3.0.0 but not used */ +#else + (cmpfunc)SwigPyObject_compare, /* tp_compare */ +#endif + (reprfunc)SwigPyObject_repr, /* tp_repr */ + &SwigPyObject_as_number, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + (hashfunc)0, /* tp_hash */ + (ternaryfunc)0, /* tp_call */ + (reprfunc)SwigPyObject_str, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + swigobject_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + (richcmpfunc)SwigPyObject_richcompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ +#if PY_VERSION_HEX >= 0x02020000 + 0, /* tp_iter */ + 0, /* tp_iternext */ + swigobject_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ + 0, /* tp_bases */ + 0, /* tp_mro */ + 0, /* tp_cache */ + 0, /* tp_subclasses */ + 0, /* tp_weaklist */ +#endif +#if PY_VERSION_HEX >= 0x02030000 + 0, /* tp_del */ +#endif +#ifdef COUNT_ALLOCS + 0,0,0,0 /* tp_alloc -> tp_next */ +#endif + }; + swigpyobject_type = tmp; + /* for Python 3 we already assigned ob_type in PyVarObject_HEAD_INIT() */ +#if PY_VERSION_HEX < 0x03000000 + swigpyobject_type.ob_type = &PyType_Type; +#endif + type_init = 1; + } + return &swigpyobject_type; +} + +SWIGRUNTIME PyObject * +SwigPyObject_New(void *ptr, swig_type_info *ty, int own) +{ + SwigPyObject *sobj = PyObject_NEW(SwigPyObject, SwigPyObject_type()); + if (sobj) { + sobj->ptr = ptr; + sobj->ty = ty; + sobj->own = own; + sobj->next = 0; + } + return (PyObject *)sobj; +} + +/* ----------------------------------------------------------------------------- + * Implements a simple Swig Packed type, and use it instead of string + * ----------------------------------------------------------------------------- */ + +typedef struct { + PyObject_HEAD + void *pack; + swig_type_info *ty; + size_t size; +} SwigPyPacked; + +SWIGRUNTIME int +SwigPyPacked_print(SwigPyPacked *v, FILE *fp, int SWIGUNUSEDPARM(flags)) +{ + char result[SWIG_BUFFER_SIZE]; + fputs("pack, v->size, 0, sizeof(result))) { + fputs("at ", fp); + fputs(result, fp); + } + fputs(v->ty->name,fp); + fputs(">", fp); + return 0; +} + +SWIGRUNTIME PyObject * +SwigPyPacked_repr(SwigPyPacked *v) +{ + char result[SWIG_BUFFER_SIZE]; + if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { + return SWIG_Python_str_FromFormat("", result, v->ty->name); + } else { + return SWIG_Python_str_FromFormat("", v->ty->name); + } +} + +SWIGRUNTIME PyObject * +SwigPyPacked_str(SwigPyPacked *v) +{ + char result[SWIG_BUFFER_SIZE]; + if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){ + return SWIG_Python_str_FromFormat("%s%s", result, v->ty->name); + } else { + return SWIG_Python_str_FromChar(v->ty->name); + } +} + +SWIGRUNTIME int +SwigPyPacked_compare(SwigPyPacked *v, SwigPyPacked *w) +{ + size_t i = v->size; + size_t j = w->size; + int s = (i < j) ? -1 : ((i > j) ? 1 : 0); + return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size); +} + +SWIGRUNTIME PyTypeObject* _PySwigPacked_type(void); + +SWIGRUNTIME PyTypeObject* +SwigPyPacked_type(void) { + static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigPacked_type(); + return type; +} + +SWIGRUNTIMEINLINE int +SwigPyPacked_Check(PyObject *op) { + return ((op)->ob_type == _PySwigPacked_type()) + || (strcmp((op)->ob_type->tp_name,"SwigPyPacked") == 0); +} + +SWIGRUNTIME void +SwigPyPacked_dealloc(PyObject *v) +{ + if (SwigPyPacked_Check(v)) { + SwigPyPacked *sobj = (SwigPyPacked *) v; + free(sobj->pack); + } + PyObject_DEL(v); +} + +SWIGRUNTIME PyTypeObject* +_PySwigPacked_type(void) { + static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer"; + static PyTypeObject swigpypacked_type; + static int type_init = 0; + if (!type_init) { + const PyTypeObject tmp + = { + /* PyObject header changed in Python 3 */ +#if PY_VERSION_HEX>=0x03000000 + PyVarObject_HEAD_INIT(&PyType_Type, 0) +#else + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ +#endif + (char *)"SwigPyPacked", /* tp_name */ + sizeof(SwigPyPacked), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)SwigPyPacked_dealloc, /* tp_dealloc */ + (printfunc)SwigPyPacked_print, /* tp_print */ + (getattrfunc)0, /* tp_getattr */ + (setattrfunc)0, /* tp_setattr */ +#if PY_VERSION_HEX>=0x03000000 + 0, /* tp_reserved in 3.0.1 */ +#else + (cmpfunc)SwigPyPacked_compare, /* tp_compare */ +#endif + (reprfunc)SwigPyPacked_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + (hashfunc)0, /* tp_hash */ + (ternaryfunc)0, /* tp_call */ + (reprfunc)SwigPyPacked_str, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + swigpacked_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ +#if PY_VERSION_HEX >= 0x02020000 + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ + 0, /* tp_bases */ + 0, /* tp_mro */ + 0, /* tp_cache */ + 0, /* tp_subclasses */ + 0, /* tp_weaklist */ +#endif +#if PY_VERSION_HEX >= 0x02030000 + 0, /* tp_del */ +#endif +#ifdef COUNT_ALLOCS + 0,0,0,0 /* tp_alloc -> tp_next */ +#endif + }; + swigpypacked_type = tmp; + /* for Python 3 the ob_type already assigned in PyVarObject_HEAD_INIT() */ +#if PY_VERSION_HEX < 0x03000000 + swigpypacked_type.ob_type = &PyType_Type; +#endif + type_init = 1; + } + return &swigpypacked_type; +} + +SWIGRUNTIME PyObject * +SwigPyPacked_New(void *ptr, size_t size, swig_type_info *ty) +{ + SwigPyPacked *sobj = PyObject_NEW(SwigPyPacked, SwigPyPacked_type()); + if (sobj) { + void *pack = malloc(size); + if (pack) { + memcpy(pack, ptr, size); + sobj->pack = pack; + sobj->ty = ty; + sobj->size = size; + } else { + PyObject_DEL((PyObject *) sobj); + sobj = 0; + } + } + return (PyObject *) sobj; +} + +SWIGRUNTIME swig_type_info * +SwigPyPacked_UnpackData(PyObject *obj, void *ptr, size_t size) +{ + if (SwigPyPacked_Check(obj)) { + SwigPyPacked *sobj = (SwigPyPacked *)obj; + if (sobj->size != size) return 0; + memcpy(ptr, sobj->pack, size); + return sobj->ty; + } else { + return 0; + } +} + +/* ----------------------------------------------------------------------------- + * pointers/data manipulation + * ----------------------------------------------------------------------------- */ + +SWIGRUNTIMEINLINE PyObject * +_SWIG_This(void) +{ + return SWIG_Python_str_FromChar("this"); +} + +static PyObject *swig_this = NULL; + +SWIGRUNTIME PyObject * +SWIG_This(void) +{ + if (swig_this == NULL) + swig_this = _SWIG_This(); + return swig_this; +} + +/* #define SWIG_PYTHON_SLOW_GETSET_THIS */ + +/* TODO: I don't know how to implement the fast getset in Python 3 right now */ +#if PY_VERSION_HEX>=0x03000000 +#define SWIG_PYTHON_SLOW_GETSET_THIS +#endif + +SWIGRUNTIME SwigPyObject * +SWIG_Python_GetSwigThis(PyObject *pyobj) +{ + if (SwigPyObject_Check(pyobj)) + return (SwigPyObject *) pyobj; + +#ifdef SWIGPYTHON_BUILTIN +# ifdef PyWeakref_CheckProxy + if (PyWeakref_CheckProxy(pyobj)) { + pyobj = PyWeakref_GET_OBJECT(pyobj); + if (pyobj && SwigPyObject_Check(pyobj)) + return (SwigPyObject*) pyobj; + } +# endif + return NULL; +#endif + + PyObject *obj = 0; + +#if (!defined(SWIG_PYTHON_SLOW_GETSET_THIS) && (PY_VERSION_HEX >= 0x02030000)) + if (PyInstance_Check(pyobj)) { + obj = _PyInstance_Lookup(pyobj, SWIG_This()); + } else { + PyObject **dictptr = _PyObject_GetDictPtr(pyobj); + if (dictptr != NULL) { + PyObject *dict = *dictptr; + obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0; + } else { +#ifdef PyWeakref_CheckProxy + if (PyWeakref_CheckProxy(pyobj)) { + PyObject *wobj = PyWeakref_GET_OBJECT(pyobj); + return wobj ? SWIG_Python_GetSwigThis(wobj) : 0; + } +#endif + obj = PyObject_GetAttr(pyobj,SWIG_This()); + if (obj) { + Py_DECREF(obj); + } else { + if (PyErr_Occurred()) PyErr_Clear(); + return 0; + } + } + } +#else + obj = PyObject_GetAttr(pyobj,SWIG_This()); + if (obj) { + Py_DECREF(obj); + } else { + if (PyErr_Occurred()) PyErr_Clear(); + return 0; + } +#endif + if (obj && !SwigPyObject_Check(obj)) { + /* a PyObject is called 'this', try to get the 'real this' + SwigPyObject from it */ + return SWIG_Python_GetSwigThis(obj); + } + return (SwigPyObject *)obj; +} + +/* Acquire a pointer value */ + +SWIGRUNTIME int +SWIG_Python_AcquirePtr(PyObject *obj, int own) { + if (own == SWIG_POINTER_OWN) { + SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj); + if (sobj) { + int oldown = sobj->own; + sobj->own = own; + return oldown; + } + } + return 0; +} + +/* Convert a pointer value */ + +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) { + if (ptr) *ptr = 0; + return SWIG_OK; + } + + /* + if (ty && ty->clientdata && ((SwigPyClientData*) ty->clientdata)->pytype) { + PyTypeObject *target_tp = ((SwigPyClientData*) ty->clientdata)->pytype; + SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj); + for (; sobj; sobj = (SwigPyObject*) sobj->next) { + if (!sobj->ty->clientdata) + continue; + PyTypeObject *candidate_tp = ((SwigPyClientData*) sobj->ty->clientdata)->pytype; + if (candidate_tp && PyType_IsSubtype(candidate_tp, target_tp)) { + if (own) + *own = *own | sobj->own; + if (flags & SWIG_POINTER_DISOWN) + sobj->own = 0; + if (ptr) + *ptr = sobj->ptr; + return SWIG_OK; + } + } + return SWIG_ERROR; + } + */ + + int 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 { + 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); + } + } + } + } + } + return res; +} + +/* Convert a function ptr value */ + +SWIGRUNTIME int +SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) { + if (!PyCFunction_Check(obj)) { + return SWIG_ConvertPtr(obj, ptr, ty, 0); + } else { + void *vptr = 0; + + /* here we get the method pointer for callbacks */ + const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc); + const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0; + if (desc) + desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0; + if (!desc) + return SWIG_ERROR; + if (ty) { + swig_cast_info *tc = SWIG_TypeCheck(desc,ty); + if (tc) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc,vptr,&newmemory); + assert(!newmemory); /* newmemory handling not yet implemented */ + } else { + return SWIG_ERROR; + } + } else { + *ptr = vptr; + } + return SWIG_OK; + } +} + +/* Convert a packed value value */ + +SWIGRUNTIME int +SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty) { + swig_type_info *to = SwigPyPacked_UnpackData(obj, ptr, sz); + if (!to) return SWIG_ERROR; + if (ty) { + if (to != ty) { + /* check type cast? */ + swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); + if (!tc) return SWIG_ERROR; + } + } + return SWIG_OK; +} + +/* ----------------------------------------------------------------------------- + * Create a new pointer object + * ----------------------------------------------------------------------------- */ + +/* + Create a new instance object, without calling __init__, and set the + 'this' attribute. +*/ + +SWIGRUNTIME PyObject* +SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this) +{ +#if (PY_VERSION_HEX >= 0x02020000) + PyObject *inst = 0; + PyObject *newraw = data->newraw; + if (newraw) { + inst = PyObject_Call(newraw, data->newargs, NULL); + if (inst) { +#if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) + PyObject **dictptr = _PyObject_GetDictPtr(inst); + if (dictptr != NULL) { + PyObject *dict = *dictptr; + if (dict == NULL) { + dict = PyDict_New(); + *dictptr = dict; + PyDict_SetItem(dict, SWIG_This(), swig_this); + } + } +#else + PyObject *key = SWIG_This(); + PyObject_SetAttr(inst, key, swig_this); +#endif + } + } else { +#if PY_VERSION_HEX >= 0x03000000 + inst = PyBaseObject_Type.tp_new((PyTypeObject*) data->newargs, Py_None, Py_None); + PyObject_SetAttr(inst, SWIG_This(), swig_this); + Py_TYPE(inst)->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG; +#else + PyObject *dict = PyDict_New(); + PyDict_SetItem(dict, SWIG_This(), swig_this); + inst = PyInstance_NewRaw(data->newargs, dict); + Py_DECREF(dict); +#endif + } + return inst; +#else +#if (PY_VERSION_HEX >= 0x02010000) + PyObject *inst; + PyObject *dict = PyDict_New(); + PyDict_SetItem(dict, SWIG_This(), swig_this); + inst = PyInstance_NewRaw(data->newargs, dict); + Py_DECREF(dict); + return (PyObject *) inst; +#else + PyInstanceObject *inst = PyObject_NEW(PyInstanceObject, &PyInstance_Type); + if (inst == NULL) { + return NULL; + } + inst->in_class = (PyClassObject *)data->newargs; + Py_INCREF(inst->in_class); + inst->in_dict = PyDict_New(); + if (inst->in_dict == NULL) { + Py_DECREF(inst); + return NULL; + } +#ifdef Py_TPFLAGS_HAVE_WEAKREFS + inst->in_weakreflist = NULL; +#endif +#ifdef Py_TPFLAGS_GC + PyObject_GC_Init(inst); +#endif + PyDict_SetItem(inst->in_dict, SWIG_This(), swig_this); + return (PyObject *) inst; +#endif +#endif +} + +SWIGRUNTIME void +SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this) +{ + PyObject *dict; +#if (PY_VERSION_HEX >= 0x02020000) && !defined(SWIG_PYTHON_SLOW_GETSET_THIS) + PyObject **dictptr = _PyObject_GetDictPtr(inst); + if (dictptr != NULL) { + dict = *dictptr; + if (dict == NULL) { + dict = PyDict_New(); + *dictptr = dict; + } + PyDict_SetItem(dict, SWIG_This(), swig_this); + return; + } +#endif + dict = PyObject_GetAttrString(inst, (char*)"__dict__"); + PyDict_SetItem(dict, SWIG_This(), swig_this); + Py_DECREF(dict); +} + + +SWIGINTERN PyObject * +SWIG_Python_InitShadowInstance(PyObject *args) { + PyObject *obj[2]; + if (!SWIG_Python_UnpackTuple(args,(char*)"swiginit", 2, 2, obj)) { + return NULL; + } else { + SwigPyObject *sthis = SWIG_Python_GetSwigThis(obj[0]); + if (sthis) { + SwigPyObject_append((PyObject*) sthis, obj[1]); + } else { + SWIG_Python_SetSwigThis(obj[0], obj[1]); + } + return SWIG_Py_Void(); + } +} + +/* Create a new pointer object */ + +SWIGRUNTIME PyObject * +SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) { + if (!ptr) + return SWIG_Py_Void(); + + SwigPyClientData *clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0; + int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; + if (clientdata && clientdata->pytype) { + SwigPyObject *newobj = PyObject_New(SwigPyObject, clientdata->pytype); + if (newobj) { + newobj->ptr = ptr; + newobj->ty = type; + newobj->own = own; + newobj->next = 0; +#ifdef SWIGPYTHON_BUILTIN + newobj->dict = 0; +#endif + return (PyObject*) newobj; + } + return SWIG_Py_Void(); + } + + PyObject *robj = SwigPyObject_New(ptr, type, own); + if (clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { + PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); + if (inst) { + Py_DECREF(robj); + robj = inst; + } + } + return robj; +} + +/* Create a new packed object */ + +SWIGRUNTIMEINLINE PyObject * +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); + SwigPyClientData *clientdata = (SwigPyClientData *)(type->clientdata); + assert(clientdata); + assert(clientdata->pytype); + int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; + SwigPyObject *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; + } + newobj->ptr = ptr; + newobj->own = own; + newobj->ty = type; + newobj->next = 0; +#ifdef SWIGPYTHON_BUILTIN + newobj->dict = 0; +#endif + return 0; +} + +/* -----------------------------------------------------------------------------* + * Get type list + * -----------------------------------------------------------------------------*/ + +#ifdef SWIG_LINK_RUNTIME +void *SWIG_ReturnGlobalTypeList(void *); +#endif + +SWIGRUNTIME swig_module_info * +SWIG_Python_GetModule(void) { + static void *type_pointer = (void *)0; + /* first check if module already created */ + if (!type_pointer) { +#ifdef SWIG_LINK_RUNTIME + type_pointer = SWIG_ReturnGlobalTypeList((void *)0); +#else + type_pointer = PyCObject_Import((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, + (char*)"type_pointer" SWIG_TYPE_TABLE_NAME); + if (PyErr_Occurred()) { + PyErr_Clear(); + type_pointer = (void *)0; + } +#endif + } + return (swig_module_info *) type_pointer; +} + +#if PY_MAJOR_VERSION < 2 +/* PyModule_AddObject function was introduced in Python 2.0. The following function + is copied out of Python/modsupport.c in python version 2.3.4 */ +SWIGINTERN int +PyModule_AddObject(PyObject *m, char *name, PyObject *o) +{ + PyObject *dict; + if (!PyModule_Check(m)) { + PyErr_SetString(PyExc_TypeError, + "PyModule_AddObject() needs module as first arg"); + return SWIG_ERROR; + } + if (!o) { + PyErr_SetString(PyExc_TypeError, + "PyModule_AddObject() needs non-NULL value"); + return SWIG_ERROR; + } + + dict = PyModule_GetDict(m); + if (dict == NULL) { + /* Internal error -- modules must have a dict! */ + PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__", + PyModule_GetName(m)); + return SWIG_ERROR; + } + if (PyDict_SetItemString(dict, name, o)) + return SWIG_ERROR; + Py_DECREF(o); + return SWIG_OK; +} +#endif + +SWIGRUNTIME void +SWIG_Python_DestroyModule(void *vptr) +{ + swig_module_info *swig_module = (swig_module_info *) vptr; + swig_type_info **types = swig_module->types; + size_t i; + for (i =0; i < swig_module->size; ++i) { + swig_type_info *ty = types[i]; + if (ty->owndata) { + SwigPyClientData *data = (SwigPyClientData *) ty->clientdata; + if (data) SwigPyClientData_Del(data); + } + } + Py_DECREF(SWIG_This()); + swig_this = NULL; +} + +SWIGRUNTIME void +SWIG_Python_SetModule(swig_module_info *swig_module) { + static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} };/* Sentinel */ + +#if PY_VERSION_HEX >= 0x03000000 + /* Add a dummy module object into sys.modules */ + PyObject *module = PyImport_AddModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION); +#else + PyObject *module = Py_InitModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, + swig_empty_runtime_method_table); +#endif + PyObject *pointer = PyCObject_FromVoidPtr((void *) swig_module, SWIG_Python_DestroyModule); + if (pointer && module) { + PyModule_AddObject(module, (char*)"type_pointer" SWIG_TYPE_TABLE_NAME, pointer); + } else { + Py_XDECREF(pointer); + } +} + +/* The python cached type query */ +SWIGRUNTIME PyObject * +SWIG_Python_TypeCache(void) { + static PyObject *SWIG_STATIC_POINTER(cache) = PyDict_New(); + return cache; +} + +SWIGRUNTIME swig_type_info * +SWIG_Python_TypeQuery(const char *type) +{ + PyObject *cache = SWIG_Python_TypeCache(); + PyObject *key = SWIG_Python_str_FromChar(type); + PyObject *obj = PyDict_GetItem(cache, key); + swig_type_info *descriptor; + if (obj) { + descriptor = (swig_type_info *) PyCObject_AsVoidPtr(obj); + } else { + swig_module_info *swig_module = SWIG_Python_GetModule(); + descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type); + if (descriptor) { + obj = PyCObject_FromVoidPtr(descriptor, NULL); + PyDict_SetItem(cache, key, obj); + Py_DECREF(obj); + } + } + Py_DECREF(key); + return descriptor; +} + +/* + For backward compatibility only +*/ +#define SWIG_POINTER_EXCEPTION 0 +#define SWIG_arg_fail(arg) SWIG_Python_ArgFail(arg) +#define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags) + +SWIGRUNTIME int +SWIG_Python_AddErrMesg(const char* mesg, int infront) +{ + if (PyErr_Occurred()) { + PyObject *type = 0; + PyObject *value = 0; + PyObject *traceback = 0; + PyErr_Fetch(&type, &value, &traceback); + if (value) { + char *tmp; + PyObject *old_str = PyObject_Str(value); + Py_XINCREF(type); + PyErr_Clear(); + if (infront) { + PyErr_Format(type, "%s %s", mesg, tmp = SWIG_Python_str_AsChar(old_str)); + } else { + PyErr_Format(type, "%s %s", tmp = SWIG_Python_str_AsChar(old_str), mesg); + } + SWIG_Python_str_DelForPy3(tmp); + Py_DECREF(old_str); + } + return 1; + } else { + return 0; + } +} + +SWIGRUNTIME int +SWIG_Python_ArgFail(int argnum) +{ + if (PyErr_Occurred()) { + /* add information about failing argument */ + char mesg[256]; + PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum); + return SWIG_Python_AddErrMesg(mesg, 1); + } else { + return 0; + } +} + +SWIGRUNTIMEINLINE const char * +SwigPyObject_GetDesc(PyObject *self) +{ + SwigPyObject *v = (SwigPyObject *)self; + swig_type_info *ty = v ? v->ty : 0; + return ty ? ty->str : (char*)""; +} + +SWIGRUNTIME void +SWIG_Python_TypeError(const char *type, PyObject *obj) +{ + if (type) { +#if defined(SWIG_COBJECT_TYPES) + if (obj && SwigPyObject_Check(obj)) { + const char *otype = (const char *) SwigPyObject_GetDesc(obj); + if (otype) { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'SwigPyObject(%s)' is received", + type, otype); + return; + } + } else +#endif + { + const char *otype = (obj ? obj->ob_type->tp_name : 0); + if (otype) { + PyObject *str = PyObject_Str(obj); + const char *cstr = str ? SWIG_Python_str_AsChar(str) : 0; + if (cstr) { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received", + type, otype, cstr); + SWIG_Python_str_DelForPy3(cstr); + } else { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received", + type, otype); + } + Py_XDECREF(str); + return; + } + } + PyErr_Format(PyExc_TypeError, "a '%s' is expected", type); + } else { + PyErr_Format(PyExc_TypeError, "unexpected type is received"); + } +} + + +/* Convert a pointer value, signal an exception on a type mismatch */ +SWIGRUNTIME void * +SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) { + void *result; + if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) { + PyErr_Clear(); +#if SWIG_POINTER_EXCEPTION + if (flags) { + SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj); + SWIG_Python_ArgFail(argnum); + } +#endif + } + 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; + PyObject *descr; + descrsetfunc f; + int res = -1; + +#ifdef Py_USING_UNICODE + if (PyString_Check(name)) { + name = PyUnicode_Decode(PyString_AsString(name), PyString_Size(name), NULL, NULL); + if (name == NULL) + return -1; + } else if (!PyUnicode_Check(name)) { +#else + if (!PyString_Check(name)) { +#endif + PyErr_Format(PyExc_TypeError, + "attribute name must be string, not '%.200s'", + name->ob_type->tp_name); + return -1; + } else { + Py_INCREF(name); + } + + if (tp->tp_dict == NULL) { + if (PyType_Ready(tp) < 0) + goto done; + } + + descr = _PyType_Lookup(tp, name); + f = NULL; + if (descr != NULL) + f = descr->ob_type->tp_descr_set; + if (f == NULL) { + PyErr_Format(PyExc_AttributeError, +#ifdef Py_USING_UNICODE + "'%.100s' object has no attribute '%.200U'", +#else + "'%.100s' object has no attribute '%.200S'", +#endif + tp->tp_name, name); + } else { + res = f(descr, obj, value); + } + + done: + Py_DECREF(name); + return res; + } + + +#ifdef __cplusplus +#if 0 +{ /* cc-mode */ +#endif +} +#endif + +#define PYSWIG_UNARYFUNC_CLOSURE(wrapper) \ +SWIGINTERN PyObject* \ +wrapper##_closure (PyObject *a) \ +{ \ + return wrapper(a, NULL); \ +} + +#define PYSWIG_DESTRUCTOR_CLOSURE(wrapper) \ +SWIGINTERN void \ +wrapper##_closure (PyObject *a) \ +{ \ + SwigPyObject *sobj = (SwigPyObject*) a; \ + if (sobj->own) { \ + PyObject *o = wrapper(a, NULL); \ + Py_XDECREF(o); \ + } \ +} + +#define PYSWIG_INQUIRY_CLOSURE(wrapper) \ +SWIGINTERN int \ +wrapper##_closure (PyObject *a) \ +{ \ + PyObject *pyresult = wrapper(a, NULL); \ + int result = pyresult && PyObject_IsTrue(pyresult) ? 1 : 0; \ + Py_XDECREF(pyresult); \ + return result; \ +} + +#define PYSWIG_BINARYFUNC_CLOSURE(wrapper) \ +SWIGINTERN PyObject* \ +wrapper##_closure (PyObject *a, PyObject *b) \ +{ \ + PyObject *tuple = PyTuple_New(1); \ + assert(tuple); \ + PyTuple_SET_ITEM(tuple, 0, b); \ + Py_XINCREF(b); \ + PyObject *result = wrapper(a, tuple); \ + Py_DECREF(tuple); \ + return result; \ +} + +#define PYSWIG_TERNARYFUNC_CLOSURE(wrapper) \ +SWIGINTERN PyObject* \ +wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \ +{ \ + PyObject *tuple = PyTuple_New(2); \ + assert(tuple); \ + PyTuple_SET_ITEM(tuple, 0, b); \ + PyTuple_SET_ITEM(tuple, 1, c); \ + Py_XINCREF(b); \ + Py_XINCREF(c); \ + PyObject *result = wrapper(a, tuple); \ + Py_DECREF(tuple); \ + return result; \ +} + +#define PYSWIG_LENFUNC_CLOSURE(wrapper) \ +SWIGINTERN Py_ssize_t \ +wrapper##_closure (PyObject *a) \ +{ \ + PyObject *resultobj = wrapper(a, NULL); \ + Py_ssize_t result = PyNumber_AsSsize_t(resultobj, NULL); \ + Py_DECREF(resultobj); \ + return result; \ +} + +#define PYSWIG_SSIZESSIZEARGFUNC_CLOSURE(wrapper) \ +SWIGINTERN PyObject* \ +wrapper##_closure (PyObject *a, Py_ssize_t b, Py_ssize_t c) \ +{ \ + PyObject *tuple = PyTuple_New(2); \ + assert(tuple); \ + PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \ + PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c)); \ + PyObject *result = wrapper(a, tuple); \ + Py_DECREF(tuple); \ + return result; \ +} + +#define PYSWIG_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); \ + assert(tuple); \ + PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \ + PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c)); \ + if (d) { \ + PyTuple_SET_ITEM(tuple, 2, d); \ + Py_INCREF(d); \ + } \ + PyObject *resultobj = wrapper(a, tuple); \ + int result = resultobj ? 0 : -1; \ + Py_DECREF(tuple); \ + Py_XDECREF(resultobj); \ + return result; \ +} + +#define PYSWIG_SSIZEARGFUNC_CLOSURE(wrapper) \ +SWIGINTERN PyObject* \ +wrapper##_closure (PyObject *a, Py_ssize_t b) \ +{ \ + PyObject *tuple = PyTuple_New(1); \ + assert(tuple); \ + PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \ + PyObject *result = wrapper(a, tuple); \ + Py_DECREF(tuple); \ + return result; \ +} + +#define PYSWIG_FUNPACK_SSIZEARGFUNC_CLOSURE(wrapper) \ +SWIGINTERN PyObject* \ +wrapper##_closure (PyObject *a, Py_ssize_t b) \ +{ \ + PyObject *arg = _PyLong_FromSsize_t(b); \ + PyObject *result = wrapper(a, arg); \ + Py_DECREF(arg); \ + return result; \ +} + +#define PYSWIG_SSIZEOBJARGPROC_CLOSURE(wrapper) \ +SWIGINTERN int \ +wrapper##_closure (PyObject *a, Py_ssize_t b, PyObject *c) \ +{ \ + PyObject *tuple = PyTuple_New(2); \ + assert(tuple); \ + PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \ + PyTuple_SET_ITEM(tuple, 1, c); \ + Py_XINCREF(c); \ + PyObject *resultobj = wrapper(a, tuple); \ + int result = resultobj ? 0 : -1; \ + Py_XDECREF(resultobj); \ + Py_DECREF(tuple); \ + return result; \ +} + +#define PYSWIG_OBJOBJARGPROC_CLOSURE(wrapper) \ +SWIGINTERN int \ +wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \ +{ \ + PyObject *tuple = PyTuple_New(c ? 2 : 1); \ + assert(tuple); \ + PyTuple_SET_ITEM(tuple, 0, b); \ + Py_XINCREF(b); \ + if (c) { \ + PyTuple_SET_ITEM(tuple, 1, c); \ + Py_XINCREF(c); \ + } \ + PyObject *resultobj = wrapper(a, tuple); \ + int result = resultobj ? 0 : -1; \ + Py_XDECREF(resultobj); \ + Py_DECREF(tuple); \ + return result; \ +} + +#define PYSWIG_REPRFUNC_CLOSURE(wrapper) \ +SWIGINTERN PyObject* \ +wrapper##_closure (PyObject *a) \ +{ \ + return wrapper(a, NULL); \ +} + +#define PYSWIG_HASHFUNC_CLOSURE(wrapper) \ +SWIGINTERN long \ +wrapper##_closure (PyObject *a) \ +{ \ + PyObject *pyresult = wrapper(a, NULL); \ + if (!pyresult || !PyLong_Check(pyresult)) \ + return -1; \ + long result = PyLong_AsLong(pyresult); \ + Py_DECREF(pyresult); \ + return result; \ +} + +#define PYSWIG_ITERNEXT_CLOSURE(wrapper) \ +SWIGINTERN PyObject* \ +wrapper##_closure (PyObject *a) \ +{ \ + PyObject *result = wrapper(a, NULL); \ + if (result && result == Py_None) { \ + Py_DECREF(result); \ + result = NULL; \ + } \ + return result; \ +} + +SWIGRUNTIME int py_builtin_bad_init (PyObject *self, PyObject *args, PyObject *kwds) +{ + PyErr_Format(PyExc_TypeError, "Cannot create new instances of type '%.300s'", self->ob_type->tp_name); + return -1; +} + +SWIGRUNTIME void py_builtin_bad_dealloc (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); + } +} + +typedef struct { + PyCFunction get; + PyCFunction set; +} SwigPyGetSet; + +SWIGRUNTIME PyObject* +pyswig_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; +} + +SWIGRUNTIME PyObject* +pyswig_funpack_getter_closure (PyObject *obj, void *closure) +{ + if (!closure) + return SWIG_Py_Void(); + SwigPyGetSet *getset = (SwigPyGetSet*) closure; + if (!getset->get) + return SWIG_Py_Void(); + PyObject *result = (*getset->get)(obj, NULL); + return result; +} + +SWIGRUNTIME int +pyswig_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 member variable assignment in type '%.300s'", obj->ob_type->tp_name); + 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; +} + +SWIGRUNTIME int +pyswig_funpack_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 member variable assignment in type '%.300s'", obj->ob_type->tp_name); + return -1; + } + PyObject *result = (*getset->set)(obj, val); + Py_XDECREF(result); + return result ? 0 : -1; +} + +SWIGRUNTIME 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; +} + +SWIGRUNTIME 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; +} + +SWIGRUNTIME void +SwigPyStaticVar_dealloc(PyDescrObject *descr) +{ + _PyObject_GC_UNTRACK(descr); + Py_XDECREF(descr->d_type); + Py_XDECREF(descr->d_name); + PyObject_GC_Del(descr); +} + +SWIGRUNTIME PyObject * +SwigPyStaticVar_repr(PyGetSetDescrObject *descr) +{ +#if PY_VERSION_HEX >= 0x03000000 + 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 +} + +SWIGRUNTIME int +SwigPyStaticVar_traverse(PyObject *self, visitproc visit, void *arg) +{ + PyDescrObject *descr = (PyDescrObject *)self; + Py_VISIT(descr->d_type); + return 0; +} + +SWIGRUNTIME PyObject * +SwigPyStaticVar_get (PyGetSetDescrObject *descr, PyObject *obj, PyObject *type) +{ + if (descr->d_getset->get != NULL) + return descr->d_getset->get(obj, descr->d_getset->closure); +#if PY_VERSION_HEX >= 0x03000000 + PyErr_Format(PyExc_AttributeError, + "attribute '%.300U' of '%.100s' objects is not readable", + descr->d_name, descr->d_type->tp_name); +#else + PyErr_Format(PyExc_AttributeError, + "attribute '%.300s' of '%.100s' objects is not readable", + PyString_AsString(descr->d_name), descr->d_type->tp_name); +#endif + return NULL; +} + +SWIGRUNTIME int +SwigPyStaticVar_set (PyGetSetDescrObject *descr, PyObject *obj, PyObject *value) +{ + int res; + + if (descr->d_getset->set != NULL) + return descr->d_getset->set(obj, value, descr->d_getset->closure); +#if PY_VERSION_HEX >= 0x03000000 + PyErr_Format(PyExc_AttributeError, + "attribute '%.300U' of '%.100s' objects is not writable", + descr->d_name, + descr->d_type->tp_name); +#else + PyErr_Format(PyExc_AttributeError, + "attribute '%.300s' of '%.100s' objects is not writable", + PyString_AsString(descr->d_name), + descr->d_type->tp_name); +#endif + return -1; +} + +SWIGRUNTIME PyTypeObject SwigPyStaticVar_Type = { +#if PY_VERSION_HEX >= 0x03000000 + PyVarObject_HEAD_INIT(&PyType_Type, 0) +#else + PyObject_HEAD_INIT(&PyType_Type) + 0, +#endif + "swig_static_var_getset_descriptor", + sizeof(PyGetSetDescrObject), + 0, + (destructor)SwigPyStaticVar_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + (reprfunc)SwigPyStaticVar_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_HAVE_CLASS, /* tp_flags */ + 0, /* tp_doc */ + SwigPyStaticVar_traverse, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + (descrgetfunc)SwigPyStaticVar_get, /* tp_descr_get */ + (descrsetfunc)SwigPyStaticVar_set, /* tp_descr_set */ +}; + +SWIGRUNTIME int +SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value) +{ + PyObject *attribute = _PyType_Lookup(type, name); + if (attribute != NULL) { + /* Implement descriptor functionality, if any */ + descrsetfunc local_set = attribute->ob_type->tp_descr_set; + if (local_set != NULL) + return local_set(attribute, (PyObject*) type, value); +#if PY_VERSION_HEX >= 0x03000000 + PyErr_Format(PyExc_AttributeError, + "cannot modify read-only attribute '%.50s.%.400U'", + type->tp_name, name); +#else + PyErr_Format(PyExc_AttributeError, + "cannot modify read-only attribute '%.50s.%.400s'", + type->tp_name, PyString_AS_STRING(name)); +#endif + } else { +#if PY_VERSION_HEX >= 0x03000000 + PyErr_Format(PyExc_AttributeError, + "type '%.50s' has no attribute '%.400U'", + type->tp_name, name); +#else + PyErr_Format(PyExc_AttributeError, + "type '%.50s' has no attribute '%.400s'", + type->tp_name, PyString_AS_STRING(name)); +#endif + } + + return -1; +} + +SWIGINTERN PyGetSetDescrObject* +SwigPyStaticVar_new_getset (PyTypeObject *type, PyGetSetDef *getset) +{ + PyGetSetDescrObject *descr = (PyGetSetDescrObject*) PyType_GenericAlloc(&SwigPyStaticVar_Type, 0); + assert(descr); + Py_XINCREF(type); + descr->d_type = type; + descr->d_name = PyString_InternFromString(getset->name); + descr->d_getset = getset; + if (descr->d_name == NULL) { + Py_DECREF(descr); + descr = NULL; + } + return descr; +} + +#ifdef __cplusplus + +#include + +SWIGINTERN void +pyswig_builtin_init_bases (PyTypeObject *type, std::vector& bases) +{ + if (!bases.size()) + bases.push_back(SwigPyObject_type()); + 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) { + PyTuple_SET_ITEM(tuple, i, (PyObject*) bases[i]); + Py_INCREF((PyObject*) bases[i]); + } + type->tp_bases = tuple; +} + +SWIGINTERN PyObject* +pyswig_this_closure (PyObject *self, void *closure) +{ + PyObject *result = (PyObject*) SWIG_Python_GetSwigThis(self); + Py_XINCREF(result); + return result; +} + +#endif + + + +#define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) + +#define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } else + + + +/* -------- TYPES TABLE (BEGIN) -------- */ + +#define SWIGTYPE_p_A swig_types[0] +#define SWIGTYPE_p_B swig_types[1] +#define SWIGTYPE_p_C swig_types[2] +#define SWIGTYPE_p_D swig_types[3] +#define SWIGTYPE_p_E swig_types[4] +#define SWIGTYPE_p_F swig_types[5] +#define SWIGTYPE_p_G swig_types[6] +#define SWIGTYPE_p_H swig_types[7] +#define SWIGTYPE_p_SwigPyObject swig_types[8] +#define SWIGTYPE_p_char swig_types[9] +static swig_type_info *swig_types[11]; +static swig_module_info swig_module = {swig_types, 10, 0, 0, 0, 0}; +#define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) +#define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) + +/* -------- TYPES TABLE (END) -------- */ + +#if (PY_VERSION_HEX <= 0x02000000) +# if !defined(SWIG_PYTHON_CLASSIC) +# error "This python version requires swig to be run with the '-classic' option" +# endif +#endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodern' option" +#endif +#if (PY_VERSION_HEX <= 0x02020000) +# error "This python version requires swig to be run with the '-nomodernargs' option" +#endif +#ifndef METH_O +# error "This python version requires swig to be run with the '-nofastunpack' option" +#endif +#ifdef SWIG_TypeQuery +# undef SWIG_TypeQuery +#endif +#define SWIG_TypeQuery SWIG_Python_TypeQuery + +/*----------------------------------------------- + @(target):= _Simple_builtin.so + ------------------------------------------------*/ +#if PY_VERSION_HEX >= 0x03000000 +# define SWIG_init PyInit__Simple_builtin + +#else +# define SWIG_init init_Simple_builtin + +#endif +#define SWIG_name "_Simple_builtin" + +#define SWIGVERSION 0x020002 +#define SWIG_VERSION SWIGVERSION + + +#define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a)) +#define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),reinterpret_cast< void** >(a)) + + +#include + + +namespace swig { + class SwigPtr_PyObject { + protected: + PyObject *_obj; + + public: + SwigPtr_PyObject() :_obj(0) + { + } + + SwigPtr_PyObject(const SwigPtr_PyObject& item) : _obj(item._obj) + { + Py_XINCREF(_obj); + } + + SwigPtr_PyObject(PyObject *obj, bool initial_ref = true) :_obj(obj) + { + if (initial_ref) { + Py_XINCREF(_obj); + } + } + + SwigPtr_PyObject & operator=(const SwigPtr_PyObject& item) + { + Py_XINCREF(item._obj); + Py_XDECREF(_obj); + _obj = item._obj; + return *this; + } + + ~SwigPtr_PyObject() + { + Py_XDECREF(_obj); + } + + operator PyObject *() const + { + return _obj; + } + + PyObject *operator->() const + { + return _obj; + } + }; +} + + +namespace swig { + struct SwigVar_PyObject : SwigPtr_PyObject { + SwigVar_PyObject(PyObject* obj = 0) : SwigPtr_PyObject(obj, false) { } + + SwigVar_PyObject & operator = (PyObject* obj) + { + Py_XDECREF(_obj); + _obj = obj; + return *this; + } + }; +} + + + +class A { +public: + A () {} + ~A () {} + void func () {} + A& operator+= (int i) { return *this; } +}; + +class B : public A { +public: + B () {} + ~B () {} +}; + +class C : public B { +public: + C () {} + ~C () {} +}; + +class D : public C { +public: + D () {} + ~D () {} +}; + +class E : public D { +public: + E () {} + ~E () {} +}; + +class F : public E { +public: + F () {} + ~F () {} +}; + +class G : public F { +public: + G () {} + ~G () {} +}; + +class H : public G { +public: + H () {} + ~H () {} +}; + + + +#include +#if !defined(SWIG_NO_LLONG_MAX) +# if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__) +# define LLONG_MAX __LONG_LONG_MAX__ +# define LLONG_MIN (-LLONG_MAX - 1LL) +# define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL) +# endif +#endif + + +SWIGINTERN int +SWIG_AsVal_double (PyObject *obj, double *val) +{ + int res = SWIG_TypeError; + if (PyFloat_Check(obj)) { + if (val) *val = PyFloat_AsDouble(obj); + return SWIG_OK; + } else if (PyInt_Check(obj)) { + if (val) *val = PyInt_AsLong(obj); + return SWIG_OK; + } else if (PyLong_Check(obj)) { + double v = PyLong_AsDouble(obj); + if (!PyErr_Occurred()) { + if (val) *val = v; + return SWIG_OK; + } else { + PyErr_Clear(); + } + } +#ifdef SWIG_PYTHON_CAST_MODE + { + int dispatch = 0; + double d = PyFloat_AsDouble(obj); + if (!PyErr_Occurred()) { + if (val) *val = d; + return SWIG_AddCast(SWIG_OK); + } else { + PyErr_Clear(); + } + if (!dispatch) { + long v = PyLong_AsLong(obj); + if (!PyErr_Occurred()) { + if (val) *val = v; + return SWIG_AddCast(SWIG_AddCast(SWIG_OK)); + } else { + PyErr_Clear(); + } + } + } +#endif + return res; +} + + +#include + + +#include + + +SWIGINTERNINLINE int +SWIG_CanCastAsInteger(double *d, double min, double max) { + double x = *d; + if ((min <= x && x <= max)) { + double fx = floor(x); + double cx = ceil(x); + double rd = ((x - fx) < 0.5) ? fx : cx; /* simple rint */ + if ((errno == EDOM) || (errno == ERANGE)) { + errno = 0; + } else { + double summ, reps, diff; + if (rd < x) { + diff = x - rd; + } else if (rd > x) { + diff = rd - x; + } else { + return 1; + } + summ = rd + x; + reps = diff/summ; + if (reps < 8*DBL_EPSILON) { + *d = rd; + return 1; + } + } + } + return 0; +} + + +SWIGINTERN int +SWIG_AsVal_long (PyObject *obj, long* val) +{ + if (PyInt_Check(obj)) { + if (val) *val = PyInt_AsLong(obj); + return SWIG_OK; + } else if (PyLong_Check(obj)) { + long v = PyLong_AsLong(obj); + if (!PyErr_Occurred()) { + if (val) *val = v; + return SWIG_OK; + } else { + PyErr_Clear(); + } + } +#ifdef SWIG_PYTHON_CAST_MODE + { + int dispatch = 0; + long v = PyInt_AsLong(obj); + if (!PyErr_Occurred()) { + if (val) *val = v; + return SWIG_AddCast(SWIG_OK); + } else { + PyErr_Clear(); + } + if (!dispatch) { + double d; + int res = SWIG_AddCast(SWIG_AsVal_double (obj,&d)); + if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, LONG_MAX)) { + if (val) *val = (long)(d); + return res; + } + } + } +#endif + return SWIG_TypeError; +} + + +SWIGINTERN int +SWIG_AsVal_int (PyObject * obj, int *val) +{ + long v; + int res = SWIG_AsVal_long (obj, &v); + if (SWIG_IsOK(res)) { + if ((v < INT_MIN || v > INT_MAX)) { + return SWIG_OverflowError; + } else { + if (val) *val = static_cast< int >(v); + } + } + return res; +} + +SWIGINTERN void +SWIG_Python_builtin_imports() +{ + PyObject *import_str = NULL; +} +#ifdef __cplusplus +extern "C" { +#endif +SWIGINTERN int _wrap_new_A(PyObject *self, PyObject *args) { + int resultobj = 0; + A *result = 0 ; + + if (!SWIG_Python_UnpackTuple(args,"new_A",0,0,0)) SWIG_fail; + result = (A *)new A(); + + resultobj = SWIG_Python_NewBuiltinObj(self, SWIG_as_voidptr(result), SWIGTYPE_p_A, SWIG_POINTER_NEW | 0 ); + return resultobj; +fail: + return -1; +} + + +SWIGINTERN PyObject *_wrap_delete_A(PyObject *self, PyObject *args) { + PyObject *resultobj = 0; + A *arg1 = (A *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!SWIG_Python_UnpackTuple(args,"delete_A",0,0,0)) SWIG_fail; + res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_A, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_A" "', argument " "1"" of type '" "A *""'"); + } + arg1 = reinterpret_cast< A * >(argp1); + delete arg1; + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_A_func(PyObject *self, PyObject *args) { + PyObject *resultobj = 0; + A *arg1 = (A *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!SWIG_Python_UnpackTuple(args,"A_func",0,0,0)) SWIG_fail; + res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_A, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "A_func" "', argument " "1"" of type '" "A *""'"); + } + arg1 = reinterpret_cast< A * >(argp1); + (arg1)->func(); + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_A___iadd__(PyObject *self, PyObject *args) { + PyObject *resultobj = 0; + A *arg1 = (A *) 0 ; + int arg2 ; + void *argp1 = 0 ; + int res1 = 0 ; + int val2 ; + int ecode2 = 0 ; + PyObject *swig_obj[2] ; + A *result = 0 ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_A, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "A___iadd__" "', argument " "1"" of type '" "A *""'"); + } + arg1 = reinterpret_cast< A * >(argp1); + ecode2 = SWIG_AsVal_int(swig_obj[0], &val2); + if (!SWIG_IsOK(ecode2)) { + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "A___iadd__" "', argument " "2"" of type '" "int""'"); + } + arg2 = static_cast< int >(val2); + result = (A *) &(arg1)->operator +=(arg2); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_A, SWIG_POINTER_OWN | 0 ); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN int _wrap_new_B(PyObject *self, PyObject *args) { + int resultobj = 0; + B *result = 0 ; + + if (!SWIG_Python_UnpackTuple(args,"new_B",0,0,0)) SWIG_fail; + result = (B *)new B(); + + resultobj = SWIG_Python_NewBuiltinObj(self, SWIG_as_voidptr(result), SWIGTYPE_p_B, SWIG_POINTER_NEW | 0 ); + return resultobj; +fail: + return -1; +} + + +SWIGINTERN PyObject *_wrap_delete_B(PyObject *self, PyObject *args) { + PyObject *resultobj = 0; + B *arg1 = (B *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!SWIG_Python_UnpackTuple(args,"delete_B",0,0,0)) SWIG_fail; + res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_B, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_B" "', argument " "1"" of type '" "B *""'"); + } + arg1 = reinterpret_cast< B * >(argp1); + delete arg1; + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN int _wrap_new_C(PyObject *self, PyObject *args) { + int resultobj = 0; + C *result = 0 ; + + if (!SWIG_Python_UnpackTuple(args,"new_C",0,0,0)) SWIG_fail; + result = (C *)new C(); + + resultobj = SWIG_Python_NewBuiltinObj(self, SWIG_as_voidptr(result), SWIGTYPE_p_C, SWIG_POINTER_NEW | 0 ); + return resultobj; +fail: + return -1; +} + + +SWIGINTERN PyObject *_wrap_delete_C(PyObject *self, PyObject *args) { + PyObject *resultobj = 0; + C *arg1 = (C *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!SWIG_Python_UnpackTuple(args,"delete_C",0,0,0)) SWIG_fail; + res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_C, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_C" "', argument " "1"" of type '" "C *""'"); + } + arg1 = reinterpret_cast< C * >(argp1); + delete arg1; + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN int _wrap_new_D(PyObject *self, PyObject *args) { + int resultobj = 0; + D *result = 0 ; + + if (!SWIG_Python_UnpackTuple(args,"new_D",0,0,0)) SWIG_fail; + result = (D *)new D(); + + resultobj = SWIG_Python_NewBuiltinObj(self, SWIG_as_voidptr(result), SWIGTYPE_p_D, SWIG_POINTER_NEW | 0 ); + return resultobj; +fail: + return -1; +} + + +SWIGINTERN PyObject *_wrap_delete_D(PyObject *self, PyObject *args) { + PyObject *resultobj = 0; + D *arg1 = (D *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!SWIG_Python_UnpackTuple(args,"delete_D",0,0,0)) SWIG_fail; + res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_D, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_D" "', argument " "1"" of type '" "D *""'"); + } + arg1 = reinterpret_cast< D * >(argp1); + delete arg1; + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN int _wrap_new_E(PyObject *self, PyObject *args) { + int resultobj = 0; + E *result = 0 ; + + if (!SWIG_Python_UnpackTuple(args,"new_E",0,0,0)) SWIG_fail; + result = (E *)new E(); + + resultobj = SWIG_Python_NewBuiltinObj(self, SWIG_as_voidptr(result), SWIGTYPE_p_E, SWIG_POINTER_NEW | 0 ); + return resultobj; +fail: + return -1; +} + + +SWIGINTERN PyObject *_wrap_delete_E(PyObject *self, PyObject *args) { + PyObject *resultobj = 0; + E *arg1 = (E *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!SWIG_Python_UnpackTuple(args,"delete_E",0,0,0)) SWIG_fail; + res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_E, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_E" "', argument " "1"" of type '" "E *""'"); + } + arg1 = reinterpret_cast< E * >(argp1); + delete arg1; + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN int _wrap_new_F(PyObject *self, PyObject *args) { + int resultobj = 0; + F *result = 0 ; + + if (!SWIG_Python_UnpackTuple(args,"new_F",0,0,0)) SWIG_fail; + result = (F *)new F(); + + resultobj = SWIG_Python_NewBuiltinObj(self, SWIG_as_voidptr(result), SWIGTYPE_p_F, SWIG_POINTER_NEW | 0 ); + return resultobj; +fail: + return -1; +} + + +SWIGINTERN PyObject *_wrap_delete_F(PyObject *self, PyObject *args) { + PyObject *resultobj = 0; + F *arg1 = (F *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!SWIG_Python_UnpackTuple(args,"delete_F",0,0,0)) SWIG_fail; + res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_F, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_F" "', argument " "1"" of type '" "F *""'"); + } + arg1 = reinterpret_cast< F * >(argp1); + delete arg1; + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN int _wrap_new_G(PyObject *self, PyObject *args) { + int resultobj = 0; + G *result = 0 ; + + if (!SWIG_Python_UnpackTuple(args,"new_G",0,0,0)) SWIG_fail; + result = (G *)new G(); + + resultobj = SWIG_Python_NewBuiltinObj(self, SWIG_as_voidptr(result), SWIGTYPE_p_G, SWIG_POINTER_NEW | 0 ); + return resultobj; +fail: + return -1; +} + + +SWIGINTERN PyObject *_wrap_delete_G(PyObject *self, PyObject *args) { + PyObject *resultobj = 0; + G *arg1 = (G *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!SWIG_Python_UnpackTuple(args,"delete_G",0,0,0)) SWIG_fail; + res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_G, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_G" "', argument " "1"" of type '" "G *""'"); + } + arg1 = reinterpret_cast< G * >(argp1); + delete arg1; + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN int _wrap_new_H(PyObject *self, PyObject *args) { + int resultobj = 0; + H *result = 0 ; + + if (!SWIG_Python_UnpackTuple(args,"new_H",0,0,0)) SWIG_fail; + result = (H *)new H(); + + resultobj = SWIG_Python_NewBuiltinObj(self, SWIG_as_voidptr(result), SWIGTYPE_p_H, SWIG_POINTER_NEW | 0 ); + return resultobj; +fail: + return -1; +} + + +SWIGINTERN PyObject *_wrap_delete_H(PyObject *self, PyObject *args) { + PyObject *resultobj = 0; + H *arg1 = (H *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!SWIG_Python_UnpackTuple(args,"delete_H",0,0,0)) SWIG_fail; + res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_H, SWIG_POINTER_DISOWN | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_H" "', argument " "1"" of type '" "H *""'"); + } + arg1 = reinterpret_cast< H * >(argp1); + delete arg1; + resultobj = SWIG_Py_Void(); + return resultobj; +fail: + return NULL; +} + + +static PyMethodDef SwigMethods[] = { + { (char *)"SWIG_PyInstanceMethod_New", (PyCFunction)SWIG_PyInstanceMethod_New, METH_O, NULL}, + { NULL, NULL, 0, NULL } +}; + +#ifdef __cplusplus +namespace { +#endif + +PYSWIG_DESTRUCTOR_CLOSURE(_wrap_delete_A); +SWIGINTERN PyGetSetDef SwigPyBuiltin__A_getset[] = { + {NULL} // Sentinel +}; + +SWIGINTERN PyObject* +SwigPyBuiltin__A_richcompare (PyObject *self, PyObject *other, int op) +{ + PyObject *result = NULL; + switch (op) { + default : break; + } + if (result == NULL) { + if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) { + result = SwigPyObject_richcompare((SwigPyObject*) self, (SwigPyObject*) other, op); + } else { + result = Py_NotImplemented; + Py_INCREF(result); + } + } + return result; +} + +SWIGINTERN PyMethodDef SwigPyBuiltin__A_methods[] = { + { "func", (PyCFunction) _wrap_A_func, METH_NOARGS, "" }, + { "__iadd__", (PyCFunction) _wrap_A___iadd__, METH_O, "" }, + {NULL} // Sentinel +}; + +static PyHeapTypeObject SwigPyBuiltin__A_type = { + { +#if PY_VERSION_HEX >= 0x03000000 + PyVarObject_HEAD_INIT(&PyType_Type, 0) +#else + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ +#endif + "A", /*tp_name*/ + sizeof(SwigPyObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + _wrap_delete_A_closure, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + &SwigPyBuiltin__A_type.as_number, /*tp_as_number*/ + &SwigPyBuiltin__A_type.as_sequence, /*tp_as_sequence*/ + &SwigPyBuiltin__A_type.as_mapping, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &SwigPyBuiltin__A_type.as_buffer, /*tp_as_buffer*/ +#if PY_VERSION_HEX >= 0x03000000 + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/ +#else + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ +#endif + "::A", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + SwigPyBuiltin__A_richcompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc) 0, /* tp_iter */ + (iternextfunc) 0, /* tp_iternext */ + SwigPyBuiltin__A_methods, /* tp_methods */ + 0, /* tp_members */ + SwigPyBuiltin__A_getset, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */ + (initproc)_wrap_new_A, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0 /* tp_free */ + }, + { + (binaryfunc) 0, // nb_add; + (binaryfunc) 0, // nb_subtract; + (binaryfunc) 0, // nb_multiply; +#if PY_VERSION_HEX < 0x03000000 + (binaryfunc) 0, // nb_divide; +#endif + (binaryfunc) 0, // nb_remainder; + (binaryfunc) 0, // nb_divmod; + (ternaryfunc) 0, // nb_power; + (unaryfunc) 0, // nb_negative; + (unaryfunc) 0, // nb_positive; + (unaryfunc) 0, // nb_absolute; + (inquiry) 0, // nb_nonzero; + (unaryfunc) 0, // nb_invert; + (binaryfunc) 0, // nb_lshift; + (binaryfunc) 0, // nb_rshift; + (binaryfunc) 0, // nb_and; + (binaryfunc) 0, // nb_xor; + (binaryfunc) 0, // nb_or; +#if PY_VERSION_HEX < 0x03000000 + (coercion) 0, // nb_coerce; +#endif + (unaryfunc) 0, // nb_int; +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // nb_reserved; +#else + (unaryfunc) 0, // nb_long; +#endif + (unaryfunc) 0, // nb_float; +#if PY_VERSION_HEX < 0x03000000 + (unaryfunc) 0, // nb_oct; + (unaryfunc) 0, // nb_hex; +#endif + (binaryfunc) _wrap_A___iadd__, // nb_inplace_add; + (binaryfunc) 0, // nb_inplace_subtract; + (binaryfunc) 0, // nb_inplace_multiply; +#if PY_VERSION_HEX < 0x03000000 + (binaryfunc) 0, // nb_inplace_divide; +#endif + (binaryfunc) 0, // nb_inplace_remainder; + (ternaryfunc) 0, // nb_inplace_power; + (binaryfunc) 0, // nb_inplace_lshift; + (binaryfunc) 0, // nb_inplace_rshift; + (binaryfunc) 0, // nb_inplace_and; + (binaryfunc) 0, // nb_inplace_xor; + (binaryfunc) 0, // nb_inplace_or; + (binaryfunc) 0, // nb_floor_divide; + (binaryfunc) 0, // nb_true_divide; + (binaryfunc) 0, // nb_inplace_floor_divide; + (binaryfunc) 0, // nb_inplace_true_divide; + (unaryfunc) 0, // nb_index; + }, + { + (lenfunc) 0, // mp_length; + (binaryfunc) 0, // mp_subscript; + (objobjargproc) 0, // mp_ass_subscript; + }, + { + (lenfunc) 0, // sq_length + (binaryfunc) 0, // sq_concat + (ssizeargfunc) 0, // sq_repeat + (ssizeargfunc) 0, // sq_item +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // was_sq_slice +#else + (ssizessizeargfunc) 0, // sq_slice +#endif + (ssizeobjargproc) 0, // sq_ass_item +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // was_sq_ass_slice +#else + (ssizessizeobjargproc) 0, // sq_ass_slice +#endif + (objobjproc) 0, // sq_contains + (binaryfunc) 0, // sq_inplace_concat + (ssizeargfunc) 0, // sq_inplace_repeat + }, + { +#if PY_VERSION_HEX >= 0x03000000 + (getbufferproc) 0, // bf_getbuffer + (releasebufferproc) 0, // bf_releasebuffer +#else + (readbufferproc) 0, // bf_getreadbuffer + (writebufferproc) 0, // bf_getwritebuffer + (segcountproc) 0, // bf_getsegcount + (charbufferproc) 0, // bf_getcharbuffer +#endif + }, + (PyObject*) 0, // ht_name + (PyObject*) 0, // ht_slots +}; + +SWIGINTERN SwigPyClientData SwigPyBuiltin__A_clientdata = {0, 0, 0, 0, 0, 0, (PyTypeObject*) &SwigPyBuiltin__A_type}; + +PYSWIG_DESTRUCTOR_CLOSURE(_wrap_delete_B); +SWIGINTERN PyGetSetDef SwigPyBuiltin__B_getset[] = { + {NULL} // Sentinel +}; + +SWIGINTERN PyObject* +SwigPyBuiltin__B_richcompare (PyObject *self, PyObject *other, int op) +{ + PyObject *result = NULL; + switch (op) { + default : break; + } + if (result == NULL) { + if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) { + result = SwigPyObject_richcompare((SwigPyObject*) self, (SwigPyObject*) other, op); + } else { + result = Py_NotImplemented; + Py_INCREF(result); + } + } + return result; +} + +SWIGINTERN PyMethodDef SwigPyBuiltin__B_methods[] = { + {NULL} // Sentinel +}; + +static PyHeapTypeObject SwigPyBuiltin__B_type = { + { +#if PY_VERSION_HEX >= 0x03000000 + PyVarObject_HEAD_INIT(&PyType_Type, 0) +#else + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ +#endif + "B", /*tp_name*/ + sizeof(SwigPyObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + _wrap_delete_B_closure, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + &SwigPyBuiltin__B_type.as_number, /*tp_as_number*/ + &SwigPyBuiltin__B_type.as_sequence, /*tp_as_sequence*/ + &SwigPyBuiltin__B_type.as_mapping, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &SwigPyBuiltin__B_type.as_buffer, /*tp_as_buffer*/ +#if PY_VERSION_HEX >= 0x03000000 + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/ +#else + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ +#endif + "::B", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + SwigPyBuiltin__B_richcompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc) 0, /* tp_iter */ + (iternextfunc) 0, /* tp_iternext */ + SwigPyBuiltin__B_methods, /* tp_methods */ + 0, /* tp_members */ + SwigPyBuiltin__B_getset, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */ + (initproc)_wrap_new_B, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0 /* tp_free */ + }, + { + (binaryfunc) 0, // nb_add; + (binaryfunc) 0, // nb_subtract; + (binaryfunc) 0, // nb_multiply; +#if PY_VERSION_HEX < 0x03000000 + (binaryfunc) 0, // nb_divide; +#endif + (binaryfunc) 0, // nb_remainder; + (binaryfunc) 0, // nb_divmod; + (ternaryfunc) 0, // nb_power; + (unaryfunc) 0, // nb_negative; + (unaryfunc) 0, // nb_positive; + (unaryfunc) 0, // nb_absolute; + (inquiry) 0, // nb_nonzero; + (unaryfunc) 0, // nb_invert; + (binaryfunc) 0, // nb_lshift; + (binaryfunc) 0, // nb_rshift; + (binaryfunc) 0, // nb_and; + (binaryfunc) 0, // nb_xor; + (binaryfunc) 0, // nb_or; +#if PY_VERSION_HEX < 0x03000000 + (coercion) 0, // nb_coerce; +#endif + (unaryfunc) 0, // nb_int; +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // nb_reserved; +#else + (unaryfunc) 0, // nb_long; +#endif + (unaryfunc) 0, // nb_float; +#if PY_VERSION_HEX < 0x03000000 + (unaryfunc) 0, // nb_oct; + (unaryfunc) 0, // nb_hex; +#endif + (binaryfunc) 0, // nb_inplace_add; + (binaryfunc) 0, // nb_inplace_subtract; + (binaryfunc) 0, // nb_inplace_multiply; +#if PY_VERSION_HEX < 0x03000000 + (binaryfunc) 0, // nb_inplace_divide; +#endif + (binaryfunc) 0, // nb_inplace_remainder; + (ternaryfunc) 0, // nb_inplace_power; + (binaryfunc) 0, // nb_inplace_lshift; + (binaryfunc) 0, // nb_inplace_rshift; + (binaryfunc) 0, // nb_inplace_and; + (binaryfunc) 0, // nb_inplace_xor; + (binaryfunc) 0, // nb_inplace_or; + (binaryfunc) 0, // nb_floor_divide; + (binaryfunc) 0, // nb_true_divide; + (binaryfunc) 0, // nb_inplace_floor_divide; + (binaryfunc) 0, // nb_inplace_true_divide; + (unaryfunc) 0, // nb_index; + }, + { + (lenfunc) 0, // mp_length; + (binaryfunc) 0, // mp_subscript; + (objobjargproc) 0, // mp_ass_subscript; + }, + { + (lenfunc) 0, // sq_length + (binaryfunc) 0, // sq_concat + (ssizeargfunc) 0, // sq_repeat + (ssizeargfunc) 0, // sq_item +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // was_sq_slice +#else + (ssizessizeargfunc) 0, // sq_slice +#endif + (ssizeobjargproc) 0, // sq_ass_item +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // was_sq_ass_slice +#else + (ssizessizeobjargproc) 0, // sq_ass_slice +#endif + (objobjproc) 0, // sq_contains + (binaryfunc) 0, // sq_inplace_concat + (ssizeargfunc) 0, // sq_inplace_repeat + }, + { +#if PY_VERSION_HEX >= 0x03000000 + (getbufferproc) 0, // bf_getbuffer + (releasebufferproc) 0, // bf_releasebuffer +#else + (readbufferproc) 0, // bf_getreadbuffer + (writebufferproc) 0, // bf_getwritebuffer + (segcountproc) 0, // bf_getsegcount + (charbufferproc) 0, // bf_getcharbuffer +#endif + }, + (PyObject*) 0, // ht_name + (PyObject*) 0, // ht_slots +}; + +SWIGINTERN SwigPyClientData SwigPyBuiltin__B_clientdata = {0, 0, 0, 0, 0, 0, (PyTypeObject*) &SwigPyBuiltin__B_type}; + +PYSWIG_DESTRUCTOR_CLOSURE(_wrap_delete_C); +SWIGINTERN PyGetSetDef SwigPyBuiltin__C_getset[] = { + {NULL} // Sentinel +}; + +SWIGINTERN PyObject* +SwigPyBuiltin__C_richcompare (PyObject *self, PyObject *other, int op) +{ + PyObject *result = NULL; + switch (op) { + default : break; + } + if (result == NULL) { + if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) { + result = SwigPyObject_richcompare((SwigPyObject*) self, (SwigPyObject*) other, op); + } else { + result = Py_NotImplemented; + Py_INCREF(result); + } + } + return result; +} + +SWIGINTERN PyMethodDef SwigPyBuiltin__C_methods[] = { + {NULL} // Sentinel +}; + +static PyHeapTypeObject SwigPyBuiltin__C_type = { + { +#if PY_VERSION_HEX >= 0x03000000 + PyVarObject_HEAD_INIT(&PyType_Type, 0) +#else + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ +#endif + "C", /*tp_name*/ + sizeof(SwigPyObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + _wrap_delete_C_closure, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + &SwigPyBuiltin__C_type.as_number, /*tp_as_number*/ + &SwigPyBuiltin__C_type.as_sequence, /*tp_as_sequence*/ + &SwigPyBuiltin__C_type.as_mapping, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &SwigPyBuiltin__C_type.as_buffer, /*tp_as_buffer*/ +#if PY_VERSION_HEX >= 0x03000000 + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/ +#else + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ +#endif + "::C", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + SwigPyBuiltin__C_richcompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc) 0, /* tp_iter */ + (iternextfunc) 0, /* tp_iternext */ + SwigPyBuiltin__C_methods, /* tp_methods */ + 0, /* tp_members */ + SwigPyBuiltin__C_getset, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */ + (initproc)_wrap_new_C, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0 /* tp_free */ + }, + { + (binaryfunc) 0, // nb_add; + (binaryfunc) 0, // nb_subtract; + (binaryfunc) 0, // nb_multiply; +#if PY_VERSION_HEX < 0x03000000 + (binaryfunc) 0, // nb_divide; +#endif + (binaryfunc) 0, // nb_remainder; + (binaryfunc) 0, // nb_divmod; + (ternaryfunc) 0, // nb_power; + (unaryfunc) 0, // nb_negative; + (unaryfunc) 0, // nb_positive; + (unaryfunc) 0, // nb_absolute; + (inquiry) 0, // nb_nonzero; + (unaryfunc) 0, // nb_invert; + (binaryfunc) 0, // nb_lshift; + (binaryfunc) 0, // nb_rshift; + (binaryfunc) 0, // nb_and; + (binaryfunc) 0, // nb_xor; + (binaryfunc) 0, // nb_or; +#if PY_VERSION_HEX < 0x03000000 + (coercion) 0, // nb_coerce; +#endif + (unaryfunc) 0, // nb_int; +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // nb_reserved; +#else + (unaryfunc) 0, // nb_long; +#endif + (unaryfunc) 0, // nb_float; +#if PY_VERSION_HEX < 0x03000000 + (unaryfunc) 0, // nb_oct; + (unaryfunc) 0, // nb_hex; +#endif + (binaryfunc) 0, // nb_inplace_add; + (binaryfunc) 0, // nb_inplace_subtract; + (binaryfunc) 0, // nb_inplace_multiply; +#if PY_VERSION_HEX < 0x03000000 + (binaryfunc) 0, // nb_inplace_divide; +#endif + (binaryfunc) 0, // nb_inplace_remainder; + (ternaryfunc) 0, // nb_inplace_power; + (binaryfunc) 0, // nb_inplace_lshift; + (binaryfunc) 0, // nb_inplace_rshift; + (binaryfunc) 0, // nb_inplace_and; + (binaryfunc) 0, // nb_inplace_xor; + (binaryfunc) 0, // nb_inplace_or; + (binaryfunc) 0, // nb_floor_divide; + (binaryfunc) 0, // nb_true_divide; + (binaryfunc) 0, // nb_inplace_floor_divide; + (binaryfunc) 0, // nb_inplace_true_divide; + (unaryfunc) 0, // nb_index; + }, + { + (lenfunc) 0, // mp_length; + (binaryfunc) 0, // mp_subscript; + (objobjargproc) 0, // mp_ass_subscript; + }, + { + (lenfunc) 0, // sq_length + (binaryfunc) 0, // sq_concat + (ssizeargfunc) 0, // sq_repeat + (ssizeargfunc) 0, // sq_item +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // was_sq_slice +#else + (ssizessizeargfunc) 0, // sq_slice +#endif + (ssizeobjargproc) 0, // sq_ass_item +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // was_sq_ass_slice +#else + (ssizessizeobjargproc) 0, // sq_ass_slice +#endif + (objobjproc) 0, // sq_contains + (binaryfunc) 0, // sq_inplace_concat + (ssizeargfunc) 0, // sq_inplace_repeat + }, + { +#if PY_VERSION_HEX >= 0x03000000 + (getbufferproc) 0, // bf_getbuffer + (releasebufferproc) 0, // bf_releasebuffer +#else + (readbufferproc) 0, // bf_getreadbuffer + (writebufferproc) 0, // bf_getwritebuffer + (segcountproc) 0, // bf_getsegcount + (charbufferproc) 0, // bf_getcharbuffer +#endif + }, + (PyObject*) 0, // ht_name + (PyObject*) 0, // ht_slots +}; + +SWIGINTERN SwigPyClientData SwigPyBuiltin__C_clientdata = {0, 0, 0, 0, 0, 0, (PyTypeObject*) &SwigPyBuiltin__C_type}; + +PYSWIG_DESTRUCTOR_CLOSURE(_wrap_delete_D); +SWIGINTERN PyGetSetDef SwigPyBuiltin__D_getset[] = { + {NULL} // Sentinel +}; + +SWIGINTERN PyObject* +SwigPyBuiltin__D_richcompare (PyObject *self, PyObject *other, int op) +{ + PyObject *result = NULL; + switch (op) { + default : break; + } + if (result == NULL) { + if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) { + result = SwigPyObject_richcompare((SwigPyObject*) self, (SwigPyObject*) other, op); + } else { + result = Py_NotImplemented; + Py_INCREF(result); + } + } + return result; +} + +SWIGINTERN PyMethodDef SwigPyBuiltin__D_methods[] = { + {NULL} // Sentinel +}; + +static PyHeapTypeObject SwigPyBuiltin__D_type = { + { +#if PY_VERSION_HEX >= 0x03000000 + PyVarObject_HEAD_INIT(&PyType_Type, 0) +#else + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ +#endif + "D", /*tp_name*/ + sizeof(SwigPyObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + _wrap_delete_D_closure, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + &SwigPyBuiltin__D_type.as_number, /*tp_as_number*/ + &SwigPyBuiltin__D_type.as_sequence, /*tp_as_sequence*/ + &SwigPyBuiltin__D_type.as_mapping, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &SwigPyBuiltin__D_type.as_buffer, /*tp_as_buffer*/ +#if PY_VERSION_HEX >= 0x03000000 + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/ +#else + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ +#endif + "::D", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + SwigPyBuiltin__D_richcompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc) 0, /* tp_iter */ + (iternextfunc) 0, /* tp_iternext */ + SwigPyBuiltin__D_methods, /* tp_methods */ + 0, /* tp_members */ + SwigPyBuiltin__D_getset, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */ + (initproc)_wrap_new_D, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0 /* tp_free */ + }, + { + (binaryfunc) 0, // nb_add; + (binaryfunc) 0, // nb_subtract; + (binaryfunc) 0, // nb_multiply; +#if PY_VERSION_HEX < 0x03000000 + (binaryfunc) 0, // nb_divide; +#endif + (binaryfunc) 0, // nb_remainder; + (binaryfunc) 0, // nb_divmod; + (ternaryfunc) 0, // nb_power; + (unaryfunc) 0, // nb_negative; + (unaryfunc) 0, // nb_positive; + (unaryfunc) 0, // nb_absolute; + (inquiry) 0, // nb_nonzero; + (unaryfunc) 0, // nb_invert; + (binaryfunc) 0, // nb_lshift; + (binaryfunc) 0, // nb_rshift; + (binaryfunc) 0, // nb_and; + (binaryfunc) 0, // nb_xor; + (binaryfunc) 0, // nb_or; +#if PY_VERSION_HEX < 0x03000000 + (coercion) 0, // nb_coerce; +#endif + (unaryfunc) 0, // nb_int; +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // nb_reserved; +#else + (unaryfunc) 0, // nb_long; +#endif + (unaryfunc) 0, // nb_float; +#if PY_VERSION_HEX < 0x03000000 + (unaryfunc) 0, // nb_oct; + (unaryfunc) 0, // nb_hex; +#endif + (binaryfunc) 0, // nb_inplace_add; + (binaryfunc) 0, // nb_inplace_subtract; + (binaryfunc) 0, // nb_inplace_multiply; +#if PY_VERSION_HEX < 0x03000000 + (binaryfunc) 0, // nb_inplace_divide; +#endif + (binaryfunc) 0, // nb_inplace_remainder; + (ternaryfunc) 0, // nb_inplace_power; + (binaryfunc) 0, // nb_inplace_lshift; + (binaryfunc) 0, // nb_inplace_rshift; + (binaryfunc) 0, // nb_inplace_and; + (binaryfunc) 0, // nb_inplace_xor; + (binaryfunc) 0, // nb_inplace_or; + (binaryfunc) 0, // nb_floor_divide; + (binaryfunc) 0, // nb_true_divide; + (binaryfunc) 0, // nb_inplace_floor_divide; + (binaryfunc) 0, // nb_inplace_true_divide; + (unaryfunc) 0, // nb_index; + }, + { + (lenfunc) 0, // mp_length; + (binaryfunc) 0, // mp_subscript; + (objobjargproc) 0, // mp_ass_subscript; + }, + { + (lenfunc) 0, // sq_length + (binaryfunc) 0, // sq_concat + (ssizeargfunc) 0, // sq_repeat + (ssizeargfunc) 0, // sq_item +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // was_sq_slice +#else + (ssizessizeargfunc) 0, // sq_slice +#endif + (ssizeobjargproc) 0, // sq_ass_item +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // was_sq_ass_slice +#else + (ssizessizeobjargproc) 0, // sq_ass_slice +#endif + (objobjproc) 0, // sq_contains + (binaryfunc) 0, // sq_inplace_concat + (ssizeargfunc) 0, // sq_inplace_repeat + }, + { +#if PY_VERSION_HEX >= 0x03000000 + (getbufferproc) 0, // bf_getbuffer + (releasebufferproc) 0, // bf_releasebuffer +#else + (readbufferproc) 0, // bf_getreadbuffer + (writebufferproc) 0, // bf_getwritebuffer + (segcountproc) 0, // bf_getsegcount + (charbufferproc) 0, // bf_getcharbuffer +#endif + }, + (PyObject*) 0, // ht_name + (PyObject*) 0, // ht_slots +}; + +SWIGINTERN SwigPyClientData SwigPyBuiltin__D_clientdata = {0, 0, 0, 0, 0, 0, (PyTypeObject*) &SwigPyBuiltin__D_type}; + +PYSWIG_DESTRUCTOR_CLOSURE(_wrap_delete_E); +SWIGINTERN PyGetSetDef SwigPyBuiltin__E_getset[] = { + {NULL} // Sentinel +}; + +SWIGINTERN PyObject* +SwigPyBuiltin__E_richcompare (PyObject *self, PyObject *other, int op) +{ + PyObject *result = NULL; + switch (op) { + default : break; + } + if (result == NULL) { + if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) { + result = SwigPyObject_richcompare((SwigPyObject*) self, (SwigPyObject*) other, op); + } else { + result = Py_NotImplemented; + Py_INCREF(result); + } + } + return result; +} + +SWIGINTERN PyMethodDef SwigPyBuiltin__E_methods[] = { + {NULL} // Sentinel +}; + +static PyHeapTypeObject SwigPyBuiltin__E_type = { + { +#if PY_VERSION_HEX >= 0x03000000 + PyVarObject_HEAD_INIT(&PyType_Type, 0) +#else + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ +#endif + "E", /*tp_name*/ + sizeof(SwigPyObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + _wrap_delete_E_closure, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + &SwigPyBuiltin__E_type.as_number, /*tp_as_number*/ + &SwigPyBuiltin__E_type.as_sequence, /*tp_as_sequence*/ + &SwigPyBuiltin__E_type.as_mapping, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &SwigPyBuiltin__E_type.as_buffer, /*tp_as_buffer*/ +#if PY_VERSION_HEX >= 0x03000000 + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/ +#else + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ +#endif + "::E", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + SwigPyBuiltin__E_richcompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc) 0, /* tp_iter */ + (iternextfunc) 0, /* tp_iternext */ + SwigPyBuiltin__E_methods, /* tp_methods */ + 0, /* tp_members */ + SwigPyBuiltin__E_getset, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */ + (initproc)_wrap_new_E, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0 /* tp_free */ + }, + { + (binaryfunc) 0, // nb_add; + (binaryfunc) 0, // nb_subtract; + (binaryfunc) 0, // nb_multiply; +#if PY_VERSION_HEX < 0x03000000 + (binaryfunc) 0, // nb_divide; +#endif + (binaryfunc) 0, // nb_remainder; + (binaryfunc) 0, // nb_divmod; + (ternaryfunc) 0, // nb_power; + (unaryfunc) 0, // nb_negative; + (unaryfunc) 0, // nb_positive; + (unaryfunc) 0, // nb_absolute; + (inquiry) 0, // nb_nonzero; + (unaryfunc) 0, // nb_invert; + (binaryfunc) 0, // nb_lshift; + (binaryfunc) 0, // nb_rshift; + (binaryfunc) 0, // nb_and; + (binaryfunc) 0, // nb_xor; + (binaryfunc) 0, // nb_or; +#if PY_VERSION_HEX < 0x03000000 + (coercion) 0, // nb_coerce; +#endif + (unaryfunc) 0, // nb_int; +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // nb_reserved; +#else + (unaryfunc) 0, // nb_long; +#endif + (unaryfunc) 0, // nb_float; +#if PY_VERSION_HEX < 0x03000000 + (unaryfunc) 0, // nb_oct; + (unaryfunc) 0, // nb_hex; +#endif + (binaryfunc) 0, // nb_inplace_add; + (binaryfunc) 0, // nb_inplace_subtract; + (binaryfunc) 0, // nb_inplace_multiply; +#if PY_VERSION_HEX < 0x03000000 + (binaryfunc) 0, // nb_inplace_divide; +#endif + (binaryfunc) 0, // nb_inplace_remainder; + (ternaryfunc) 0, // nb_inplace_power; + (binaryfunc) 0, // nb_inplace_lshift; + (binaryfunc) 0, // nb_inplace_rshift; + (binaryfunc) 0, // nb_inplace_and; + (binaryfunc) 0, // nb_inplace_xor; + (binaryfunc) 0, // nb_inplace_or; + (binaryfunc) 0, // nb_floor_divide; + (binaryfunc) 0, // nb_true_divide; + (binaryfunc) 0, // nb_inplace_floor_divide; + (binaryfunc) 0, // nb_inplace_true_divide; + (unaryfunc) 0, // nb_index; + }, + { + (lenfunc) 0, // mp_length; + (binaryfunc) 0, // mp_subscript; + (objobjargproc) 0, // mp_ass_subscript; + }, + { + (lenfunc) 0, // sq_length + (binaryfunc) 0, // sq_concat + (ssizeargfunc) 0, // sq_repeat + (ssizeargfunc) 0, // sq_item +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // was_sq_slice +#else + (ssizessizeargfunc) 0, // sq_slice +#endif + (ssizeobjargproc) 0, // sq_ass_item +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // was_sq_ass_slice +#else + (ssizessizeobjargproc) 0, // sq_ass_slice +#endif + (objobjproc) 0, // sq_contains + (binaryfunc) 0, // sq_inplace_concat + (ssizeargfunc) 0, // sq_inplace_repeat + }, + { +#if PY_VERSION_HEX >= 0x03000000 + (getbufferproc) 0, // bf_getbuffer + (releasebufferproc) 0, // bf_releasebuffer +#else + (readbufferproc) 0, // bf_getreadbuffer + (writebufferproc) 0, // bf_getwritebuffer + (segcountproc) 0, // bf_getsegcount + (charbufferproc) 0, // bf_getcharbuffer +#endif + }, + (PyObject*) 0, // ht_name + (PyObject*) 0, // ht_slots +}; + +SWIGINTERN SwigPyClientData SwigPyBuiltin__E_clientdata = {0, 0, 0, 0, 0, 0, (PyTypeObject*) &SwigPyBuiltin__E_type}; + +PYSWIG_DESTRUCTOR_CLOSURE(_wrap_delete_F); +SWIGINTERN PyGetSetDef SwigPyBuiltin__F_getset[] = { + {NULL} // Sentinel +}; + +SWIGINTERN PyObject* +SwigPyBuiltin__F_richcompare (PyObject *self, PyObject *other, int op) +{ + PyObject *result = NULL; + switch (op) { + default : break; + } + if (result == NULL) { + if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) { + result = SwigPyObject_richcompare((SwigPyObject*) self, (SwigPyObject*) other, op); + } else { + result = Py_NotImplemented; + Py_INCREF(result); + } + } + return result; +} + +SWIGINTERN PyMethodDef SwigPyBuiltin__F_methods[] = { + {NULL} // Sentinel +}; + +static PyHeapTypeObject SwigPyBuiltin__F_type = { + { +#if PY_VERSION_HEX >= 0x03000000 + PyVarObject_HEAD_INIT(&PyType_Type, 0) +#else + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ +#endif + "F", /*tp_name*/ + sizeof(SwigPyObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + _wrap_delete_F_closure, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + &SwigPyBuiltin__F_type.as_number, /*tp_as_number*/ + &SwigPyBuiltin__F_type.as_sequence, /*tp_as_sequence*/ + &SwigPyBuiltin__F_type.as_mapping, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &SwigPyBuiltin__F_type.as_buffer, /*tp_as_buffer*/ +#if PY_VERSION_HEX >= 0x03000000 + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/ +#else + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ +#endif + "::F", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + SwigPyBuiltin__F_richcompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc) 0, /* tp_iter */ + (iternextfunc) 0, /* tp_iternext */ + SwigPyBuiltin__F_methods, /* tp_methods */ + 0, /* tp_members */ + SwigPyBuiltin__F_getset, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */ + (initproc)_wrap_new_F, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0 /* tp_free */ + }, + { + (binaryfunc) 0, // nb_add; + (binaryfunc) 0, // nb_subtract; + (binaryfunc) 0, // nb_multiply; +#if PY_VERSION_HEX < 0x03000000 + (binaryfunc) 0, // nb_divide; +#endif + (binaryfunc) 0, // nb_remainder; + (binaryfunc) 0, // nb_divmod; + (ternaryfunc) 0, // nb_power; + (unaryfunc) 0, // nb_negative; + (unaryfunc) 0, // nb_positive; + (unaryfunc) 0, // nb_absolute; + (inquiry) 0, // nb_nonzero; + (unaryfunc) 0, // nb_invert; + (binaryfunc) 0, // nb_lshift; + (binaryfunc) 0, // nb_rshift; + (binaryfunc) 0, // nb_and; + (binaryfunc) 0, // nb_xor; + (binaryfunc) 0, // nb_or; +#if PY_VERSION_HEX < 0x03000000 + (coercion) 0, // nb_coerce; +#endif + (unaryfunc) 0, // nb_int; +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // nb_reserved; +#else + (unaryfunc) 0, // nb_long; +#endif + (unaryfunc) 0, // nb_float; +#if PY_VERSION_HEX < 0x03000000 + (unaryfunc) 0, // nb_oct; + (unaryfunc) 0, // nb_hex; +#endif + (binaryfunc) 0, // nb_inplace_add; + (binaryfunc) 0, // nb_inplace_subtract; + (binaryfunc) 0, // nb_inplace_multiply; +#if PY_VERSION_HEX < 0x03000000 + (binaryfunc) 0, // nb_inplace_divide; +#endif + (binaryfunc) 0, // nb_inplace_remainder; + (ternaryfunc) 0, // nb_inplace_power; + (binaryfunc) 0, // nb_inplace_lshift; + (binaryfunc) 0, // nb_inplace_rshift; + (binaryfunc) 0, // nb_inplace_and; + (binaryfunc) 0, // nb_inplace_xor; + (binaryfunc) 0, // nb_inplace_or; + (binaryfunc) 0, // nb_floor_divide; + (binaryfunc) 0, // nb_true_divide; + (binaryfunc) 0, // nb_inplace_floor_divide; + (binaryfunc) 0, // nb_inplace_true_divide; + (unaryfunc) 0, // nb_index; + }, + { + (lenfunc) 0, // mp_length; + (binaryfunc) 0, // mp_subscript; + (objobjargproc) 0, // mp_ass_subscript; + }, + { + (lenfunc) 0, // sq_length + (binaryfunc) 0, // sq_concat + (ssizeargfunc) 0, // sq_repeat + (ssizeargfunc) 0, // sq_item +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // was_sq_slice +#else + (ssizessizeargfunc) 0, // sq_slice +#endif + (ssizeobjargproc) 0, // sq_ass_item +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // was_sq_ass_slice +#else + (ssizessizeobjargproc) 0, // sq_ass_slice +#endif + (objobjproc) 0, // sq_contains + (binaryfunc) 0, // sq_inplace_concat + (ssizeargfunc) 0, // sq_inplace_repeat + }, + { +#if PY_VERSION_HEX >= 0x03000000 + (getbufferproc) 0, // bf_getbuffer + (releasebufferproc) 0, // bf_releasebuffer +#else + (readbufferproc) 0, // bf_getreadbuffer + (writebufferproc) 0, // bf_getwritebuffer + (segcountproc) 0, // bf_getsegcount + (charbufferproc) 0, // bf_getcharbuffer +#endif + }, + (PyObject*) 0, // ht_name + (PyObject*) 0, // ht_slots +}; + +SWIGINTERN SwigPyClientData SwigPyBuiltin__F_clientdata = {0, 0, 0, 0, 0, 0, (PyTypeObject*) &SwigPyBuiltin__F_type}; + +PYSWIG_DESTRUCTOR_CLOSURE(_wrap_delete_G); +SWIGINTERN PyGetSetDef SwigPyBuiltin__G_getset[] = { + {NULL} // Sentinel +}; + +SWIGINTERN PyObject* +SwigPyBuiltin__G_richcompare (PyObject *self, PyObject *other, int op) +{ + PyObject *result = NULL; + switch (op) { + default : break; + } + if (result == NULL) { + if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) { + result = SwigPyObject_richcompare((SwigPyObject*) self, (SwigPyObject*) other, op); + } else { + result = Py_NotImplemented; + Py_INCREF(result); + } + } + return result; +} + +SWIGINTERN PyMethodDef SwigPyBuiltin__G_methods[] = { + {NULL} // Sentinel +}; + +static PyHeapTypeObject SwigPyBuiltin__G_type = { + { +#if PY_VERSION_HEX >= 0x03000000 + PyVarObject_HEAD_INIT(&PyType_Type, 0) +#else + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ +#endif + "G", /*tp_name*/ + sizeof(SwigPyObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + _wrap_delete_G_closure, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + &SwigPyBuiltin__G_type.as_number, /*tp_as_number*/ + &SwigPyBuiltin__G_type.as_sequence, /*tp_as_sequence*/ + &SwigPyBuiltin__G_type.as_mapping, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &SwigPyBuiltin__G_type.as_buffer, /*tp_as_buffer*/ +#if PY_VERSION_HEX >= 0x03000000 + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/ +#else + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ +#endif + "::G", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + SwigPyBuiltin__G_richcompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc) 0, /* tp_iter */ + (iternextfunc) 0, /* tp_iternext */ + SwigPyBuiltin__G_methods, /* tp_methods */ + 0, /* tp_members */ + SwigPyBuiltin__G_getset, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */ + (initproc)_wrap_new_G, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0 /* tp_free */ + }, + { + (binaryfunc) 0, // nb_add; + (binaryfunc) 0, // nb_subtract; + (binaryfunc) 0, // nb_multiply; +#if PY_VERSION_HEX < 0x03000000 + (binaryfunc) 0, // nb_divide; +#endif + (binaryfunc) 0, // nb_remainder; + (binaryfunc) 0, // nb_divmod; + (ternaryfunc) 0, // nb_power; + (unaryfunc) 0, // nb_negative; + (unaryfunc) 0, // nb_positive; + (unaryfunc) 0, // nb_absolute; + (inquiry) 0, // nb_nonzero; + (unaryfunc) 0, // nb_invert; + (binaryfunc) 0, // nb_lshift; + (binaryfunc) 0, // nb_rshift; + (binaryfunc) 0, // nb_and; + (binaryfunc) 0, // nb_xor; + (binaryfunc) 0, // nb_or; +#if PY_VERSION_HEX < 0x03000000 + (coercion) 0, // nb_coerce; +#endif + (unaryfunc) 0, // nb_int; +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // nb_reserved; +#else + (unaryfunc) 0, // nb_long; +#endif + (unaryfunc) 0, // nb_float; +#if PY_VERSION_HEX < 0x03000000 + (unaryfunc) 0, // nb_oct; + (unaryfunc) 0, // nb_hex; +#endif + (binaryfunc) 0, // nb_inplace_add; + (binaryfunc) 0, // nb_inplace_subtract; + (binaryfunc) 0, // nb_inplace_multiply; +#if PY_VERSION_HEX < 0x03000000 + (binaryfunc) 0, // nb_inplace_divide; +#endif + (binaryfunc) 0, // nb_inplace_remainder; + (ternaryfunc) 0, // nb_inplace_power; + (binaryfunc) 0, // nb_inplace_lshift; + (binaryfunc) 0, // nb_inplace_rshift; + (binaryfunc) 0, // nb_inplace_and; + (binaryfunc) 0, // nb_inplace_xor; + (binaryfunc) 0, // nb_inplace_or; + (binaryfunc) 0, // nb_floor_divide; + (binaryfunc) 0, // nb_true_divide; + (binaryfunc) 0, // nb_inplace_floor_divide; + (binaryfunc) 0, // nb_inplace_true_divide; + (unaryfunc) 0, // nb_index; + }, + { + (lenfunc) 0, // mp_length; + (binaryfunc) 0, // mp_subscript; + (objobjargproc) 0, // mp_ass_subscript; + }, + { + (lenfunc) 0, // sq_length + (binaryfunc) 0, // sq_concat + (ssizeargfunc) 0, // sq_repeat + (ssizeargfunc) 0, // sq_item +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // was_sq_slice +#else + (ssizessizeargfunc) 0, // sq_slice +#endif + (ssizeobjargproc) 0, // sq_ass_item +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // was_sq_ass_slice +#else + (ssizessizeobjargproc) 0, // sq_ass_slice +#endif + (objobjproc) 0, // sq_contains + (binaryfunc) 0, // sq_inplace_concat + (ssizeargfunc) 0, // sq_inplace_repeat + }, + { +#if PY_VERSION_HEX >= 0x03000000 + (getbufferproc) 0, // bf_getbuffer + (releasebufferproc) 0, // bf_releasebuffer +#else + (readbufferproc) 0, // bf_getreadbuffer + (writebufferproc) 0, // bf_getwritebuffer + (segcountproc) 0, // bf_getsegcount + (charbufferproc) 0, // bf_getcharbuffer +#endif + }, + (PyObject*) 0, // ht_name + (PyObject*) 0, // ht_slots +}; + +SWIGINTERN SwigPyClientData SwigPyBuiltin__G_clientdata = {0, 0, 0, 0, 0, 0, (PyTypeObject*) &SwigPyBuiltin__G_type}; + +PYSWIG_DESTRUCTOR_CLOSURE(_wrap_delete_H); +SWIGINTERN PyGetSetDef SwigPyBuiltin__H_getset[] = { + {NULL} // Sentinel +}; + +SWIGINTERN PyObject* +SwigPyBuiltin__H_richcompare (PyObject *self, PyObject *other, int op) +{ + PyObject *result = NULL; + switch (op) { + default : break; + } + if (result == NULL) { + if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) { + result = SwigPyObject_richcompare((SwigPyObject*) self, (SwigPyObject*) other, op); + } else { + result = Py_NotImplemented; + Py_INCREF(result); + } + } + return result; +} + +SWIGINTERN PyMethodDef SwigPyBuiltin__H_methods[] = { + {NULL} // Sentinel +}; + +static PyHeapTypeObject SwigPyBuiltin__H_type = { + { +#if PY_VERSION_HEX >= 0x03000000 + PyVarObject_HEAD_INIT(&PyType_Type, 0) +#else + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ +#endif + "H", /*tp_name*/ + sizeof(SwigPyObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + _wrap_delete_H_closure, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + &SwigPyBuiltin__H_type.as_number, /*tp_as_number*/ + &SwigPyBuiltin__H_type.as_sequence, /*tp_as_sequence*/ + &SwigPyBuiltin__H_type.as_mapping, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &SwigPyBuiltin__H_type.as_buffer, /*tp_as_buffer*/ +#if PY_VERSION_HEX >= 0x03000000 + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/ +#else + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ +#endif + "::H", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + SwigPyBuiltin__H_richcompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc) 0, /* tp_iter */ + (iternextfunc) 0, /* tp_iternext */ + SwigPyBuiltin__H_methods, /* tp_methods */ + 0, /* tp_members */ + SwigPyBuiltin__H_getset, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */ + (initproc)_wrap_new_H, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0 /* tp_free */ + }, + { + (binaryfunc) 0, // nb_add; + (binaryfunc) 0, // nb_subtract; + (binaryfunc) 0, // nb_multiply; +#if PY_VERSION_HEX < 0x03000000 + (binaryfunc) 0, // nb_divide; +#endif + (binaryfunc) 0, // nb_remainder; + (binaryfunc) 0, // nb_divmod; + (ternaryfunc) 0, // nb_power; + (unaryfunc) 0, // nb_negative; + (unaryfunc) 0, // nb_positive; + (unaryfunc) 0, // nb_absolute; + (inquiry) 0, // nb_nonzero; + (unaryfunc) 0, // nb_invert; + (binaryfunc) 0, // nb_lshift; + (binaryfunc) 0, // nb_rshift; + (binaryfunc) 0, // nb_and; + (binaryfunc) 0, // nb_xor; + (binaryfunc) 0, // nb_or; +#if PY_VERSION_HEX < 0x03000000 + (coercion) 0, // nb_coerce; +#endif + (unaryfunc) 0, // nb_int; +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // nb_reserved; +#else + (unaryfunc) 0, // nb_long; +#endif + (unaryfunc) 0, // nb_float; +#if PY_VERSION_HEX < 0x03000000 + (unaryfunc) 0, // nb_oct; + (unaryfunc) 0, // nb_hex; +#endif + (binaryfunc) 0, // nb_inplace_add; + (binaryfunc) 0, // nb_inplace_subtract; + (binaryfunc) 0, // nb_inplace_multiply; +#if PY_VERSION_HEX < 0x03000000 + (binaryfunc) 0, // nb_inplace_divide; +#endif + (binaryfunc) 0, // nb_inplace_remainder; + (ternaryfunc) 0, // nb_inplace_power; + (binaryfunc) 0, // nb_inplace_lshift; + (binaryfunc) 0, // nb_inplace_rshift; + (binaryfunc) 0, // nb_inplace_and; + (binaryfunc) 0, // nb_inplace_xor; + (binaryfunc) 0, // nb_inplace_or; + (binaryfunc) 0, // nb_floor_divide; + (binaryfunc) 0, // nb_true_divide; + (binaryfunc) 0, // nb_inplace_floor_divide; + (binaryfunc) 0, // nb_inplace_true_divide; + (unaryfunc) 0, // nb_index; + }, + { + (lenfunc) 0, // mp_length; + (binaryfunc) 0, // mp_subscript; + (objobjargproc) 0, // mp_ass_subscript; + }, + { + (lenfunc) 0, // sq_length + (binaryfunc) 0, // sq_concat + (ssizeargfunc) 0, // sq_repeat + (ssizeargfunc) 0, // sq_item +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // was_sq_slice +#else + (ssizessizeargfunc) 0, // sq_slice +#endif + (ssizeobjargproc) 0, // sq_ass_item +#if PY_VERSION_HEX >= 0x03000000 + (void*) 0, // was_sq_ass_slice +#else + (ssizessizeobjargproc) 0, // sq_ass_slice +#endif + (objobjproc) 0, // sq_contains + (binaryfunc) 0, // sq_inplace_concat + (ssizeargfunc) 0, // sq_inplace_repeat + }, + { +#if PY_VERSION_HEX >= 0x03000000 + (getbufferproc) 0, // bf_getbuffer + (releasebufferproc) 0, // bf_releasebuffer +#else + (readbufferproc) 0, // bf_getreadbuffer + (writebufferproc) 0, // bf_getwritebuffer + (segcountproc) 0, // bf_getsegcount + (charbufferproc) 0, // bf_getcharbuffer +#endif + }, + (PyObject*) 0, // ht_name + (PyObject*) 0, // ht_slots +}; + +SWIGINTERN SwigPyClientData SwigPyBuiltin__H_clientdata = {0, 0, 0, 0, 0, 0, (PyTypeObject*) &SwigPyBuiltin__H_type}; + +#ifdef __cplusplus +} // namespace { +#endif + + +/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ + +static void *_p_FTo_p_D(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((D *) (E *) ((F *) x)); +} +static void *_p_GTo_p_D(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((D *) (E *)(F *) ((G *) x)); +} +static void *_p_HTo_p_D(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((D *) (E *)(F *)(G *) ((H *) x)); +} +static void *_p_ETo_p_D(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((D *) ((E *) x)); +} +static void *_p_FTo_p_E(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((E *) ((F *) x)); +} +static void *_p_GTo_p_E(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((E *) (F *) ((G *) x)); +} +static void *_p_HTo_p_E(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((E *) (F *)(G *) ((H *) x)); +} +static void *_p_FTo_p_A(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((A *) (B *)(C *)(D *)(E *) ((F *) x)); +} +static void *_p_GTo_p_A(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((A *) (B *)(C *)(D *)(E *)(F *) ((G *) x)); +} +static void *_p_HTo_p_A(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((A *) (B *)(C *)(D *)(E *)(F *)(G *) ((H *) x)); +} +static void *_p_BTo_p_A(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((A *) ((B *) x)); +} +static void *_p_CTo_p_A(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((A *) (B *) ((C *) x)); +} +static void *_p_DTo_p_A(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((A *) (B *)(C *) ((D *) x)); +} +static void *_p_ETo_p_A(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((A *) (B *)(C *)(D *) ((E *) x)); +} +static void *_p_GTo_p_F(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((F *) ((G *) x)); +} +static void *_p_HTo_p_F(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((F *) (G *) ((H *) x)); +} +static void *_p_HTo_p_G(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((G *) ((H *) x)); +} +static void *_p_FTo_p_B(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((B *) (C *)(D *)(E *) ((F *) x)); +} +static void *_p_GTo_p_B(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((B *) (C *)(D *)(E *)(F *) ((G *) x)); +} +static void *_p_HTo_p_B(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((B *) (C *)(D *)(E *)(F *)(G *) ((H *) x)); +} +static void *_p_CTo_p_B(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((B *) ((C *) x)); +} +static void *_p_DTo_p_B(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((B *) (C *) ((D *) x)); +} +static void *_p_ETo_p_B(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((B *) (C *)(D *) ((E *) x)); +} +static void *_p_FTo_p_C(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((C *) (D *)(E *) ((F *) x)); +} +static void *_p_GTo_p_C(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((C *) (D *)(E *)(F *) ((G *) x)); +} +static void *_p_HTo_p_C(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((C *) (D *)(E *)(F *)(G *) ((H *) x)); +} +static void *_p_DTo_p_C(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((C *) ((D *) x)); +} +static void *_p_ETo_p_C(void *x, int *SWIGUNUSEDPARM(newmemory)) { + return (void *)((C *) (D *) ((E *) x)); +} +static swig_type_info _swigt__p_A = {"_p_A", "A *", 0, 0, (void*)&SwigPyBuiltin__A_clientdata, 0}; +static swig_type_info _swigt__p_B = {"_p_B", "B *", 0, 0, (void*)&SwigPyBuiltin__B_clientdata, 0}; +static swig_type_info _swigt__p_C = {"_p_C", "C *", 0, 0, (void*)&SwigPyBuiltin__C_clientdata, 0}; +static swig_type_info _swigt__p_D = {"_p_D", "D *", 0, 0, (void*)&SwigPyBuiltin__D_clientdata, 0}; +static swig_type_info _swigt__p_E = {"_p_E", "E *", 0, 0, (void*)&SwigPyBuiltin__E_clientdata, 0}; +static swig_type_info _swigt__p_F = {"_p_F", "F *", 0, 0, (void*)&SwigPyBuiltin__F_clientdata, 0}; +static swig_type_info _swigt__p_G = {"_p_G", "G *", 0, 0, (void*)&SwigPyBuiltin__G_clientdata, 0}; +static swig_type_info _swigt__p_H = {"_p_H", "H *", 0, 0, (void*)&SwigPyBuiltin__H_clientdata, 0}; +static swig_type_info _swigt__p_SwigPyObject = {"_p_SwigPyObject", "SwigPyObject *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; + +static swig_type_info *swig_type_initial[] = { + &_swigt__p_A, + &_swigt__p_B, + &_swigt__p_C, + &_swigt__p_D, + &_swigt__p_E, + &_swigt__p_F, + &_swigt__p_G, + &_swigt__p_H, + &_swigt__p_SwigPyObject, + &_swigt__p_char, +}; + +static swig_cast_info _swigc__p_A[] = { {&_swigt__p_G, _p_GTo_p_A, 0, 0}, {&_swigt__p_A, 0, 0, 0}, {&_swigt__p_H, _p_HTo_p_A, 0, 0}, {&_swigt__p_B, _p_BTo_p_A, 0, 0}, {&_swigt__p_C, _p_CTo_p_A, 0, 0}, {&_swigt__p_D, _p_DTo_p_A, 0, 0}, {&_swigt__p_E, _p_ETo_p_A, 0, 0}, {&_swigt__p_F, _p_FTo_p_A, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_B[] = { {&_swigt__p_G, _p_GTo_p_B, 0, 0}, {&_swigt__p_H, _p_HTo_p_B, 0, 0}, {&_swigt__p_B, 0, 0, 0}, {&_swigt__p_C, _p_CTo_p_B, 0, 0}, {&_swigt__p_D, _p_DTo_p_B, 0, 0}, {&_swigt__p_E, _p_ETo_p_B, 0, 0}, {&_swigt__p_F, _p_FTo_p_B, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_C[] = { {&_swigt__p_G, _p_GTo_p_C, 0, 0}, {&_swigt__p_H, _p_HTo_p_C, 0, 0}, {&_swigt__p_C, 0, 0, 0}, {&_swigt__p_D, _p_DTo_p_C, 0, 0}, {&_swigt__p_E, _p_ETo_p_C, 0, 0}, {&_swigt__p_F, _p_FTo_p_C, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_D[] = { {&_swigt__p_G, _p_GTo_p_D, 0, 0}, {&_swigt__p_H, _p_HTo_p_D, 0, 0}, {&_swigt__p_D, 0, 0, 0}, {&_swigt__p_E, _p_ETo_p_D, 0, 0}, {&_swigt__p_F, _p_FTo_p_D, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_E[] = { {&_swigt__p_G, _p_GTo_p_E, 0, 0}, {&_swigt__p_H, _p_HTo_p_E, 0, 0}, {&_swigt__p_E, 0, 0, 0}, {&_swigt__p_F, _p_FTo_p_E, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_F[] = { {&_swigt__p_G, _p_GTo_p_F, 0, 0}, {&_swigt__p_H, _p_HTo_p_F, 0, 0}, {&_swigt__p_F, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_G[] = { {&_swigt__p_G, 0, 0, 0}, {&_swigt__p_H, _p_HTo_p_G, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_H[] = { {&_swigt__p_H, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_SwigPyObject[] = { {&_swigt__p_SwigPyObject, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; + +static swig_cast_info *swig_cast_initial[] = { + _swigc__p_A, + _swigc__p_B, + _swigc__p_C, + _swigc__p_D, + _swigc__p_E, + _swigc__p_F, + _swigc__p_G, + _swigc__p_H, + _swigc__p_SwigPyObject, + _swigc__p_char, +}; + + +/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ + +static swig_const_info swig_const_table[] = { +{0, 0, 0, 0.0, 0, 0}}; + +#ifdef __cplusplus +} +#endif +/* ----------------------------------------------------------------------------- + * Type initialization: + * This problem is tough by the requirement that no dynamic + * memory is used. Also, since swig_type_info structures store pointers to + * swig_cast_info structures and swig_cast_info structures store pointers back + * to swig_type_info structures, we need some lookup code at initialization. + * The idea is that swig generates all the structures that are needed. + * The runtime then collects these partially filled structures. + * The SWIG_InitializeModule function takes these initial arrays out of + * swig_module, and does all the lookup, filling in the swig_module.types + * array with the correct data and linking the correct swig_cast_info + * structures together. + * + * The generated swig_type_info structures are assigned staticly to an initial + * array. We just loop through that array, and handle each type individually. + * First we lookup if this type has been already loaded, and if so, use the + * loaded structure instead of the generated one. Then we have to fill in the + * cast linked list. The cast data is initially stored in something like a + * two-dimensional array. Each row corresponds to a type (there are the same + * number of rows as there are in the swig_type_initial array). Each entry in + * a column is one of the swig_cast_info structures for that type. + * The cast_initial array is actually an array of arrays, because each row has + * a variable number of columns. So to actually build the cast linked list, + * we find the array of casts associated with the type, and loop through it + * adding the casts to the list. The one last trick we need to do is making + * sure the type pointer in the swig_cast_info struct is correct. + * + * First off, we lookup the cast->type name to see if it is already loaded. + * There are three cases to handle: + * 1) If the cast->type has already been loaded AND the type we are adding + * casting info to has not been loaded (it is in this module), THEN we + * replace the cast->type pointer with the type pointer that has already + * been loaded. + * 2) If BOTH types (the one we are adding casting info to, and the + * cast->type) are loaded, THEN the cast info has already been loaded by + * the previous module so we just ignore it. + * 3) Finally, if cast->type has not already been loaded, then we add that + * swig_cast_info to the linked list (because the cast->type) pointer will + * be correct. + * ----------------------------------------------------------------------------- */ + +#ifdef __cplusplus +extern "C" { +#if 0 +} /* c-mode */ +#endif +#endif + +#if 0 +#define SWIGRUNTIME_DEBUG +#endif + + +SWIGRUNTIME void +SWIG_InitializeModule(void *clientdata) { + size_t i; + swig_module_info *module_head, *iter; + int found, init; + + clientdata = clientdata; + + /* check to see if the circular list has been setup, if not, set it up */ + if (swig_module.next==0) { + /* Initialize the swig_module */ + swig_module.type_initial = swig_type_initial; + swig_module.cast_initial = swig_cast_initial; + swig_module.next = &swig_module; + init = 1; + } else { + init = 0; + } + + /* Try and load any already created modules */ + module_head = SWIG_GetModule(clientdata); + if (!module_head) { + /* This is the first module loaded for this interpreter */ + /* so set the swig module into the interpreter */ + SWIG_SetModule(clientdata, &swig_module); + module_head = &swig_module; + } else { + /* the interpreter has loaded a SWIG module, but has it loaded this one? */ + found=0; + iter=module_head; + do { + if (iter==&swig_module) { + found=1; + break; + } + iter=iter->next; + } while (iter!= module_head); + + /* if the is found in the list, then all is done and we may leave */ + if (found) return; + /* otherwise we must add out module into the list */ + swig_module.next = module_head->next; + module_head->next = &swig_module; + } + + /* When multiple interpeters are used, a module could have already been initialized in + a different interpreter, but not yet have a pointer in this interpreter. + In this case, we do not want to continue adding types... everything should be + set up already */ + if (init == 0) return; + + /* Now work on filling in swig_module.types */ +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: size %d\n", swig_module.size); +#endif + for (i = 0; i < swig_module.size; ++i) { + swig_type_info *type = 0; + swig_type_info *ret; + swig_cast_info *cast; + +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); +#endif + + /* if there is another module already loaded */ + if (swig_module.next != &swig_module) { + type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); + } + if (type) { + /* Overwrite clientdata field */ +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: found type %s\n", type->name); +#endif + if (swig_module.type_initial[i]->clientdata) { + type->clientdata = swig_module.type_initial[i]->clientdata; +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); +#endif + } + } else { + type = swig_module.type_initial[i]; + } + + /* Insert casting types */ + cast = swig_module.cast_initial[i]; + while (cast->type) { + /* Don't need to add information already in the list */ + ret = 0; +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); +#endif + if (swig_module.next != &swig_module) { + ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); +#ifdef SWIGRUNTIME_DEBUG + if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); +#endif + } + if (ret) { + if (type == swig_module.type_initial[i]) { +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: skip old type %s\n", ret->name); +#endif + cast->type = ret; + ret = 0; + } else { + /* Check for casting already in the list */ + swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); +#ifdef SWIGRUNTIME_DEBUG + if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); +#endif + if (!ocast) ret = 0; + } + } + + if (!ret) { +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); +#endif + if (type->cast) { + type->cast->prev = cast; + cast->next = type->cast; + } + type->cast = cast; + } + cast++; + } + /* Set entry in modules->types array equal to the type */ + swig_module.types[i] = type; + } + swig_module.types[i] = 0; + +#ifdef SWIGRUNTIME_DEBUG + printf("**** SWIG_InitializeModule: Cast List ******\n"); + for (i = 0; i < swig_module.size; ++i) { + int j = 0; + swig_cast_info *cast = swig_module.cast_initial[i]; + printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); + while (cast->type) { + printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); + cast++; + ++j; + } + printf("---- Total casts: %d\n",j); + } + printf("**** SWIG_InitializeModule: Cast List ******\n"); +#endif +} + +/* This function will propagate the clientdata field of type to +* any new swig_type_info structures that have been added into the list +* of equivalent types. It is like calling +* SWIG_TypeClientData(type, clientdata) a second time. +*/ +SWIGRUNTIME void +SWIG_PropagateClientData(void) { + size_t i; + swig_cast_info *equiv; + static int init_run = 0; + + if (init_run) return; + init_run = 1; + + for (i = 0; i < swig_module.size; i++) { + if (swig_module.types[i]->clientdata) { + equiv = swig_module.types[i]->cast; + while (equiv) { + if (!equiv->converter) { + if (equiv->type && !equiv->type->clientdata) + SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); + } + equiv = equiv->next; + } + } + } +} + +#ifdef __cplusplus +#if 0 +{ + /* c-mode */ +#endif +} +#endif + + + +#ifdef __cplusplus +#include + +extern "C" { +#endif + + /* Python-specific SWIG API */ +#define SWIG_newvarlink() SWIG_Python_newvarlink() +#define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr) +#define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants) + + /* ----------------------------------------------------------------------------- + * global variable support code. + * ----------------------------------------------------------------------------- */ + + typedef struct swig_globalvar { + char *name; /* Name of global variable */ + PyObject *(*get_attr)(void); /* Return the current value */ + int (*set_attr)(PyObject *); /* Set the value */ + struct swig_globalvar *next; + } swig_globalvar; + + typedef struct swig_varlinkobject { + PyObject_HEAD + swig_globalvar *vars; + } swig_varlinkobject; + + SWIGINTERN PyObject * + swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) { +#if PY_VERSION_HEX >= 0x03000000 + return PyUnicode_InternFromString(""); +#else + return PyString_FromString(""); +#endif + } + + SWIGINTERN PyObject * + swig_varlink_str(swig_varlinkobject *v) { +#if PY_VERSION_HEX >= 0x03000000 + PyObject *str = PyUnicode_InternFromString("("); + PyObject *tail; + PyObject *joined; + swig_globalvar *var; + for (var = v->vars; var; var=var->next) { + tail = PyUnicode_FromString(var->name); + joined = PyUnicode_Concat(str, tail); + Py_DecRef(str); + Py_DecRef(tail); + str = joined; + if (var->next) { + tail = PyUnicode_InternFromString(", "); + joined = PyUnicode_Concat(str, tail); + Py_DecRef(str); + Py_DecRef(tail); + str = joined; + } + } + tail = PyUnicode_InternFromString(")"); + joined = PyUnicode_Concat(str, tail); + Py_DecRef(str); + Py_DecRef(tail); + str = joined; +#else + PyObject *str = PyString_FromString("("); + swig_globalvar *var; + for (var = v->vars; var; var=var->next) { + PyString_ConcatAndDel(&str,PyString_FromString(var->name)); + if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", ")); + } + PyString_ConcatAndDel(&str,PyString_FromString(")")); +#endif + return str; + } + + SWIGINTERN int + swig_varlink_print(swig_varlinkobject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) { + char *tmp; + PyObject *str = swig_varlink_str(v); + fprintf(fp,"Swig global variables "); + fprintf(fp,"%s\n", tmp = SWIG_Python_str_AsChar(str)); + SWIG_Python_str_DelForPy3(tmp); + Py_DECREF(str); + return 0; + } + + SWIGINTERN void + swig_varlink_dealloc(swig_varlinkobject *v) { + swig_globalvar *var = v->vars; + while (var) { + swig_globalvar *n = var->next; + free(var->name); + free(var); + var = n; + } + } + + SWIGINTERN PyObject * + swig_varlink_getattr(swig_varlinkobject *v, char *n) { + PyObject *res = NULL; + swig_globalvar *var = v->vars; + while (var) { + if (strcmp(var->name,n) == 0) { + res = (*var->get_attr)(); + break; + } + var = var->next; + } + if (res == NULL && !PyErr_Occurred()) { + PyErr_SetString(PyExc_NameError,"Unknown C global variable"); + } + return res; + } + + SWIGINTERN int + swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) { + int res = 1; + swig_globalvar *var = v->vars; + while (var) { + if (strcmp(var->name,n) == 0) { + res = (*var->set_attr)(p); + break; + } + var = var->next; + } + if (res == 1 && !PyErr_Occurred()) { + PyErr_SetString(PyExc_NameError,"Unknown C global variable"); + } + return res; + } + + SWIGINTERN PyTypeObject* + swig_varlink_type(void) { + static char varlink__doc__[] = "Swig var link object"; + static PyTypeObject varlink_type; + static int type_init = 0; + if (!type_init) { + const PyTypeObject tmp + = { + /* PyObject header changed in Python 3 */ +#if PY_VERSION_HEX >= 0x03000000 + PyVarObject_HEAD_INIT(&PyType_Type, 0) +#else + PyObject_HEAD_INIT(NULL) + 0, /* Number of items in variable part (ob_size) */ +#endif + (char *)"swigvarlink", /* Type name (tp_name) */ + sizeof(swig_varlinkobject), /* Basic size (tp_basicsize) */ + 0, /* Itemsize (tp_itemsize) */ + (destructor) swig_varlink_dealloc, /* Deallocator (tp_dealloc) */ + (printfunc) swig_varlink_print, /* Print (tp_print) */ + (getattrfunc) swig_varlink_getattr, /* get attr (tp_getattr) */ + (setattrfunc) swig_varlink_setattr, /* Set attr (tp_setattr) */ + 0, /* tp_compare */ + (reprfunc) swig_varlink_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + (reprfunc) swig_varlink_str, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + 0, /* tp_flags */ + varlink__doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ +#if PY_VERSION_HEX >= 0x02020000 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */ +#endif +#if PY_VERSION_HEX >= 0x02030000 + 0, /* tp_del */ +#endif +#ifdef COUNT_ALLOCS + 0,0,0,0 /* tp_alloc -> tp_next */ +#endif + }; + varlink_type = tmp; + /* for Python 3 we already assigned ob_type in PyVarObject_HEAD_INIT() */ +#if PY_VERSION_HEX < 0x03000000 + varlink_type.ob_type = &PyType_Type; +#endif + type_init = 1; + } + return &varlink_type; + } + + /* Create a variable linking object for use later */ + SWIGINTERN PyObject * + SWIG_Python_newvarlink(void) { + swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type()); + if (result) { + result->vars = 0; + } + return ((PyObject*) result); + } + + SWIGINTERN void + SWIG_Python_addvarlink(PyObject *p, char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) { + swig_varlinkobject *v = (swig_varlinkobject *) p; + swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar)); + if (gv) { + size_t size = strlen(name)+1; + gv->name = (char *)malloc(size); + if (gv->name) { + strncpy(gv->name,name,size); + gv->get_attr = get_attr; + gv->set_attr = set_attr; + gv->next = v->vars; + } + } + v->vars = gv; + } + + SWIGINTERN PyObject * + SWIG_globals(void) { + static PyObject *_SWIG_globals = 0; + if (!_SWIG_globals) _SWIG_globals = SWIG_newvarlink(); + return _SWIG_globals; + } + + /* ----------------------------------------------------------------------------- + * constants/methods manipulation + * ----------------------------------------------------------------------------- */ + + /* Install Constants */ + SWIGINTERN void + SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { + PyObject *obj = 0; + size_t i; + 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); + break; + case SWIG_PY_BINARY: + obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype)); + break; + default: + obj = 0; + break; + } + if (obj) { + PyDict_SetItemString(d, constants[i].name, obj); + Py_DECREF(obj); + } + } + } + + /* -----------------------------------------------------------------------------*/ + /* Fix SwigMethods to carry the callback ptrs when needed */ + /* -----------------------------------------------------------------------------*/ + + SWIGINTERN void + SWIG_Python_FixMethods(PyMethodDef *methods, + swig_const_info *const_table, + swig_type_info **types, + swig_type_info **types_initial) { + size_t i; + for (i = 0; methods[i].ml_name; ++i) { + const char *c = methods[i].ml_doc; + if (c && (c = strstr(c, "swig_ptr: "))) { + int j; + swig_const_info *ci = 0; + const char *name = c + 10; + for (j = 0; const_table[j].type; ++j) { + if (strncmp(const_table[j].name, name, + strlen(const_table[j].name)) == 0) { + ci = &(const_table[j]); + break; + } + } + if (ci) { + void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0; + if (ptr) { + size_t shift = (ci->ptype) - types; + swig_type_info *ty = types_initial[shift]; + size_t ldoc = (c - methods[i].ml_doc); + size_t lptr = strlen(ty->name)+2*sizeof(void*)+2; + char *ndoc = (char*)malloc(ldoc + lptr + 10); + if (ndoc) { + char *buff = ndoc; + strncpy(buff, methods[i].ml_doc, ldoc); + buff += ldoc; + strncpy(buff, "swig_ptr: ", 10); + buff += 10; + SWIG_PackVoidPtr(buff, ptr, ty->name, lptr); + methods[i].ml_doc = ndoc; + } + } + } + } + } + } + +#ifdef __cplusplus +} +#endif + +/* -----------------------------------------------------------------------------* + * Partial Init method + * -----------------------------------------------------------------------------*/ + +#ifdef __cplusplus +extern "C" +#endif + +SWIGEXPORT +#if PY_VERSION_HEX >= 0x03000000 +PyObject* +#else +void +#endif +SWIG_init(void) { + PyObject *m, *d, *md; + PyTypeObject *builtin_type; +#if PY_VERSION_HEX >= 0x03000000 + static struct PyModuleDef SWIG_module = { + PyModuleDef_HEAD_INIT, + (char *) SWIG_name, + NULL, + -1, + SwigMethods, + NULL, + NULL, + NULL, + NULL + }; +#endif + +#if defined(SWIGPYTHON_BUILTIN) + PyTypeObject *builtin_pytype = 0; +#ifdef __cplusplus + std::vector builtin_bases; +#endif + swig_type_info *builtin_basetype = 0; + PyObject *tuple = NULL; + PyGetSetDescrObject *static_getset = NULL; + + int i; + + // 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); + assert(metatype); + Py_DECREF(metatype_args); + metatype->tp_setattro = (setattrofunc) &SwigPyObjectType_setattro; + assert(PyType_Ready(metatype) >= 0); + + SWIG_Python_builtin_imports(); + +#endif + + /* Fix SwigMethods to carry the callback ptrs when needed */ + SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial); + +#if PY_VERSION_HEX >= 0x03000000 + m = PyModule_Create(&SWIG_module); +#else + m = Py_InitModule((char *) SWIG_name, SwigMethods); +#endif + md = d = PyModule_GetDict(m); + + SWIG_InitializeModule(0); + +#ifdef SWIGPYTHON_BUILTIN + static SwigPyClientData SwigPyObject_clientdata = { + 0 + }; + SwigPyObject_stype = SWIG_MangledTypeQuery("_p_SwigPyObject"); + assert(SwigPyObject_stype); + SwigPyClientData *cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; + if (!cd) { + SwigPyObject_stype->clientdata = &SwigPyObject_clientdata; + SwigPyObject_clientdata.pytype = _PySwigObject_type(); + } + + // All objects have a 'this' attribute + static PyGetSetDef this_getset_def = { + const_cast("this"), pyswig_this_closure, NULL, NULL, NULL + }; + PyObject *this_descr = PyDescr_NewGetSet(SwigPyObject_type(), &this_getset_def); + + // 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 + }; + PyObject *thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def); + + PyObject *public_interface = PyList_New(0); + PyObject *public_symbol = 0; + 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); + for (i = 0; swig_const_table[i].name != 0; ++i) + pyswig_add_public_symbol(public_interface, swig_const_table[i].name); +#endif + + SWIG_InstallConstants(d,swig_const_table); + + + // type '::A' + builtin_pytype = (PyTypeObject*) &SwigPyBuiltin__A_type; + builtin_pytype->tp_dict = d = PyDict_New(); +#if PY_VERSION_HEX >= 0x03000000 + builtin_pytype->ob_base.ob_base.ob_type = metatype; +#else + builtin_pytype->ob_type = metatype; +#endif + builtin_pytype->tp_new = PyType_GenericNew; + pyswig_builtin_init_bases(builtin_pytype, builtin_bases); + builtin_bases.clear(); + PyDict_SetItemString(d, "this", this_descr); + PyDict_SetItemString(d, "thisown", thisown_descr); + if (PyType_Ready(builtin_pytype) < 0) { + PyErr_SetString(PyExc_TypeError, "Couldn't create type 'A'"); +#if PY_VERSION_HEX >= 0x03000000 + return NULL; +#else + return; +#endif + } + Py_INCREF(builtin_pytype); + PyModule_AddObject(m, "A", (PyObject*) builtin_pytype); + pyswig_add_public_symbol(public_interface, "A"); + d = md; + + // type '::B' + builtin_pytype = (PyTypeObject*) &SwigPyBuiltin__B_type; + builtin_pytype->tp_dict = d = PyDict_New(); +#if PY_VERSION_HEX >= 0x03000000 + builtin_pytype->ob_base.ob_base.ob_type = metatype; +#else + builtin_pytype->ob_type = metatype; +#endif + builtin_pytype->tp_new = PyType_GenericNew; + builtin_basetype = SWIG_MangledTypeQuery("_p_A"); + if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) { + builtin_bases.push_back(((SwigPyClientData*) builtin_basetype->clientdata)->pytype); + } + pyswig_builtin_init_bases(builtin_pytype, builtin_bases); + builtin_bases.clear(); + PyDict_SetItemString(d, "this", this_descr); + PyDict_SetItemString(d, "thisown", thisown_descr); + if (PyType_Ready(builtin_pytype) < 0) { + PyErr_SetString(PyExc_TypeError, "Couldn't create type 'B'"); +#if PY_VERSION_HEX >= 0x03000000 + return NULL; +#else + return; +#endif + } + Py_INCREF(builtin_pytype); + PyModule_AddObject(m, "B", (PyObject*) builtin_pytype); + pyswig_add_public_symbol(public_interface, "B"); + d = md; + + // type '::C' + builtin_pytype = (PyTypeObject*) &SwigPyBuiltin__C_type; + builtin_pytype->tp_dict = d = PyDict_New(); +#if PY_VERSION_HEX >= 0x03000000 + builtin_pytype->ob_base.ob_base.ob_type = metatype; +#else + builtin_pytype->ob_type = metatype; +#endif + builtin_pytype->tp_new = PyType_GenericNew; + builtin_basetype = SWIG_MangledTypeQuery("_p_B"); + if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) { + builtin_bases.push_back(((SwigPyClientData*) builtin_basetype->clientdata)->pytype); + } + pyswig_builtin_init_bases(builtin_pytype, builtin_bases); + builtin_bases.clear(); + PyDict_SetItemString(d, "this", this_descr); + PyDict_SetItemString(d, "thisown", thisown_descr); + if (PyType_Ready(builtin_pytype) < 0) { + PyErr_SetString(PyExc_TypeError, "Couldn't create type 'C'"); +#if PY_VERSION_HEX >= 0x03000000 + return NULL; +#else + return; +#endif + } + Py_INCREF(builtin_pytype); + PyModule_AddObject(m, "C", (PyObject*) builtin_pytype); + pyswig_add_public_symbol(public_interface, "C"); + d = md; + + // type '::D' + builtin_pytype = (PyTypeObject*) &SwigPyBuiltin__D_type; + builtin_pytype->tp_dict = d = PyDict_New(); +#if PY_VERSION_HEX >= 0x03000000 + builtin_pytype->ob_base.ob_base.ob_type = metatype; +#else + builtin_pytype->ob_type = metatype; +#endif + builtin_pytype->tp_new = PyType_GenericNew; + builtin_basetype = SWIG_MangledTypeQuery("_p_C"); + if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) { + builtin_bases.push_back(((SwigPyClientData*) builtin_basetype->clientdata)->pytype); + } + pyswig_builtin_init_bases(builtin_pytype, builtin_bases); + builtin_bases.clear(); + PyDict_SetItemString(d, "this", this_descr); + PyDict_SetItemString(d, "thisown", thisown_descr); + if (PyType_Ready(builtin_pytype) < 0) { + PyErr_SetString(PyExc_TypeError, "Couldn't create type 'D'"); +#if PY_VERSION_HEX >= 0x03000000 + return NULL; +#else + return; +#endif + } + Py_INCREF(builtin_pytype); + PyModule_AddObject(m, "D", (PyObject*) builtin_pytype); + pyswig_add_public_symbol(public_interface, "D"); + d = md; + + // type '::E' + builtin_pytype = (PyTypeObject*) &SwigPyBuiltin__E_type; + builtin_pytype->tp_dict = d = PyDict_New(); +#if PY_VERSION_HEX >= 0x03000000 + builtin_pytype->ob_base.ob_base.ob_type = metatype; +#else + builtin_pytype->ob_type = metatype; +#endif + builtin_pytype->tp_new = PyType_GenericNew; + builtin_basetype = SWIG_MangledTypeQuery("_p_D"); + if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) { + builtin_bases.push_back(((SwigPyClientData*) builtin_basetype->clientdata)->pytype); + } + pyswig_builtin_init_bases(builtin_pytype, builtin_bases); + builtin_bases.clear(); + PyDict_SetItemString(d, "this", this_descr); + PyDict_SetItemString(d, "thisown", thisown_descr); + if (PyType_Ready(builtin_pytype) < 0) { + PyErr_SetString(PyExc_TypeError, "Couldn't create type 'E'"); +#if PY_VERSION_HEX >= 0x03000000 + return NULL; +#else + return; +#endif + } + Py_INCREF(builtin_pytype); + PyModule_AddObject(m, "E", (PyObject*) builtin_pytype); + pyswig_add_public_symbol(public_interface, "E"); + d = md; + + // type '::F' + builtin_pytype = (PyTypeObject*) &SwigPyBuiltin__F_type; + builtin_pytype->tp_dict = d = PyDict_New(); +#if PY_VERSION_HEX >= 0x03000000 + builtin_pytype->ob_base.ob_base.ob_type = metatype; +#else + builtin_pytype->ob_type = metatype; +#endif + builtin_pytype->tp_new = PyType_GenericNew; + builtin_basetype = SWIG_MangledTypeQuery("_p_E"); + if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) { + builtin_bases.push_back(((SwigPyClientData*) builtin_basetype->clientdata)->pytype); + } + pyswig_builtin_init_bases(builtin_pytype, builtin_bases); + builtin_bases.clear(); + PyDict_SetItemString(d, "this", this_descr); + PyDict_SetItemString(d, "thisown", thisown_descr); + if (PyType_Ready(builtin_pytype) < 0) { + PyErr_SetString(PyExc_TypeError, "Couldn't create type 'F'"); +#if PY_VERSION_HEX >= 0x03000000 + return NULL; +#else + return; +#endif + } + Py_INCREF(builtin_pytype); + PyModule_AddObject(m, "F", (PyObject*) builtin_pytype); + pyswig_add_public_symbol(public_interface, "F"); + d = md; + + // type '::G' + builtin_pytype = (PyTypeObject*) &SwigPyBuiltin__G_type; + builtin_pytype->tp_dict = d = PyDict_New(); +#if PY_VERSION_HEX >= 0x03000000 + builtin_pytype->ob_base.ob_base.ob_type = metatype; +#else + builtin_pytype->ob_type = metatype; +#endif + builtin_pytype->tp_new = PyType_GenericNew; + builtin_basetype = SWIG_MangledTypeQuery("_p_F"); + if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) { + builtin_bases.push_back(((SwigPyClientData*) builtin_basetype->clientdata)->pytype); + } + pyswig_builtin_init_bases(builtin_pytype, builtin_bases); + builtin_bases.clear(); + PyDict_SetItemString(d, "this", this_descr); + PyDict_SetItemString(d, "thisown", thisown_descr); + if (PyType_Ready(builtin_pytype) < 0) { + PyErr_SetString(PyExc_TypeError, "Couldn't create type 'G'"); +#if PY_VERSION_HEX >= 0x03000000 + return NULL; +#else + return; +#endif + } + Py_INCREF(builtin_pytype); + PyModule_AddObject(m, "G", (PyObject*) builtin_pytype); + pyswig_add_public_symbol(public_interface, "G"); + d = md; + + // type '::H' + builtin_pytype = (PyTypeObject*) &SwigPyBuiltin__H_type; + builtin_pytype->tp_dict = d = PyDict_New(); +#if PY_VERSION_HEX >= 0x03000000 + builtin_pytype->ob_base.ob_base.ob_type = metatype; +#else + builtin_pytype->ob_type = metatype; +#endif + builtin_pytype->tp_new = PyType_GenericNew; + builtin_basetype = SWIG_MangledTypeQuery("_p_G"); + if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) { + builtin_bases.push_back(((SwigPyClientData*) builtin_basetype->clientdata)->pytype); + } + pyswig_builtin_init_bases(builtin_pytype, builtin_bases); + builtin_bases.clear(); + PyDict_SetItemString(d, "this", this_descr); + PyDict_SetItemString(d, "thisown", thisown_descr); + if (PyType_Ready(builtin_pytype) < 0) { + PyErr_SetString(PyExc_TypeError, "Couldn't create type 'H'"); +#if PY_VERSION_HEX >= 0x03000000 + return NULL; +#else + return; +#endif + } + Py_INCREF(builtin_pytype); + PyModule_AddObject(m, "H", (PyObject*) builtin_pytype); + pyswig_add_public_symbol(public_interface, "H"); + d = md; +#if PY_VERSION_HEX >= 0x03000000 + return m; +#else + return; +#endif +} + diff --git a/Examples/python/performance/hierarchy_operator/runme.py b/Examples/python/performance/hierarchy_operator/runme.py new file mode 100644 index 000000000..7e50aff16 --- /dev/null +++ b/Examples/python/performance/hierarchy_operator/runme.py @@ -0,0 +1,17 @@ +#!/usr/bin/env + +import sys +from subprocess import * + +proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + +proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + +proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + diff --git a/Examples/python/performance/hierarchy_operator/runme_baseline.py b/Examples/python/performance/hierarchy_operator/runme_baseline.py new file mode 100644 index 000000000..38b4814de --- /dev/null +++ b/Examples/python/performance/hierarchy_operator/runme_baseline.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_baseline +import time + +t1 = time.clock() +x = Simple_baseline.H() +for i in range(10000000) : + x += i +t2 = time.clock() +print "Simple_baseline took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/hierarchy_operator/runme_builtin.py b/Examples/python/performance/hierarchy_operator/runme_builtin.py new file mode 100644 index 000000000..2ce0459a8 --- /dev/null +++ b/Examples/python/performance/hierarchy_operator/runme_builtin.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_builtin +import time + +t1 = time.clock() +x = Simple_builtin.H() +for i in range(10000000) : + x += i +t2 = time.clock() +print "Simple_builtin took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/hierarchy_operator/runme_optimized.py b/Examples/python/performance/hierarchy_operator/runme_optimized.py new file mode 100644 index 000000000..7d849051b --- /dev/null +++ b/Examples/python/performance/hierarchy_operator/runme_optimized.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_optimized +import time + +t1 = time.clock() +x = Simple_optimized.H() +for i in range(10000000) : + x += i +t2 = time.clock() +print "Simple_optimized took %f seconds" % (t2 - t1) From 3852ca8f449053a65e7edefaa215ce1fa74029cb Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Thu, 10 Feb 2011 05:17:31 +0000 Subject: [PATCH 25/56] Accidentally imported build products. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12450 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/python/performance/Makefile | 2 +- .../{deep_hierarchy => hierarchy}/Makefile | 0 .../{deep_hierarchy => hierarchy}/Simple.i | 0 .../Simple_baseline.py | 0 .../Simple_builtin.py | 0 .../Simple_optimized.py | 0 .../{deep_hierarchy => hierarchy}/runme.py | 0 .../runme_baseline.py | 0 .../runme_builtin.py | 0 .../runme_optimized.py | 0 .../hierarchy_operator/Simple_baseline.py | 206 - .../hierarchy_operator/Simple_builtin.py | 88 - .../hierarchy_operator/Simple_optimized.py | 157 - .../hierarchy_operator/Simple_wrap.cxx | 6456 ----------------- 14 files changed, 1 insertion(+), 6908 deletions(-) rename Examples/python/performance/{deep_hierarchy => hierarchy}/Makefile (100%) rename Examples/python/performance/{deep_hierarchy => hierarchy}/Simple.i (100%) rename Examples/python/performance/{deep_hierarchy => hierarchy}/Simple_baseline.py (100%) rename Examples/python/performance/{deep_hierarchy => hierarchy}/Simple_builtin.py (100%) rename Examples/python/performance/{deep_hierarchy => hierarchy}/Simple_optimized.py (100%) rename Examples/python/performance/{deep_hierarchy => hierarchy}/runme.py (100%) rename Examples/python/performance/{deep_hierarchy => hierarchy}/runme_baseline.py (100%) rename Examples/python/performance/{deep_hierarchy => hierarchy}/runme_builtin.py (100%) rename Examples/python/performance/{deep_hierarchy => hierarchy}/runme_optimized.py (100%) delete mode 100644 Examples/python/performance/hierarchy_operator/Simple_baseline.py delete mode 100644 Examples/python/performance/hierarchy_operator/Simple_builtin.py delete mode 100644 Examples/python/performance/hierarchy_operator/Simple_optimized.py delete mode 100644 Examples/python/performance/hierarchy_operator/Simple_wrap.cxx diff --git a/Examples/python/performance/Makefile b/Examples/python/performance/Makefile index 0a2dabaa9..6f6db22b5 100644 --- a/Examples/python/performance/Makefile +++ b/Examples/python/performance/Makefile @@ -10,7 +10,7 @@ else PYSCRIPT = runme3.py endif -SUBDIRS := constructor func deep_hierarchy +SUBDIRS := constructor func hierarchy operator default : all diff --git a/Examples/python/performance/deep_hierarchy/Makefile b/Examples/python/performance/hierarchy/Makefile similarity index 100% rename from Examples/python/performance/deep_hierarchy/Makefile rename to Examples/python/performance/hierarchy/Makefile diff --git a/Examples/python/performance/deep_hierarchy/Simple.i b/Examples/python/performance/hierarchy/Simple.i similarity index 100% rename from Examples/python/performance/deep_hierarchy/Simple.i rename to Examples/python/performance/hierarchy/Simple.i diff --git a/Examples/python/performance/deep_hierarchy/Simple_baseline.py b/Examples/python/performance/hierarchy/Simple_baseline.py similarity index 100% rename from Examples/python/performance/deep_hierarchy/Simple_baseline.py rename to Examples/python/performance/hierarchy/Simple_baseline.py diff --git a/Examples/python/performance/deep_hierarchy/Simple_builtin.py b/Examples/python/performance/hierarchy/Simple_builtin.py similarity index 100% rename from Examples/python/performance/deep_hierarchy/Simple_builtin.py rename to Examples/python/performance/hierarchy/Simple_builtin.py diff --git a/Examples/python/performance/deep_hierarchy/Simple_optimized.py b/Examples/python/performance/hierarchy/Simple_optimized.py similarity index 100% rename from Examples/python/performance/deep_hierarchy/Simple_optimized.py rename to Examples/python/performance/hierarchy/Simple_optimized.py diff --git a/Examples/python/performance/deep_hierarchy/runme.py b/Examples/python/performance/hierarchy/runme.py similarity index 100% rename from Examples/python/performance/deep_hierarchy/runme.py rename to Examples/python/performance/hierarchy/runme.py diff --git a/Examples/python/performance/deep_hierarchy/runme_baseline.py b/Examples/python/performance/hierarchy/runme_baseline.py similarity index 100% rename from Examples/python/performance/deep_hierarchy/runme_baseline.py rename to Examples/python/performance/hierarchy/runme_baseline.py diff --git a/Examples/python/performance/deep_hierarchy/runme_builtin.py b/Examples/python/performance/hierarchy/runme_builtin.py similarity index 100% rename from Examples/python/performance/deep_hierarchy/runme_builtin.py rename to Examples/python/performance/hierarchy/runme_builtin.py diff --git a/Examples/python/performance/deep_hierarchy/runme_optimized.py b/Examples/python/performance/hierarchy/runme_optimized.py similarity index 100% rename from Examples/python/performance/deep_hierarchy/runme_optimized.py rename to Examples/python/performance/hierarchy/runme_optimized.py diff --git a/Examples/python/performance/hierarchy_operator/Simple_baseline.py b/Examples/python/performance/hierarchy_operator/Simple_baseline.py deleted file mode 100644 index ab5dc8594..000000000 --- a/Examples/python/performance/hierarchy_operator/Simple_baseline.py +++ /dev/null @@ -1,206 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. -# This file is compatible with both classic and new-style classes. - -from sys import version_info -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_baseline', [dirname(__file__)]) - except ImportError: - import _Simple_baseline - return _Simple_baseline - if fp is not None: - try: - _mod = imp.load_module('_Simple_baseline', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_baseline = swig_import_helper() - del swig_import_helper -else: - import _Simple_baseline -del version_info -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -class A(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, A, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, A, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_A() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_A - __del__ = lambda self : None; - def func(self): return _Simple_baseline.A_func(self) - def __iadd__(self, *args): return _Simple_baseline.A___iadd__(self, *args) -A_swigregister = _Simple_baseline.A_swigregister -A_swigregister(A) - -class B(A): - __swig_setmethods__ = {} - for _s in [A]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, B, name, value) - __swig_getmethods__ = {} - for _s in [A]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, B, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_B() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_B - __del__ = lambda self : None; -B_swigregister = _Simple_baseline.B_swigregister -B_swigregister(B) - -class C(B): - __swig_setmethods__ = {} - for _s in [B]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, C, name, value) - __swig_getmethods__ = {} - for _s in [B]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, C, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_C() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_C - __del__ = lambda self : None; -C_swigregister = _Simple_baseline.C_swigregister -C_swigregister(C) - -class D(C): - __swig_setmethods__ = {} - for _s in [C]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, D, name, value) - __swig_getmethods__ = {} - for _s in [C]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, D, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_D() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_D - __del__ = lambda self : None; -D_swigregister = _Simple_baseline.D_swigregister -D_swigregister(D) - -class E(D): - __swig_setmethods__ = {} - for _s in [D]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, E, name, value) - __swig_getmethods__ = {} - for _s in [D]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, E, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_E() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_E - __del__ = lambda self : None; -E_swigregister = _Simple_baseline.E_swigregister -E_swigregister(E) - -class F(E): - __swig_setmethods__ = {} - for _s in [E]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, F, name, value) - __swig_getmethods__ = {} - for _s in [E]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, F, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_F() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_F - __del__ = lambda self : None; -F_swigregister = _Simple_baseline.F_swigregister -F_swigregister(F) - -class G(F): - __swig_setmethods__ = {} - for _s in [F]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, G, name, value) - __swig_getmethods__ = {} - for _s in [F]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, G, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_G() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_G - __del__ = lambda self : None; -G_swigregister = _Simple_baseline.G_swigregister -G_swigregister(G) - -class H(G): - __swig_setmethods__ = {} - for _s in [G]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, H, name, value) - __swig_getmethods__ = {} - for _s in [G]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, H, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_H() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_H - __del__ = lambda self : None; -H_swigregister = _Simple_baseline.H_swigregister -H_swigregister(H) - - - diff --git a/Examples/python/performance/hierarchy_operator/Simple_builtin.py b/Examples/python/performance/hierarchy_operator/Simple_builtin.py deleted file mode 100644 index 6572f16bc..000000000 --- a/Examples/python/performance/hierarchy_operator/Simple_builtin.py +++ /dev/null @@ -1,88 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. - -from sys import version_info -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_builtin', [dirname(__file__)]) - except ImportError: - import _Simple_builtin - return _Simple_builtin - if fp is not None: - try: - _mod = imp.load_module('_Simple_builtin', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_builtin = swig_import_helper() - del swig_import_helper -else: - import _Simple_builtin -del version_info -from _Simple_builtin import * -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -def _swig_setattr_nondynamic_method(set): - def set_attr(self,name,value): - if (name == "thisown"): return self.this.own(value) - if hasattr(self,name) or (name == "this"): - set(self,name,value) - else: - raise AttributeError("You cannot add attributes to %s" % self) - return set_attr - - - - - - - - - - - - diff --git a/Examples/python/performance/hierarchy_operator/Simple_optimized.py b/Examples/python/performance/hierarchy_operator/Simple_optimized.py deleted file mode 100644 index 0e824ea40..000000000 --- a/Examples/python/performance/hierarchy_operator/Simple_optimized.py +++ /dev/null @@ -1,157 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. - -from sys import version_info -if version_info >= (3,0,0): - new_instancemethod = lambda func, inst, cls: _Simple_optimized.SWIG_PyInstanceMethod_New(func) -else: - from new import instancemethod as new_instancemethod -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_optimized', [dirname(__file__)]) - except ImportError: - import _Simple_optimized - return _Simple_optimized - if fp is not None: - try: - _mod = imp.load_module('_Simple_optimized', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_optimized = swig_import_helper() - del swig_import_helper -else: - import _Simple_optimized -del version_info -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -def _swig_setattr_nondynamic_method(set): - def set_attr(self,name,value): - if (name == "thisown"): return self.this.own(value) - if hasattr(self,name) or (name == "this"): - set(self,name,value) - else: - raise AttributeError("You cannot add attributes to %s" % self) - return set_attr - - -class A(object): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.A_swiginit(self,_Simple_optimized.new_A()) - __swig_destroy__ = _Simple_optimized.delete_A -A.func = new_instancemethod(_Simple_optimized.A_func,None,A) -A.__iadd__ = new_instancemethod(_Simple_optimized.A___iadd__,None,A) -A_swigregister = _Simple_optimized.A_swigregister -A_swigregister(A) - -class B(A): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.B_swiginit(self,_Simple_optimized.new_B()) - __swig_destroy__ = _Simple_optimized.delete_B -B_swigregister = _Simple_optimized.B_swigregister -B_swigregister(B) - -class C(B): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.C_swiginit(self,_Simple_optimized.new_C()) - __swig_destroy__ = _Simple_optimized.delete_C -C_swigregister = _Simple_optimized.C_swigregister -C_swigregister(C) - -class D(C): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.D_swiginit(self,_Simple_optimized.new_D()) - __swig_destroy__ = _Simple_optimized.delete_D -D_swigregister = _Simple_optimized.D_swigregister -D_swigregister(D) - -class E(D): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.E_swiginit(self,_Simple_optimized.new_E()) - __swig_destroy__ = _Simple_optimized.delete_E -E_swigregister = _Simple_optimized.E_swigregister -E_swigregister(E) - -class F(E): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.F_swiginit(self,_Simple_optimized.new_F()) - __swig_destroy__ = _Simple_optimized.delete_F -F_swigregister = _Simple_optimized.F_swigregister -F_swigregister(F) - -class G(F): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.G_swiginit(self,_Simple_optimized.new_G()) - __swig_destroy__ = _Simple_optimized.delete_G -G_swigregister = _Simple_optimized.G_swigregister -G_swigregister(G) - -class H(G): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.H_swiginit(self,_Simple_optimized.new_H()) - __swig_destroy__ = _Simple_optimized.delete_H -H_swigregister = _Simple_optimized.H_swigregister -H_swigregister(H) - - - diff --git a/Examples/python/performance/hierarchy_operator/Simple_wrap.cxx b/Examples/python/performance/hierarchy_operator/Simple_wrap.cxx deleted file mode 100644 index 0b1c79bed..000000000 --- a/Examples/python/performance/hierarchy_operator/Simple_wrap.cxx +++ /dev/null @@ -1,6456 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 2.0.2 - * - * This file is not intended to be easily readable and contains a number of - * coding conventions designed to improve portability and efficiency. Do not make - * changes to this file unless you know what you are doing--modify the SWIG - * interface file instead. - * ----------------------------------------------------------------------------- */ - -#define SWIGPYTHON -#define SWIG_PYTHON_NO_BUILD_NONE -#define SWIG_PYTHON_DIRECTOR_NO_VTABLE -#define SWIGPYTHON_BUILTIN - - -#ifdef __cplusplus -/* SwigValueWrapper is described in swig.swg */ -template class SwigValueWrapper { - struct SwigMovePointer { - T *ptr; - SwigMovePointer(T *p) : ptr(p) { } - ~SwigMovePointer() { delete ptr; } - SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; } - } pointer; - SwigValueWrapper& operator=(const SwigValueWrapper& rhs); - SwigValueWrapper(const SwigValueWrapper& rhs); -public: - SwigValueWrapper() : pointer(0) { } - SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; } - operator T&() const { return *pointer.ptr; } - T *operator&() { return pointer.ptr; } -}; - -template T SwigValueInit() { - return T(); -} -#endif - -/* ----------------------------------------------------------------------------- - * This section contains generic SWIG labels for method/variable - * declarations/attributes, and other compiler dependent labels. - * ----------------------------------------------------------------------------- */ - -/* template workaround for compilers that cannot correctly implement the C++ standard */ -#ifndef SWIGTEMPLATEDISAMBIGUATOR -# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) -# define SWIGTEMPLATEDISAMBIGUATOR template -# elif defined(__HP_aCC) -/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ -/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ -# define SWIGTEMPLATEDISAMBIGUATOR template -# else -# define SWIGTEMPLATEDISAMBIGUATOR -# endif -#endif - -/* inline attribute */ -#ifndef SWIGINLINE -# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) -# define SWIGINLINE inline -# else -# define SWIGINLINE -# endif -#endif - -/* attribute recognised by some compilers to avoid 'unused' warnings */ -#ifndef SWIGUNUSED -# if defined(__GNUC__) -# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -# define SWIGUNUSED __attribute__ ((__unused__)) -# else -# define SWIGUNUSED -# endif -# elif defined(__ICC) -# define SWIGUNUSED __attribute__ ((__unused__)) -# else -# define SWIGUNUSED -# endif -#endif - -#ifndef SWIG_MSC_UNSUPPRESS_4505 -# if defined(_MSC_VER) -# pragma warning(disable : 4505) /* unreferenced local function has been removed */ -# endif -#endif - -#ifndef SWIGUNUSEDPARM -# ifdef __cplusplus -# define SWIGUNUSEDPARM(p) -# else -# define SWIGUNUSEDPARM(p) p SWIGUNUSED -# endif -#endif - -/* internal SWIG method */ -#ifndef SWIGINTERN -# define SWIGINTERN static SWIGUNUSED -#endif - -/* internal inline SWIG method */ -#ifndef SWIGINTERNINLINE -# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE -#endif - -/* exporting methods */ -#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) -# ifndef GCC_HASCLASSVISIBILITY -# define GCC_HASCLASSVISIBILITY -# endif -#endif - -#ifndef SWIGEXPORT -# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# if defined(STATIC_LINKED) -# define SWIGEXPORT -# else -# define SWIGEXPORT __declspec(dllexport) -# endif -# else -# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) -# define SWIGEXPORT __attribute__ ((visibility("default"))) -# else -# define SWIGEXPORT -# endif -# endif -#endif - -/* calling conventions for Windows */ -#ifndef SWIGSTDCALL -# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# define SWIGSTDCALL __stdcall -# else -# define SWIGSTDCALL -# endif -#endif - -/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ -#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) -# define _CRT_SECURE_NO_DEPRECATE -#endif - -/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ -#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) -# define _SCL_SECURE_NO_DEPRECATE -#endif - - - -/* Python.h has to appear first */ -#include - -/* ----------------------------------------------------------------------------- - * swigrun.swg - * - * This file contains generic C API SWIG runtime support for pointer - * type checking. - * ----------------------------------------------------------------------------- */ - -/* This should only be incremented when either the layout of swig_type_info changes, - or for whatever reason, the runtime changes incompatibly */ -#define SWIG_RUNTIME_VERSION "4" - -/* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ -#ifdef SWIG_TYPE_TABLE -# define SWIG_QUOTE_STRING(x) #x -# define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) -# define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) -#else -# define SWIG_TYPE_TABLE_NAME -#endif - -/* - You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for - creating a static or dynamic library from the SWIG runtime code. - In 99.9% of the cases, SWIG just needs to declare them as 'static'. - - But only do this if strictly necessary, ie, if you have problems - with your compiler or suchlike. -*/ - -#ifndef SWIGRUNTIME -# define SWIGRUNTIME SWIGINTERN -#endif - -#ifndef SWIGRUNTIMEINLINE -# define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE -#endif - -/* Generic buffer size */ -#ifndef SWIG_BUFFER_SIZE -# define SWIG_BUFFER_SIZE 1024 -#endif - -/* Flags for pointer conversions */ -#define SWIG_POINTER_DISOWN 0x1 -#define SWIG_CAST_NEW_MEMORY 0x2 - -/* Flags for new pointer objects */ -#define SWIG_POINTER_OWN 0x1 - - -/* - Flags/methods for returning states. - - The SWIG conversion methods, as ConvertPtr, return an integer - that tells if the conversion was successful or not. And if not, - an error code can be returned (see swigerrors.swg for the codes). - - Use the following macros/flags to set or process the returning - states. - - In old versions of SWIG, code such as the following was usually written: - - if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) { - // success code - } else { - //fail code - } - - Now you can be more explicit: - - int res = SWIG_ConvertPtr(obj,vptr,ty.flags); - if (SWIG_IsOK(res)) { - // success code - } else { - // fail code - } - - which is the same really, but now you can also do - - Type *ptr; - int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags); - if (SWIG_IsOK(res)) { - // success code - if (SWIG_IsNewObj(res) { - ... - delete *ptr; - } else { - ... - } - } else { - // fail code - } - - I.e., now SWIG_ConvertPtr can return new objects and you can - identify the case and take care of the deallocation. Of course that - also requires SWIG_ConvertPtr to return new result values, such as - - int SWIG_ConvertPtr(obj, ptr,...) { - if () { - if () { - *ptr = ; - return SWIG_NEWOBJ; - } else { - *ptr = ; - return SWIG_OLDOBJ; - } - } else { - return SWIG_BADOBJ; - } - } - - Of course, returning the plain '0(success)/-1(fail)' still works, but you can be - more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the - SWIG errors code. - - Finally, if the SWIG_CASTRANK_MODE is enabled, the result code - allows to return the 'cast rank', for example, if you have this - - int food(double) - int fooi(int); - - and you call - - food(1) // cast rank '1' (1 -> 1.0) - fooi(1) // cast rank '0' - - just use the SWIG_AddCast()/SWIG_CheckState() -*/ - -#define SWIG_OK (0) -#define SWIG_ERROR (-1) -#define SWIG_IsOK(r) (r >= 0) -#define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError) - -/* The CastRankLimit says how many bits are used for the cast rank */ -#define SWIG_CASTRANKLIMIT (1 << 8) -/* The NewMask denotes the object was created (using new/malloc) */ -#define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1) -/* The TmpMask is for in/out typemaps that use temporal objects */ -#define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1) -/* Simple returning values */ -#define SWIG_BADOBJ (SWIG_ERROR) -#define SWIG_OLDOBJ (SWIG_OK) -#define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK) -#define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK) -/* Check, add and del mask methods */ -#define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r) -#define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r) -#define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK)) -#define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r) -#define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r) -#define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK)) - -/* Cast-Rank Mode */ -#if defined(SWIG_CASTRANK_MODE) -# ifndef SWIG_TypeRank -# define SWIG_TypeRank unsigned long -# endif -# ifndef SWIG_MAXCASTRANK /* Default cast allowed */ -# define SWIG_MAXCASTRANK (2) -# endif -# define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) -# define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) -SWIGINTERNINLINE int SWIG_AddCast(int r) { - return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; -} -SWIGINTERNINLINE int SWIG_CheckState(int r) { - return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; -} -#else /* no cast-rank mode */ -# define SWIG_AddCast -# define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) -#endif - - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void *(*swig_converter_func)(void *, int *); -typedef struct swig_type_info *(*swig_dycast_func)(void **); - -/* Structure to store information on one type */ -typedef struct swig_type_info { - const char *name; /* mangled name of this type */ - const char *str; /* human readable name of this type */ - swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ - struct swig_cast_info *cast; /* linked list of types that can cast into this type */ - void *clientdata; /* language specific type data */ - int owndata; /* flag if the structure owns the clientdata */ -} swig_type_info; - -/* Structure to store a type and conversion function used for casting */ -typedef struct swig_cast_info { - swig_type_info *type; /* pointer to type that is equivalent to this type */ - swig_converter_func converter; /* function to cast the void pointers */ - struct swig_cast_info *next; /* pointer to next cast in linked list */ - struct swig_cast_info *prev; /* pointer to the previous cast */ -} swig_cast_info; - -/* Structure used to store module information - * Each module generates one structure like this, and the runtime collects - * all of these structures and stores them in a circularly linked list.*/ -typedef struct swig_module_info { - swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ - size_t size; /* Number of types in this module */ - struct swig_module_info *next; /* Pointer to next element in circularly linked list */ - swig_type_info **type_initial; /* Array of initially generated type structures */ - swig_cast_info **cast_initial; /* Array of initially generated casting structures */ - void *clientdata; /* Language specific module data */ -} swig_module_info; - -/* - Compare two type names skipping the space characters, therefore - "char*" == "char *" and "Class" == "Class", etc. - - Return 0 when the two name types are equivalent, as in - strncmp, but skipping ' '. -*/ -SWIGRUNTIME int -SWIG_TypeNameComp(const char *f1, const char *l1, - const char *f2, const char *l2) { - for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { - while ((*f1 == ' ') && (f1 != l1)) ++f1; - while ((*f2 == ' ') && (f2 != l2)) ++f2; - if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1; - } - return (int)((l1 - f1) - (l2 - f2)); -} - -/* - Check type equivalence in a name list like ||... - Return 0 if not equal, 1 if equal -*/ -SWIGRUNTIME int -SWIG_TypeEquiv(const char *nb, const char *tb) { - int equiv = 0; - const char* te = tb + strlen(tb); - const char* ne = nb; - while (!equiv && *ne) { - for (nb = ne; *ne; ++ne) { - if (*ne == '|') break; - } - equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0; - if (*ne) ++ne; - } - return equiv; -} - -/* - Check type equivalence in a name list like ||... - Return 0 if equal, -1 if nb < tb, 1 if nb > tb -*/ -SWIGRUNTIME int -SWIG_TypeCompare(const char *nb, const char *tb) { - int equiv = 0; - const char* te = tb + strlen(tb); - const char* ne = nb; - while (!equiv && *ne) { - for (nb = ne; *ne; ++ne) { - if (*ne == '|') break; - } - equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0; - if (*ne) ++ne; - } - return equiv; -} - - -/* - Check the typename -*/ -SWIGRUNTIME swig_cast_info * -SWIG_TypeCheck(const char *c, swig_type_info *ty) { - if (ty) { - swig_cast_info *iter = ty->cast; - while (iter) { - if (strcmp(iter->type->name, c) == 0) { - if (iter == ty->cast) - return iter; - /* Move iter to the top of the linked list */ - iter->prev->next = iter->next; - if (iter->next) - iter->next->prev = iter->prev; - iter->next = ty->cast; - iter->prev = 0; - if (ty->cast) ty->cast->prev = iter; - ty->cast = iter; - return iter; - } - iter = iter->next; - } - } - return 0; -} - -/* - Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison -*/ -SWIGRUNTIME swig_cast_info * -SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *ty) { - if (ty) { - swig_cast_info *iter = ty->cast; - while (iter) { - if (iter->type == from) { - if (iter == ty->cast) - return iter; - /* Move iter to the top of the linked list */ - iter->prev->next = iter->next; - if (iter->next) - iter->next->prev = iter->prev; - iter->next = ty->cast; - iter->prev = 0; - if (ty->cast) ty->cast->prev = iter; - ty->cast = iter; - return iter; - } - iter = iter->next; - } - } - return 0; -} - -/* - Cast a pointer up an inheritance hierarchy -*/ -SWIGRUNTIMEINLINE void * -SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { - return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); -} - -/* - Dynamic pointer casting. Down an inheritance hierarchy -*/ -SWIGRUNTIME swig_type_info * -SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { - swig_type_info *lastty = ty; - if (!ty || !ty->dcast) return ty; - while (ty && (ty->dcast)) { - ty = (*ty->dcast)(ptr); - if (ty) lastty = ty; - } - return lastty; -} - -/* - Return the name associated with this type -*/ -SWIGRUNTIMEINLINE const char * -SWIG_TypeName(const swig_type_info *ty) { - return ty->name; -} - -/* - Return the pretty name associated with this type, - that is an unmangled type name in a form presentable to the user. -*/ -SWIGRUNTIME const char * -SWIG_TypePrettyName(const swig_type_info *type) { - /* The "str" field contains the equivalent pretty names of the - type, separated by vertical-bar characters. We choose - to print the last name, as it is often (?) the most - specific. */ - if (!type) return NULL; - if (type->str != NULL) { - const char *last_name = type->str; - const char *s; - for (s = type->str; *s; s++) - if (*s == '|') last_name = s+1; - return last_name; - } - else - return type->name; -} - -/* - Set the clientdata field for a type -*/ -SWIGRUNTIME void -SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { - swig_cast_info *cast = ti->cast; - /* if (ti->clientdata == clientdata) return; */ - ti->clientdata = clientdata; - - while (cast) { - if (!cast->converter) { - swig_type_info *tc = cast->type; - if (!tc->clientdata) { - SWIG_TypeClientData(tc, clientdata); - } - } - cast = cast->next; - } -} -SWIGRUNTIME void -SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { - SWIG_TypeClientData(ti, clientdata); - ti->owndata = 1; -} - -/* - Search for a swig_type_info structure only by mangled name - Search is a O(log #types) - - We start searching at module start, and finish searching when start == end. - Note: if start == end at the beginning of the function, we go all the way around - the circular list. -*/ -SWIGRUNTIME swig_type_info * -SWIG_MangledTypeQueryModule(swig_module_info *start, - swig_module_info *end, - const char *name) { - swig_module_info *iter = start; - do { - if (iter->size) { - register size_t l = 0; - register size_t r = iter->size - 1; - do { - /* since l+r >= 0, we can (>> 1) instead (/ 2) */ - register size_t i = (l + r) >> 1; - const char *iname = iter->types[i]->name; - if (iname) { - register int compare = strcmp(name, iname); - if (compare == 0) { - return iter->types[i]; - } else if (compare < 0) { - if (i) { - r = i - 1; - } else { - break; - } - } else if (compare > 0) { - l = i + 1; - } - } else { - break; /* should never happen */ - } - } while (l <= r); - } - iter = iter->next; - } while (iter != end); - return 0; -} - -/* - Search for a swig_type_info structure for either a mangled name or a human readable name. - It first searches the mangled names of the types, which is a O(log #types) - If a type is not found it then searches the human readable names, which is O(#types). - - We start searching at module start, and finish searching when start == end. - Note: if start == end at the beginning of the function, we go all the way around - the circular list. -*/ -SWIGRUNTIME swig_type_info * -SWIG_TypeQueryModule(swig_module_info *start, - swig_module_info *end, - const char *name) { - /* STEP 1: Search the name field using binary search */ - swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); - if (ret) { - return ret; - } else { - /* STEP 2: If the type hasn't been found, do a complete search - of the str field (the human readable name) */ - swig_module_info *iter = start; - do { - register size_t i = 0; - for (; i < iter->size; ++i) { - if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) - return iter->types[i]; - } - iter = iter->next; - } while (iter != end); - } - - /* neither found a match */ - return 0; -} - -/* - Pack binary data into a string -*/ -SWIGRUNTIME char * -SWIG_PackData(char *c, void *ptr, size_t sz) { - static const char hex[17] = "0123456789abcdef"; - register const unsigned char *u = (unsigned char *) ptr; - register const unsigned char *eu = u + sz; - for (; u != eu; ++u) { - register unsigned char uu = *u; - *(c++) = hex[(uu & 0xf0) >> 4]; - *(c++) = hex[uu & 0xf]; - } - return c; -} - -/* - Unpack binary data from a string -*/ -SWIGRUNTIME const char * -SWIG_UnpackData(const char *c, void *ptr, size_t sz) { - register unsigned char *u = (unsigned char *) ptr; - register const unsigned char *eu = u + sz; - for (; u != eu; ++u) { - register char d = *(c++); - register unsigned char uu; - if ((d >= '0') && (d <= '9')) - uu = ((d - '0') << 4); - else if ((d >= 'a') && (d <= 'f')) - uu = ((d - ('a'-10)) << 4); - else - return (char *) 0; - d = *(c++); - if ((d >= '0') && (d <= '9')) - uu |= (d - '0'); - else if ((d >= 'a') && (d <= 'f')) - uu |= (d - ('a'-10)); - else - return (char *) 0; - *u = uu; - } - return c; -} - -/* - Pack 'void *' into a string buffer. -*/ -SWIGRUNTIME char * -SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) { - char *r = buff; - if ((2*sizeof(void *) + 2) > bsz) return 0; - *(r++) = '_'; - r = SWIG_PackData(r,&ptr,sizeof(void *)); - if (strlen(name) + 1 > (bsz - (r - buff))) return 0; - strcpy(r,name); - return buff; -} - -SWIGRUNTIME const char * -SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) { - if (*c != '_') { - if (strcmp(c,"NULL") == 0) { - *ptr = (void *) 0; - return name; - } else { - return 0; - } - } - return SWIG_UnpackData(++c,ptr,sizeof(void *)); -} - -SWIGRUNTIME char * -SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) { - char *r = buff; - size_t lname = (name ? strlen(name) : 0); - if ((2*sz + 2 + lname) > bsz) return 0; - *(r++) = '_'; - r = SWIG_PackData(r,ptr,sz); - if (lname) { - strncpy(r,name,lname+1); - } else { - *r = 0; - } - return buff; -} - -SWIGRUNTIME const char * -SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { - if (*c != '_') { - if (strcmp(c,"NULL") == 0) { - memset(ptr,0,sz); - return name; - } else { - return 0; - } - } - return SWIG_UnpackData(++c,ptr,sz); -} - -#ifdef __cplusplus -} -#endif - -/* Errors in SWIG */ -#define SWIG_UnknownError -1 -#define SWIG_IOError -2 -#define SWIG_RuntimeError -3 -#define SWIG_IndexError -4 -#define SWIG_TypeError -5 -#define SWIG_DivisionByZero -6 -#define SWIG_OverflowError -7 -#define SWIG_SyntaxError -8 -#define SWIG_ValueError -9 -#define SWIG_SystemError -10 -#define SWIG_AttributeError -11 -#define SWIG_MemoryError -12 -#define SWIG_NullReferenceError -13 - - - -/* Compatibility macros for Python 3 */ -#if PY_VERSION_HEX >= 0x03000000 - -#define PyClass_Check(obj) PyObject_IsInstance(obj, (PyObject *)&PyType_Type) -#define PyInt_Check(x) PyLong_Check(x) -#define PyInt_AsLong(x) PyLong_AsLong(x) -#define PyInt_FromLong(x) PyLong_FromLong(x) -#define PyString_Check(name) PyBytes_Check(name) -#define PyString_FromString(x) PyUnicode_FromString(x) -#define PyString_Format(fmt, args) PyUnicode_Format(fmt, args) -#define PyString_AsString(str) PyBytes_AsString(str) -#define PyString_Size(str) PyBytes_Size(str) -#define PyString_InternFromString(key) PyUnicode_InternFromString(key) -#define Py_TPFLAGS_HAVE_CLASS Py_TPFLAGS_BASETYPE -#define PyString_AS_STRING(x) PyUnicode_AS_STRING(x) -#define _PyLong_FromSsize_t(x) PyLong_FromSsize_t(x) - -#endif - -#ifndef Py_TYPE -# define Py_TYPE(op) ((op)->ob_type) -#endif - -/* SWIG APIs for compatibility of both Python 2 & 3 */ - -#if PY_VERSION_HEX >= 0x03000000 -# define SWIG_Python_str_FromFormat PyUnicode_FromFormat -#else -# define SWIG_Python_str_FromFormat PyString_FromFormat -#endif - - -/* Warning: This function will allocate a new string in Python 3, - * so please call SWIG_Python_str_DelForPy3(x) to free the space. - */ -SWIGINTERN char* -SWIG_Python_str_AsChar(PyObject *str) -{ -#if PY_VERSION_HEX >= 0x03000000 - char *cstr; - char *newstr; - Py_ssize_t len; - str = PyUnicode_AsUTF8String(str); - PyBytes_AsStringAndSize(str, &cstr, &len); - newstr = (char *) malloc(len+1); - memcpy(newstr, cstr, len+1); - Py_XDECREF(str); - return newstr; -#else - return PyString_AsString(str); -#endif -} - -#if PY_VERSION_HEX >= 0x03000000 -# define SWIG_Python_str_DelForPy3(x) free( (void*) (x) ) -#else -# define SWIG_Python_str_DelForPy3(x) -#endif - - -SWIGINTERN PyObject* -SWIG_Python_str_FromChar(const char *c) -{ -#if PY_VERSION_HEX >= 0x03000000 - return PyUnicode_FromString(c); -#else - return PyString_FromString(c); -#endif -} - -/* Add PyOS_snprintf for old Pythons */ -#if PY_VERSION_HEX < 0x02020000 -# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) -# define PyOS_snprintf _snprintf -# else -# define PyOS_snprintf snprintf -# endif -#endif - -/* A crude PyString_FromFormat implementation for old Pythons */ -#if PY_VERSION_HEX < 0x02020000 - -#ifndef SWIG_PYBUFFER_SIZE -# define SWIG_PYBUFFER_SIZE 1024 -#endif - -static PyObject * -PyString_FromFormat(const char *fmt, ...) { - va_list ap; - char buf[SWIG_PYBUFFER_SIZE * 2]; - int res; - va_start(ap, fmt); - res = vsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); - return (res < 0 || res >= (int)sizeof(buf)) ? 0 : PyString_FromString(buf); -} -#endif - -/* Add PyObject_Del for old Pythons */ -#if PY_VERSION_HEX < 0x01060000 -# define PyObject_Del(op) PyMem_DEL((op)) -#endif -#ifndef PyObject_DEL -# define PyObject_DEL PyObject_Del -#endif - -/* A crude PyExc_StopIteration exception for old Pythons */ -#if PY_VERSION_HEX < 0x02020000 -# ifndef PyExc_StopIteration -# define PyExc_StopIteration PyExc_RuntimeError -# endif -# ifndef PyObject_GenericGetAttr -# define PyObject_GenericGetAttr 0 -# endif -#endif - -/* Py_NotImplemented is defined in 2.1 and up. */ -#if PY_VERSION_HEX < 0x02010000 -# ifndef Py_NotImplemented -# define Py_NotImplemented PyExc_RuntimeError -# endif -#endif - -/* A crude PyString_AsStringAndSize implementation for old Pythons */ -#if PY_VERSION_HEX < 0x02010000 -# ifndef PyString_AsStringAndSize -# define PyString_AsStringAndSize(obj, s, len) {*s = PyString_AsString(obj); *len = *s ? strlen(*s) : 0;} -# endif -#endif - -/* PySequence_Size for old Pythons */ -#if PY_VERSION_HEX < 0x02000000 -# ifndef PySequence_Size -# define PySequence_Size PySequence_Length -# endif -#endif - -/* PyBool_FromLong for old Pythons */ -#if PY_VERSION_HEX < 0x02030000 -static -PyObject *PyBool_FromLong(long ok) -{ - PyObject *result = ok ? Py_True : Py_False; - Py_INCREF(result); - return result; -} -#endif - -/* Py_ssize_t for old Pythons */ -/* This code is as recommended by: */ -/* http://www.python.org/dev/peps/pep-0353/#conversion-guidelines */ -#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) -typedef int Py_ssize_t; -# define PY_SSIZE_T_MAX INT_MAX -# define PY_SSIZE_T_MIN INT_MIN -#endif - -/* ----------------------------------------------------------------------------- - * error manipulation - * ----------------------------------------------------------------------------- */ - -SWIGRUNTIME PyObject* -SWIG_Python_ErrorType(int code) { - PyObject* type = 0; - switch(code) { - case SWIG_MemoryError: - type = PyExc_MemoryError; - break; - case SWIG_IOError: - type = PyExc_IOError; - break; - case SWIG_RuntimeError: - type = PyExc_RuntimeError; - break; - case SWIG_IndexError: - type = PyExc_IndexError; - break; - case SWIG_TypeError: - type = PyExc_TypeError; - break; - case SWIG_DivisionByZero: - type = PyExc_ZeroDivisionError; - break; - case SWIG_OverflowError: - type = PyExc_OverflowError; - break; - case SWIG_SyntaxError: - type = PyExc_SyntaxError; - break; - case SWIG_ValueError: - type = PyExc_ValueError; - break; - case SWIG_SystemError: - type = PyExc_SystemError; - break; - case SWIG_AttributeError: - type = PyExc_AttributeError; - break; - default: - type = PyExc_RuntimeError; - } - return type; -} - - -SWIGRUNTIME void -SWIG_Python_AddErrorMsg(const char* mesg) -{ - PyObject *type = 0; - PyObject *value = 0; - PyObject *traceback = 0; - - if (PyErr_Occurred()) PyErr_Fetch(&type, &value, &traceback); - if (value) { - char *tmp; - PyObject *old_str = PyObject_Str(value); - PyErr_Clear(); - Py_XINCREF(type); - - PyErr_Format(type, "%s %s", tmp = SWIG_Python_str_AsChar(old_str), mesg); - SWIG_Python_str_DelForPy3(tmp); - Py_DECREF(old_str); - Py_DECREF(value); - } else { - PyErr_SetString(PyExc_RuntimeError, mesg); - } -} - -#if defined(SWIG_PYTHON_NO_THREADS) -# if defined(SWIG_PYTHON_THREADS) -# undef SWIG_PYTHON_THREADS -# endif -#endif -#if defined(SWIG_PYTHON_THREADS) /* Threading support is enabled */ -# if !defined(SWIG_PYTHON_USE_GIL) && !defined(SWIG_PYTHON_NO_USE_GIL) -# if (PY_VERSION_HEX >= 0x02030000) /* For 2.3 or later, use the PyGILState calls */ -# define SWIG_PYTHON_USE_GIL -# endif -# endif -# if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */ -# ifndef SWIG_PYTHON_INITIALIZE_THREADS -# define SWIG_PYTHON_INITIALIZE_THREADS PyEval_InitThreads() -# endif -# ifdef __cplusplus /* C++ code */ - class SWIG_Python_Thread_Block { - bool status; - PyGILState_STATE state; - public: - void end() { if (status) { PyGILState_Release(state); status = false;} } - SWIG_Python_Thread_Block() : status(true), state(PyGILState_Ensure()) {} - ~SWIG_Python_Thread_Block() { end(); } - }; - class SWIG_Python_Thread_Allow { - bool status; - PyThreadState *save; - public: - void end() { if (status) { PyEval_RestoreThread(save); status = false; }} - SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {} - ~SWIG_Python_Thread_Allow() { end(); } - }; -# define SWIG_PYTHON_THREAD_BEGIN_BLOCK SWIG_Python_Thread_Block _swig_thread_block -# define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end() -# define SWIG_PYTHON_THREAD_BEGIN_ALLOW SWIG_Python_Thread_Allow _swig_thread_allow -# define SWIG_PYTHON_THREAD_END_ALLOW _swig_thread_allow.end() -# else /* C code */ -# define SWIG_PYTHON_THREAD_BEGIN_BLOCK PyGILState_STATE _swig_thread_block = PyGILState_Ensure() -# define SWIG_PYTHON_THREAD_END_BLOCK PyGILState_Release(_swig_thread_block) -# define SWIG_PYTHON_THREAD_BEGIN_ALLOW PyThreadState *_swig_thread_allow = PyEval_SaveThread() -# define SWIG_PYTHON_THREAD_END_ALLOW PyEval_RestoreThread(_swig_thread_allow) -# endif -# else /* Old thread way, not implemented, user must provide it */ -# if !defined(SWIG_PYTHON_INITIALIZE_THREADS) -# define SWIG_PYTHON_INITIALIZE_THREADS -# endif -# if !defined(SWIG_PYTHON_THREAD_BEGIN_BLOCK) -# define SWIG_PYTHON_THREAD_BEGIN_BLOCK -# endif -# if !defined(SWIG_PYTHON_THREAD_END_BLOCK) -# define SWIG_PYTHON_THREAD_END_BLOCK -# endif -# if !defined(SWIG_PYTHON_THREAD_BEGIN_ALLOW) -# define SWIG_PYTHON_THREAD_BEGIN_ALLOW -# endif -# if !defined(SWIG_PYTHON_THREAD_END_ALLOW) -# define SWIG_PYTHON_THREAD_END_ALLOW -# endif -# endif -#else /* No thread support */ -# define SWIG_PYTHON_INITIALIZE_THREADS -# define SWIG_PYTHON_THREAD_BEGIN_BLOCK -# define SWIG_PYTHON_THREAD_END_BLOCK -# define SWIG_PYTHON_THREAD_BEGIN_ALLOW -# define SWIG_PYTHON_THREAD_END_ALLOW -#endif - -/* ----------------------------------------------------------------------------- - * Python API portion that goes into the runtime - * ----------------------------------------------------------------------------- */ - -#ifdef __cplusplus -extern "C" { -#if 0 -} /* cc-mode */ -#endif -#endif - -/* ----------------------------------------------------------------------------- - * Constant declarations - * ----------------------------------------------------------------------------- */ - -/* Constant Types */ -#define SWIG_PY_POINTER 4 -#define SWIG_PY_BINARY 5 - -/* Constant information structure */ -typedef struct swig_const_info { - int type; - char *name; - long lvalue; - double dvalue; - void *pvalue; - swig_type_info **ptype; -} swig_const_info; - - -/* ----------------------------------------------------------------------------- - * Wrapper of PyInstanceMethod_New() used in Python 3 - * It is exported to the generated module, used for -fastproxy - * ----------------------------------------------------------------------------- */ -SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *self, PyObject *func) -{ -#if PY_VERSION_HEX >= 0x03000000 - return PyInstanceMethod_New(func); -#else - return NULL; -#endif -} - -#ifdef __cplusplus -#if 0 -{ /* cc-mode */ -#endif -} -#endif - - -/* ----------------------------------------------------------------------------- - * pyrun.swg - * - * This file contains the runtime support for Python modules - * and includes code for managing global variables and pointer - * type checking. - * - * ----------------------------------------------------------------------------- */ - -/* Common SWIG API */ - -/* for raw pointers */ -#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) -#define SWIG_CheckImplicit(ty) SWIG_Python_CheckImplicit(ty) -#define SWIG_AcquirePtr(ptr, src) SWIG_Python_AcquirePtr(ptr, src) -#define swig_owntype int - -/* for raw packed data */ -#define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) -#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) - -/* for class or struct pointers */ -#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags) -#define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags) - -/* 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) - -/* for C++ member pointers, ie, member methods */ -#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) -#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) - - -/* Runtime API */ - -#define SWIG_GetModule(clientdata) SWIG_Python_GetModule() -#define SWIG_SetModule(clientdata, pointer) SWIG_Python_SetModule(pointer) -#define SWIG_NewClientData(obj) SwigPyClientData_New(obj) - -#define SWIG_SetErrorObj SWIG_Python_SetErrorObj -#define SWIG_SetErrorMsg SWIG_Python_SetErrorMsg -#define SWIG_ErrorType(code) SWIG_Python_ErrorType(code) -#define SWIG_Error(code, msg) SWIG_Python_SetErrorMsg(SWIG_ErrorType(code), msg) -#define SWIG_fail goto fail - - -/* Runtime API implementation */ - -/* Error manipulation */ - -SWIGINTERN void -SWIG_Python_SetErrorObj(PyObject *errtype, PyObject *obj) { - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyErr_SetObject(errtype, obj); - Py_DECREF(obj); - SWIG_PYTHON_THREAD_END_BLOCK; -} - -SWIGINTERN void -SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) { - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyErr_SetString(errtype, (char *) msg); - SWIG_PYTHON_THREAD_END_BLOCK; -} - -#define SWIG_Python_Raise(obj, type, desc) SWIG_Python_SetErrorObj(SWIG_Python_ExceptionType(desc), obj) - -/* Set a constant value */ - -#if defined(SWIGPYTHON_BUILTIN) - -SWIGINTERN void -pyswig_add_public_symbol (PyObject *seq, const char *key) { - PyObject *s = PyString_InternFromString(key); - PyList_Append(seq, s); - Py_DECREF(s); -} - -SWIGINTERN void -SWIG_Python_SetConstant(PyObject *d, PyObject *public_interface, const char *name, PyObject *obj) { - PyDict_SetItemString(d, (char*) name, obj); - Py_DECREF(obj); - if (public_interface) - pyswig_add_public_symbol(public_interface, name); -} - -#else - -SWIGINTERN void -SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) { - PyDict_SetItemString(d, (char*) name, obj); - Py_DECREF(obj); -} - -#endif - -/* Append a value to the result obj */ - -SWIGINTERN PyObject* -SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) { -#if !defined(SWIG_PYTHON_OUTPUT_TUPLE) - if (!result) { - result = obj; - } else if (result == Py_None) { - Py_DECREF(result); - result = obj; - } else { - if (!PyList_Check(result)) { - PyObject *o2 = result; - result = PyList_New(1); - PyList_SetItem(result, 0, o2); - } - PyList_Append(result,obj); - Py_DECREF(obj); - } - return result; -#else - PyObject* o2; - PyObject* o3; - if (!result) { - result = obj; - } else if (result == Py_None) { - Py_DECREF(result); - result = obj; - } else { - if (!PyTuple_Check(result)) { - o2 = result; - result = PyTuple_New(1); - PyTuple_SET_ITEM(result, 0, o2); - } - o3 = PyTuple_New(1); - PyTuple_SET_ITEM(o3, 0, obj); - o2 = result; - result = PySequence_Concat(o2, o3); - Py_DECREF(o2); - Py_DECREF(o3); - } - return result; -#endif -} - -/* Unpack the argument tuple */ - -SWIGINTERN int -SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, PyObject **objs) -{ - if (!args) { - if (!min && !max) { - return 1; - } else { - PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got none", - name, (min == max ? "" : "at least "), (int)min); - return 0; - } - } - if (!PyTuple_Check(args)) { - PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple"); - return 0; - } else { - register Py_ssize_t l = PyTuple_GET_SIZE(args); - if (l < min) { - PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", - name, (min == max ? "" : "at least "), (int)min, (int)l); - return 0; - } else if (l > max) { - PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", - name, (min == max ? "" : "at most "), (int)max, (int)l); - return 0; - } else { - register int i; - for (i = 0; i < l; ++i) { - objs[i] = PyTuple_GET_ITEM(args, i); - } - for (; l < max; ++l) { - objs[l] = 0; - } - return i + 1; - } - } -} - -/* A functor is a function object with one single object argument */ -#if PY_VERSION_HEX >= 0x02020000 -#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunctionObjArgs(functor, obj, NULL); -#else -#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunction(functor, "O", obj); -#endif - -/* - Helper for static pointer initialization for both C and C++ code, for example - static PyObject *SWIG_STATIC_POINTER(MyVar) = NewSomething(...); -*/ -#ifdef __cplusplus -#define SWIG_STATIC_POINTER(var) var -#else -#define SWIG_STATIC_POINTER(var) var = 0; if (!var) var -#endif - -/* ----------------------------------------------------------------------------- - * Pointer declarations - * ----------------------------------------------------------------------------- */ - -/* Flags for new pointer objects */ -#define SWIG_POINTER_NOSHADOW (SWIG_POINTER_OWN << 1) -#define SWIG_POINTER_NEW (SWIG_POINTER_NOSHADOW | SWIG_POINTER_OWN) - -#define SWIG_POINTER_IMPLICIT_CONV (SWIG_POINTER_DISOWN << 1) - -#ifdef __cplusplus -extern "C" { -#if 0 -} /* cc-mode */ -#endif -#endif - -/* How to access Py_None */ -#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# ifndef SWIG_PYTHON_NO_BUILD_NONE -# ifndef SWIG_PYTHON_BUILD_NONE -# define SWIG_PYTHON_BUILD_NONE -# endif -# endif -#endif - -#ifdef SWIG_PYTHON_BUILD_NONE -# ifdef Py_None -# undef Py_None -# define Py_None SWIG_Py_None() -# endif -SWIGRUNTIMEINLINE PyObject * -_SWIG_Py_None(void) -{ - PyObject *none = Py_BuildValue((char*)""); - Py_DECREF(none); - return none; -} -SWIGRUNTIME PyObject * -SWIG_Py_None(void) -{ - static PyObject *SWIG_STATIC_POINTER(none) = _SWIG_Py_None(); - return none; -} -#endif - -/* The python void return value */ - -SWIGRUNTIMEINLINE PyObject * -SWIG_Py_Void(void) -{ - PyObject *none = Py_None; - Py_INCREF(none); - return none; -} - -/* SwigPyClientData */ - -typedef struct { - PyObject *klass; - PyObject *newraw; - PyObject *newargs; - PyObject *destroy; - int delargs; - int implicitconv; - PyTypeObject *pytype; -} SwigPyClientData; - -SWIGRUNTIMEINLINE int -SWIG_Python_CheckImplicit(swig_type_info *ty) -{ - SwigPyClientData *data = (SwigPyClientData *)ty->clientdata; - return data ? data->implicitconv : 0; -} - -SWIGRUNTIMEINLINE PyObject * -SWIG_Python_ExceptionType(swig_type_info *desc) { - SwigPyClientData *data = desc ? (SwigPyClientData *) desc->clientdata : 0; - PyObject *klass = data ? data->klass : 0; - return (klass ? klass : PyExc_RuntimeError); -} - - -SWIGRUNTIME SwigPyClientData * -SwigPyClientData_New(PyObject* obj) -{ - if (!obj) { - return 0; - } else { - SwigPyClientData *data = (SwigPyClientData *)malloc(sizeof(SwigPyClientData)); - /* the klass element */ - data->klass = obj; - Py_INCREF(data->klass); - /* the newraw method and newargs arguments used to create a new raw instance */ - if (PyClass_Check(obj)) { - data->newraw = 0; - data->newargs = obj; - Py_INCREF(obj); - } else { -#if (PY_VERSION_HEX < 0x02020000) - data->newraw = 0; -#else - data->newraw = PyObject_GetAttrString(data->klass, (char *)"__new__"); -#endif - if (data->newraw) { - Py_INCREF(data->newraw); - data->newargs = PyTuple_New(1); - PyTuple_SetItem(data->newargs, 0, obj); - } else { - data->newargs = obj; - } - Py_INCREF(data->newargs); - } - /* the destroy method, aka as the C++ delete method */ - data->destroy = PyObject_GetAttrString(data->klass, (char *)"__swig_destroy__"); - if (PyErr_Occurred()) { - PyErr_Clear(); - data->destroy = 0; - } - if (data->destroy) { - int flags; - Py_INCREF(data->destroy); - flags = PyCFunction_GET_FLAGS(data->destroy); -#ifdef METH_O - data->delargs = !(flags & (METH_O)); -#else - data->delargs = 0; -#endif - } else { - data->delargs = 0; - } - data->implicitconv = 0; - data->pytype = 0; - return data; - } -} - -SWIGRUNTIME void -SwigPyClientData_Del(SwigPyClientData* data) -{ - Py_XDECREF(data->newraw); - Py_XDECREF(data->newargs); - Py_XDECREF(data->destroy); -} - -/* =============== SwigPyObject =====================*/ - -typedef struct { - PyObject_HEAD - void *ptr; - swig_type_info *ty; - int own; - PyObject *next; -#ifdef SWIGPYTHON_BUILTIN - PyObject *dict; -#endif -} SwigPyObject; - -SWIGRUNTIME PyObject * -SwigPyObject_long(SwigPyObject *v) -{ - return PyLong_FromVoidPtr(v->ptr); -} - -SWIGRUNTIME PyObject * -SwigPyObject_format(const char* fmt, SwigPyObject *v) -{ - PyObject *res = NULL; - PyObject *args = PyTuple_New(1); - if (args) { - if (PyTuple_SetItem(args, 0, SwigPyObject_long(v)) == 0) { - PyObject *ofmt = SWIG_Python_str_FromChar(fmt); - if (ofmt) { -#if PY_VERSION_HEX >= 0x03000000 - res = PyUnicode_Format(ofmt,args); -#else - res = PyString_Format(ofmt,args); -#endif - Py_DECREF(ofmt); - } - Py_DECREF(args); - } - } - return res; -} - -SWIGRUNTIME PyObject * -SwigPyObject_oct(SwigPyObject *v) -{ - return SwigPyObject_format("%o",v); -} - -SWIGRUNTIME PyObject * -SwigPyObject_hex(SwigPyObject *v) -{ - return SwigPyObject_format("%x",v); -} - -SWIGRUNTIME PyObject * -#ifdef METH_NOARGS -SwigPyObject_repr(SwigPyObject *v) -#else -SwigPyObject_repr(SwigPyObject *v, PyObject *args) -#endif -{ - const char *name = SWIG_TypePrettyName(v->ty); - PyObject *repr = SWIG_Python_str_FromFormat("", name, v); - if (v->next) { -# ifdef METH_NOARGS - PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next); -# else - PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next, args); -# endif -# if PY_VERSION_HEX >= 0x03000000 - PyObject *joined = PyUnicode_Concat(repr, nrep); - Py_DecRef(repr); - Py_DecRef(nrep); - repr = joined; -# else - PyString_ConcatAndDel(&repr,nrep); -# endif - } - return repr; -} - -SWIGRUNTIME int -SwigPyObject_print(SwigPyObject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) -{ - char *str; -#ifdef METH_NOARGS - PyObject *repr = SwigPyObject_repr(v); -#else - PyObject *repr = SwigPyObject_repr(v, NULL); -#endif - if (repr) { - str = SWIG_Python_str_AsChar(repr); - fputs(str, fp); - SWIG_Python_str_DelForPy3(str); - Py_DECREF(repr); - return 0; - } else { - return 1; - } -} - -SWIGRUNTIME PyObject * -SwigPyObject_str(SwigPyObject *v) -{ - char result[SWIG_BUFFER_SIZE]; - return SWIG_PackVoidPtr(result, v->ptr, v->ty->name, sizeof(result)) ? - SWIG_Python_str_FromChar(result) : 0; -} - -SWIGRUNTIME int -SwigPyObject_compare(SwigPyObject *v, SwigPyObject *w) -{ - void *i = v->ptr; - void *j = w->ptr; - return (i < j) ? -1 : ((i > j) ? 1 : 0); -} - -/* Added for Python 3.x, would it also be useful for Python 2.x? */ -SWIGRUNTIME PyObject* -SwigPyObject_richcompare(SwigPyObject *v, SwigPyObject *w, int op) -{ - PyObject* res; - if( op != Py_EQ && op != Py_NE ) { - Py_INCREF(Py_NotImplemented); - return Py_NotImplemented; - } - if( (SwigPyObject_compare(v, w)==0) == (op == Py_EQ) ) - res = Py_True; - else - res = Py_False; - Py_INCREF(res); - return res; -} - - -SWIGRUNTIME PyTypeObject* _PySwigObject_type(void); - -#ifdef SWIGPYTHON_BUILTIN -static swig_type_info *SwigPyObject_stype = 0; -SWIGRUNTIME PyTypeObject* -SwigPyObject_type(void) { - assert(SwigPyObject_stype); - SwigPyClientData *cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; - assert(cd); - assert(cd->pytype); - return cd->pytype; -} -#else -SWIGRUNTIME PyTypeObject* -SwigPyObject_type(void) { - static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigObject_type(); - return type; -} -#endif - -SWIGRUNTIMEINLINE int -SwigPyObject_Check(PyObject *op) { -#ifdef SWIGPYTHON_BUILTIN - PyTypeObject *target_tp = SwigPyObject_type(); - PyTypeObject *obj_tp; - if (PyType_IsSubtype(op->ob_type, target_tp)) - return 1; - return (strcmp(op->ob_type->tp_name, "SwigPyObject") == 0); -#else - return (Py_TYPE(op) == SwigPyObject_type()) - || (strcmp(Py_TYPE(op)->tp_name,"SwigPyObject") == 0); -#endif -} - -SWIGRUNTIME PyObject * -SwigPyObject_New(void *ptr, swig_type_info *ty, int own); - -SWIGRUNTIME void -SwigPyObject_dealloc(PyObject *v) -{ - SwigPyObject *sobj = (SwigPyObject *) v; - PyObject *next = sobj->next; - if (sobj->own == SWIG_POINTER_OWN) { - swig_type_info *ty = sobj->ty; - SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0; - PyObject *destroy = data ? data->destroy : 0; - if (destroy) { - /* destroy is always a VARARGS method */ - PyObject *res; - if (data->delargs) { - /* we need to create a temporary object to carry the destroy operation */ - PyObject *tmp = SwigPyObject_New(sobj->ptr, ty, 0); - res = SWIG_Python_CallFunctor(destroy, tmp); - Py_DECREF(tmp); - } else { - PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); - PyObject *mself = PyCFunction_GET_SELF(destroy); - res = ((*meth)(mself, v)); - } - Py_XDECREF(res); - } -#if !defined(SWIG_PYTHON_SILENT_MEMLEAK) - else { - const char *name = SWIG_TypePrettyName(ty); - printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown")); - } -#endif - } - Py_XDECREF(next); - PyObject_DEL(v); -} - -SWIGRUNTIME PyObject* -SwigPyObject_append(PyObject* v, PyObject* next) -{ - SwigPyObject *sobj = (SwigPyObject *) v; -#ifndef METH_O - PyObject *tmp = 0; - if (!PyArg_ParseTuple(next,(char *)"O:append", &tmp)) return NULL; - next = tmp; -#endif - if (!SwigPyObject_Check(next)) { - return NULL; - } - sobj->next = next; - Py_INCREF(next); - return SWIG_Py_Void(); -} - -SWIGRUNTIME PyObject* -#ifdef METH_NOARGS -SwigPyObject_next(PyObject* v) -#else -SwigPyObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) -#endif -{ - SwigPyObject *sobj = (SwigPyObject *) v; - if (sobj->next) { - Py_INCREF(sobj->next); - return sobj->next; - } else { - return SWIG_Py_Void(); - } -} - -SWIGINTERN PyObject* -#ifdef METH_NOARGS -SwigPyObject_disown(PyObject *v) -#else -SwigPyObject_disown(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) -#endif -{ - SwigPyObject *sobj = (SwigPyObject *)v; - sobj->own = 0; - return SWIG_Py_Void(); -} - -SWIGINTERN PyObject* -#ifdef METH_NOARGS -SwigPyObject_acquire(PyObject *v) -#else -SwigPyObject_acquire(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) -#endif -{ - SwigPyObject *sobj = (SwigPyObject *)v; - sobj->own = SWIG_POINTER_OWN; - return SWIG_Py_Void(); -} - -SWIGINTERN PyObject* -SwigPyObject_own(PyObject *v, PyObject *args) -{ - PyObject *val = 0; -#if (PY_VERSION_HEX < 0x02020000) - if (!PyArg_ParseTuple(args,(char *)"|O:own",&val)) -#else - if (!PyArg_UnpackTuple(args, (char *)"own", 0, 1, &val)) -#endif - { - return NULL; - } - else - { - SwigPyObject *sobj = (SwigPyObject *)v; - PyObject *obj = PyBool_FromLong(sobj->own); - if (val) { -#ifdef METH_NOARGS - if (PyObject_IsTrue(val)) { - SwigPyObject_acquire(v); - } else { - SwigPyObject_disown(v); - } -#else - if (PyObject_IsTrue(val)) { - SwigPyObject_acquire(v,args); - } else { - SwigPyObject_disown(v,args); - } -#endif - } - return obj; - } -} - -#ifdef METH_O -static PyMethodDef -swigobject_methods[] = { - {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_NOARGS, (char *)"releases ownership of the pointer"}, - {(char *)"acquire", (PyCFunction)SwigPyObject_acquire, METH_NOARGS, (char *)"aquires ownership of the pointer"}, - {(char *)"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, - {(char *)"append", (PyCFunction)SwigPyObject_append, METH_O, (char *)"appends another 'this' object"}, - {(char *)"next", (PyCFunction)SwigPyObject_next, METH_NOARGS, (char *)"returns the next 'this' object"}, - {(char *)"__repr__",(PyCFunction)SwigPyObject_repr, METH_NOARGS, (char *)"returns object representation"}, - {0, 0, 0, 0} -}; -#else -static PyMethodDef -swigobject_methods[] = { - {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_VARARGS, (char *)"releases ownership of the pointer"}, - {(char *)"acquire", (PyCFunction)SwigPyObject_acquire, METH_VARARGS, (char *)"aquires ownership of the pointer"}, - {(char *)"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, - {(char *)"append", (PyCFunction)SwigPyObject_append, METH_VARARGS, (char *)"appends another 'this' object"}, - {(char *)"next", (PyCFunction)SwigPyObject_next, METH_VARARGS, (char *)"returns the next 'this' object"}, - {(char *)"__repr__",(PyCFunction)SwigPyObject_repr, METH_VARARGS, (char *)"returns object representation"}, - {0, 0, 0, 0} -}; -#endif - -#if PY_VERSION_HEX < 0x02020000 -SWIGINTERN PyObject * -SwigPyObject_getattr(SwigPyObject *sobj,char *name) -{ - return Py_FindMethod(swigobject_methods, (PyObject *)sobj, name); -} -#endif - -SWIGRUNTIME PyTypeObject* -_PySwigObject_type(void) { - static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer"; - - static PyNumberMethods SwigPyObject_as_number = { - (binaryfunc)0, /*nb_add*/ - (binaryfunc)0, /*nb_subtract*/ - (binaryfunc)0, /*nb_multiply*/ - /* nb_divide removed in Python 3 */ -#if PY_VERSION_HEX < 0x03000000 - (binaryfunc)0, /*nb_divide*/ -#endif - (binaryfunc)0, /*nb_remainder*/ - (binaryfunc)0, /*nb_divmod*/ - (ternaryfunc)0,/*nb_power*/ - (unaryfunc)0, /*nb_negative*/ - (unaryfunc)0, /*nb_positive*/ - (unaryfunc)0, /*nb_absolute*/ - (inquiry)0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ -#if PY_VERSION_HEX < 0x03000000 - 0, /*nb_coerce*/ -#endif - (unaryfunc)SwigPyObject_long, /*nb_int*/ -#if PY_VERSION_HEX < 0x03000000 - (unaryfunc)SwigPyObject_long, /*nb_long*/ -#else - 0, /*nb_reserved*/ -#endif - (unaryfunc)0, /*nb_float*/ -#if PY_VERSION_HEX < 0x03000000 - (unaryfunc)SwigPyObject_oct, /*nb_oct*/ - (unaryfunc)SwigPyObject_hex, /*nb_hex*/ -#endif -#if PY_VERSION_HEX >= 0x03000000 /* 3.0 */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index, nb_inplace_divide removed */ -#elif PY_VERSION_HEX >= 0x02050000 /* 2.5.0 */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index */ -#elif PY_VERSION_HEX >= 0x02020000 /* 2.2.0 */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_true_divide */ -#elif PY_VERSION_HEX >= 0x02000000 /* 2.0.0 */ - 0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_or */ -#endif - }; - - static PyTypeObject swigpyobject_type; - static int type_init = 0; - if (!type_init) { - const PyTypeObject tmp - = { - /* PyObject header changed in Python 3 */ -#if PY_VERSION_HEX >= 0x03000000 - PyVarObject_HEAD_INIT(&PyType_Type, 0) -#else - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ -#endif - (char *)"SwigPyObject", /* tp_name */ - sizeof(SwigPyObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)SwigPyObject_dealloc, /* tp_dealloc */ - (printfunc)SwigPyObject_print, /* tp_print */ -#if PY_VERSION_HEX < 0x02020000 - (getattrfunc)SwigPyObject_getattr, /* tp_getattr */ -#else - (getattrfunc)0, /* tp_getattr */ -#endif - (setattrfunc)0, /* tp_setattr */ -#if PY_VERSION_HEX >= 0x03000000 - 0, /* tp_reserved in 3.0.1, tp_compare in 3.0.0 but not used */ -#else - (cmpfunc)SwigPyObject_compare, /* tp_compare */ -#endif - (reprfunc)SwigPyObject_repr, /* tp_repr */ - &SwigPyObject_as_number, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - (hashfunc)0, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)SwigPyObject_str, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - swigobject_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - (richcmpfunc)SwigPyObject_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ -#if PY_VERSION_HEX >= 0x02020000 - 0, /* tp_iter */ - 0, /* tp_iternext */ - swigobject_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0, /* tp_free */ - 0, /* tp_is_gc */ - 0, /* tp_bases */ - 0, /* tp_mro */ - 0, /* tp_cache */ - 0, /* tp_subclasses */ - 0, /* tp_weaklist */ -#endif -#if PY_VERSION_HEX >= 0x02030000 - 0, /* tp_del */ -#endif -#ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ -#endif - }; - swigpyobject_type = tmp; - /* for Python 3 we already assigned ob_type in PyVarObject_HEAD_INIT() */ -#if PY_VERSION_HEX < 0x03000000 - swigpyobject_type.ob_type = &PyType_Type; -#endif - type_init = 1; - } - return &swigpyobject_type; -} - -SWIGRUNTIME PyObject * -SwigPyObject_New(void *ptr, swig_type_info *ty, int own) -{ - SwigPyObject *sobj = PyObject_NEW(SwigPyObject, SwigPyObject_type()); - if (sobj) { - sobj->ptr = ptr; - sobj->ty = ty; - sobj->own = own; - sobj->next = 0; - } - return (PyObject *)sobj; -} - -/* ----------------------------------------------------------------------------- - * Implements a simple Swig Packed type, and use it instead of string - * ----------------------------------------------------------------------------- */ - -typedef struct { - PyObject_HEAD - void *pack; - swig_type_info *ty; - size_t size; -} SwigPyPacked; - -SWIGRUNTIME int -SwigPyPacked_print(SwigPyPacked *v, FILE *fp, int SWIGUNUSEDPARM(flags)) -{ - char result[SWIG_BUFFER_SIZE]; - fputs("pack, v->size, 0, sizeof(result))) { - fputs("at ", fp); - fputs(result, fp); - } - fputs(v->ty->name,fp); - fputs(">", fp); - return 0; -} - -SWIGRUNTIME PyObject * -SwigPyPacked_repr(SwigPyPacked *v) -{ - char result[SWIG_BUFFER_SIZE]; - if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { - return SWIG_Python_str_FromFormat("", result, v->ty->name); - } else { - return SWIG_Python_str_FromFormat("", v->ty->name); - } -} - -SWIGRUNTIME PyObject * -SwigPyPacked_str(SwigPyPacked *v) -{ - char result[SWIG_BUFFER_SIZE]; - if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){ - return SWIG_Python_str_FromFormat("%s%s", result, v->ty->name); - } else { - return SWIG_Python_str_FromChar(v->ty->name); - } -} - -SWIGRUNTIME int -SwigPyPacked_compare(SwigPyPacked *v, SwigPyPacked *w) -{ - size_t i = v->size; - size_t j = w->size; - int s = (i < j) ? -1 : ((i > j) ? 1 : 0); - return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size); -} - -SWIGRUNTIME PyTypeObject* _PySwigPacked_type(void); - -SWIGRUNTIME PyTypeObject* -SwigPyPacked_type(void) { - static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigPacked_type(); - return type; -} - -SWIGRUNTIMEINLINE int -SwigPyPacked_Check(PyObject *op) { - return ((op)->ob_type == _PySwigPacked_type()) - || (strcmp((op)->ob_type->tp_name,"SwigPyPacked") == 0); -} - -SWIGRUNTIME void -SwigPyPacked_dealloc(PyObject *v) -{ - if (SwigPyPacked_Check(v)) { - SwigPyPacked *sobj = (SwigPyPacked *) v; - free(sobj->pack); - } - PyObject_DEL(v); -} - -SWIGRUNTIME PyTypeObject* -_PySwigPacked_type(void) { - static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer"; - static PyTypeObject swigpypacked_type; - static int type_init = 0; - if (!type_init) { - const PyTypeObject tmp - = { - /* PyObject header changed in Python 3 */ -#if PY_VERSION_HEX>=0x03000000 - PyVarObject_HEAD_INIT(&PyType_Type, 0) -#else - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ -#endif - (char *)"SwigPyPacked", /* tp_name */ - sizeof(SwigPyPacked), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)SwigPyPacked_dealloc, /* tp_dealloc */ - (printfunc)SwigPyPacked_print, /* tp_print */ - (getattrfunc)0, /* tp_getattr */ - (setattrfunc)0, /* tp_setattr */ -#if PY_VERSION_HEX>=0x03000000 - 0, /* tp_reserved in 3.0.1 */ -#else - (cmpfunc)SwigPyPacked_compare, /* tp_compare */ -#endif - (reprfunc)SwigPyPacked_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - (hashfunc)0, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)SwigPyPacked_str, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - swigpacked_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ -#if PY_VERSION_HEX >= 0x02020000 - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0, /* tp_free */ - 0, /* tp_is_gc */ - 0, /* tp_bases */ - 0, /* tp_mro */ - 0, /* tp_cache */ - 0, /* tp_subclasses */ - 0, /* tp_weaklist */ -#endif -#if PY_VERSION_HEX >= 0x02030000 - 0, /* tp_del */ -#endif -#ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ -#endif - }; - swigpypacked_type = tmp; - /* for Python 3 the ob_type already assigned in PyVarObject_HEAD_INIT() */ -#if PY_VERSION_HEX < 0x03000000 - swigpypacked_type.ob_type = &PyType_Type; -#endif - type_init = 1; - } - return &swigpypacked_type; -} - -SWIGRUNTIME PyObject * -SwigPyPacked_New(void *ptr, size_t size, swig_type_info *ty) -{ - SwigPyPacked *sobj = PyObject_NEW(SwigPyPacked, SwigPyPacked_type()); - if (sobj) { - void *pack = malloc(size); - if (pack) { - memcpy(pack, ptr, size); - sobj->pack = pack; - sobj->ty = ty; - sobj->size = size; - } else { - PyObject_DEL((PyObject *) sobj); - sobj = 0; - } - } - return (PyObject *) sobj; -} - -SWIGRUNTIME swig_type_info * -SwigPyPacked_UnpackData(PyObject *obj, void *ptr, size_t size) -{ - if (SwigPyPacked_Check(obj)) { - SwigPyPacked *sobj = (SwigPyPacked *)obj; - if (sobj->size != size) return 0; - memcpy(ptr, sobj->pack, size); - return sobj->ty; - } else { - return 0; - } -} - -/* ----------------------------------------------------------------------------- - * pointers/data manipulation - * ----------------------------------------------------------------------------- */ - -SWIGRUNTIMEINLINE PyObject * -_SWIG_This(void) -{ - return SWIG_Python_str_FromChar("this"); -} - -static PyObject *swig_this = NULL; - -SWIGRUNTIME PyObject * -SWIG_This(void) -{ - if (swig_this == NULL) - swig_this = _SWIG_This(); - return swig_this; -} - -/* #define SWIG_PYTHON_SLOW_GETSET_THIS */ - -/* TODO: I don't know how to implement the fast getset in Python 3 right now */ -#if PY_VERSION_HEX>=0x03000000 -#define SWIG_PYTHON_SLOW_GETSET_THIS -#endif - -SWIGRUNTIME SwigPyObject * -SWIG_Python_GetSwigThis(PyObject *pyobj) -{ - if (SwigPyObject_Check(pyobj)) - return (SwigPyObject *) pyobj; - -#ifdef SWIGPYTHON_BUILTIN -# ifdef PyWeakref_CheckProxy - if (PyWeakref_CheckProxy(pyobj)) { - pyobj = PyWeakref_GET_OBJECT(pyobj); - if (pyobj && SwigPyObject_Check(pyobj)) - return (SwigPyObject*) pyobj; - } -# endif - return NULL; -#endif - - PyObject *obj = 0; - -#if (!defined(SWIG_PYTHON_SLOW_GETSET_THIS) && (PY_VERSION_HEX >= 0x02030000)) - if (PyInstance_Check(pyobj)) { - obj = _PyInstance_Lookup(pyobj, SWIG_This()); - } else { - PyObject **dictptr = _PyObject_GetDictPtr(pyobj); - if (dictptr != NULL) { - PyObject *dict = *dictptr; - obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0; - } else { -#ifdef PyWeakref_CheckProxy - if (PyWeakref_CheckProxy(pyobj)) { - PyObject *wobj = PyWeakref_GET_OBJECT(pyobj); - return wobj ? SWIG_Python_GetSwigThis(wobj) : 0; - } -#endif - obj = PyObject_GetAttr(pyobj,SWIG_This()); - if (obj) { - Py_DECREF(obj); - } else { - if (PyErr_Occurred()) PyErr_Clear(); - return 0; - } - } - } -#else - obj = PyObject_GetAttr(pyobj,SWIG_This()); - if (obj) { - Py_DECREF(obj); - } else { - if (PyErr_Occurred()) PyErr_Clear(); - return 0; - } -#endif - if (obj && !SwigPyObject_Check(obj)) { - /* a PyObject is called 'this', try to get the 'real this' - SwigPyObject from it */ - return SWIG_Python_GetSwigThis(obj); - } - return (SwigPyObject *)obj; -} - -/* Acquire a pointer value */ - -SWIGRUNTIME int -SWIG_Python_AcquirePtr(PyObject *obj, int own) { - if (own == SWIG_POINTER_OWN) { - SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj); - if (sobj) { - int oldown = sobj->own; - sobj->own = own; - return oldown; - } - } - return 0; -} - -/* Convert a pointer value */ - -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) { - if (ptr) *ptr = 0; - return SWIG_OK; - } - - /* - if (ty && ty->clientdata && ((SwigPyClientData*) ty->clientdata)->pytype) { - PyTypeObject *target_tp = ((SwigPyClientData*) ty->clientdata)->pytype; - SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj); - for (; sobj; sobj = (SwigPyObject*) sobj->next) { - if (!sobj->ty->clientdata) - continue; - PyTypeObject *candidate_tp = ((SwigPyClientData*) sobj->ty->clientdata)->pytype; - if (candidate_tp && PyType_IsSubtype(candidate_tp, target_tp)) { - if (own) - *own = *own | sobj->own; - if (flags & SWIG_POINTER_DISOWN) - sobj->own = 0; - if (ptr) - *ptr = sobj->ptr; - return SWIG_OK; - } - } - return SWIG_ERROR; - } - */ - - int 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 { - 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); - } - } - } - } - } - return res; -} - -/* Convert a function ptr value */ - -SWIGRUNTIME int -SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) { - if (!PyCFunction_Check(obj)) { - return SWIG_ConvertPtr(obj, ptr, ty, 0); - } else { - void *vptr = 0; - - /* here we get the method pointer for callbacks */ - const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc); - const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0; - if (desc) - desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0; - if (!desc) - return SWIG_ERROR; - if (ty) { - swig_cast_info *tc = SWIG_TypeCheck(desc,ty); - if (tc) { - int newmemory = 0; - *ptr = SWIG_TypeCast(tc,vptr,&newmemory); - assert(!newmemory); /* newmemory handling not yet implemented */ - } else { - return SWIG_ERROR; - } - } else { - *ptr = vptr; - } - return SWIG_OK; - } -} - -/* Convert a packed value value */ - -SWIGRUNTIME int -SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty) { - swig_type_info *to = SwigPyPacked_UnpackData(obj, ptr, sz); - if (!to) return SWIG_ERROR; - if (ty) { - if (to != ty) { - /* check type cast? */ - swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); - if (!tc) return SWIG_ERROR; - } - } - return SWIG_OK; -} - -/* ----------------------------------------------------------------------------- - * Create a new pointer object - * ----------------------------------------------------------------------------- */ - -/* - Create a new instance object, without calling __init__, and set the - 'this' attribute. -*/ - -SWIGRUNTIME PyObject* -SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this) -{ -#if (PY_VERSION_HEX >= 0x02020000) - PyObject *inst = 0; - PyObject *newraw = data->newraw; - if (newraw) { - inst = PyObject_Call(newraw, data->newargs, NULL); - if (inst) { -#if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) - PyObject **dictptr = _PyObject_GetDictPtr(inst); - if (dictptr != NULL) { - PyObject *dict = *dictptr; - if (dict == NULL) { - dict = PyDict_New(); - *dictptr = dict; - PyDict_SetItem(dict, SWIG_This(), swig_this); - } - } -#else - PyObject *key = SWIG_This(); - PyObject_SetAttr(inst, key, swig_this); -#endif - } - } else { -#if PY_VERSION_HEX >= 0x03000000 - inst = PyBaseObject_Type.tp_new((PyTypeObject*) data->newargs, Py_None, Py_None); - PyObject_SetAttr(inst, SWIG_This(), swig_this); - Py_TYPE(inst)->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG; -#else - PyObject *dict = PyDict_New(); - PyDict_SetItem(dict, SWIG_This(), swig_this); - inst = PyInstance_NewRaw(data->newargs, dict); - Py_DECREF(dict); -#endif - } - return inst; -#else -#if (PY_VERSION_HEX >= 0x02010000) - PyObject *inst; - PyObject *dict = PyDict_New(); - PyDict_SetItem(dict, SWIG_This(), swig_this); - inst = PyInstance_NewRaw(data->newargs, dict); - Py_DECREF(dict); - return (PyObject *) inst; -#else - PyInstanceObject *inst = PyObject_NEW(PyInstanceObject, &PyInstance_Type); - if (inst == NULL) { - return NULL; - } - inst->in_class = (PyClassObject *)data->newargs; - Py_INCREF(inst->in_class); - inst->in_dict = PyDict_New(); - if (inst->in_dict == NULL) { - Py_DECREF(inst); - return NULL; - } -#ifdef Py_TPFLAGS_HAVE_WEAKREFS - inst->in_weakreflist = NULL; -#endif -#ifdef Py_TPFLAGS_GC - PyObject_GC_Init(inst); -#endif - PyDict_SetItem(inst->in_dict, SWIG_This(), swig_this); - return (PyObject *) inst; -#endif -#endif -} - -SWIGRUNTIME void -SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this) -{ - PyObject *dict; -#if (PY_VERSION_HEX >= 0x02020000) && !defined(SWIG_PYTHON_SLOW_GETSET_THIS) - PyObject **dictptr = _PyObject_GetDictPtr(inst); - if (dictptr != NULL) { - dict = *dictptr; - if (dict == NULL) { - dict = PyDict_New(); - *dictptr = dict; - } - PyDict_SetItem(dict, SWIG_This(), swig_this); - return; - } -#endif - dict = PyObject_GetAttrString(inst, (char*)"__dict__"); - PyDict_SetItem(dict, SWIG_This(), swig_this); - Py_DECREF(dict); -} - - -SWIGINTERN PyObject * -SWIG_Python_InitShadowInstance(PyObject *args) { - PyObject *obj[2]; - if (!SWIG_Python_UnpackTuple(args,(char*)"swiginit", 2, 2, obj)) { - return NULL; - } else { - SwigPyObject *sthis = SWIG_Python_GetSwigThis(obj[0]); - if (sthis) { - SwigPyObject_append((PyObject*) sthis, obj[1]); - } else { - SWIG_Python_SetSwigThis(obj[0], obj[1]); - } - return SWIG_Py_Void(); - } -} - -/* Create a new pointer object */ - -SWIGRUNTIME PyObject * -SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) { - if (!ptr) - return SWIG_Py_Void(); - - SwigPyClientData *clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0; - int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; - if (clientdata && clientdata->pytype) { - SwigPyObject *newobj = PyObject_New(SwigPyObject, clientdata->pytype); - if (newobj) { - newobj->ptr = ptr; - newobj->ty = type; - newobj->own = own; - newobj->next = 0; -#ifdef SWIGPYTHON_BUILTIN - newobj->dict = 0; -#endif - return (PyObject*) newobj; - } - return SWIG_Py_Void(); - } - - PyObject *robj = SwigPyObject_New(ptr, type, own); - if (clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { - PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); - if (inst) { - Py_DECREF(robj); - robj = inst; - } - } - return robj; -} - -/* Create a new packed object */ - -SWIGRUNTIMEINLINE PyObject * -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); - SwigPyClientData *clientdata = (SwigPyClientData *)(type->clientdata); - assert(clientdata); - assert(clientdata->pytype); - int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; - SwigPyObject *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; - } - newobj->ptr = ptr; - newobj->own = own; - newobj->ty = type; - newobj->next = 0; -#ifdef SWIGPYTHON_BUILTIN - newobj->dict = 0; -#endif - return 0; -} - -/* -----------------------------------------------------------------------------* - * Get type list - * -----------------------------------------------------------------------------*/ - -#ifdef SWIG_LINK_RUNTIME -void *SWIG_ReturnGlobalTypeList(void *); -#endif - -SWIGRUNTIME swig_module_info * -SWIG_Python_GetModule(void) { - static void *type_pointer = (void *)0; - /* first check if module already created */ - if (!type_pointer) { -#ifdef SWIG_LINK_RUNTIME - type_pointer = SWIG_ReturnGlobalTypeList((void *)0); -#else - type_pointer = PyCObject_Import((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, - (char*)"type_pointer" SWIG_TYPE_TABLE_NAME); - if (PyErr_Occurred()) { - PyErr_Clear(); - type_pointer = (void *)0; - } -#endif - } - return (swig_module_info *) type_pointer; -} - -#if PY_MAJOR_VERSION < 2 -/* PyModule_AddObject function was introduced in Python 2.0. The following function - is copied out of Python/modsupport.c in python version 2.3.4 */ -SWIGINTERN int -PyModule_AddObject(PyObject *m, char *name, PyObject *o) -{ - PyObject *dict; - if (!PyModule_Check(m)) { - PyErr_SetString(PyExc_TypeError, - "PyModule_AddObject() needs module as first arg"); - return SWIG_ERROR; - } - if (!o) { - PyErr_SetString(PyExc_TypeError, - "PyModule_AddObject() needs non-NULL value"); - return SWIG_ERROR; - } - - dict = PyModule_GetDict(m); - if (dict == NULL) { - /* Internal error -- modules must have a dict! */ - PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__", - PyModule_GetName(m)); - return SWIG_ERROR; - } - if (PyDict_SetItemString(dict, name, o)) - return SWIG_ERROR; - Py_DECREF(o); - return SWIG_OK; -} -#endif - -SWIGRUNTIME void -SWIG_Python_DestroyModule(void *vptr) -{ - swig_module_info *swig_module = (swig_module_info *) vptr; - swig_type_info **types = swig_module->types; - size_t i; - for (i =0; i < swig_module->size; ++i) { - swig_type_info *ty = types[i]; - if (ty->owndata) { - SwigPyClientData *data = (SwigPyClientData *) ty->clientdata; - if (data) SwigPyClientData_Del(data); - } - } - Py_DECREF(SWIG_This()); - swig_this = NULL; -} - -SWIGRUNTIME void -SWIG_Python_SetModule(swig_module_info *swig_module) { - static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} };/* Sentinel */ - -#if PY_VERSION_HEX >= 0x03000000 - /* Add a dummy module object into sys.modules */ - PyObject *module = PyImport_AddModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION); -#else - PyObject *module = Py_InitModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, - swig_empty_runtime_method_table); -#endif - PyObject *pointer = PyCObject_FromVoidPtr((void *) swig_module, SWIG_Python_DestroyModule); - if (pointer && module) { - PyModule_AddObject(module, (char*)"type_pointer" SWIG_TYPE_TABLE_NAME, pointer); - } else { - Py_XDECREF(pointer); - } -} - -/* The python cached type query */ -SWIGRUNTIME PyObject * -SWIG_Python_TypeCache(void) { - static PyObject *SWIG_STATIC_POINTER(cache) = PyDict_New(); - return cache; -} - -SWIGRUNTIME swig_type_info * -SWIG_Python_TypeQuery(const char *type) -{ - PyObject *cache = SWIG_Python_TypeCache(); - PyObject *key = SWIG_Python_str_FromChar(type); - PyObject *obj = PyDict_GetItem(cache, key); - swig_type_info *descriptor; - if (obj) { - descriptor = (swig_type_info *) PyCObject_AsVoidPtr(obj); - } else { - swig_module_info *swig_module = SWIG_Python_GetModule(); - descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type); - if (descriptor) { - obj = PyCObject_FromVoidPtr(descriptor, NULL); - PyDict_SetItem(cache, key, obj); - Py_DECREF(obj); - } - } - Py_DECREF(key); - return descriptor; -} - -/* - For backward compatibility only -*/ -#define SWIG_POINTER_EXCEPTION 0 -#define SWIG_arg_fail(arg) SWIG_Python_ArgFail(arg) -#define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags) - -SWIGRUNTIME int -SWIG_Python_AddErrMesg(const char* mesg, int infront) -{ - if (PyErr_Occurred()) { - PyObject *type = 0; - PyObject *value = 0; - PyObject *traceback = 0; - PyErr_Fetch(&type, &value, &traceback); - if (value) { - char *tmp; - PyObject *old_str = PyObject_Str(value); - Py_XINCREF(type); - PyErr_Clear(); - if (infront) { - PyErr_Format(type, "%s %s", mesg, tmp = SWIG_Python_str_AsChar(old_str)); - } else { - PyErr_Format(type, "%s %s", tmp = SWIG_Python_str_AsChar(old_str), mesg); - } - SWIG_Python_str_DelForPy3(tmp); - Py_DECREF(old_str); - } - return 1; - } else { - return 0; - } -} - -SWIGRUNTIME int -SWIG_Python_ArgFail(int argnum) -{ - if (PyErr_Occurred()) { - /* add information about failing argument */ - char mesg[256]; - PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum); - return SWIG_Python_AddErrMesg(mesg, 1); - } else { - return 0; - } -} - -SWIGRUNTIMEINLINE const char * -SwigPyObject_GetDesc(PyObject *self) -{ - SwigPyObject *v = (SwigPyObject *)self; - swig_type_info *ty = v ? v->ty : 0; - return ty ? ty->str : (char*)""; -} - -SWIGRUNTIME void -SWIG_Python_TypeError(const char *type, PyObject *obj) -{ - if (type) { -#if defined(SWIG_COBJECT_TYPES) - if (obj && SwigPyObject_Check(obj)) { - const char *otype = (const char *) SwigPyObject_GetDesc(obj); - if (otype) { - PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'SwigPyObject(%s)' is received", - type, otype); - return; - } - } else -#endif - { - const char *otype = (obj ? obj->ob_type->tp_name : 0); - if (otype) { - PyObject *str = PyObject_Str(obj); - const char *cstr = str ? SWIG_Python_str_AsChar(str) : 0; - if (cstr) { - PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received", - type, otype, cstr); - SWIG_Python_str_DelForPy3(cstr); - } else { - PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received", - type, otype); - } - Py_XDECREF(str); - return; - } - } - PyErr_Format(PyExc_TypeError, "a '%s' is expected", type); - } else { - PyErr_Format(PyExc_TypeError, "unexpected type is received"); - } -} - - -/* Convert a pointer value, signal an exception on a type mismatch */ -SWIGRUNTIME void * -SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) { - void *result; - if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) { - PyErr_Clear(); -#if SWIG_POINTER_EXCEPTION - if (flags) { - SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj); - SWIG_Python_ArgFail(argnum); - } -#endif - } - 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; - PyObject *descr; - descrsetfunc f; - int res = -1; - -#ifdef Py_USING_UNICODE - if (PyString_Check(name)) { - name = PyUnicode_Decode(PyString_AsString(name), PyString_Size(name), NULL, NULL); - if (name == NULL) - return -1; - } else if (!PyUnicode_Check(name)) { -#else - if (!PyString_Check(name)) { -#endif - PyErr_Format(PyExc_TypeError, - "attribute name must be string, not '%.200s'", - name->ob_type->tp_name); - return -1; - } else { - Py_INCREF(name); - } - - if (tp->tp_dict == NULL) { - if (PyType_Ready(tp) < 0) - goto done; - } - - descr = _PyType_Lookup(tp, name); - f = NULL; - if (descr != NULL) - f = descr->ob_type->tp_descr_set; - if (f == NULL) { - PyErr_Format(PyExc_AttributeError, -#ifdef Py_USING_UNICODE - "'%.100s' object has no attribute '%.200U'", -#else - "'%.100s' object has no attribute '%.200S'", -#endif - tp->tp_name, name); - } else { - res = f(descr, obj, value); - } - - done: - Py_DECREF(name); - return res; - } - - -#ifdef __cplusplus -#if 0 -{ /* cc-mode */ -#endif -} -#endif - -#define PYSWIG_UNARYFUNC_CLOSURE(wrapper) \ -SWIGINTERN PyObject* \ -wrapper##_closure (PyObject *a) \ -{ \ - return wrapper(a, NULL); \ -} - -#define PYSWIG_DESTRUCTOR_CLOSURE(wrapper) \ -SWIGINTERN void \ -wrapper##_closure (PyObject *a) \ -{ \ - SwigPyObject *sobj = (SwigPyObject*) a; \ - if (sobj->own) { \ - PyObject *o = wrapper(a, NULL); \ - Py_XDECREF(o); \ - } \ -} - -#define PYSWIG_INQUIRY_CLOSURE(wrapper) \ -SWIGINTERN int \ -wrapper##_closure (PyObject *a) \ -{ \ - PyObject *pyresult = wrapper(a, NULL); \ - int result = pyresult && PyObject_IsTrue(pyresult) ? 1 : 0; \ - Py_XDECREF(pyresult); \ - return result; \ -} - -#define PYSWIG_BINARYFUNC_CLOSURE(wrapper) \ -SWIGINTERN PyObject* \ -wrapper##_closure (PyObject *a, PyObject *b) \ -{ \ - PyObject *tuple = PyTuple_New(1); \ - assert(tuple); \ - PyTuple_SET_ITEM(tuple, 0, b); \ - Py_XINCREF(b); \ - PyObject *result = wrapper(a, tuple); \ - Py_DECREF(tuple); \ - return result; \ -} - -#define PYSWIG_TERNARYFUNC_CLOSURE(wrapper) \ -SWIGINTERN PyObject* \ -wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \ -{ \ - PyObject *tuple = PyTuple_New(2); \ - assert(tuple); \ - PyTuple_SET_ITEM(tuple, 0, b); \ - PyTuple_SET_ITEM(tuple, 1, c); \ - Py_XINCREF(b); \ - Py_XINCREF(c); \ - PyObject *result = wrapper(a, tuple); \ - Py_DECREF(tuple); \ - return result; \ -} - -#define PYSWIG_LENFUNC_CLOSURE(wrapper) \ -SWIGINTERN Py_ssize_t \ -wrapper##_closure (PyObject *a) \ -{ \ - PyObject *resultobj = wrapper(a, NULL); \ - Py_ssize_t result = PyNumber_AsSsize_t(resultobj, NULL); \ - Py_DECREF(resultobj); \ - return result; \ -} - -#define PYSWIG_SSIZESSIZEARGFUNC_CLOSURE(wrapper) \ -SWIGINTERN PyObject* \ -wrapper##_closure (PyObject *a, Py_ssize_t b, Py_ssize_t c) \ -{ \ - PyObject *tuple = PyTuple_New(2); \ - assert(tuple); \ - PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \ - PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c)); \ - PyObject *result = wrapper(a, tuple); \ - Py_DECREF(tuple); \ - return result; \ -} - -#define PYSWIG_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); \ - assert(tuple); \ - PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \ - PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c)); \ - if (d) { \ - PyTuple_SET_ITEM(tuple, 2, d); \ - Py_INCREF(d); \ - } \ - PyObject *resultobj = wrapper(a, tuple); \ - int result = resultobj ? 0 : -1; \ - Py_DECREF(tuple); \ - Py_XDECREF(resultobj); \ - return result; \ -} - -#define PYSWIG_SSIZEARGFUNC_CLOSURE(wrapper) \ -SWIGINTERN PyObject* \ -wrapper##_closure (PyObject *a, Py_ssize_t b) \ -{ \ - PyObject *tuple = PyTuple_New(1); \ - assert(tuple); \ - PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \ - PyObject *result = wrapper(a, tuple); \ - Py_DECREF(tuple); \ - return result; \ -} - -#define PYSWIG_FUNPACK_SSIZEARGFUNC_CLOSURE(wrapper) \ -SWIGINTERN PyObject* \ -wrapper##_closure (PyObject *a, Py_ssize_t b) \ -{ \ - PyObject *arg = _PyLong_FromSsize_t(b); \ - PyObject *result = wrapper(a, arg); \ - Py_DECREF(arg); \ - return result; \ -} - -#define PYSWIG_SSIZEOBJARGPROC_CLOSURE(wrapper) \ -SWIGINTERN int \ -wrapper##_closure (PyObject *a, Py_ssize_t b, PyObject *c) \ -{ \ - PyObject *tuple = PyTuple_New(2); \ - assert(tuple); \ - PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \ - PyTuple_SET_ITEM(tuple, 1, c); \ - Py_XINCREF(c); \ - PyObject *resultobj = wrapper(a, tuple); \ - int result = resultobj ? 0 : -1; \ - Py_XDECREF(resultobj); \ - Py_DECREF(tuple); \ - return result; \ -} - -#define PYSWIG_OBJOBJARGPROC_CLOSURE(wrapper) \ -SWIGINTERN int \ -wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \ -{ \ - PyObject *tuple = PyTuple_New(c ? 2 : 1); \ - assert(tuple); \ - PyTuple_SET_ITEM(tuple, 0, b); \ - Py_XINCREF(b); \ - if (c) { \ - PyTuple_SET_ITEM(tuple, 1, c); \ - Py_XINCREF(c); \ - } \ - PyObject *resultobj = wrapper(a, tuple); \ - int result = resultobj ? 0 : -1; \ - Py_XDECREF(resultobj); \ - Py_DECREF(tuple); \ - return result; \ -} - -#define PYSWIG_REPRFUNC_CLOSURE(wrapper) \ -SWIGINTERN PyObject* \ -wrapper##_closure (PyObject *a) \ -{ \ - return wrapper(a, NULL); \ -} - -#define PYSWIG_HASHFUNC_CLOSURE(wrapper) \ -SWIGINTERN long \ -wrapper##_closure (PyObject *a) \ -{ \ - PyObject *pyresult = wrapper(a, NULL); \ - if (!pyresult || !PyLong_Check(pyresult)) \ - return -1; \ - long result = PyLong_AsLong(pyresult); \ - Py_DECREF(pyresult); \ - return result; \ -} - -#define PYSWIG_ITERNEXT_CLOSURE(wrapper) \ -SWIGINTERN PyObject* \ -wrapper##_closure (PyObject *a) \ -{ \ - PyObject *result = wrapper(a, NULL); \ - if (result && result == Py_None) { \ - Py_DECREF(result); \ - result = NULL; \ - } \ - return result; \ -} - -SWIGRUNTIME int py_builtin_bad_init (PyObject *self, PyObject *args, PyObject *kwds) -{ - PyErr_Format(PyExc_TypeError, "Cannot create new instances of type '%.300s'", self->ob_type->tp_name); - return -1; -} - -SWIGRUNTIME void py_builtin_bad_dealloc (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); - } -} - -typedef struct { - PyCFunction get; - PyCFunction set; -} SwigPyGetSet; - -SWIGRUNTIME PyObject* -pyswig_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; -} - -SWIGRUNTIME PyObject* -pyswig_funpack_getter_closure (PyObject *obj, void *closure) -{ - if (!closure) - return SWIG_Py_Void(); - SwigPyGetSet *getset = (SwigPyGetSet*) closure; - if (!getset->get) - return SWIG_Py_Void(); - PyObject *result = (*getset->get)(obj, NULL); - return result; -} - -SWIGRUNTIME int -pyswig_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 member variable assignment in type '%.300s'", obj->ob_type->tp_name); - 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; -} - -SWIGRUNTIME int -pyswig_funpack_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 member variable assignment in type '%.300s'", obj->ob_type->tp_name); - return -1; - } - PyObject *result = (*getset->set)(obj, val); - Py_XDECREF(result); - return result ? 0 : -1; -} - -SWIGRUNTIME 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; -} - -SWIGRUNTIME 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; -} - -SWIGRUNTIME void -SwigPyStaticVar_dealloc(PyDescrObject *descr) -{ - _PyObject_GC_UNTRACK(descr); - Py_XDECREF(descr->d_type); - Py_XDECREF(descr->d_name); - PyObject_GC_Del(descr); -} - -SWIGRUNTIME PyObject * -SwigPyStaticVar_repr(PyGetSetDescrObject *descr) -{ -#if PY_VERSION_HEX >= 0x03000000 - 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 -} - -SWIGRUNTIME int -SwigPyStaticVar_traverse(PyObject *self, visitproc visit, void *arg) -{ - PyDescrObject *descr = (PyDescrObject *)self; - Py_VISIT(descr->d_type); - return 0; -} - -SWIGRUNTIME PyObject * -SwigPyStaticVar_get (PyGetSetDescrObject *descr, PyObject *obj, PyObject *type) -{ - if (descr->d_getset->get != NULL) - return descr->d_getset->get(obj, descr->d_getset->closure); -#if PY_VERSION_HEX >= 0x03000000 - PyErr_Format(PyExc_AttributeError, - "attribute '%.300U' of '%.100s' objects is not readable", - descr->d_name, descr->d_type->tp_name); -#else - PyErr_Format(PyExc_AttributeError, - "attribute '%.300s' of '%.100s' objects is not readable", - PyString_AsString(descr->d_name), descr->d_type->tp_name); -#endif - return NULL; -} - -SWIGRUNTIME int -SwigPyStaticVar_set (PyGetSetDescrObject *descr, PyObject *obj, PyObject *value) -{ - int res; - - if (descr->d_getset->set != NULL) - return descr->d_getset->set(obj, value, descr->d_getset->closure); -#if PY_VERSION_HEX >= 0x03000000 - PyErr_Format(PyExc_AttributeError, - "attribute '%.300U' of '%.100s' objects is not writable", - descr->d_name, - descr->d_type->tp_name); -#else - PyErr_Format(PyExc_AttributeError, - "attribute '%.300s' of '%.100s' objects is not writable", - PyString_AsString(descr->d_name), - descr->d_type->tp_name); -#endif - return -1; -} - -SWIGRUNTIME PyTypeObject SwigPyStaticVar_Type = { -#if PY_VERSION_HEX >= 0x03000000 - PyVarObject_HEAD_INIT(&PyType_Type, 0) -#else - PyObject_HEAD_INIT(&PyType_Type) - 0, -#endif - "swig_static_var_getset_descriptor", - sizeof(PyGetSetDescrObject), - 0, - (destructor)SwigPyStaticVar_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - (reprfunc)SwigPyStaticVar_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_HAVE_CLASS, /* tp_flags */ - 0, /* tp_doc */ - SwigPyStaticVar_traverse, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - (descrgetfunc)SwigPyStaticVar_get, /* tp_descr_get */ - (descrsetfunc)SwigPyStaticVar_set, /* tp_descr_set */ -}; - -SWIGRUNTIME int -SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value) -{ - PyObject *attribute = _PyType_Lookup(type, name); - if (attribute != NULL) { - /* Implement descriptor functionality, if any */ - descrsetfunc local_set = attribute->ob_type->tp_descr_set; - if (local_set != NULL) - return local_set(attribute, (PyObject*) type, value); -#if PY_VERSION_HEX >= 0x03000000 - PyErr_Format(PyExc_AttributeError, - "cannot modify read-only attribute '%.50s.%.400U'", - type->tp_name, name); -#else - PyErr_Format(PyExc_AttributeError, - "cannot modify read-only attribute '%.50s.%.400s'", - type->tp_name, PyString_AS_STRING(name)); -#endif - } else { -#if PY_VERSION_HEX >= 0x03000000 - PyErr_Format(PyExc_AttributeError, - "type '%.50s' has no attribute '%.400U'", - type->tp_name, name); -#else - PyErr_Format(PyExc_AttributeError, - "type '%.50s' has no attribute '%.400s'", - type->tp_name, PyString_AS_STRING(name)); -#endif - } - - return -1; -} - -SWIGINTERN PyGetSetDescrObject* -SwigPyStaticVar_new_getset (PyTypeObject *type, PyGetSetDef *getset) -{ - PyGetSetDescrObject *descr = (PyGetSetDescrObject*) PyType_GenericAlloc(&SwigPyStaticVar_Type, 0); - assert(descr); - Py_XINCREF(type); - descr->d_type = type; - descr->d_name = PyString_InternFromString(getset->name); - descr->d_getset = getset; - if (descr->d_name == NULL) { - Py_DECREF(descr); - descr = NULL; - } - return descr; -} - -#ifdef __cplusplus - -#include - -SWIGINTERN void -pyswig_builtin_init_bases (PyTypeObject *type, std::vector& bases) -{ - if (!bases.size()) - bases.push_back(SwigPyObject_type()); - 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) { - PyTuple_SET_ITEM(tuple, i, (PyObject*) bases[i]); - Py_INCREF((PyObject*) bases[i]); - } - type->tp_bases = tuple; -} - -SWIGINTERN PyObject* -pyswig_this_closure (PyObject *self, void *closure) -{ - PyObject *result = (PyObject*) SWIG_Python_GetSwigThis(self); - Py_XINCREF(result); - return result; -} - -#endif - - - -#define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) - -#define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } else - - - -/* -------- TYPES TABLE (BEGIN) -------- */ - -#define SWIGTYPE_p_A swig_types[0] -#define SWIGTYPE_p_B swig_types[1] -#define SWIGTYPE_p_C swig_types[2] -#define SWIGTYPE_p_D swig_types[3] -#define SWIGTYPE_p_E swig_types[4] -#define SWIGTYPE_p_F swig_types[5] -#define SWIGTYPE_p_G swig_types[6] -#define SWIGTYPE_p_H swig_types[7] -#define SWIGTYPE_p_SwigPyObject swig_types[8] -#define SWIGTYPE_p_char swig_types[9] -static swig_type_info *swig_types[11]; -static swig_module_info swig_module = {swig_types, 10, 0, 0, 0, 0}; -#define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) -#define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) - -/* -------- TYPES TABLE (END) -------- */ - -#if (PY_VERSION_HEX <= 0x02000000) -# if !defined(SWIG_PYTHON_CLASSIC) -# error "This python version requires swig to be run with the '-classic' option" -# endif -#endif -#if (PY_VERSION_HEX <= 0x02020000) -# error "This python version requires swig to be run with the '-nomodern' option" -#endif -#if (PY_VERSION_HEX <= 0x02020000) -# error "This python version requires swig to be run with the '-nomodernargs' option" -#endif -#ifndef METH_O -# error "This python version requires swig to be run with the '-nofastunpack' option" -#endif -#ifdef SWIG_TypeQuery -# undef SWIG_TypeQuery -#endif -#define SWIG_TypeQuery SWIG_Python_TypeQuery - -/*----------------------------------------------- - @(target):= _Simple_builtin.so - ------------------------------------------------*/ -#if PY_VERSION_HEX >= 0x03000000 -# define SWIG_init PyInit__Simple_builtin - -#else -# define SWIG_init init_Simple_builtin - -#endif -#define SWIG_name "_Simple_builtin" - -#define SWIGVERSION 0x020002 -#define SWIG_VERSION SWIGVERSION - - -#define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a)) -#define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),reinterpret_cast< void** >(a)) - - -#include - - -namespace swig { - class SwigPtr_PyObject { - protected: - PyObject *_obj; - - public: - SwigPtr_PyObject() :_obj(0) - { - } - - SwigPtr_PyObject(const SwigPtr_PyObject& item) : _obj(item._obj) - { - Py_XINCREF(_obj); - } - - SwigPtr_PyObject(PyObject *obj, bool initial_ref = true) :_obj(obj) - { - if (initial_ref) { - Py_XINCREF(_obj); - } - } - - SwigPtr_PyObject & operator=(const SwigPtr_PyObject& item) - { - Py_XINCREF(item._obj); - Py_XDECREF(_obj); - _obj = item._obj; - return *this; - } - - ~SwigPtr_PyObject() - { - Py_XDECREF(_obj); - } - - operator PyObject *() const - { - return _obj; - } - - PyObject *operator->() const - { - return _obj; - } - }; -} - - -namespace swig { - struct SwigVar_PyObject : SwigPtr_PyObject { - SwigVar_PyObject(PyObject* obj = 0) : SwigPtr_PyObject(obj, false) { } - - SwigVar_PyObject & operator = (PyObject* obj) - { - Py_XDECREF(_obj); - _obj = obj; - return *this; - } - }; -} - - - -class A { -public: - A () {} - ~A () {} - void func () {} - A& operator+= (int i) { return *this; } -}; - -class B : public A { -public: - B () {} - ~B () {} -}; - -class C : public B { -public: - C () {} - ~C () {} -}; - -class D : public C { -public: - D () {} - ~D () {} -}; - -class E : public D { -public: - E () {} - ~E () {} -}; - -class F : public E { -public: - F () {} - ~F () {} -}; - -class G : public F { -public: - G () {} - ~G () {} -}; - -class H : public G { -public: - H () {} - ~H () {} -}; - - - -#include -#if !defined(SWIG_NO_LLONG_MAX) -# if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__) -# define LLONG_MAX __LONG_LONG_MAX__ -# define LLONG_MIN (-LLONG_MAX - 1LL) -# define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL) -# endif -#endif - - -SWIGINTERN int -SWIG_AsVal_double (PyObject *obj, double *val) -{ - int res = SWIG_TypeError; - if (PyFloat_Check(obj)) { - if (val) *val = PyFloat_AsDouble(obj); - return SWIG_OK; - } else if (PyInt_Check(obj)) { - if (val) *val = PyInt_AsLong(obj); - return SWIG_OK; - } else if (PyLong_Check(obj)) { - double v = PyLong_AsDouble(obj); - if (!PyErr_Occurred()) { - if (val) *val = v; - return SWIG_OK; - } else { - PyErr_Clear(); - } - } -#ifdef SWIG_PYTHON_CAST_MODE - { - int dispatch = 0; - double d = PyFloat_AsDouble(obj); - if (!PyErr_Occurred()) { - if (val) *val = d; - return SWIG_AddCast(SWIG_OK); - } else { - PyErr_Clear(); - } - if (!dispatch) { - long v = PyLong_AsLong(obj); - if (!PyErr_Occurred()) { - if (val) *val = v; - return SWIG_AddCast(SWIG_AddCast(SWIG_OK)); - } else { - PyErr_Clear(); - } - } - } -#endif - return res; -} - - -#include - - -#include - - -SWIGINTERNINLINE int -SWIG_CanCastAsInteger(double *d, double min, double max) { - double x = *d; - if ((min <= x && x <= max)) { - double fx = floor(x); - double cx = ceil(x); - double rd = ((x - fx) < 0.5) ? fx : cx; /* simple rint */ - if ((errno == EDOM) || (errno == ERANGE)) { - errno = 0; - } else { - double summ, reps, diff; - if (rd < x) { - diff = x - rd; - } else if (rd > x) { - diff = rd - x; - } else { - return 1; - } - summ = rd + x; - reps = diff/summ; - if (reps < 8*DBL_EPSILON) { - *d = rd; - return 1; - } - } - } - return 0; -} - - -SWIGINTERN int -SWIG_AsVal_long (PyObject *obj, long* val) -{ - if (PyInt_Check(obj)) { - if (val) *val = PyInt_AsLong(obj); - return SWIG_OK; - } else if (PyLong_Check(obj)) { - long v = PyLong_AsLong(obj); - if (!PyErr_Occurred()) { - if (val) *val = v; - return SWIG_OK; - } else { - PyErr_Clear(); - } - } -#ifdef SWIG_PYTHON_CAST_MODE - { - int dispatch = 0; - long v = PyInt_AsLong(obj); - if (!PyErr_Occurred()) { - if (val) *val = v; - return SWIG_AddCast(SWIG_OK); - } else { - PyErr_Clear(); - } - if (!dispatch) { - double d; - int res = SWIG_AddCast(SWIG_AsVal_double (obj,&d)); - if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, LONG_MAX)) { - if (val) *val = (long)(d); - return res; - } - } - } -#endif - return SWIG_TypeError; -} - - -SWIGINTERN int -SWIG_AsVal_int (PyObject * obj, int *val) -{ - long v; - int res = SWIG_AsVal_long (obj, &v); - if (SWIG_IsOK(res)) { - if ((v < INT_MIN || v > INT_MAX)) { - return SWIG_OverflowError; - } else { - if (val) *val = static_cast< int >(v); - } - } - return res; -} - -SWIGINTERN void -SWIG_Python_builtin_imports() -{ - PyObject *import_str = NULL; -} -#ifdef __cplusplus -extern "C" { -#endif -SWIGINTERN int _wrap_new_A(PyObject *self, PyObject *args) { - int resultobj = 0; - A *result = 0 ; - - if (!SWIG_Python_UnpackTuple(args,"new_A",0,0,0)) SWIG_fail; - result = (A *)new A(); - - resultobj = SWIG_Python_NewBuiltinObj(self, SWIG_as_voidptr(result), SWIGTYPE_p_A, SWIG_POINTER_NEW | 0 ); - return resultobj; -fail: - return -1; -} - - -SWIGINTERN PyObject *_wrap_delete_A(PyObject *self, PyObject *args) { - PyObject *resultobj = 0; - A *arg1 = (A *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!SWIG_Python_UnpackTuple(args,"delete_A",0,0,0)) SWIG_fail; - res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_A, SWIG_POINTER_DISOWN | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_A" "', argument " "1"" of type '" "A *""'"); - } - arg1 = reinterpret_cast< A * >(argp1); - delete arg1; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_A_func(PyObject *self, PyObject *args) { - PyObject *resultobj = 0; - A *arg1 = (A *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!SWIG_Python_UnpackTuple(args,"A_func",0,0,0)) SWIG_fail; - res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_A, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "A_func" "', argument " "1"" of type '" "A *""'"); - } - arg1 = reinterpret_cast< A * >(argp1); - (arg1)->func(); - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *_wrap_A___iadd__(PyObject *self, PyObject *args) { - PyObject *resultobj = 0; - A *arg1 = (A *) 0 ; - int arg2 ; - void *argp1 = 0 ; - int res1 = 0 ; - int val2 ; - int ecode2 = 0 ; - PyObject *swig_obj[2] ; - A *result = 0 ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_A, SWIG_POINTER_DISOWN | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "A___iadd__" "', argument " "1"" of type '" "A *""'"); - } - arg1 = reinterpret_cast< A * >(argp1); - ecode2 = SWIG_AsVal_int(swig_obj[0], &val2); - if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "A___iadd__" "', argument " "2"" of type '" "int""'"); - } - arg2 = static_cast< int >(val2); - result = (A *) &(arg1)->operator +=(arg2); - resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_A, SWIG_POINTER_OWN | 0 ); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN int _wrap_new_B(PyObject *self, PyObject *args) { - int resultobj = 0; - B *result = 0 ; - - if (!SWIG_Python_UnpackTuple(args,"new_B",0,0,0)) SWIG_fail; - result = (B *)new B(); - - resultobj = SWIG_Python_NewBuiltinObj(self, SWIG_as_voidptr(result), SWIGTYPE_p_B, SWIG_POINTER_NEW | 0 ); - return resultobj; -fail: - return -1; -} - - -SWIGINTERN PyObject *_wrap_delete_B(PyObject *self, PyObject *args) { - PyObject *resultobj = 0; - B *arg1 = (B *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!SWIG_Python_UnpackTuple(args,"delete_B",0,0,0)) SWIG_fail; - res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_B, SWIG_POINTER_DISOWN | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_B" "', argument " "1"" of type '" "B *""'"); - } - arg1 = reinterpret_cast< B * >(argp1); - delete arg1; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN int _wrap_new_C(PyObject *self, PyObject *args) { - int resultobj = 0; - C *result = 0 ; - - if (!SWIG_Python_UnpackTuple(args,"new_C",0,0,0)) SWIG_fail; - result = (C *)new C(); - - resultobj = SWIG_Python_NewBuiltinObj(self, SWIG_as_voidptr(result), SWIGTYPE_p_C, SWIG_POINTER_NEW | 0 ); - return resultobj; -fail: - return -1; -} - - -SWIGINTERN PyObject *_wrap_delete_C(PyObject *self, PyObject *args) { - PyObject *resultobj = 0; - C *arg1 = (C *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!SWIG_Python_UnpackTuple(args,"delete_C",0,0,0)) SWIG_fail; - res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_C, SWIG_POINTER_DISOWN | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_C" "', argument " "1"" of type '" "C *""'"); - } - arg1 = reinterpret_cast< C * >(argp1); - delete arg1; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN int _wrap_new_D(PyObject *self, PyObject *args) { - int resultobj = 0; - D *result = 0 ; - - if (!SWIG_Python_UnpackTuple(args,"new_D",0,0,0)) SWIG_fail; - result = (D *)new D(); - - resultobj = SWIG_Python_NewBuiltinObj(self, SWIG_as_voidptr(result), SWIGTYPE_p_D, SWIG_POINTER_NEW | 0 ); - return resultobj; -fail: - return -1; -} - - -SWIGINTERN PyObject *_wrap_delete_D(PyObject *self, PyObject *args) { - PyObject *resultobj = 0; - D *arg1 = (D *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!SWIG_Python_UnpackTuple(args,"delete_D",0,0,0)) SWIG_fail; - res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_D, SWIG_POINTER_DISOWN | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_D" "', argument " "1"" of type '" "D *""'"); - } - arg1 = reinterpret_cast< D * >(argp1); - delete arg1; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN int _wrap_new_E(PyObject *self, PyObject *args) { - int resultobj = 0; - E *result = 0 ; - - if (!SWIG_Python_UnpackTuple(args,"new_E",0,0,0)) SWIG_fail; - result = (E *)new E(); - - resultobj = SWIG_Python_NewBuiltinObj(self, SWIG_as_voidptr(result), SWIGTYPE_p_E, SWIG_POINTER_NEW | 0 ); - return resultobj; -fail: - return -1; -} - - -SWIGINTERN PyObject *_wrap_delete_E(PyObject *self, PyObject *args) { - PyObject *resultobj = 0; - E *arg1 = (E *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!SWIG_Python_UnpackTuple(args,"delete_E",0,0,0)) SWIG_fail; - res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_E, SWIG_POINTER_DISOWN | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_E" "', argument " "1"" of type '" "E *""'"); - } - arg1 = reinterpret_cast< E * >(argp1); - delete arg1; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN int _wrap_new_F(PyObject *self, PyObject *args) { - int resultobj = 0; - F *result = 0 ; - - if (!SWIG_Python_UnpackTuple(args,"new_F",0,0,0)) SWIG_fail; - result = (F *)new F(); - - resultobj = SWIG_Python_NewBuiltinObj(self, SWIG_as_voidptr(result), SWIGTYPE_p_F, SWIG_POINTER_NEW | 0 ); - return resultobj; -fail: - return -1; -} - - -SWIGINTERN PyObject *_wrap_delete_F(PyObject *self, PyObject *args) { - PyObject *resultobj = 0; - F *arg1 = (F *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!SWIG_Python_UnpackTuple(args,"delete_F",0,0,0)) SWIG_fail; - res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_F, SWIG_POINTER_DISOWN | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_F" "', argument " "1"" of type '" "F *""'"); - } - arg1 = reinterpret_cast< F * >(argp1); - delete arg1; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN int _wrap_new_G(PyObject *self, PyObject *args) { - int resultobj = 0; - G *result = 0 ; - - if (!SWIG_Python_UnpackTuple(args,"new_G",0,0,0)) SWIG_fail; - result = (G *)new G(); - - resultobj = SWIG_Python_NewBuiltinObj(self, SWIG_as_voidptr(result), SWIGTYPE_p_G, SWIG_POINTER_NEW | 0 ); - return resultobj; -fail: - return -1; -} - - -SWIGINTERN PyObject *_wrap_delete_G(PyObject *self, PyObject *args) { - PyObject *resultobj = 0; - G *arg1 = (G *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!SWIG_Python_UnpackTuple(args,"delete_G",0,0,0)) SWIG_fail; - res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_G, SWIG_POINTER_DISOWN | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_G" "', argument " "1"" of type '" "G *""'"); - } - arg1 = reinterpret_cast< G * >(argp1); - delete arg1; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN int _wrap_new_H(PyObject *self, PyObject *args) { - int resultobj = 0; - H *result = 0 ; - - if (!SWIG_Python_UnpackTuple(args,"new_H",0,0,0)) SWIG_fail; - result = (H *)new H(); - - resultobj = SWIG_Python_NewBuiltinObj(self, SWIG_as_voidptr(result), SWIGTYPE_p_H, SWIG_POINTER_NEW | 0 ); - return resultobj; -fail: - return -1; -} - - -SWIGINTERN PyObject *_wrap_delete_H(PyObject *self, PyObject *args) { - PyObject *resultobj = 0; - H *arg1 = (H *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!SWIG_Python_UnpackTuple(args,"delete_H",0,0,0)) SWIG_fail; - res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_H, SWIG_POINTER_DISOWN | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_H" "', argument " "1"" of type '" "H *""'"); - } - arg1 = reinterpret_cast< H * >(argp1); - delete arg1; - resultobj = SWIG_Py_Void(); - return resultobj; -fail: - return NULL; -} - - -static PyMethodDef SwigMethods[] = { - { (char *)"SWIG_PyInstanceMethod_New", (PyCFunction)SWIG_PyInstanceMethod_New, METH_O, NULL}, - { NULL, NULL, 0, NULL } -}; - -#ifdef __cplusplus -namespace { -#endif - -PYSWIG_DESTRUCTOR_CLOSURE(_wrap_delete_A); -SWIGINTERN PyGetSetDef SwigPyBuiltin__A_getset[] = { - {NULL} // Sentinel -}; - -SWIGINTERN PyObject* -SwigPyBuiltin__A_richcompare (PyObject *self, PyObject *other, int op) -{ - PyObject *result = NULL; - switch (op) { - default : break; - } - if (result == NULL) { - if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) { - result = SwigPyObject_richcompare((SwigPyObject*) self, (SwigPyObject*) other, op); - } else { - result = Py_NotImplemented; - Py_INCREF(result); - } - } - return result; -} - -SWIGINTERN PyMethodDef SwigPyBuiltin__A_methods[] = { - { "func", (PyCFunction) _wrap_A_func, METH_NOARGS, "" }, - { "__iadd__", (PyCFunction) _wrap_A___iadd__, METH_O, "" }, - {NULL} // Sentinel -}; - -static PyHeapTypeObject SwigPyBuiltin__A_type = { - { -#if PY_VERSION_HEX >= 0x03000000 - PyVarObject_HEAD_INIT(&PyType_Type, 0) -#else - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ -#endif - "A", /*tp_name*/ - sizeof(SwigPyObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - _wrap_delete_A_closure, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - &SwigPyBuiltin__A_type.as_number, /*tp_as_number*/ - &SwigPyBuiltin__A_type.as_sequence, /*tp_as_sequence*/ - &SwigPyBuiltin__A_type.as_mapping, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &SwigPyBuiltin__A_type.as_buffer, /*tp_as_buffer*/ -#if PY_VERSION_HEX >= 0x03000000 - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/ -#else - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ -#endif - "::A", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - SwigPyBuiltin__A_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc) 0, /* tp_iter */ - (iternextfunc) 0, /* tp_iternext */ - SwigPyBuiltin__A_methods, /* tp_methods */ - 0, /* tp_members */ - SwigPyBuiltin__A_getset, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */ - (initproc)_wrap_new_A, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0 /* tp_free */ - }, - { - (binaryfunc) 0, // nb_add; - (binaryfunc) 0, // nb_subtract; - (binaryfunc) 0, // nb_multiply; -#if PY_VERSION_HEX < 0x03000000 - (binaryfunc) 0, // nb_divide; -#endif - (binaryfunc) 0, // nb_remainder; - (binaryfunc) 0, // nb_divmod; - (ternaryfunc) 0, // nb_power; - (unaryfunc) 0, // nb_negative; - (unaryfunc) 0, // nb_positive; - (unaryfunc) 0, // nb_absolute; - (inquiry) 0, // nb_nonzero; - (unaryfunc) 0, // nb_invert; - (binaryfunc) 0, // nb_lshift; - (binaryfunc) 0, // nb_rshift; - (binaryfunc) 0, // nb_and; - (binaryfunc) 0, // nb_xor; - (binaryfunc) 0, // nb_or; -#if PY_VERSION_HEX < 0x03000000 - (coercion) 0, // nb_coerce; -#endif - (unaryfunc) 0, // nb_int; -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // nb_reserved; -#else - (unaryfunc) 0, // nb_long; -#endif - (unaryfunc) 0, // nb_float; -#if PY_VERSION_HEX < 0x03000000 - (unaryfunc) 0, // nb_oct; - (unaryfunc) 0, // nb_hex; -#endif - (binaryfunc) _wrap_A___iadd__, // nb_inplace_add; - (binaryfunc) 0, // nb_inplace_subtract; - (binaryfunc) 0, // nb_inplace_multiply; -#if PY_VERSION_HEX < 0x03000000 - (binaryfunc) 0, // nb_inplace_divide; -#endif - (binaryfunc) 0, // nb_inplace_remainder; - (ternaryfunc) 0, // nb_inplace_power; - (binaryfunc) 0, // nb_inplace_lshift; - (binaryfunc) 0, // nb_inplace_rshift; - (binaryfunc) 0, // nb_inplace_and; - (binaryfunc) 0, // nb_inplace_xor; - (binaryfunc) 0, // nb_inplace_or; - (binaryfunc) 0, // nb_floor_divide; - (binaryfunc) 0, // nb_true_divide; - (binaryfunc) 0, // nb_inplace_floor_divide; - (binaryfunc) 0, // nb_inplace_true_divide; - (unaryfunc) 0, // nb_index; - }, - { - (lenfunc) 0, // mp_length; - (binaryfunc) 0, // mp_subscript; - (objobjargproc) 0, // mp_ass_subscript; - }, - { - (lenfunc) 0, // sq_length - (binaryfunc) 0, // sq_concat - (ssizeargfunc) 0, // sq_repeat - (ssizeargfunc) 0, // sq_item -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // was_sq_slice -#else - (ssizessizeargfunc) 0, // sq_slice -#endif - (ssizeobjargproc) 0, // sq_ass_item -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // was_sq_ass_slice -#else - (ssizessizeobjargproc) 0, // sq_ass_slice -#endif - (objobjproc) 0, // sq_contains - (binaryfunc) 0, // sq_inplace_concat - (ssizeargfunc) 0, // sq_inplace_repeat - }, - { -#if PY_VERSION_HEX >= 0x03000000 - (getbufferproc) 0, // bf_getbuffer - (releasebufferproc) 0, // bf_releasebuffer -#else - (readbufferproc) 0, // bf_getreadbuffer - (writebufferproc) 0, // bf_getwritebuffer - (segcountproc) 0, // bf_getsegcount - (charbufferproc) 0, // bf_getcharbuffer -#endif - }, - (PyObject*) 0, // ht_name - (PyObject*) 0, // ht_slots -}; - -SWIGINTERN SwigPyClientData SwigPyBuiltin__A_clientdata = {0, 0, 0, 0, 0, 0, (PyTypeObject*) &SwigPyBuiltin__A_type}; - -PYSWIG_DESTRUCTOR_CLOSURE(_wrap_delete_B); -SWIGINTERN PyGetSetDef SwigPyBuiltin__B_getset[] = { - {NULL} // Sentinel -}; - -SWIGINTERN PyObject* -SwigPyBuiltin__B_richcompare (PyObject *self, PyObject *other, int op) -{ - PyObject *result = NULL; - switch (op) { - default : break; - } - if (result == NULL) { - if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) { - result = SwigPyObject_richcompare((SwigPyObject*) self, (SwigPyObject*) other, op); - } else { - result = Py_NotImplemented; - Py_INCREF(result); - } - } - return result; -} - -SWIGINTERN PyMethodDef SwigPyBuiltin__B_methods[] = { - {NULL} // Sentinel -}; - -static PyHeapTypeObject SwigPyBuiltin__B_type = { - { -#if PY_VERSION_HEX >= 0x03000000 - PyVarObject_HEAD_INIT(&PyType_Type, 0) -#else - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ -#endif - "B", /*tp_name*/ - sizeof(SwigPyObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - _wrap_delete_B_closure, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - &SwigPyBuiltin__B_type.as_number, /*tp_as_number*/ - &SwigPyBuiltin__B_type.as_sequence, /*tp_as_sequence*/ - &SwigPyBuiltin__B_type.as_mapping, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &SwigPyBuiltin__B_type.as_buffer, /*tp_as_buffer*/ -#if PY_VERSION_HEX >= 0x03000000 - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/ -#else - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ -#endif - "::B", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - SwigPyBuiltin__B_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc) 0, /* tp_iter */ - (iternextfunc) 0, /* tp_iternext */ - SwigPyBuiltin__B_methods, /* tp_methods */ - 0, /* tp_members */ - SwigPyBuiltin__B_getset, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */ - (initproc)_wrap_new_B, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0 /* tp_free */ - }, - { - (binaryfunc) 0, // nb_add; - (binaryfunc) 0, // nb_subtract; - (binaryfunc) 0, // nb_multiply; -#if PY_VERSION_HEX < 0x03000000 - (binaryfunc) 0, // nb_divide; -#endif - (binaryfunc) 0, // nb_remainder; - (binaryfunc) 0, // nb_divmod; - (ternaryfunc) 0, // nb_power; - (unaryfunc) 0, // nb_negative; - (unaryfunc) 0, // nb_positive; - (unaryfunc) 0, // nb_absolute; - (inquiry) 0, // nb_nonzero; - (unaryfunc) 0, // nb_invert; - (binaryfunc) 0, // nb_lshift; - (binaryfunc) 0, // nb_rshift; - (binaryfunc) 0, // nb_and; - (binaryfunc) 0, // nb_xor; - (binaryfunc) 0, // nb_or; -#if PY_VERSION_HEX < 0x03000000 - (coercion) 0, // nb_coerce; -#endif - (unaryfunc) 0, // nb_int; -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // nb_reserved; -#else - (unaryfunc) 0, // nb_long; -#endif - (unaryfunc) 0, // nb_float; -#if PY_VERSION_HEX < 0x03000000 - (unaryfunc) 0, // nb_oct; - (unaryfunc) 0, // nb_hex; -#endif - (binaryfunc) 0, // nb_inplace_add; - (binaryfunc) 0, // nb_inplace_subtract; - (binaryfunc) 0, // nb_inplace_multiply; -#if PY_VERSION_HEX < 0x03000000 - (binaryfunc) 0, // nb_inplace_divide; -#endif - (binaryfunc) 0, // nb_inplace_remainder; - (ternaryfunc) 0, // nb_inplace_power; - (binaryfunc) 0, // nb_inplace_lshift; - (binaryfunc) 0, // nb_inplace_rshift; - (binaryfunc) 0, // nb_inplace_and; - (binaryfunc) 0, // nb_inplace_xor; - (binaryfunc) 0, // nb_inplace_or; - (binaryfunc) 0, // nb_floor_divide; - (binaryfunc) 0, // nb_true_divide; - (binaryfunc) 0, // nb_inplace_floor_divide; - (binaryfunc) 0, // nb_inplace_true_divide; - (unaryfunc) 0, // nb_index; - }, - { - (lenfunc) 0, // mp_length; - (binaryfunc) 0, // mp_subscript; - (objobjargproc) 0, // mp_ass_subscript; - }, - { - (lenfunc) 0, // sq_length - (binaryfunc) 0, // sq_concat - (ssizeargfunc) 0, // sq_repeat - (ssizeargfunc) 0, // sq_item -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // was_sq_slice -#else - (ssizessizeargfunc) 0, // sq_slice -#endif - (ssizeobjargproc) 0, // sq_ass_item -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // was_sq_ass_slice -#else - (ssizessizeobjargproc) 0, // sq_ass_slice -#endif - (objobjproc) 0, // sq_contains - (binaryfunc) 0, // sq_inplace_concat - (ssizeargfunc) 0, // sq_inplace_repeat - }, - { -#if PY_VERSION_HEX >= 0x03000000 - (getbufferproc) 0, // bf_getbuffer - (releasebufferproc) 0, // bf_releasebuffer -#else - (readbufferproc) 0, // bf_getreadbuffer - (writebufferproc) 0, // bf_getwritebuffer - (segcountproc) 0, // bf_getsegcount - (charbufferproc) 0, // bf_getcharbuffer -#endif - }, - (PyObject*) 0, // ht_name - (PyObject*) 0, // ht_slots -}; - -SWIGINTERN SwigPyClientData SwigPyBuiltin__B_clientdata = {0, 0, 0, 0, 0, 0, (PyTypeObject*) &SwigPyBuiltin__B_type}; - -PYSWIG_DESTRUCTOR_CLOSURE(_wrap_delete_C); -SWIGINTERN PyGetSetDef SwigPyBuiltin__C_getset[] = { - {NULL} // Sentinel -}; - -SWIGINTERN PyObject* -SwigPyBuiltin__C_richcompare (PyObject *self, PyObject *other, int op) -{ - PyObject *result = NULL; - switch (op) { - default : break; - } - if (result == NULL) { - if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) { - result = SwigPyObject_richcompare((SwigPyObject*) self, (SwigPyObject*) other, op); - } else { - result = Py_NotImplemented; - Py_INCREF(result); - } - } - return result; -} - -SWIGINTERN PyMethodDef SwigPyBuiltin__C_methods[] = { - {NULL} // Sentinel -}; - -static PyHeapTypeObject SwigPyBuiltin__C_type = { - { -#if PY_VERSION_HEX >= 0x03000000 - PyVarObject_HEAD_INIT(&PyType_Type, 0) -#else - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ -#endif - "C", /*tp_name*/ - sizeof(SwigPyObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - _wrap_delete_C_closure, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - &SwigPyBuiltin__C_type.as_number, /*tp_as_number*/ - &SwigPyBuiltin__C_type.as_sequence, /*tp_as_sequence*/ - &SwigPyBuiltin__C_type.as_mapping, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &SwigPyBuiltin__C_type.as_buffer, /*tp_as_buffer*/ -#if PY_VERSION_HEX >= 0x03000000 - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/ -#else - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ -#endif - "::C", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - SwigPyBuiltin__C_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc) 0, /* tp_iter */ - (iternextfunc) 0, /* tp_iternext */ - SwigPyBuiltin__C_methods, /* tp_methods */ - 0, /* tp_members */ - SwigPyBuiltin__C_getset, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */ - (initproc)_wrap_new_C, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0 /* tp_free */ - }, - { - (binaryfunc) 0, // nb_add; - (binaryfunc) 0, // nb_subtract; - (binaryfunc) 0, // nb_multiply; -#if PY_VERSION_HEX < 0x03000000 - (binaryfunc) 0, // nb_divide; -#endif - (binaryfunc) 0, // nb_remainder; - (binaryfunc) 0, // nb_divmod; - (ternaryfunc) 0, // nb_power; - (unaryfunc) 0, // nb_negative; - (unaryfunc) 0, // nb_positive; - (unaryfunc) 0, // nb_absolute; - (inquiry) 0, // nb_nonzero; - (unaryfunc) 0, // nb_invert; - (binaryfunc) 0, // nb_lshift; - (binaryfunc) 0, // nb_rshift; - (binaryfunc) 0, // nb_and; - (binaryfunc) 0, // nb_xor; - (binaryfunc) 0, // nb_or; -#if PY_VERSION_HEX < 0x03000000 - (coercion) 0, // nb_coerce; -#endif - (unaryfunc) 0, // nb_int; -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // nb_reserved; -#else - (unaryfunc) 0, // nb_long; -#endif - (unaryfunc) 0, // nb_float; -#if PY_VERSION_HEX < 0x03000000 - (unaryfunc) 0, // nb_oct; - (unaryfunc) 0, // nb_hex; -#endif - (binaryfunc) 0, // nb_inplace_add; - (binaryfunc) 0, // nb_inplace_subtract; - (binaryfunc) 0, // nb_inplace_multiply; -#if PY_VERSION_HEX < 0x03000000 - (binaryfunc) 0, // nb_inplace_divide; -#endif - (binaryfunc) 0, // nb_inplace_remainder; - (ternaryfunc) 0, // nb_inplace_power; - (binaryfunc) 0, // nb_inplace_lshift; - (binaryfunc) 0, // nb_inplace_rshift; - (binaryfunc) 0, // nb_inplace_and; - (binaryfunc) 0, // nb_inplace_xor; - (binaryfunc) 0, // nb_inplace_or; - (binaryfunc) 0, // nb_floor_divide; - (binaryfunc) 0, // nb_true_divide; - (binaryfunc) 0, // nb_inplace_floor_divide; - (binaryfunc) 0, // nb_inplace_true_divide; - (unaryfunc) 0, // nb_index; - }, - { - (lenfunc) 0, // mp_length; - (binaryfunc) 0, // mp_subscript; - (objobjargproc) 0, // mp_ass_subscript; - }, - { - (lenfunc) 0, // sq_length - (binaryfunc) 0, // sq_concat - (ssizeargfunc) 0, // sq_repeat - (ssizeargfunc) 0, // sq_item -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // was_sq_slice -#else - (ssizessizeargfunc) 0, // sq_slice -#endif - (ssizeobjargproc) 0, // sq_ass_item -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // was_sq_ass_slice -#else - (ssizessizeobjargproc) 0, // sq_ass_slice -#endif - (objobjproc) 0, // sq_contains - (binaryfunc) 0, // sq_inplace_concat - (ssizeargfunc) 0, // sq_inplace_repeat - }, - { -#if PY_VERSION_HEX >= 0x03000000 - (getbufferproc) 0, // bf_getbuffer - (releasebufferproc) 0, // bf_releasebuffer -#else - (readbufferproc) 0, // bf_getreadbuffer - (writebufferproc) 0, // bf_getwritebuffer - (segcountproc) 0, // bf_getsegcount - (charbufferproc) 0, // bf_getcharbuffer -#endif - }, - (PyObject*) 0, // ht_name - (PyObject*) 0, // ht_slots -}; - -SWIGINTERN SwigPyClientData SwigPyBuiltin__C_clientdata = {0, 0, 0, 0, 0, 0, (PyTypeObject*) &SwigPyBuiltin__C_type}; - -PYSWIG_DESTRUCTOR_CLOSURE(_wrap_delete_D); -SWIGINTERN PyGetSetDef SwigPyBuiltin__D_getset[] = { - {NULL} // Sentinel -}; - -SWIGINTERN PyObject* -SwigPyBuiltin__D_richcompare (PyObject *self, PyObject *other, int op) -{ - PyObject *result = NULL; - switch (op) { - default : break; - } - if (result == NULL) { - if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) { - result = SwigPyObject_richcompare((SwigPyObject*) self, (SwigPyObject*) other, op); - } else { - result = Py_NotImplemented; - Py_INCREF(result); - } - } - return result; -} - -SWIGINTERN PyMethodDef SwigPyBuiltin__D_methods[] = { - {NULL} // Sentinel -}; - -static PyHeapTypeObject SwigPyBuiltin__D_type = { - { -#if PY_VERSION_HEX >= 0x03000000 - PyVarObject_HEAD_INIT(&PyType_Type, 0) -#else - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ -#endif - "D", /*tp_name*/ - sizeof(SwigPyObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - _wrap_delete_D_closure, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - &SwigPyBuiltin__D_type.as_number, /*tp_as_number*/ - &SwigPyBuiltin__D_type.as_sequence, /*tp_as_sequence*/ - &SwigPyBuiltin__D_type.as_mapping, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &SwigPyBuiltin__D_type.as_buffer, /*tp_as_buffer*/ -#if PY_VERSION_HEX >= 0x03000000 - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/ -#else - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ -#endif - "::D", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - SwigPyBuiltin__D_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc) 0, /* tp_iter */ - (iternextfunc) 0, /* tp_iternext */ - SwigPyBuiltin__D_methods, /* tp_methods */ - 0, /* tp_members */ - SwigPyBuiltin__D_getset, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */ - (initproc)_wrap_new_D, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0 /* tp_free */ - }, - { - (binaryfunc) 0, // nb_add; - (binaryfunc) 0, // nb_subtract; - (binaryfunc) 0, // nb_multiply; -#if PY_VERSION_HEX < 0x03000000 - (binaryfunc) 0, // nb_divide; -#endif - (binaryfunc) 0, // nb_remainder; - (binaryfunc) 0, // nb_divmod; - (ternaryfunc) 0, // nb_power; - (unaryfunc) 0, // nb_negative; - (unaryfunc) 0, // nb_positive; - (unaryfunc) 0, // nb_absolute; - (inquiry) 0, // nb_nonzero; - (unaryfunc) 0, // nb_invert; - (binaryfunc) 0, // nb_lshift; - (binaryfunc) 0, // nb_rshift; - (binaryfunc) 0, // nb_and; - (binaryfunc) 0, // nb_xor; - (binaryfunc) 0, // nb_or; -#if PY_VERSION_HEX < 0x03000000 - (coercion) 0, // nb_coerce; -#endif - (unaryfunc) 0, // nb_int; -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // nb_reserved; -#else - (unaryfunc) 0, // nb_long; -#endif - (unaryfunc) 0, // nb_float; -#if PY_VERSION_HEX < 0x03000000 - (unaryfunc) 0, // nb_oct; - (unaryfunc) 0, // nb_hex; -#endif - (binaryfunc) 0, // nb_inplace_add; - (binaryfunc) 0, // nb_inplace_subtract; - (binaryfunc) 0, // nb_inplace_multiply; -#if PY_VERSION_HEX < 0x03000000 - (binaryfunc) 0, // nb_inplace_divide; -#endif - (binaryfunc) 0, // nb_inplace_remainder; - (ternaryfunc) 0, // nb_inplace_power; - (binaryfunc) 0, // nb_inplace_lshift; - (binaryfunc) 0, // nb_inplace_rshift; - (binaryfunc) 0, // nb_inplace_and; - (binaryfunc) 0, // nb_inplace_xor; - (binaryfunc) 0, // nb_inplace_or; - (binaryfunc) 0, // nb_floor_divide; - (binaryfunc) 0, // nb_true_divide; - (binaryfunc) 0, // nb_inplace_floor_divide; - (binaryfunc) 0, // nb_inplace_true_divide; - (unaryfunc) 0, // nb_index; - }, - { - (lenfunc) 0, // mp_length; - (binaryfunc) 0, // mp_subscript; - (objobjargproc) 0, // mp_ass_subscript; - }, - { - (lenfunc) 0, // sq_length - (binaryfunc) 0, // sq_concat - (ssizeargfunc) 0, // sq_repeat - (ssizeargfunc) 0, // sq_item -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // was_sq_slice -#else - (ssizessizeargfunc) 0, // sq_slice -#endif - (ssizeobjargproc) 0, // sq_ass_item -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // was_sq_ass_slice -#else - (ssizessizeobjargproc) 0, // sq_ass_slice -#endif - (objobjproc) 0, // sq_contains - (binaryfunc) 0, // sq_inplace_concat - (ssizeargfunc) 0, // sq_inplace_repeat - }, - { -#if PY_VERSION_HEX >= 0x03000000 - (getbufferproc) 0, // bf_getbuffer - (releasebufferproc) 0, // bf_releasebuffer -#else - (readbufferproc) 0, // bf_getreadbuffer - (writebufferproc) 0, // bf_getwritebuffer - (segcountproc) 0, // bf_getsegcount - (charbufferproc) 0, // bf_getcharbuffer -#endif - }, - (PyObject*) 0, // ht_name - (PyObject*) 0, // ht_slots -}; - -SWIGINTERN SwigPyClientData SwigPyBuiltin__D_clientdata = {0, 0, 0, 0, 0, 0, (PyTypeObject*) &SwigPyBuiltin__D_type}; - -PYSWIG_DESTRUCTOR_CLOSURE(_wrap_delete_E); -SWIGINTERN PyGetSetDef SwigPyBuiltin__E_getset[] = { - {NULL} // Sentinel -}; - -SWIGINTERN PyObject* -SwigPyBuiltin__E_richcompare (PyObject *self, PyObject *other, int op) -{ - PyObject *result = NULL; - switch (op) { - default : break; - } - if (result == NULL) { - if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) { - result = SwigPyObject_richcompare((SwigPyObject*) self, (SwigPyObject*) other, op); - } else { - result = Py_NotImplemented; - Py_INCREF(result); - } - } - return result; -} - -SWIGINTERN PyMethodDef SwigPyBuiltin__E_methods[] = { - {NULL} // Sentinel -}; - -static PyHeapTypeObject SwigPyBuiltin__E_type = { - { -#if PY_VERSION_HEX >= 0x03000000 - PyVarObject_HEAD_INIT(&PyType_Type, 0) -#else - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ -#endif - "E", /*tp_name*/ - sizeof(SwigPyObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - _wrap_delete_E_closure, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - &SwigPyBuiltin__E_type.as_number, /*tp_as_number*/ - &SwigPyBuiltin__E_type.as_sequence, /*tp_as_sequence*/ - &SwigPyBuiltin__E_type.as_mapping, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &SwigPyBuiltin__E_type.as_buffer, /*tp_as_buffer*/ -#if PY_VERSION_HEX >= 0x03000000 - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/ -#else - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ -#endif - "::E", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - SwigPyBuiltin__E_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc) 0, /* tp_iter */ - (iternextfunc) 0, /* tp_iternext */ - SwigPyBuiltin__E_methods, /* tp_methods */ - 0, /* tp_members */ - SwigPyBuiltin__E_getset, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */ - (initproc)_wrap_new_E, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0 /* tp_free */ - }, - { - (binaryfunc) 0, // nb_add; - (binaryfunc) 0, // nb_subtract; - (binaryfunc) 0, // nb_multiply; -#if PY_VERSION_HEX < 0x03000000 - (binaryfunc) 0, // nb_divide; -#endif - (binaryfunc) 0, // nb_remainder; - (binaryfunc) 0, // nb_divmod; - (ternaryfunc) 0, // nb_power; - (unaryfunc) 0, // nb_negative; - (unaryfunc) 0, // nb_positive; - (unaryfunc) 0, // nb_absolute; - (inquiry) 0, // nb_nonzero; - (unaryfunc) 0, // nb_invert; - (binaryfunc) 0, // nb_lshift; - (binaryfunc) 0, // nb_rshift; - (binaryfunc) 0, // nb_and; - (binaryfunc) 0, // nb_xor; - (binaryfunc) 0, // nb_or; -#if PY_VERSION_HEX < 0x03000000 - (coercion) 0, // nb_coerce; -#endif - (unaryfunc) 0, // nb_int; -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // nb_reserved; -#else - (unaryfunc) 0, // nb_long; -#endif - (unaryfunc) 0, // nb_float; -#if PY_VERSION_HEX < 0x03000000 - (unaryfunc) 0, // nb_oct; - (unaryfunc) 0, // nb_hex; -#endif - (binaryfunc) 0, // nb_inplace_add; - (binaryfunc) 0, // nb_inplace_subtract; - (binaryfunc) 0, // nb_inplace_multiply; -#if PY_VERSION_HEX < 0x03000000 - (binaryfunc) 0, // nb_inplace_divide; -#endif - (binaryfunc) 0, // nb_inplace_remainder; - (ternaryfunc) 0, // nb_inplace_power; - (binaryfunc) 0, // nb_inplace_lshift; - (binaryfunc) 0, // nb_inplace_rshift; - (binaryfunc) 0, // nb_inplace_and; - (binaryfunc) 0, // nb_inplace_xor; - (binaryfunc) 0, // nb_inplace_or; - (binaryfunc) 0, // nb_floor_divide; - (binaryfunc) 0, // nb_true_divide; - (binaryfunc) 0, // nb_inplace_floor_divide; - (binaryfunc) 0, // nb_inplace_true_divide; - (unaryfunc) 0, // nb_index; - }, - { - (lenfunc) 0, // mp_length; - (binaryfunc) 0, // mp_subscript; - (objobjargproc) 0, // mp_ass_subscript; - }, - { - (lenfunc) 0, // sq_length - (binaryfunc) 0, // sq_concat - (ssizeargfunc) 0, // sq_repeat - (ssizeargfunc) 0, // sq_item -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // was_sq_slice -#else - (ssizessizeargfunc) 0, // sq_slice -#endif - (ssizeobjargproc) 0, // sq_ass_item -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // was_sq_ass_slice -#else - (ssizessizeobjargproc) 0, // sq_ass_slice -#endif - (objobjproc) 0, // sq_contains - (binaryfunc) 0, // sq_inplace_concat - (ssizeargfunc) 0, // sq_inplace_repeat - }, - { -#if PY_VERSION_HEX >= 0x03000000 - (getbufferproc) 0, // bf_getbuffer - (releasebufferproc) 0, // bf_releasebuffer -#else - (readbufferproc) 0, // bf_getreadbuffer - (writebufferproc) 0, // bf_getwritebuffer - (segcountproc) 0, // bf_getsegcount - (charbufferproc) 0, // bf_getcharbuffer -#endif - }, - (PyObject*) 0, // ht_name - (PyObject*) 0, // ht_slots -}; - -SWIGINTERN SwigPyClientData SwigPyBuiltin__E_clientdata = {0, 0, 0, 0, 0, 0, (PyTypeObject*) &SwigPyBuiltin__E_type}; - -PYSWIG_DESTRUCTOR_CLOSURE(_wrap_delete_F); -SWIGINTERN PyGetSetDef SwigPyBuiltin__F_getset[] = { - {NULL} // Sentinel -}; - -SWIGINTERN PyObject* -SwigPyBuiltin__F_richcompare (PyObject *self, PyObject *other, int op) -{ - PyObject *result = NULL; - switch (op) { - default : break; - } - if (result == NULL) { - if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) { - result = SwigPyObject_richcompare((SwigPyObject*) self, (SwigPyObject*) other, op); - } else { - result = Py_NotImplemented; - Py_INCREF(result); - } - } - return result; -} - -SWIGINTERN PyMethodDef SwigPyBuiltin__F_methods[] = { - {NULL} // Sentinel -}; - -static PyHeapTypeObject SwigPyBuiltin__F_type = { - { -#if PY_VERSION_HEX >= 0x03000000 - PyVarObject_HEAD_INIT(&PyType_Type, 0) -#else - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ -#endif - "F", /*tp_name*/ - sizeof(SwigPyObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - _wrap_delete_F_closure, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - &SwigPyBuiltin__F_type.as_number, /*tp_as_number*/ - &SwigPyBuiltin__F_type.as_sequence, /*tp_as_sequence*/ - &SwigPyBuiltin__F_type.as_mapping, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &SwigPyBuiltin__F_type.as_buffer, /*tp_as_buffer*/ -#if PY_VERSION_HEX >= 0x03000000 - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/ -#else - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ -#endif - "::F", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - SwigPyBuiltin__F_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc) 0, /* tp_iter */ - (iternextfunc) 0, /* tp_iternext */ - SwigPyBuiltin__F_methods, /* tp_methods */ - 0, /* tp_members */ - SwigPyBuiltin__F_getset, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */ - (initproc)_wrap_new_F, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0 /* tp_free */ - }, - { - (binaryfunc) 0, // nb_add; - (binaryfunc) 0, // nb_subtract; - (binaryfunc) 0, // nb_multiply; -#if PY_VERSION_HEX < 0x03000000 - (binaryfunc) 0, // nb_divide; -#endif - (binaryfunc) 0, // nb_remainder; - (binaryfunc) 0, // nb_divmod; - (ternaryfunc) 0, // nb_power; - (unaryfunc) 0, // nb_negative; - (unaryfunc) 0, // nb_positive; - (unaryfunc) 0, // nb_absolute; - (inquiry) 0, // nb_nonzero; - (unaryfunc) 0, // nb_invert; - (binaryfunc) 0, // nb_lshift; - (binaryfunc) 0, // nb_rshift; - (binaryfunc) 0, // nb_and; - (binaryfunc) 0, // nb_xor; - (binaryfunc) 0, // nb_or; -#if PY_VERSION_HEX < 0x03000000 - (coercion) 0, // nb_coerce; -#endif - (unaryfunc) 0, // nb_int; -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // nb_reserved; -#else - (unaryfunc) 0, // nb_long; -#endif - (unaryfunc) 0, // nb_float; -#if PY_VERSION_HEX < 0x03000000 - (unaryfunc) 0, // nb_oct; - (unaryfunc) 0, // nb_hex; -#endif - (binaryfunc) 0, // nb_inplace_add; - (binaryfunc) 0, // nb_inplace_subtract; - (binaryfunc) 0, // nb_inplace_multiply; -#if PY_VERSION_HEX < 0x03000000 - (binaryfunc) 0, // nb_inplace_divide; -#endif - (binaryfunc) 0, // nb_inplace_remainder; - (ternaryfunc) 0, // nb_inplace_power; - (binaryfunc) 0, // nb_inplace_lshift; - (binaryfunc) 0, // nb_inplace_rshift; - (binaryfunc) 0, // nb_inplace_and; - (binaryfunc) 0, // nb_inplace_xor; - (binaryfunc) 0, // nb_inplace_or; - (binaryfunc) 0, // nb_floor_divide; - (binaryfunc) 0, // nb_true_divide; - (binaryfunc) 0, // nb_inplace_floor_divide; - (binaryfunc) 0, // nb_inplace_true_divide; - (unaryfunc) 0, // nb_index; - }, - { - (lenfunc) 0, // mp_length; - (binaryfunc) 0, // mp_subscript; - (objobjargproc) 0, // mp_ass_subscript; - }, - { - (lenfunc) 0, // sq_length - (binaryfunc) 0, // sq_concat - (ssizeargfunc) 0, // sq_repeat - (ssizeargfunc) 0, // sq_item -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // was_sq_slice -#else - (ssizessizeargfunc) 0, // sq_slice -#endif - (ssizeobjargproc) 0, // sq_ass_item -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // was_sq_ass_slice -#else - (ssizessizeobjargproc) 0, // sq_ass_slice -#endif - (objobjproc) 0, // sq_contains - (binaryfunc) 0, // sq_inplace_concat - (ssizeargfunc) 0, // sq_inplace_repeat - }, - { -#if PY_VERSION_HEX >= 0x03000000 - (getbufferproc) 0, // bf_getbuffer - (releasebufferproc) 0, // bf_releasebuffer -#else - (readbufferproc) 0, // bf_getreadbuffer - (writebufferproc) 0, // bf_getwritebuffer - (segcountproc) 0, // bf_getsegcount - (charbufferproc) 0, // bf_getcharbuffer -#endif - }, - (PyObject*) 0, // ht_name - (PyObject*) 0, // ht_slots -}; - -SWIGINTERN SwigPyClientData SwigPyBuiltin__F_clientdata = {0, 0, 0, 0, 0, 0, (PyTypeObject*) &SwigPyBuiltin__F_type}; - -PYSWIG_DESTRUCTOR_CLOSURE(_wrap_delete_G); -SWIGINTERN PyGetSetDef SwigPyBuiltin__G_getset[] = { - {NULL} // Sentinel -}; - -SWIGINTERN PyObject* -SwigPyBuiltin__G_richcompare (PyObject *self, PyObject *other, int op) -{ - PyObject *result = NULL; - switch (op) { - default : break; - } - if (result == NULL) { - if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) { - result = SwigPyObject_richcompare((SwigPyObject*) self, (SwigPyObject*) other, op); - } else { - result = Py_NotImplemented; - Py_INCREF(result); - } - } - return result; -} - -SWIGINTERN PyMethodDef SwigPyBuiltin__G_methods[] = { - {NULL} // Sentinel -}; - -static PyHeapTypeObject SwigPyBuiltin__G_type = { - { -#if PY_VERSION_HEX >= 0x03000000 - PyVarObject_HEAD_INIT(&PyType_Type, 0) -#else - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ -#endif - "G", /*tp_name*/ - sizeof(SwigPyObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - _wrap_delete_G_closure, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - &SwigPyBuiltin__G_type.as_number, /*tp_as_number*/ - &SwigPyBuiltin__G_type.as_sequence, /*tp_as_sequence*/ - &SwigPyBuiltin__G_type.as_mapping, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &SwigPyBuiltin__G_type.as_buffer, /*tp_as_buffer*/ -#if PY_VERSION_HEX >= 0x03000000 - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/ -#else - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ -#endif - "::G", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - SwigPyBuiltin__G_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc) 0, /* tp_iter */ - (iternextfunc) 0, /* tp_iternext */ - SwigPyBuiltin__G_methods, /* tp_methods */ - 0, /* tp_members */ - SwigPyBuiltin__G_getset, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */ - (initproc)_wrap_new_G, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0 /* tp_free */ - }, - { - (binaryfunc) 0, // nb_add; - (binaryfunc) 0, // nb_subtract; - (binaryfunc) 0, // nb_multiply; -#if PY_VERSION_HEX < 0x03000000 - (binaryfunc) 0, // nb_divide; -#endif - (binaryfunc) 0, // nb_remainder; - (binaryfunc) 0, // nb_divmod; - (ternaryfunc) 0, // nb_power; - (unaryfunc) 0, // nb_negative; - (unaryfunc) 0, // nb_positive; - (unaryfunc) 0, // nb_absolute; - (inquiry) 0, // nb_nonzero; - (unaryfunc) 0, // nb_invert; - (binaryfunc) 0, // nb_lshift; - (binaryfunc) 0, // nb_rshift; - (binaryfunc) 0, // nb_and; - (binaryfunc) 0, // nb_xor; - (binaryfunc) 0, // nb_or; -#if PY_VERSION_HEX < 0x03000000 - (coercion) 0, // nb_coerce; -#endif - (unaryfunc) 0, // nb_int; -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // nb_reserved; -#else - (unaryfunc) 0, // nb_long; -#endif - (unaryfunc) 0, // nb_float; -#if PY_VERSION_HEX < 0x03000000 - (unaryfunc) 0, // nb_oct; - (unaryfunc) 0, // nb_hex; -#endif - (binaryfunc) 0, // nb_inplace_add; - (binaryfunc) 0, // nb_inplace_subtract; - (binaryfunc) 0, // nb_inplace_multiply; -#if PY_VERSION_HEX < 0x03000000 - (binaryfunc) 0, // nb_inplace_divide; -#endif - (binaryfunc) 0, // nb_inplace_remainder; - (ternaryfunc) 0, // nb_inplace_power; - (binaryfunc) 0, // nb_inplace_lshift; - (binaryfunc) 0, // nb_inplace_rshift; - (binaryfunc) 0, // nb_inplace_and; - (binaryfunc) 0, // nb_inplace_xor; - (binaryfunc) 0, // nb_inplace_or; - (binaryfunc) 0, // nb_floor_divide; - (binaryfunc) 0, // nb_true_divide; - (binaryfunc) 0, // nb_inplace_floor_divide; - (binaryfunc) 0, // nb_inplace_true_divide; - (unaryfunc) 0, // nb_index; - }, - { - (lenfunc) 0, // mp_length; - (binaryfunc) 0, // mp_subscript; - (objobjargproc) 0, // mp_ass_subscript; - }, - { - (lenfunc) 0, // sq_length - (binaryfunc) 0, // sq_concat - (ssizeargfunc) 0, // sq_repeat - (ssizeargfunc) 0, // sq_item -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // was_sq_slice -#else - (ssizessizeargfunc) 0, // sq_slice -#endif - (ssizeobjargproc) 0, // sq_ass_item -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // was_sq_ass_slice -#else - (ssizessizeobjargproc) 0, // sq_ass_slice -#endif - (objobjproc) 0, // sq_contains - (binaryfunc) 0, // sq_inplace_concat - (ssizeargfunc) 0, // sq_inplace_repeat - }, - { -#if PY_VERSION_HEX >= 0x03000000 - (getbufferproc) 0, // bf_getbuffer - (releasebufferproc) 0, // bf_releasebuffer -#else - (readbufferproc) 0, // bf_getreadbuffer - (writebufferproc) 0, // bf_getwritebuffer - (segcountproc) 0, // bf_getsegcount - (charbufferproc) 0, // bf_getcharbuffer -#endif - }, - (PyObject*) 0, // ht_name - (PyObject*) 0, // ht_slots -}; - -SWIGINTERN SwigPyClientData SwigPyBuiltin__G_clientdata = {0, 0, 0, 0, 0, 0, (PyTypeObject*) &SwigPyBuiltin__G_type}; - -PYSWIG_DESTRUCTOR_CLOSURE(_wrap_delete_H); -SWIGINTERN PyGetSetDef SwigPyBuiltin__H_getset[] = { - {NULL} // Sentinel -}; - -SWIGINTERN PyObject* -SwigPyBuiltin__H_richcompare (PyObject *self, PyObject *other, int op) -{ - PyObject *result = NULL; - switch (op) { - default : break; - } - if (result == NULL) { - if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) { - result = SwigPyObject_richcompare((SwigPyObject*) self, (SwigPyObject*) other, op); - } else { - result = Py_NotImplemented; - Py_INCREF(result); - } - } - return result; -} - -SWIGINTERN PyMethodDef SwigPyBuiltin__H_methods[] = { - {NULL} // Sentinel -}; - -static PyHeapTypeObject SwigPyBuiltin__H_type = { - { -#if PY_VERSION_HEX >= 0x03000000 - PyVarObject_HEAD_INIT(&PyType_Type, 0) -#else - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ -#endif - "H", /*tp_name*/ - sizeof(SwigPyObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - _wrap_delete_H_closure, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - &SwigPyBuiltin__H_type.as_number, /*tp_as_number*/ - &SwigPyBuiltin__H_type.as_sequence, /*tp_as_sequence*/ - &SwigPyBuiltin__H_type.as_mapping, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &SwigPyBuiltin__H_type.as_buffer, /*tp_as_buffer*/ -#if PY_VERSION_HEX >= 0x03000000 - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/ -#else - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ -#endif - "::H", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - SwigPyBuiltin__H_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc) 0, /* tp_iter */ - (iternextfunc) 0, /* tp_iternext */ - SwigPyBuiltin__H_methods, /* tp_methods */ - 0, /* tp_members */ - SwigPyBuiltin__H_getset, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */ - (initproc)_wrap_new_H, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0 /* tp_free */ - }, - { - (binaryfunc) 0, // nb_add; - (binaryfunc) 0, // nb_subtract; - (binaryfunc) 0, // nb_multiply; -#if PY_VERSION_HEX < 0x03000000 - (binaryfunc) 0, // nb_divide; -#endif - (binaryfunc) 0, // nb_remainder; - (binaryfunc) 0, // nb_divmod; - (ternaryfunc) 0, // nb_power; - (unaryfunc) 0, // nb_negative; - (unaryfunc) 0, // nb_positive; - (unaryfunc) 0, // nb_absolute; - (inquiry) 0, // nb_nonzero; - (unaryfunc) 0, // nb_invert; - (binaryfunc) 0, // nb_lshift; - (binaryfunc) 0, // nb_rshift; - (binaryfunc) 0, // nb_and; - (binaryfunc) 0, // nb_xor; - (binaryfunc) 0, // nb_or; -#if PY_VERSION_HEX < 0x03000000 - (coercion) 0, // nb_coerce; -#endif - (unaryfunc) 0, // nb_int; -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // nb_reserved; -#else - (unaryfunc) 0, // nb_long; -#endif - (unaryfunc) 0, // nb_float; -#if PY_VERSION_HEX < 0x03000000 - (unaryfunc) 0, // nb_oct; - (unaryfunc) 0, // nb_hex; -#endif - (binaryfunc) 0, // nb_inplace_add; - (binaryfunc) 0, // nb_inplace_subtract; - (binaryfunc) 0, // nb_inplace_multiply; -#if PY_VERSION_HEX < 0x03000000 - (binaryfunc) 0, // nb_inplace_divide; -#endif - (binaryfunc) 0, // nb_inplace_remainder; - (ternaryfunc) 0, // nb_inplace_power; - (binaryfunc) 0, // nb_inplace_lshift; - (binaryfunc) 0, // nb_inplace_rshift; - (binaryfunc) 0, // nb_inplace_and; - (binaryfunc) 0, // nb_inplace_xor; - (binaryfunc) 0, // nb_inplace_or; - (binaryfunc) 0, // nb_floor_divide; - (binaryfunc) 0, // nb_true_divide; - (binaryfunc) 0, // nb_inplace_floor_divide; - (binaryfunc) 0, // nb_inplace_true_divide; - (unaryfunc) 0, // nb_index; - }, - { - (lenfunc) 0, // mp_length; - (binaryfunc) 0, // mp_subscript; - (objobjargproc) 0, // mp_ass_subscript; - }, - { - (lenfunc) 0, // sq_length - (binaryfunc) 0, // sq_concat - (ssizeargfunc) 0, // sq_repeat - (ssizeargfunc) 0, // sq_item -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // was_sq_slice -#else - (ssizessizeargfunc) 0, // sq_slice -#endif - (ssizeobjargproc) 0, // sq_ass_item -#if PY_VERSION_HEX >= 0x03000000 - (void*) 0, // was_sq_ass_slice -#else - (ssizessizeobjargproc) 0, // sq_ass_slice -#endif - (objobjproc) 0, // sq_contains - (binaryfunc) 0, // sq_inplace_concat - (ssizeargfunc) 0, // sq_inplace_repeat - }, - { -#if PY_VERSION_HEX >= 0x03000000 - (getbufferproc) 0, // bf_getbuffer - (releasebufferproc) 0, // bf_releasebuffer -#else - (readbufferproc) 0, // bf_getreadbuffer - (writebufferproc) 0, // bf_getwritebuffer - (segcountproc) 0, // bf_getsegcount - (charbufferproc) 0, // bf_getcharbuffer -#endif - }, - (PyObject*) 0, // ht_name - (PyObject*) 0, // ht_slots -}; - -SWIGINTERN SwigPyClientData SwigPyBuiltin__H_clientdata = {0, 0, 0, 0, 0, 0, (PyTypeObject*) &SwigPyBuiltin__H_type}; - -#ifdef __cplusplus -} // namespace { -#endif - - -/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ - -static void *_p_FTo_p_D(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((D *) (E *) ((F *) x)); -} -static void *_p_GTo_p_D(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((D *) (E *)(F *) ((G *) x)); -} -static void *_p_HTo_p_D(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((D *) (E *)(F *)(G *) ((H *) x)); -} -static void *_p_ETo_p_D(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((D *) ((E *) x)); -} -static void *_p_FTo_p_E(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((E *) ((F *) x)); -} -static void *_p_GTo_p_E(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((E *) (F *) ((G *) x)); -} -static void *_p_HTo_p_E(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((E *) (F *)(G *) ((H *) x)); -} -static void *_p_FTo_p_A(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((A *) (B *)(C *)(D *)(E *) ((F *) x)); -} -static void *_p_GTo_p_A(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((A *) (B *)(C *)(D *)(E *)(F *) ((G *) x)); -} -static void *_p_HTo_p_A(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((A *) (B *)(C *)(D *)(E *)(F *)(G *) ((H *) x)); -} -static void *_p_BTo_p_A(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((A *) ((B *) x)); -} -static void *_p_CTo_p_A(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((A *) (B *) ((C *) x)); -} -static void *_p_DTo_p_A(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((A *) (B *)(C *) ((D *) x)); -} -static void *_p_ETo_p_A(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((A *) (B *)(C *)(D *) ((E *) x)); -} -static void *_p_GTo_p_F(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((F *) ((G *) x)); -} -static void *_p_HTo_p_F(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((F *) (G *) ((H *) x)); -} -static void *_p_HTo_p_G(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((G *) ((H *) x)); -} -static void *_p_FTo_p_B(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((B *) (C *)(D *)(E *) ((F *) x)); -} -static void *_p_GTo_p_B(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((B *) (C *)(D *)(E *)(F *) ((G *) x)); -} -static void *_p_HTo_p_B(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((B *) (C *)(D *)(E *)(F *)(G *) ((H *) x)); -} -static void *_p_CTo_p_B(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((B *) ((C *) x)); -} -static void *_p_DTo_p_B(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((B *) (C *) ((D *) x)); -} -static void *_p_ETo_p_B(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((B *) (C *)(D *) ((E *) x)); -} -static void *_p_FTo_p_C(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((C *) (D *)(E *) ((F *) x)); -} -static void *_p_GTo_p_C(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((C *) (D *)(E *)(F *) ((G *) x)); -} -static void *_p_HTo_p_C(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((C *) (D *)(E *)(F *)(G *) ((H *) x)); -} -static void *_p_DTo_p_C(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((C *) ((D *) x)); -} -static void *_p_ETo_p_C(void *x, int *SWIGUNUSEDPARM(newmemory)) { - return (void *)((C *) (D *) ((E *) x)); -} -static swig_type_info _swigt__p_A = {"_p_A", "A *", 0, 0, (void*)&SwigPyBuiltin__A_clientdata, 0}; -static swig_type_info _swigt__p_B = {"_p_B", "B *", 0, 0, (void*)&SwigPyBuiltin__B_clientdata, 0}; -static swig_type_info _swigt__p_C = {"_p_C", "C *", 0, 0, (void*)&SwigPyBuiltin__C_clientdata, 0}; -static swig_type_info _swigt__p_D = {"_p_D", "D *", 0, 0, (void*)&SwigPyBuiltin__D_clientdata, 0}; -static swig_type_info _swigt__p_E = {"_p_E", "E *", 0, 0, (void*)&SwigPyBuiltin__E_clientdata, 0}; -static swig_type_info _swigt__p_F = {"_p_F", "F *", 0, 0, (void*)&SwigPyBuiltin__F_clientdata, 0}; -static swig_type_info _swigt__p_G = {"_p_G", "G *", 0, 0, (void*)&SwigPyBuiltin__G_clientdata, 0}; -static swig_type_info _swigt__p_H = {"_p_H", "H *", 0, 0, (void*)&SwigPyBuiltin__H_clientdata, 0}; -static swig_type_info _swigt__p_SwigPyObject = {"_p_SwigPyObject", "SwigPyObject *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; - -static swig_type_info *swig_type_initial[] = { - &_swigt__p_A, - &_swigt__p_B, - &_swigt__p_C, - &_swigt__p_D, - &_swigt__p_E, - &_swigt__p_F, - &_swigt__p_G, - &_swigt__p_H, - &_swigt__p_SwigPyObject, - &_swigt__p_char, -}; - -static swig_cast_info _swigc__p_A[] = { {&_swigt__p_G, _p_GTo_p_A, 0, 0}, {&_swigt__p_A, 0, 0, 0}, {&_swigt__p_H, _p_HTo_p_A, 0, 0}, {&_swigt__p_B, _p_BTo_p_A, 0, 0}, {&_swigt__p_C, _p_CTo_p_A, 0, 0}, {&_swigt__p_D, _p_DTo_p_A, 0, 0}, {&_swigt__p_E, _p_ETo_p_A, 0, 0}, {&_swigt__p_F, _p_FTo_p_A, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_B[] = { {&_swigt__p_G, _p_GTo_p_B, 0, 0}, {&_swigt__p_H, _p_HTo_p_B, 0, 0}, {&_swigt__p_B, 0, 0, 0}, {&_swigt__p_C, _p_CTo_p_B, 0, 0}, {&_swigt__p_D, _p_DTo_p_B, 0, 0}, {&_swigt__p_E, _p_ETo_p_B, 0, 0}, {&_swigt__p_F, _p_FTo_p_B, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_C[] = { {&_swigt__p_G, _p_GTo_p_C, 0, 0}, {&_swigt__p_H, _p_HTo_p_C, 0, 0}, {&_swigt__p_C, 0, 0, 0}, {&_swigt__p_D, _p_DTo_p_C, 0, 0}, {&_swigt__p_E, _p_ETo_p_C, 0, 0}, {&_swigt__p_F, _p_FTo_p_C, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_D[] = { {&_swigt__p_G, _p_GTo_p_D, 0, 0}, {&_swigt__p_H, _p_HTo_p_D, 0, 0}, {&_swigt__p_D, 0, 0, 0}, {&_swigt__p_E, _p_ETo_p_D, 0, 0}, {&_swigt__p_F, _p_FTo_p_D, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_E[] = { {&_swigt__p_G, _p_GTo_p_E, 0, 0}, {&_swigt__p_H, _p_HTo_p_E, 0, 0}, {&_swigt__p_E, 0, 0, 0}, {&_swigt__p_F, _p_FTo_p_E, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_F[] = { {&_swigt__p_G, _p_GTo_p_F, 0, 0}, {&_swigt__p_H, _p_HTo_p_F, 0, 0}, {&_swigt__p_F, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_G[] = { {&_swigt__p_G, 0, 0, 0}, {&_swigt__p_H, _p_HTo_p_G, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_H[] = { {&_swigt__p_H, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_SwigPyObject[] = { {&_swigt__p_SwigPyObject, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; - -static swig_cast_info *swig_cast_initial[] = { - _swigc__p_A, - _swigc__p_B, - _swigc__p_C, - _swigc__p_D, - _swigc__p_E, - _swigc__p_F, - _swigc__p_G, - _swigc__p_H, - _swigc__p_SwigPyObject, - _swigc__p_char, -}; - - -/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ - -static swig_const_info swig_const_table[] = { -{0, 0, 0, 0.0, 0, 0}}; - -#ifdef __cplusplus -} -#endif -/* ----------------------------------------------------------------------------- - * Type initialization: - * This problem is tough by the requirement that no dynamic - * memory is used. Also, since swig_type_info structures store pointers to - * swig_cast_info structures and swig_cast_info structures store pointers back - * to swig_type_info structures, we need some lookup code at initialization. - * The idea is that swig generates all the structures that are needed. - * The runtime then collects these partially filled structures. - * The SWIG_InitializeModule function takes these initial arrays out of - * swig_module, and does all the lookup, filling in the swig_module.types - * array with the correct data and linking the correct swig_cast_info - * structures together. - * - * The generated swig_type_info structures are assigned staticly to an initial - * array. We just loop through that array, and handle each type individually. - * First we lookup if this type has been already loaded, and if so, use the - * loaded structure instead of the generated one. Then we have to fill in the - * cast linked list. The cast data is initially stored in something like a - * two-dimensional array. Each row corresponds to a type (there are the same - * number of rows as there are in the swig_type_initial array). Each entry in - * a column is one of the swig_cast_info structures for that type. - * The cast_initial array is actually an array of arrays, because each row has - * a variable number of columns. So to actually build the cast linked list, - * we find the array of casts associated with the type, and loop through it - * adding the casts to the list. The one last trick we need to do is making - * sure the type pointer in the swig_cast_info struct is correct. - * - * First off, we lookup the cast->type name to see if it is already loaded. - * There are three cases to handle: - * 1) If the cast->type has already been loaded AND the type we are adding - * casting info to has not been loaded (it is in this module), THEN we - * replace the cast->type pointer with the type pointer that has already - * been loaded. - * 2) If BOTH types (the one we are adding casting info to, and the - * cast->type) are loaded, THEN the cast info has already been loaded by - * the previous module so we just ignore it. - * 3) Finally, if cast->type has not already been loaded, then we add that - * swig_cast_info to the linked list (because the cast->type) pointer will - * be correct. - * ----------------------------------------------------------------------------- */ - -#ifdef __cplusplus -extern "C" { -#if 0 -} /* c-mode */ -#endif -#endif - -#if 0 -#define SWIGRUNTIME_DEBUG -#endif - - -SWIGRUNTIME void -SWIG_InitializeModule(void *clientdata) { - size_t i; - swig_module_info *module_head, *iter; - int found, init; - - clientdata = clientdata; - - /* check to see if the circular list has been setup, if not, set it up */ - if (swig_module.next==0) { - /* Initialize the swig_module */ - swig_module.type_initial = swig_type_initial; - swig_module.cast_initial = swig_cast_initial; - swig_module.next = &swig_module; - init = 1; - } else { - init = 0; - } - - /* Try and load any already created modules */ - module_head = SWIG_GetModule(clientdata); - if (!module_head) { - /* This is the first module loaded for this interpreter */ - /* so set the swig module into the interpreter */ - SWIG_SetModule(clientdata, &swig_module); - module_head = &swig_module; - } else { - /* the interpreter has loaded a SWIG module, but has it loaded this one? */ - found=0; - iter=module_head; - do { - if (iter==&swig_module) { - found=1; - break; - } - iter=iter->next; - } while (iter!= module_head); - - /* if the is found in the list, then all is done and we may leave */ - if (found) return; - /* otherwise we must add out module into the list */ - swig_module.next = module_head->next; - module_head->next = &swig_module; - } - - /* When multiple interpeters are used, a module could have already been initialized in - a different interpreter, but not yet have a pointer in this interpreter. - In this case, we do not want to continue adding types... everything should be - set up already */ - if (init == 0) return; - - /* Now work on filling in swig_module.types */ -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: size %d\n", swig_module.size); -#endif - for (i = 0; i < swig_module.size; ++i) { - swig_type_info *type = 0; - swig_type_info *ret; - swig_cast_info *cast; - -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); -#endif - - /* if there is another module already loaded */ - if (swig_module.next != &swig_module) { - type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); - } - if (type) { - /* Overwrite clientdata field */ -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: found type %s\n", type->name); -#endif - if (swig_module.type_initial[i]->clientdata) { - type->clientdata = swig_module.type_initial[i]->clientdata; -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); -#endif - } - } else { - type = swig_module.type_initial[i]; - } - - /* Insert casting types */ - cast = swig_module.cast_initial[i]; - while (cast->type) { - /* Don't need to add information already in the list */ - ret = 0; -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); -#endif - if (swig_module.next != &swig_module) { - ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); -#ifdef SWIGRUNTIME_DEBUG - if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); -#endif - } - if (ret) { - if (type == swig_module.type_initial[i]) { -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: skip old type %s\n", ret->name); -#endif - cast->type = ret; - ret = 0; - } else { - /* Check for casting already in the list */ - swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); -#ifdef SWIGRUNTIME_DEBUG - if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); -#endif - if (!ocast) ret = 0; - } - } - - if (!ret) { -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); -#endif - if (type->cast) { - type->cast->prev = cast; - cast->next = type->cast; - } - type->cast = cast; - } - cast++; - } - /* Set entry in modules->types array equal to the type */ - swig_module.types[i] = type; - } - swig_module.types[i] = 0; - -#ifdef SWIGRUNTIME_DEBUG - printf("**** SWIG_InitializeModule: Cast List ******\n"); - for (i = 0; i < swig_module.size; ++i) { - int j = 0; - swig_cast_info *cast = swig_module.cast_initial[i]; - printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); - while (cast->type) { - printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); - cast++; - ++j; - } - printf("---- Total casts: %d\n",j); - } - printf("**** SWIG_InitializeModule: Cast List ******\n"); -#endif -} - -/* This function will propagate the clientdata field of type to -* any new swig_type_info structures that have been added into the list -* of equivalent types. It is like calling -* SWIG_TypeClientData(type, clientdata) a second time. -*/ -SWIGRUNTIME void -SWIG_PropagateClientData(void) { - size_t i; - swig_cast_info *equiv; - static int init_run = 0; - - if (init_run) return; - init_run = 1; - - for (i = 0; i < swig_module.size; i++) { - if (swig_module.types[i]->clientdata) { - equiv = swig_module.types[i]->cast; - while (equiv) { - if (!equiv->converter) { - if (equiv->type && !equiv->type->clientdata) - SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); - } - equiv = equiv->next; - } - } - } -} - -#ifdef __cplusplus -#if 0 -{ - /* c-mode */ -#endif -} -#endif - - - -#ifdef __cplusplus -#include - -extern "C" { -#endif - - /* Python-specific SWIG API */ -#define SWIG_newvarlink() SWIG_Python_newvarlink() -#define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr) -#define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants) - - /* ----------------------------------------------------------------------------- - * global variable support code. - * ----------------------------------------------------------------------------- */ - - typedef struct swig_globalvar { - char *name; /* Name of global variable */ - PyObject *(*get_attr)(void); /* Return the current value */ - int (*set_attr)(PyObject *); /* Set the value */ - struct swig_globalvar *next; - } swig_globalvar; - - typedef struct swig_varlinkobject { - PyObject_HEAD - swig_globalvar *vars; - } swig_varlinkobject; - - SWIGINTERN PyObject * - swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) { -#if PY_VERSION_HEX >= 0x03000000 - return PyUnicode_InternFromString(""); -#else - return PyString_FromString(""); -#endif - } - - SWIGINTERN PyObject * - swig_varlink_str(swig_varlinkobject *v) { -#if PY_VERSION_HEX >= 0x03000000 - PyObject *str = PyUnicode_InternFromString("("); - PyObject *tail; - PyObject *joined; - swig_globalvar *var; - for (var = v->vars; var; var=var->next) { - tail = PyUnicode_FromString(var->name); - joined = PyUnicode_Concat(str, tail); - Py_DecRef(str); - Py_DecRef(tail); - str = joined; - if (var->next) { - tail = PyUnicode_InternFromString(", "); - joined = PyUnicode_Concat(str, tail); - Py_DecRef(str); - Py_DecRef(tail); - str = joined; - } - } - tail = PyUnicode_InternFromString(")"); - joined = PyUnicode_Concat(str, tail); - Py_DecRef(str); - Py_DecRef(tail); - str = joined; -#else - PyObject *str = PyString_FromString("("); - swig_globalvar *var; - for (var = v->vars; var; var=var->next) { - PyString_ConcatAndDel(&str,PyString_FromString(var->name)); - if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", ")); - } - PyString_ConcatAndDel(&str,PyString_FromString(")")); -#endif - return str; - } - - SWIGINTERN int - swig_varlink_print(swig_varlinkobject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) { - char *tmp; - PyObject *str = swig_varlink_str(v); - fprintf(fp,"Swig global variables "); - fprintf(fp,"%s\n", tmp = SWIG_Python_str_AsChar(str)); - SWIG_Python_str_DelForPy3(tmp); - Py_DECREF(str); - return 0; - } - - SWIGINTERN void - swig_varlink_dealloc(swig_varlinkobject *v) { - swig_globalvar *var = v->vars; - while (var) { - swig_globalvar *n = var->next; - free(var->name); - free(var); - var = n; - } - } - - SWIGINTERN PyObject * - swig_varlink_getattr(swig_varlinkobject *v, char *n) { - PyObject *res = NULL; - swig_globalvar *var = v->vars; - while (var) { - if (strcmp(var->name,n) == 0) { - res = (*var->get_attr)(); - break; - } - var = var->next; - } - if (res == NULL && !PyErr_Occurred()) { - PyErr_SetString(PyExc_NameError,"Unknown C global variable"); - } - return res; - } - - SWIGINTERN int - swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) { - int res = 1; - swig_globalvar *var = v->vars; - while (var) { - if (strcmp(var->name,n) == 0) { - res = (*var->set_attr)(p); - break; - } - var = var->next; - } - if (res == 1 && !PyErr_Occurred()) { - PyErr_SetString(PyExc_NameError,"Unknown C global variable"); - } - return res; - } - - SWIGINTERN PyTypeObject* - swig_varlink_type(void) { - static char varlink__doc__[] = "Swig var link object"; - static PyTypeObject varlink_type; - static int type_init = 0; - if (!type_init) { - const PyTypeObject tmp - = { - /* PyObject header changed in Python 3 */ -#if PY_VERSION_HEX >= 0x03000000 - PyVarObject_HEAD_INIT(&PyType_Type, 0) -#else - PyObject_HEAD_INIT(NULL) - 0, /* Number of items in variable part (ob_size) */ -#endif - (char *)"swigvarlink", /* Type name (tp_name) */ - sizeof(swig_varlinkobject), /* Basic size (tp_basicsize) */ - 0, /* Itemsize (tp_itemsize) */ - (destructor) swig_varlink_dealloc, /* Deallocator (tp_dealloc) */ - (printfunc) swig_varlink_print, /* Print (tp_print) */ - (getattrfunc) swig_varlink_getattr, /* get attr (tp_getattr) */ - (setattrfunc) swig_varlink_setattr, /* Set attr (tp_setattr) */ - 0, /* tp_compare */ - (reprfunc) swig_varlink_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - (reprfunc) swig_varlink_str, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - 0, /* tp_flags */ - varlink__doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ -#if PY_VERSION_HEX >= 0x02020000 - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */ -#endif -#if PY_VERSION_HEX >= 0x02030000 - 0, /* tp_del */ -#endif -#ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ -#endif - }; - varlink_type = tmp; - /* for Python 3 we already assigned ob_type in PyVarObject_HEAD_INIT() */ -#if PY_VERSION_HEX < 0x03000000 - varlink_type.ob_type = &PyType_Type; -#endif - type_init = 1; - } - return &varlink_type; - } - - /* Create a variable linking object for use later */ - SWIGINTERN PyObject * - SWIG_Python_newvarlink(void) { - swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type()); - if (result) { - result->vars = 0; - } - return ((PyObject*) result); - } - - SWIGINTERN void - SWIG_Python_addvarlink(PyObject *p, char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) { - swig_varlinkobject *v = (swig_varlinkobject *) p; - swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar)); - if (gv) { - size_t size = strlen(name)+1; - gv->name = (char *)malloc(size); - if (gv->name) { - strncpy(gv->name,name,size); - gv->get_attr = get_attr; - gv->set_attr = set_attr; - gv->next = v->vars; - } - } - v->vars = gv; - } - - SWIGINTERN PyObject * - SWIG_globals(void) { - static PyObject *_SWIG_globals = 0; - if (!_SWIG_globals) _SWIG_globals = SWIG_newvarlink(); - return _SWIG_globals; - } - - /* ----------------------------------------------------------------------------- - * constants/methods manipulation - * ----------------------------------------------------------------------------- */ - - /* Install Constants */ - SWIGINTERN void - SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { - PyObject *obj = 0; - size_t i; - 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); - break; - case SWIG_PY_BINARY: - obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype)); - break; - default: - obj = 0; - break; - } - if (obj) { - PyDict_SetItemString(d, constants[i].name, obj); - Py_DECREF(obj); - } - } - } - - /* -----------------------------------------------------------------------------*/ - /* Fix SwigMethods to carry the callback ptrs when needed */ - /* -----------------------------------------------------------------------------*/ - - SWIGINTERN void - SWIG_Python_FixMethods(PyMethodDef *methods, - swig_const_info *const_table, - swig_type_info **types, - swig_type_info **types_initial) { - size_t i; - for (i = 0; methods[i].ml_name; ++i) { - const char *c = methods[i].ml_doc; - if (c && (c = strstr(c, "swig_ptr: "))) { - int j; - swig_const_info *ci = 0; - const char *name = c + 10; - for (j = 0; const_table[j].type; ++j) { - if (strncmp(const_table[j].name, name, - strlen(const_table[j].name)) == 0) { - ci = &(const_table[j]); - break; - } - } - if (ci) { - void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0; - if (ptr) { - size_t shift = (ci->ptype) - types; - swig_type_info *ty = types_initial[shift]; - size_t ldoc = (c - methods[i].ml_doc); - size_t lptr = strlen(ty->name)+2*sizeof(void*)+2; - char *ndoc = (char*)malloc(ldoc + lptr + 10); - if (ndoc) { - char *buff = ndoc; - strncpy(buff, methods[i].ml_doc, ldoc); - buff += ldoc; - strncpy(buff, "swig_ptr: ", 10); - buff += 10; - SWIG_PackVoidPtr(buff, ptr, ty->name, lptr); - methods[i].ml_doc = ndoc; - } - } - } - } - } - } - -#ifdef __cplusplus -} -#endif - -/* -----------------------------------------------------------------------------* - * Partial Init method - * -----------------------------------------------------------------------------*/ - -#ifdef __cplusplus -extern "C" -#endif - -SWIGEXPORT -#if PY_VERSION_HEX >= 0x03000000 -PyObject* -#else -void -#endif -SWIG_init(void) { - PyObject *m, *d, *md; - PyTypeObject *builtin_type; -#if PY_VERSION_HEX >= 0x03000000 - static struct PyModuleDef SWIG_module = { - PyModuleDef_HEAD_INIT, - (char *) SWIG_name, - NULL, - -1, - SwigMethods, - NULL, - NULL, - NULL, - NULL - }; -#endif - -#if defined(SWIGPYTHON_BUILTIN) - PyTypeObject *builtin_pytype = 0; -#ifdef __cplusplus - std::vector builtin_bases; -#endif - swig_type_info *builtin_basetype = 0; - PyObject *tuple = NULL; - PyGetSetDescrObject *static_getset = NULL; - - int i; - - // 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); - assert(metatype); - Py_DECREF(metatype_args); - metatype->tp_setattro = (setattrofunc) &SwigPyObjectType_setattro; - assert(PyType_Ready(metatype) >= 0); - - SWIG_Python_builtin_imports(); - -#endif - - /* Fix SwigMethods to carry the callback ptrs when needed */ - SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial); - -#if PY_VERSION_HEX >= 0x03000000 - m = PyModule_Create(&SWIG_module); -#else - m = Py_InitModule((char *) SWIG_name, SwigMethods); -#endif - md = d = PyModule_GetDict(m); - - SWIG_InitializeModule(0); - -#ifdef SWIGPYTHON_BUILTIN - static SwigPyClientData SwigPyObject_clientdata = { - 0 - }; - SwigPyObject_stype = SWIG_MangledTypeQuery("_p_SwigPyObject"); - assert(SwigPyObject_stype); - SwigPyClientData *cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; - if (!cd) { - SwigPyObject_stype->clientdata = &SwigPyObject_clientdata; - SwigPyObject_clientdata.pytype = _PySwigObject_type(); - } - - // All objects have a 'this' attribute - static PyGetSetDef this_getset_def = { - const_cast("this"), pyswig_this_closure, NULL, NULL, NULL - }; - PyObject *this_descr = PyDescr_NewGetSet(SwigPyObject_type(), &this_getset_def); - - // 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 - }; - PyObject *thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def); - - PyObject *public_interface = PyList_New(0); - PyObject *public_symbol = 0; - 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); - for (i = 0; swig_const_table[i].name != 0; ++i) - pyswig_add_public_symbol(public_interface, swig_const_table[i].name); -#endif - - SWIG_InstallConstants(d,swig_const_table); - - - // type '::A' - builtin_pytype = (PyTypeObject*) &SwigPyBuiltin__A_type; - builtin_pytype->tp_dict = d = PyDict_New(); -#if PY_VERSION_HEX >= 0x03000000 - builtin_pytype->ob_base.ob_base.ob_type = metatype; -#else - builtin_pytype->ob_type = metatype; -#endif - builtin_pytype->tp_new = PyType_GenericNew; - pyswig_builtin_init_bases(builtin_pytype, builtin_bases); - builtin_bases.clear(); - PyDict_SetItemString(d, "this", this_descr); - PyDict_SetItemString(d, "thisown", thisown_descr); - if (PyType_Ready(builtin_pytype) < 0) { - PyErr_SetString(PyExc_TypeError, "Couldn't create type 'A'"); -#if PY_VERSION_HEX >= 0x03000000 - return NULL; -#else - return; -#endif - } - Py_INCREF(builtin_pytype); - PyModule_AddObject(m, "A", (PyObject*) builtin_pytype); - pyswig_add_public_symbol(public_interface, "A"); - d = md; - - // type '::B' - builtin_pytype = (PyTypeObject*) &SwigPyBuiltin__B_type; - builtin_pytype->tp_dict = d = PyDict_New(); -#if PY_VERSION_HEX >= 0x03000000 - builtin_pytype->ob_base.ob_base.ob_type = metatype; -#else - builtin_pytype->ob_type = metatype; -#endif - builtin_pytype->tp_new = PyType_GenericNew; - builtin_basetype = SWIG_MangledTypeQuery("_p_A"); - if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) { - builtin_bases.push_back(((SwigPyClientData*) builtin_basetype->clientdata)->pytype); - } - pyswig_builtin_init_bases(builtin_pytype, builtin_bases); - builtin_bases.clear(); - PyDict_SetItemString(d, "this", this_descr); - PyDict_SetItemString(d, "thisown", thisown_descr); - if (PyType_Ready(builtin_pytype) < 0) { - PyErr_SetString(PyExc_TypeError, "Couldn't create type 'B'"); -#if PY_VERSION_HEX >= 0x03000000 - return NULL; -#else - return; -#endif - } - Py_INCREF(builtin_pytype); - PyModule_AddObject(m, "B", (PyObject*) builtin_pytype); - pyswig_add_public_symbol(public_interface, "B"); - d = md; - - // type '::C' - builtin_pytype = (PyTypeObject*) &SwigPyBuiltin__C_type; - builtin_pytype->tp_dict = d = PyDict_New(); -#if PY_VERSION_HEX >= 0x03000000 - builtin_pytype->ob_base.ob_base.ob_type = metatype; -#else - builtin_pytype->ob_type = metatype; -#endif - builtin_pytype->tp_new = PyType_GenericNew; - builtin_basetype = SWIG_MangledTypeQuery("_p_B"); - if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) { - builtin_bases.push_back(((SwigPyClientData*) builtin_basetype->clientdata)->pytype); - } - pyswig_builtin_init_bases(builtin_pytype, builtin_bases); - builtin_bases.clear(); - PyDict_SetItemString(d, "this", this_descr); - PyDict_SetItemString(d, "thisown", thisown_descr); - if (PyType_Ready(builtin_pytype) < 0) { - PyErr_SetString(PyExc_TypeError, "Couldn't create type 'C'"); -#if PY_VERSION_HEX >= 0x03000000 - return NULL; -#else - return; -#endif - } - Py_INCREF(builtin_pytype); - PyModule_AddObject(m, "C", (PyObject*) builtin_pytype); - pyswig_add_public_symbol(public_interface, "C"); - d = md; - - // type '::D' - builtin_pytype = (PyTypeObject*) &SwigPyBuiltin__D_type; - builtin_pytype->tp_dict = d = PyDict_New(); -#if PY_VERSION_HEX >= 0x03000000 - builtin_pytype->ob_base.ob_base.ob_type = metatype; -#else - builtin_pytype->ob_type = metatype; -#endif - builtin_pytype->tp_new = PyType_GenericNew; - builtin_basetype = SWIG_MangledTypeQuery("_p_C"); - if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) { - builtin_bases.push_back(((SwigPyClientData*) builtin_basetype->clientdata)->pytype); - } - pyswig_builtin_init_bases(builtin_pytype, builtin_bases); - builtin_bases.clear(); - PyDict_SetItemString(d, "this", this_descr); - PyDict_SetItemString(d, "thisown", thisown_descr); - if (PyType_Ready(builtin_pytype) < 0) { - PyErr_SetString(PyExc_TypeError, "Couldn't create type 'D'"); -#if PY_VERSION_HEX >= 0x03000000 - return NULL; -#else - return; -#endif - } - Py_INCREF(builtin_pytype); - PyModule_AddObject(m, "D", (PyObject*) builtin_pytype); - pyswig_add_public_symbol(public_interface, "D"); - d = md; - - // type '::E' - builtin_pytype = (PyTypeObject*) &SwigPyBuiltin__E_type; - builtin_pytype->tp_dict = d = PyDict_New(); -#if PY_VERSION_HEX >= 0x03000000 - builtin_pytype->ob_base.ob_base.ob_type = metatype; -#else - builtin_pytype->ob_type = metatype; -#endif - builtin_pytype->tp_new = PyType_GenericNew; - builtin_basetype = SWIG_MangledTypeQuery("_p_D"); - if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) { - builtin_bases.push_back(((SwigPyClientData*) builtin_basetype->clientdata)->pytype); - } - pyswig_builtin_init_bases(builtin_pytype, builtin_bases); - builtin_bases.clear(); - PyDict_SetItemString(d, "this", this_descr); - PyDict_SetItemString(d, "thisown", thisown_descr); - if (PyType_Ready(builtin_pytype) < 0) { - PyErr_SetString(PyExc_TypeError, "Couldn't create type 'E'"); -#if PY_VERSION_HEX >= 0x03000000 - return NULL; -#else - return; -#endif - } - Py_INCREF(builtin_pytype); - PyModule_AddObject(m, "E", (PyObject*) builtin_pytype); - pyswig_add_public_symbol(public_interface, "E"); - d = md; - - // type '::F' - builtin_pytype = (PyTypeObject*) &SwigPyBuiltin__F_type; - builtin_pytype->tp_dict = d = PyDict_New(); -#if PY_VERSION_HEX >= 0x03000000 - builtin_pytype->ob_base.ob_base.ob_type = metatype; -#else - builtin_pytype->ob_type = metatype; -#endif - builtin_pytype->tp_new = PyType_GenericNew; - builtin_basetype = SWIG_MangledTypeQuery("_p_E"); - if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) { - builtin_bases.push_back(((SwigPyClientData*) builtin_basetype->clientdata)->pytype); - } - pyswig_builtin_init_bases(builtin_pytype, builtin_bases); - builtin_bases.clear(); - PyDict_SetItemString(d, "this", this_descr); - PyDict_SetItemString(d, "thisown", thisown_descr); - if (PyType_Ready(builtin_pytype) < 0) { - PyErr_SetString(PyExc_TypeError, "Couldn't create type 'F'"); -#if PY_VERSION_HEX >= 0x03000000 - return NULL; -#else - return; -#endif - } - Py_INCREF(builtin_pytype); - PyModule_AddObject(m, "F", (PyObject*) builtin_pytype); - pyswig_add_public_symbol(public_interface, "F"); - d = md; - - // type '::G' - builtin_pytype = (PyTypeObject*) &SwigPyBuiltin__G_type; - builtin_pytype->tp_dict = d = PyDict_New(); -#if PY_VERSION_HEX >= 0x03000000 - builtin_pytype->ob_base.ob_base.ob_type = metatype; -#else - builtin_pytype->ob_type = metatype; -#endif - builtin_pytype->tp_new = PyType_GenericNew; - builtin_basetype = SWIG_MangledTypeQuery("_p_F"); - if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) { - builtin_bases.push_back(((SwigPyClientData*) builtin_basetype->clientdata)->pytype); - } - pyswig_builtin_init_bases(builtin_pytype, builtin_bases); - builtin_bases.clear(); - PyDict_SetItemString(d, "this", this_descr); - PyDict_SetItemString(d, "thisown", thisown_descr); - if (PyType_Ready(builtin_pytype) < 0) { - PyErr_SetString(PyExc_TypeError, "Couldn't create type 'G'"); -#if PY_VERSION_HEX >= 0x03000000 - return NULL; -#else - return; -#endif - } - Py_INCREF(builtin_pytype); - PyModule_AddObject(m, "G", (PyObject*) builtin_pytype); - pyswig_add_public_symbol(public_interface, "G"); - d = md; - - // type '::H' - builtin_pytype = (PyTypeObject*) &SwigPyBuiltin__H_type; - builtin_pytype->tp_dict = d = PyDict_New(); -#if PY_VERSION_HEX >= 0x03000000 - builtin_pytype->ob_base.ob_base.ob_type = metatype; -#else - builtin_pytype->ob_type = metatype; -#endif - builtin_pytype->tp_new = PyType_GenericNew; - builtin_basetype = SWIG_MangledTypeQuery("_p_G"); - if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) { - builtin_bases.push_back(((SwigPyClientData*) builtin_basetype->clientdata)->pytype); - } - pyswig_builtin_init_bases(builtin_pytype, builtin_bases); - builtin_bases.clear(); - PyDict_SetItemString(d, "this", this_descr); - PyDict_SetItemString(d, "thisown", thisown_descr); - if (PyType_Ready(builtin_pytype) < 0) { - PyErr_SetString(PyExc_TypeError, "Couldn't create type 'H'"); -#if PY_VERSION_HEX >= 0x03000000 - return NULL; -#else - return; -#endif - } - Py_INCREF(builtin_pytype); - PyModule_AddObject(m, "H", (PyObject*) builtin_pytype); - pyswig_add_public_symbol(public_interface, "H"); - d = md; -#if PY_VERSION_HEX >= 0x03000000 - return m; -#else - return; -#endif -} - From 6bfc86dee7a909cb66d4235af0a5eac381c0d152 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Thu, 10 Feb 2011 05:19:03 +0000 Subject: [PATCH 26/56] Simple test of operator overload. -builtin should shine in this test. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12451 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/python/performance/operator/Makefile | 23 +++++ Examples/python/performance/operator/Simple.i | 8 ++ .../performance/operator/Simple_baseline.py | 86 +++++++++++++++++ .../performance/operator/Simple_builtin.py | 81 ++++++++++++++++ .../performance/operator/Simple_optimized.py | 93 +++++++++++++++++++ Examples/python/performance/operator/runme.py | 17 ++++ .../performance/operator/runme_baseline.py | 11 +++ .../performance/operator/runme_builtin.py | 11 +++ .../performance/operator/runme_optimized.py | 11 +++ 9 files changed, 341 insertions(+) create mode 100644 Examples/python/performance/operator/Makefile create mode 100644 Examples/python/performance/operator/Simple.i create mode 100644 Examples/python/performance/operator/Simple_baseline.py create mode 100644 Examples/python/performance/operator/Simple_builtin.py create mode 100644 Examples/python/performance/operator/Simple_optimized.py create mode 100644 Examples/python/performance/operator/runme.py create mode 100644 Examples/python/performance/operator/runme_baseline.py create mode 100644 Examples/python/performance/operator/runme_builtin.py create mode 100644 Examples/python/performance/operator/runme_optimized.py diff --git a/Examples/python/performance/operator/Makefile b/Examples/python/performance/operator/Makefile new file mode 100644 index 000000000..0df09d908 --- /dev/null +++ b/Examples/python/performance/operator/Makefile @@ -0,0 +1,23 @@ +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = +TARGET = Simple +INTERFACE = Simple.i + +default : all + +all : + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \ + TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \ + TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \ + TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp + +static : + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static + +clean : + $(MAKE) -f $(TOP)/Makefile python_clean + rm -f $(TARGET).py diff --git a/Examples/python/performance/operator/Simple.i b/Examples/python/performance/operator/Simple.i new file mode 100644 index 000000000..fb0dd992c --- /dev/null +++ b/Examples/python/performance/operator/Simple.i @@ -0,0 +1,8 @@ +%inline %{ +class MyClass { +public: + MyClass () {} + ~MyClass () {} + MyClass& operator+ (int i) { return *this; } +}; +%} diff --git a/Examples/python/performance/operator/Simple_baseline.py b/Examples/python/performance/operator/Simple_baseline.py new file mode 100644 index 000000000..62da3e348 --- /dev/null +++ b/Examples/python/performance/operator/Simple_baseline.py @@ -0,0 +1,86 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. +# This file is compatible with both classic and new-style classes. + +from sys import version_info +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_baseline', [dirname(__file__)]) + except ImportError: + import _Simple_baseline + return _Simple_baseline + if fp is not None: + try: + _mod = imp.load_module('_Simple_baseline', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_baseline = swig_import_helper() + del swig_import_helper +else: + import _Simple_baseline +del version_info +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +class MyClass(_object): + __swig_setmethods__ = {} + __setattr__ = lambda self, name, value: _swig_setattr(self, MyClass, name, value) + __swig_getmethods__ = {} + __getattr__ = lambda self, name: _swig_getattr(self, MyClass, name) + __repr__ = _swig_repr + def __init__(self): + this = _Simple_baseline.new_MyClass() + try: self.this.append(this) + except: self.this = this + __swig_destroy__ = _Simple_baseline.delete_MyClass + __del__ = lambda self : None; + def __add__(self, *args): return _Simple_baseline.MyClass___add__(self, *args) +MyClass_swigregister = _Simple_baseline.MyClass_swigregister +MyClass_swigregister(MyClass) + + + diff --git a/Examples/python/performance/operator/Simple_builtin.py b/Examples/python/performance/operator/Simple_builtin.py new file mode 100644 index 000000000..4ecd8a63e --- /dev/null +++ b/Examples/python/performance/operator/Simple_builtin.py @@ -0,0 +1,81 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. + +from sys import version_info +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_builtin', [dirname(__file__)]) + except ImportError: + import _Simple_builtin + return _Simple_builtin + if fp is not None: + try: + _mod = imp.load_module('_Simple_builtin', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_builtin = swig_import_helper() + del swig_import_helper +else: + import _Simple_builtin +del version_info +from _Simple_builtin import * +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + + + + diff --git a/Examples/python/performance/operator/Simple_optimized.py b/Examples/python/performance/operator/Simple_optimized.py new file mode 100644 index 000000000..2db323a34 --- /dev/null +++ b/Examples/python/performance/operator/Simple_optimized.py @@ -0,0 +1,93 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 2.0.2 +# +# Do not make changes to this file unless you know what you are doing--modify +# the SWIG interface file instead. + +from sys import version_info +if version_info >= (3,0,0): + new_instancemethod = lambda func, inst, cls: _Simple_optimized.SWIG_PyInstanceMethod_New(func) +else: + from new import instancemethod as new_instancemethod +if version_info >= (2,6,0): + def swig_import_helper(): + from os.path import dirname + import imp + fp = None + try: + fp, pathname, description = imp.find_module('_Simple_optimized', [dirname(__file__)]) + except ImportError: + import _Simple_optimized + return _Simple_optimized + if fp is not None: + try: + _mod = imp.load_module('_Simple_optimized', fp, pathname, description) + finally: + fp.close() + return _mod + _Simple_optimized = swig_import_helper() + del swig_import_helper +else: + import _Simple_optimized +del version_info +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'SwigPyObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 + + +def _swig_setattr_nondynamic_method(set): + def set_attr(self,name,value): + if (name == "thisown"): return self.this.own(value) + if hasattr(self,name) or (name == "this"): + set(self,name,value) + else: + raise AttributeError("You cannot add attributes to %s" % self) + return set_attr + + +class MyClass(object): + thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') + __repr__ = _swig_repr + def __init__(self): + _Simple_optimized.MyClass_swiginit(self,_Simple_optimized.new_MyClass()) + __swig_destroy__ = _Simple_optimized.delete_MyClass +MyClass.__add__ = new_instancemethod(_Simple_optimized.MyClass___add__,None,MyClass) +MyClass_swigregister = _Simple_optimized.MyClass_swigregister +MyClass_swigregister(MyClass) + + + diff --git a/Examples/python/performance/operator/runme.py b/Examples/python/performance/operator/runme.py new file mode 100644 index 000000000..7e50aff16 --- /dev/null +++ b/Examples/python/performance/operator/runme.py @@ -0,0 +1,17 @@ +#!/usr/bin/env + +import sys +from subprocess import * + +proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + +proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + +proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE) +(stdout, stderr) = proc.communicate() +print stdout + diff --git a/Examples/python/performance/operator/runme_baseline.py b/Examples/python/performance/operator/runme_baseline.py new file mode 100644 index 000000000..f7fa9094b --- /dev/null +++ b/Examples/python/performance/operator/runme_baseline.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_baseline +import time + +t1 = time.clock() +x = Simple_baseline.MyClass() +for i in range(10000000) : + x = x + i +t2 = time.clock() +print "Simple_baseline took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/operator/runme_builtin.py b/Examples/python/performance/operator/runme_builtin.py new file mode 100644 index 000000000..73da3afb2 --- /dev/null +++ b/Examples/python/performance/operator/runme_builtin.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_builtin +import time + +t1 = time.clock() +x = Simple_builtin.MyClass() +for i in range(10000000) : + x = x + i +t2 = time.clock() +print "Simple_builtin took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/operator/runme_optimized.py b/Examples/python/performance/operator/runme_optimized.py new file mode 100644 index 000000000..4f22e0bda --- /dev/null +++ b/Examples/python/performance/operator/runme_optimized.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +import Simple_optimized +import time + +t1 = time.clock() +x = Simple_optimized.MyClass() +for i in range(10000000) : + x = x + i +t2 = time.clock() +print "Simple_optimized took %f seconds" % (t2 - t1) From 1e094f865e6b5da8f2ac7493a82dcbbd4f44b5f2 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Thu, 10 Feb 2011 05:53:04 +0000 Subject: [PATCH 27/56] Added test harness git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12452 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/python/performance/Makefile | 3 +- .../python/performance/constructor/runme.py | 18 ++++------- .../performance/constructor/runme_baseline.py | 11 ------- .../performance/constructor/runme_builtin.py | 11 ------- .../constructor/runme_optimized.py | 11 ------- Examples/python/performance/func/runme.py | 19 +++++------- .../python/performance/func/runme_baseline.py | 11 ------- .../python/performance/func/runme_builtin.py | 11 ------- .../performance/func/runme_optimized.py | 11 ------- Examples/python/performance/harness.py | 30 +++++++++++++++++++ .../python/performance/hierarchy/runme.py | 19 +++++------- .../performance/hierarchy/runme_baseline.py | 11 ------- .../performance/hierarchy/runme_builtin.py | 11 ------- .../performance/hierarchy/runme_optimized.py | 11 ------- .../performance/hierarchy_operator/runme.py | 19 +++++------- .../hierarchy_operator/runme_baseline.py | 11 ------- .../hierarchy_operator/runme_builtin.py | 11 ------- .../hierarchy_operator/runme_optimized.py | 11 ------- Examples/python/performance/operator/runme.py | 19 +++++------- .../performance/operator/runme_baseline.py | 11 ------- .../performance/operator/runme_builtin.py | 11 ------- .../performance/operator/runme_optimized.py | 11 ------- 22 files changed, 66 insertions(+), 226 deletions(-) delete mode 100644 Examples/python/performance/constructor/runme_baseline.py delete mode 100644 Examples/python/performance/constructor/runme_builtin.py delete mode 100644 Examples/python/performance/constructor/runme_optimized.py delete mode 100644 Examples/python/performance/func/runme_baseline.py delete mode 100644 Examples/python/performance/func/runme_builtin.py delete mode 100644 Examples/python/performance/func/runme_optimized.py create mode 100644 Examples/python/performance/harness.py delete mode 100644 Examples/python/performance/hierarchy/runme_baseline.py delete mode 100644 Examples/python/performance/hierarchy/runme_builtin.py delete mode 100644 Examples/python/performance/hierarchy/runme_optimized.py delete mode 100644 Examples/python/performance/hierarchy_operator/runme_baseline.py delete mode 100644 Examples/python/performance/hierarchy_operator/runme_builtin.py delete mode 100644 Examples/python/performance/hierarchy_operator/runme_optimized.py delete mode 100644 Examples/python/performance/operator/runme_baseline.py delete mode 100644 Examples/python/performance/operator/runme_builtin.py delete mode 100644 Examples/python/performance/operator/runme_optimized.py diff --git a/Examples/python/performance/Makefile b/Examples/python/performance/Makefile index 6f6db22b5..d5ecdbe75 100644 --- a/Examples/python/performance/Makefile +++ b/Examples/python/performance/Makefile @@ -10,7 +10,7 @@ else PYSCRIPT = runme3.py endif -SUBDIRS := constructor func hierarchy operator +SUBDIRS := constructor func hierarchy operator hierarchy_operator default : all @@ -36,3 +36,4 @@ $(SUBDIRS) : $(MAKE) -s -C $* clean clean : $(SUBDIRS:%=%-clean) + rm -f *.pyc diff --git a/Examples/python/performance/constructor/runme.py b/Examples/python/performance/constructor/runme.py index 7e50aff16..23577a14d 100644 --- a/Examples/python/performance/constructor/runme.py +++ b/Examples/python/performance/constructor/runme.py @@ -1,17 +1,11 @@ #!/usr/bin/env import sys -from subprocess import * +sys.path.append('..') +import harness -proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout - -proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout - -proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout +def proc (mod) : + for i in range(1000000) : + x = mod.MyClass() +harness.run(proc) diff --git a/Examples/python/performance/constructor/runme_baseline.py b/Examples/python/performance/constructor/runme_baseline.py deleted file mode 100644 index 0eb284ccc..000000000 --- a/Examples/python/performance/constructor/runme_baseline.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_baseline -import time - -t1 = time.clock() -for i in range(1000000) : - x = Simple_baseline.MyClass() - #x.func() -t2 = time.clock() -print "Simple_baseline took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/constructor/runme_builtin.py b/Examples/python/performance/constructor/runme_builtin.py deleted file mode 100644 index 47ce37864..000000000 --- a/Examples/python/performance/constructor/runme_builtin.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_builtin -import time - -t1 = time.clock() -for i in range(1000000) : - x = Simple_builtin.MyClass() - #x.func() -t2 = time.clock() -print "Simple_builtin took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/constructor/runme_optimized.py b/Examples/python/performance/constructor/runme_optimized.py deleted file mode 100644 index 0c0ed220f..000000000 --- a/Examples/python/performance/constructor/runme_optimized.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_optimized -import time - -t1 = time.clock() -for i in range(1000000) : - x = Simple_optimized.MyClass() - #x.func() -t2 = time.clock() -print "Simple_optimized took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/func/runme.py b/Examples/python/performance/func/runme.py index 7e50aff16..fd2fb175b 100644 --- a/Examples/python/performance/func/runme.py +++ b/Examples/python/performance/func/runme.py @@ -1,17 +1,12 @@ #!/usr/bin/env import sys -from subprocess import * +sys.path.append('..') +import harness -proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout - -proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout - -proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout +def proc (mod) : + x = mod.MyClass() + for i in range(10000000) : + x.func() +harness.run(proc) diff --git a/Examples/python/performance/func/runme_baseline.py b/Examples/python/performance/func/runme_baseline.py deleted file mode 100644 index 6966fd904..000000000 --- a/Examples/python/performance/func/runme_baseline.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_baseline -import time - -t1 = time.clock() -x = Simple_baseline.MyClass() -for i in range(10000000) : - x.func() -t2 = time.clock() -print "Simple_baseline took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/func/runme_builtin.py b/Examples/python/performance/func/runme_builtin.py deleted file mode 100644 index ca2f88ac8..000000000 --- a/Examples/python/performance/func/runme_builtin.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_builtin -import time - -t1 = time.clock() -x = Simple_builtin.MyClass() -for i in range(10000000) : - x.func() -t2 = time.clock() -print "Simple_builtin took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/func/runme_optimized.py b/Examples/python/performance/func/runme_optimized.py deleted file mode 100644 index fe10eb376..000000000 --- a/Examples/python/performance/func/runme_optimized.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_optimized -import time - -t1 = time.clock() -x = Simple_optimized.MyClass() -for i in range(10000000) : - x.func() -t2 = time.clock() -print "Simple_optimized took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/harness.py b/Examples/python/performance/harness.py new file mode 100644 index 000000000..8e9b6041b --- /dev/null +++ b/Examples/python/performance/harness.py @@ -0,0 +1,30 @@ +#!/usr/bin/env + +import sys +import time +import imp +from subprocess import * + +def run (proc) : + + try : + mod = imp.find_module(sys.argv[1]) + mod = imp.load_module(sys.argv[1], *mod) + + t1 = time.clock() + proc(mod) + t2 = time.clock() + print "%s took %f seconds" % (mod.__name__, t2 - t1) + + except IndexError : + proc = Popen([sys.executable, 'runme.py', 'Simple_baseline'], stdout=PIPE) + (stdout, stderr) = proc.communicate() + print stdout + + proc = Popen([sys.executable, 'runme.py', 'Simple_optimized'], stdout=PIPE) + (stdout, stderr) = proc.communicate() + print stdout + + proc = Popen([sys.executable, 'runme.py', 'Simple_builtin'], stdout=PIPE) + (stdout, stderr) = proc.communicate() + print stdout diff --git a/Examples/python/performance/hierarchy/runme.py b/Examples/python/performance/hierarchy/runme.py index 7e50aff16..8a57da05e 100644 --- a/Examples/python/performance/hierarchy/runme.py +++ b/Examples/python/performance/hierarchy/runme.py @@ -1,17 +1,12 @@ #!/usr/bin/env import sys -from subprocess import * +sys.path.append('..') +import harness -proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout - -proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout - -proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout +def proc (mod) : + x = mod.H() + for i in range(10000000) : + x.func() +harness.run(proc) diff --git a/Examples/python/performance/hierarchy/runme_baseline.py b/Examples/python/performance/hierarchy/runme_baseline.py deleted file mode 100644 index 584b9fb97..000000000 --- a/Examples/python/performance/hierarchy/runme_baseline.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_baseline -import time - -t1 = time.clock() -x = Simple_baseline.H() -for i in range(10000000) : - x.func() -t2 = time.clock() -print "Simple_baseline took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/hierarchy/runme_builtin.py b/Examples/python/performance/hierarchy/runme_builtin.py deleted file mode 100644 index a095ed223..000000000 --- a/Examples/python/performance/hierarchy/runme_builtin.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_builtin -import time - -t1 = time.clock() -x = Simple_builtin.H() -for i in range(10000000) : - x.func() -t2 = time.clock() -print "Simple_builtin took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/hierarchy/runme_optimized.py b/Examples/python/performance/hierarchy/runme_optimized.py deleted file mode 100644 index c6f20463d..000000000 --- a/Examples/python/performance/hierarchy/runme_optimized.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_optimized -import time - -t1 = time.clock() -x = Simple_optimized.H() -for i in range(10000000) : - x.func() -t2 = time.clock() -print "Simple_optimized took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/hierarchy_operator/runme.py b/Examples/python/performance/hierarchy_operator/runme.py index 7e50aff16..cf200362f 100644 --- a/Examples/python/performance/hierarchy_operator/runme.py +++ b/Examples/python/performance/hierarchy_operator/runme.py @@ -1,17 +1,12 @@ #!/usr/bin/env import sys -from subprocess import * +sys.path.append('..') +import harness -proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout - -proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout - -proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout +def proc (mod) : + x = mod.H() + for i in range(10000000) : + x += i +harness.run(proc) diff --git a/Examples/python/performance/hierarchy_operator/runme_baseline.py b/Examples/python/performance/hierarchy_operator/runme_baseline.py deleted file mode 100644 index 38b4814de..000000000 --- a/Examples/python/performance/hierarchy_operator/runme_baseline.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_baseline -import time - -t1 = time.clock() -x = Simple_baseline.H() -for i in range(10000000) : - x += i -t2 = time.clock() -print "Simple_baseline took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/hierarchy_operator/runme_builtin.py b/Examples/python/performance/hierarchy_operator/runme_builtin.py deleted file mode 100644 index 2ce0459a8..000000000 --- a/Examples/python/performance/hierarchy_operator/runme_builtin.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_builtin -import time - -t1 = time.clock() -x = Simple_builtin.H() -for i in range(10000000) : - x += i -t2 = time.clock() -print "Simple_builtin took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/hierarchy_operator/runme_optimized.py b/Examples/python/performance/hierarchy_operator/runme_optimized.py deleted file mode 100644 index 7d849051b..000000000 --- a/Examples/python/performance/hierarchy_operator/runme_optimized.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_optimized -import time - -t1 = time.clock() -x = Simple_optimized.H() -for i in range(10000000) : - x += i -t2 = time.clock() -print "Simple_optimized took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/operator/runme.py b/Examples/python/performance/operator/runme.py index 7e50aff16..61a0e8edc 100644 --- a/Examples/python/performance/operator/runme.py +++ b/Examples/python/performance/operator/runme.py @@ -1,17 +1,12 @@ #!/usr/bin/env import sys -from subprocess import * +sys.path.append('..') +import harness -proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout - -proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout - -proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE) -(stdout, stderr) = proc.communicate() -print stdout +def proc (mod) : + x = mod.MyClass() + for i in range(10000000) : + x = x + i +harness.run(proc) diff --git a/Examples/python/performance/operator/runme_baseline.py b/Examples/python/performance/operator/runme_baseline.py deleted file mode 100644 index f7fa9094b..000000000 --- a/Examples/python/performance/operator/runme_baseline.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_baseline -import time - -t1 = time.clock() -x = Simple_baseline.MyClass() -for i in range(10000000) : - x = x + i -t2 = time.clock() -print "Simple_baseline took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/operator/runme_builtin.py b/Examples/python/performance/operator/runme_builtin.py deleted file mode 100644 index 73da3afb2..000000000 --- a/Examples/python/performance/operator/runme_builtin.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_builtin -import time - -t1 = time.clock() -x = Simple_builtin.MyClass() -for i in range(10000000) : - x = x + i -t2 = time.clock() -print "Simple_builtin took %f seconds" % (t2 - t1) diff --git a/Examples/python/performance/operator/runme_optimized.py b/Examples/python/performance/operator/runme_optimized.py deleted file mode 100644 index 4f22e0bda..000000000 --- a/Examples/python/performance/operator/runme_optimized.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import Simple_optimized -import time - -t1 = time.clock() -x = Simple_optimized.MyClass() -for i in range(10000000) : - x = x + i -t2 = time.clock() -print "Simple_optimized took %f seconds" % (t2 - t1) From f2d721aeac84c9c6815de86be01256e171284195 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Thu, 10 Feb 2011 05:56:35 +0000 Subject: [PATCH 28/56] Accidentally added build targets. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12453 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../constructor/Simple_baseline.py | 86 -------- .../performance/constructor/Simple_builtin.py | 81 ------- .../constructor/Simple_optimized.py | 93 -------- .../performance/func/Simple_baseline.py | 86 -------- .../python/performance/func/Simple_builtin.py | 81 ------- .../performance/func/Simple_optimized.py | 93 -------- .../performance/hierarchy/Simple_baseline.py | 205 ------------------ .../performance/hierarchy/Simple_builtin.py | 88 -------- .../performance/hierarchy/Simple_optimized.py | 156 ------------- .../performance/operator/Simple_baseline.py | 86 -------- .../performance/operator/Simple_builtin.py | 81 ------- .../performance/operator/Simple_optimized.py | 93 -------- 12 files changed, 1229 deletions(-) delete mode 100644 Examples/python/performance/constructor/Simple_baseline.py delete mode 100644 Examples/python/performance/constructor/Simple_builtin.py delete mode 100644 Examples/python/performance/constructor/Simple_optimized.py delete mode 100644 Examples/python/performance/func/Simple_baseline.py delete mode 100644 Examples/python/performance/func/Simple_builtin.py delete mode 100644 Examples/python/performance/func/Simple_optimized.py delete mode 100644 Examples/python/performance/hierarchy/Simple_baseline.py delete mode 100644 Examples/python/performance/hierarchy/Simple_builtin.py delete mode 100644 Examples/python/performance/hierarchy/Simple_optimized.py delete mode 100644 Examples/python/performance/operator/Simple_baseline.py delete mode 100644 Examples/python/performance/operator/Simple_builtin.py delete mode 100644 Examples/python/performance/operator/Simple_optimized.py diff --git a/Examples/python/performance/constructor/Simple_baseline.py b/Examples/python/performance/constructor/Simple_baseline.py deleted file mode 100644 index 7e401b403..000000000 --- a/Examples/python/performance/constructor/Simple_baseline.py +++ /dev/null @@ -1,86 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. -# This file is compatible with both classic and new-style classes. - -from sys import version_info -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_baseline', [dirname(__file__)]) - except ImportError: - import _Simple_baseline - return _Simple_baseline - if fp is not None: - try: - _mod = imp.load_module('_Simple_baseline', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_baseline = swig_import_helper() - del swig_import_helper -else: - import _Simple_baseline -del version_info -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -class MyClass(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, MyClass, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, MyClass, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_MyClass() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_MyClass - __del__ = lambda self : None; - def func(self): return _Simple_baseline.MyClass_func(self) -MyClass_swigregister = _Simple_baseline.MyClass_swigregister -MyClass_swigregister(MyClass) - - - diff --git a/Examples/python/performance/constructor/Simple_builtin.py b/Examples/python/performance/constructor/Simple_builtin.py deleted file mode 100644 index 4ecd8a63e..000000000 --- a/Examples/python/performance/constructor/Simple_builtin.py +++ /dev/null @@ -1,81 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. - -from sys import version_info -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_builtin', [dirname(__file__)]) - except ImportError: - import _Simple_builtin - return _Simple_builtin - if fp is not None: - try: - _mod = imp.load_module('_Simple_builtin', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_builtin = swig_import_helper() - del swig_import_helper -else: - import _Simple_builtin -del version_info -from _Simple_builtin import * -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -def _swig_setattr_nondynamic_method(set): - def set_attr(self,name,value): - if (name == "thisown"): return self.this.own(value) - if hasattr(self,name) or (name == "this"): - set(self,name,value) - else: - raise AttributeError("You cannot add attributes to %s" % self) - return set_attr - - - - - diff --git a/Examples/python/performance/constructor/Simple_optimized.py b/Examples/python/performance/constructor/Simple_optimized.py deleted file mode 100644 index 0bf42ced3..000000000 --- a/Examples/python/performance/constructor/Simple_optimized.py +++ /dev/null @@ -1,93 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. - -from sys import version_info -if version_info >= (3,0,0): - new_instancemethod = lambda func, inst, cls: _Simple_optimized.SWIG_PyInstanceMethod_New(func) -else: - from new import instancemethod as new_instancemethod -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_optimized', [dirname(__file__)]) - except ImportError: - import _Simple_optimized - return _Simple_optimized - if fp is not None: - try: - _mod = imp.load_module('_Simple_optimized', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_optimized = swig_import_helper() - del swig_import_helper -else: - import _Simple_optimized -del version_info -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -def _swig_setattr_nondynamic_method(set): - def set_attr(self,name,value): - if (name == "thisown"): return self.this.own(value) - if hasattr(self,name) or (name == "this"): - set(self,name,value) - else: - raise AttributeError("You cannot add attributes to %s" % self) - return set_attr - - -class MyClass(object): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.MyClass_swiginit(self,_Simple_optimized.new_MyClass()) - __swig_destroy__ = _Simple_optimized.delete_MyClass -MyClass.func = new_instancemethod(_Simple_optimized.MyClass_func,None,MyClass) -MyClass_swigregister = _Simple_optimized.MyClass_swigregister -MyClass_swigregister(MyClass) - - - diff --git a/Examples/python/performance/func/Simple_baseline.py b/Examples/python/performance/func/Simple_baseline.py deleted file mode 100644 index 7e401b403..000000000 --- a/Examples/python/performance/func/Simple_baseline.py +++ /dev/null @@ -1,86 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. -# This file is compatible with both classic and new-style classes. - -from sys import version_info -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_baseline', [dirname(__file__)]) - except ImportError: - import _Simple_baseline - return _Simple_baseline - if fp is not None: - try: - _mod = imp.load_module('_Simple_baseline', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_baseline = swig_import_helper() - del swig_import_helper -else: - import _Simple_baseline -del version_info -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -class MyClass(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, MyClass, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, MyClass, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_MyClass() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_MyClass - __del__ = lambda self : None; - def func(self): return _Simple_baseline.MyClass_func(self) -MyClass_swigregister = _Simple_baseline.MyClass_swigregister -MyClass_swigregister(MyClass) - - - diff --git a/Examples/python/performance/func/Simple_builtin.py b/Examples/python/performance/func/Simple_builtin.py deleted file mode 100644 index 4ecd8a63e..000000000 --- a/Examples/python/performance/func/Simple_builtin.py +++ /dev/null @@ -1,81 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. - -from sys import version_info -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_builtin', [dirname(__file__)]) - except ImportError: - import _Simple_builtin - return _Simple_builtin - if fp is not None: - try: - _mod = imp.load_module('_Simple_builtin', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_builtin = swig_import_helper() - del swig_import_helper -else: - import _Simple_builtin -del version_info -from _Simple_builtin import * -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -def _swig_setattr_nondynamic_method(set): - def set_attr(self,name,value): - if (name == "thisown"): return self.this.own(value) - if hasattr(self,name) or (name == "this"): - set(self,name,value) - else: - raise AttributeError("You cannot add attributes to %s" % self) - return set_attr - - - - - diff --git a/Examples/python/performance/func/Simple_optimized.py b/Examples/python/performance/func/Simple_optimized.py deleted file mode 100644 index 0bf42ced3..000000000 --- a/Examples/python/performance/func/Simple_optimized.py +++ /dev/null @@ -1,93 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. - -from sys import version_info -if version_info >= (3,0,0): - new_instancemethod = lambda func, inst, cls: _Simple_optimized.SWIG_PyInstanceMethod_New(func) -else: - from new import instancemethod as new_instancemethod -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_optimized', [dirname(__file__)]) - except ImportError: - import _Simple_optimized - return _Simple_optimized - if fp is not None: - try: - _mod = imp.load_module('_Simple_optimized', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_optimized = swig_import_helper() - del swig_import_helper -else: - import _Simple_optimized -del version_info -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -def _swig_setattr_nondynamic_method(set): - def set_attr(self,name,value): - if (name == "thisown"): return self.this.own(value) - if hasattr(self,name) or (name == "this"): - set(self,name,value) - else: - raise AttributeError("You cannot add attributes to %s" % self) - return set_attr - - -class MyClass(object): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.MyClass_swiginit(self,_Simple_optimized.new_MyClass()) - __swig_destroy__ = _Simple_optimized.delete_MyClass -MyClass.func = new_instancemethod(_Simple_optimized.MyClass_func,None,MyClass) -MyClass_swigregister = _Simple_optimized.MyClass_swigregister -MyClass_swigregister(MyClass) - - - diff --git a/Examples/python/performance/hierarchy/Simple_baseline.py b/Examples/python/performance/hierarchy/Simple_baseline.py deleted file mode 100644 index ed91fd14d..000000000 --- a/Examples/python/performance/hierarchy/Simple_baseline.py +++ /dev/null @@ -1,205 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. -# This file is compatible with both classic and new-style classes. - -from sys import version_info -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_baseline', [dirname(__file__)]) - except ImportError: - import _Simple_baseline - return _Simple_baseline - if fp is not None: - try: - _mod = imp.load_module('_Simple_baseline', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_baseline = swig_import_helper() - del swig_import_helper -else: - import _Simple_baseline -del version_info -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -class A(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, A, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, A, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_A() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_A - __del__ = lambda self : None; - def func(self): return _Simple_baseline.A_func(self) -A_swigregister = _Simple_baseline.A_swigregister -A_swigregister(A) - -class B(A): - __swig_setmethods__ = {} - for _s in [A]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, B, name, value) - __swig_getmethods__ = {} - for _s in [A]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, B, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_B() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_B - __del__ = lambda self : None; -B_swigregister = _Simple_baseline.B_swigregister -B_swigregister(B) - -class C(B): - __swig_setmethods__ = {} - for _s in [B]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, C, name, value) - __swig_getmethods__ = {} - for _s in [B]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, C, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_C() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_C - __del__ = lambda self : None; -C_swigregister = _Simple_baseline.C_swigregister -C_swigregister(C) - -class D(C): - __swig_setmethods__ = {} - for _s in [C]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, D, name, value) - __swig_getmethods__ = {} - for _s in [C]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, D, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_D() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_D - __del__ = lambda self : None; -D_swigregister = _Simple_baseline.D_swigregister -D_swigregister(D) - -class E(D): - __swig_setmethods__ = {} - for _s in [D]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, E, name, value) - __swig_getmethods__ = {} - for _s in [D]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, E, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_E() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_E - __del__ = lambda self : None; -E_swigregister = _Simple_baseline.E_swigregister -E_swigregister(E) - -class F(E): - __swig_setmethods__ = {} - for _s in [E]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, F, name, value) - __swig_getmethods__ = {} - for _s in [E]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, F, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_F() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_F - __del__ = lambda self : None; -F_swigregister = _Simple_baseline.F_swigregister -F_swigregister(F) - -class G(F): - __swig_setmethods__ = {} - for _s in [F]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, G, name, value) - __swig_getmethods__ = {} - for _s in [F]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, G, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_G() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_G - __del__ = lambda self : None; -G_swigregister = _Simple_baseline.G_swigregister -G_swigregister(G) - -class H(G): - __swig_setmethods__ = {} - for _s in [G]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{})) - __setattr__ = lambda self, name, value: _swig_setattr(self, H, name, value) - __swig_getmethods__ = {} - for _s in [G]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{})) - __getattr__ = lambda self, name: _swig_getattr(self, H, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_H() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_H - __del__ = lambda self : None; -H_swigregister = _Simple_baseline.H_swigregister -H_swigregister(H) - - - diff --git a/Examples/python/performance/hierarchy/Simple_builtin.py b/Examples/python/performance/hierarchy/Simple_builtin.py deleted file mode 100644 index 6572f16bc..000000000 --- a/Examples/python/performance/hierarchy/Simple_builtin.py +++ /dev/null @@ -1,88 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. - -from sys import version_info -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_builtin', [dirname(__file__)]) - except ImportError: - import _Simple_builtin - return _Simple_builtin - if fp is not None: - try: - _mod = imp.load_module('_Simple_builtin', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_builtin = swig_import_helper() - del swig_import_helper -else: - import _Simple_builtin -del version_info -from _Simple_builtin import * -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -def _swig_setattr_nondynamic_method(set): - def set_attr(self,name,value): - if (name == "thisown"): return self.this.own(value) - if hasattr(self,name) or (name == "this"): - set(self,name,value) - else: - raise AttributeError("You cannot add attributes to %s" % self) - return set_attr - - - - - - - - - - - - diff --git a/Examples/python/performance/hierarchy/Simple_optimized.py b/Examples/python/performance/hierarchy/Simple_optimized.py deleted file mode 100644 index 3cfcda3b1..000000000 --- a/Examples/python/performance/hierarchy/Simple_optimized.py +++ /dev/null @@ -1,156 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. - -from sys import version_info -if version_info >= (3,0,0): - new_instancemethod = lambda func, inst, cls: _Simple_optimized.SWIG_PyInstanceMethod_New(func) -else: - from new import instancemethod as new_instancemethod -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_optimized', [dirname(__file__)]) - except ImportError: - import _Simple_optimized - return _Simple_optimized - if fp is not None: - try: - _mod = imp.load_module('_Simple_optimized', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_optimized = swig_import_helper() - del swig_import_helper -else: - import _Simple_optimized -del version_info -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -def _swig_setattr_nondynamic_method(set): - def set_attr(self,name,value): - if (name == "thisown"): return self.this.own(value) - if hasattr(self,name) or (name == "this"): - set(self,name,value) - else: - raise AttributeError("You cannot add attributes to %s" % self) - return set_attr - - -class A(object): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.A_swiginit(self,_Simple_optimized.new_A()) - __swig_destroy__ = _Simple_optimized.delete_A -A.func = new_instancemethod(_Simple_optimized.A_func,None,A) -A_swigregister = _Simple_optimized.A_swigregister -A_swigregister(A) - -class B(A): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.B_swiginit(self,_Simple_optimized.new_B()) - __swig_destroy__ = _Simple_optimized.delete_B -B_swigregister = _Simple_optimized.B_swigregister -B_swigregister(B) - -class C(B): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.C_swiginit(self,_Simple_optimized.new_C()) - __swig_destroy__ = _Simple_optimized.delete_C -C_swigregister = _Simple_optimized.C_swigregister -C_swigregister(C) - -class D(C): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.D_swiginit(self,_Simple_optimized.new_D()) - __swig_destroy__ = _Simple_optimized.delete_D -D_swigregister = _Simple_optimized.D_swigregister -D_swigregister(D) - -class E(D): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.E_swiginit(self,_Simple_optimized.new_E()) - __swig_destroy__ = _Simple_optimized.delete_E -E_swigregister = _Simple_optimized.E_swigregister -E_swigregister(E) - -class F(E): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.F_swiginit(self,_Simple_optimized.new_F()) - __swig_destroy__ = _Simple_optimized.delete_F -F_swigregister = _Simple_optimized.F_swigregister -F_swigregister(F) - -class G(F): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.G_swiginit(self,_Simple_optimized.new_G()) - __swig_destroy__ = _Simple_optimized.delete_G -G_swigregister = _Simple_optimized.G_swigregister -G_swigregister(G) - -class H(G): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.H_swiginit(self,_Simple_optimized.new_H()) - __swig_destroy__ = _Simple_optimized.delete_H -H_swigregister = _Simple_optimized.H_swigregister -H_swigregister(H) - - - diff --git a/Examples/python/performance/operator/Simple_baseline.py b/Examples/python/performance/operator/Simple_baseline.py deleted file mode 100644 index 62da3e348..000000000 --- a/Examples/python/performance/operator/Simple_baseline.py +++ /dev/null @@ -1,86 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. -# This file is compatible with both classic and new-style classes. - -from sys import version_info -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_baseline', [dirname(__file__)]) - except ImportError: - import _Simple_baseline - return _Simple_baseline - if fp is not None: - try: - _mod = imp.load_module('_Simple_baseline', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_baseline = swig_import_helper() - del swig_import_helper -else: - import _Simple_baseline -del version_info -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -class MyClass(_object): - __swig_setmethods__ = {} - __setattr__ = lambda self, name, value: _swig_setattr(self, MyClass, name, value) - __swig_getmethods__ = {} - __getattr__ = lambda self, name: _swig_getattr(self, MyClass, name) - __repr__ = _swig_repr - def __init__(self): - this = _Simple_baseline.new_MyClass() - try: self.this.append(this) - except: self.this = this - __swig_destroy__ = _Simple_baseline.delete_MyClass - __del__ = lambda self : None; - def __add__(self, *args): return _Simple_baseline.MyClass___add__(self, *args) -MyClass_swigregister = _Simple_baseline.MyClass_swigregister -MyClass_swigregister(MyClass) - - - diff --git a/Examples/python/performance/operator/Simple_builtin.py b/Examples/python/performance/operator/Simple_builtin.py deleted file mode 100644 index 4ecd8a63e..000000000 --- a/Examples/python/performance/operator/Simple_builtin.py +++ /dev/null @@ -1,81 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. - -from sys import version_info -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_builtin', [dirname(__file__)]) - except ImportError: - import _Simple_builtin - return _Simple_builtin - if fp is not None: - try: - _mod = imp.load_module('_Simple_builtin', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_builtin = swig_import_helper() - del swig_import_helper -else: - import _Simple_builtin -del version_info -from _Simple_builtin import * -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -def _swig_setattr_nondynamic_method(set): - def set_attr(self,name,value): - if (name == "thisown"): return self.this.own(value) - if hasattr(self,name) or (name == "this"): - set(self,name,value) - else: - raise AttributeError("You cannot add attributes to %s" % self) - return set_attr - - - - - diff --git a/Examples/python/performance/operator/Simple_optimized.py b/Examples/python/performance/operator/Simple_optimized.py deleted file mode 100644 index 2db323a34..000000000 --- a/Examples/python/performance/operator/Simple_optimized.py +++ /dev/null @@ -1,93 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 2.0.2 -# -# Do not make changes to this file unless you know what you are doing--modify -# the SWIG interface file instead. - -from sys import version_info -if version_info >= (3,0,0): - new_instancemethod = lambda func, inst, cls: _Simple_optimized.SWIG_PyInstanceMethod_New(func) -else: - from new import instancemethod as new_instancemethod -if version_info >= (2,6,0): - def swig_import_helper(): - from os.path import dirname - import imp - fp = None - try: - fp, pathname, description = imp.find_module('_Simple_optimized', [dirname(__file__)]) - except ImportError: - import _Simple_optimized - return _Simple_optimized - if fp is not None: - try: - _mod = imp.load_module('_Simple_optimized', fp, pathname, description) - finally: - fp.close() - return _mod - _Simple_optimized = swig_import_helper() - del swig_import_helper -else: - import _Simple_optimized -del version_info -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'SwigPyObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError(name) - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -try: - _object = object - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 - - -def _swig_setattr_nondynamic_method(set): - def set_attr(self,name,value): - if (name == "thisown"): return self.this.own(value) - if hasattr(self,name) or (name == "this"): - set(self,name,value) - else: - raise AttributeError("You cannot add attributes to %s" % self) - return set_attr - - -class MyClass(object): - thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - __repr__ = _swig_repr - def __init__(self): - _Simple_optimized.MyClass_swiginit(self,_Simple_optimized.new_MyClass()) - __swig_destroy__ = _Simple_optimized.delete_MyClass -MyClass.__add__ = new_instancemethod(_Simple_optimized.MyClass___add__,None,MyClass) -MyClass_swigregister = _Simple_optimized.MyClass_swigregister -MyClass_swigregister(MyClass) - - - From 6b3d2aa2d5cb66ca51d6b7198e5422a01ebd232f Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Thu, 10 Feb 2011 06:32:11 +0000 Subject: [PATCH 29/56] Some incomplete documentation git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12454 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Python.html | 85 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 1b8a3f671..3ee140c59 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -43,6 +43,7 @@
  • Further details on the Python class interface @@ -2203,6 +2204,16 @@ of low-level details were omitted. This section provides a brief overview of how the proxy classes work.

    +

    New in swig version 2.0.3: +The use of Python proxy classes has performance implications that may be +unacceptable for a high-performance library. The new -builtin +option instructs swig to forego the use of proxy classes, and instead +create wrapped types as new built-in Python types. When this option is used, +the following section ("Proxy classes") does not apply. Details on the use of +the -builtin option are in the Built-in Classes +section. +

    +

    33.4.1 Proxy classes

    @@ -2292,7 +2303,77 @@ you can attach new Python methods to the class and you can even inherit from it by Python built-in types until Python 2.2).

    -

    33.4.2 Memory management

    +

    33.4.2 Built-in Classes

    + +

    +The -builtin option gives a significant performance improvement +in the wrapped code. More information about python built-in extensions is available +here. +

    + +

    33.4.2.1 Limitations

    + +

    Use of the -builtin option implies a couple of limitations: +

      +
    • Wrapped types may not be thrown as python exceptions
    • +
    • Reverse operators are not supported.
    • +
    +

    + +

    +To illustrate the second point, if you have a wrapped class called MyString, +and you want to use instances of MyString interchangeably with native python +strings, you can define an 'operator+ (const char*)' method : +

    + +
    +
    +class MyString {
    +public:
    +    MyString (const char *init);
    +    MyString operator+ (const char *other);
    +    ...
    +};
    +
    +
    + +

    +swig will automatically create an operator overload in python that will allow this: +

    + +
    +
    +from MyModule import MyString
    +
    +mystr = MyString("Nobody expects")
    +episode = mystr + " the Spanish Inquisition"
    +
    +
    + +

    +This works because the first operand -- the instance of MyString -- defines a way +to add a MyString and a native string. However, the following will not work: +

    + +
    +
    +from MyModule import MyString
    +
    +mystr = MyString("Parrot")
    +episode = "Dead " + mystr
    +
    +
    + +

    +The above code fails, because the first operand -- a native python string -- +doesn't know how to add itself to an instance of MyString. +

    + +

    33.4.2.2 Getting the most out of builtin-types

    + +

    TODO

    + +

    33.4.3 Memory management

    @@ -2484,7 +2565,7 @@ It is also possible to deal with situations like this using typemaps--an advanced topic discussed later.

    -

    33.4.3 Python 2.2 and classic classes

    +

    33.4.4 Python 2.2 and classic classes

    From ea4cab8e4cab5bc9e2aff09fb74f25227994dc3a Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Thu, 17 Feb 2011 05:52:18 +0000 Subject: [PATCH 30/56] A small unicode fix. A partial fix for the problem with overloading, varargs, and fastunpack: with this fix, the wrappers will compile. However, they still contain faulty logic and unreachable code in the dispatch function. The comprehensive fix would have to be in overload.cxx. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12465 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pyrun.swg | 2 +- Source/Modules/python.cxx | 44 +++++++++++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 57b3d1780..8957b3192 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1705,7 +1705,7 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) #ifdef Py_USING_UNICODE if (PyString_Check(name)) { - name = PyUnicode_Decode(PyString_AsString(name), PyBytes_Size(name), NULL, NULL); + name = PyUnicode_Decode(PyString_AsString(name), PyString_Size(name), NULL, NULL); if (name == NULL) return -1; } else if (!PyUnicode_Check(name)) { diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 9eaaa1f9d..693ac0f98 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -2036,6 +2036,7 @@ public: bool add_self = builtin_self && (!builtin_ctor || director_class); 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 *wrap_return = builtin_ctor ? "int " : "PyObject *"; String *linkage = NewString("SWIGINTERN "); @@ -2112,7 +2113,24 @@ public: } } - int funpack = modernargs && fastunpack && !varargs && !allow_kwargs; + if (overname) { + String *over_varargs_attr = Getattr(n, "sym:over_varargs"); + if (!over_varargs_attr) { + for (Node *sibling = n; sibling; sibling = Getattr(sibling, "sym:nextSibling")) { + if (emit_isvarargs(Getattr(sibling, "parms"))) { + over_varargs = true; + break; + } + } + 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); + } + if (strcmp(Char(over_varargs_attr), "0")) + over_varargs = true; + } + + int funpack = modernargs && fastunpack && !varargs && !over_varargs && !allow_kwargs; int noargs = funpack && (tuple_required == 0 && tuple_arguments == 0); int onearg = funpack && (tuple_required == 1 && tuple_arguments == 1); @@ -2579,12 +2597,30 @@ public: if (varargs) { DelWrapper(f); f = NewWrapper(); - Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL); + 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); + } Wrapper_add_local(f, "resultobj", builtin_ctor ? "int resultobj" : "PyObject *resultobj"); Wrapper_add_local(f, "varargs", "PyObject *varargs"); Wrapper_add_local(f, "newargs", "PyObject *newargs"); - 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); + if (funpack) { + Wrapper_add_local(f, "i", "int i"); + Printf(f->code, "newargs = PyTuple_New(%d);\n", num_arguments); + Printf(f->code, "for (i = 0; i < %d; ++i) {\n", num_arguments); + Printf(f->code, " PyTuple_SET_ITEM(newargs, i, swig_obj[i]);\n"); + Printf(f->code, " Py_XINCREF(swig_obj[i]);\n"); + Printf(f->code, "}\n"); + Printf(f->code, "varargs = PyTuple_New(nobjs > %d ? nobjs - %d : 0);\n", num_arguments, num_arguments); + Printf(f->code, "for (i = 0; i < nobjs - %d; ++i) {\n", num_arguments); + Printf(f->code, " PyTuple_SET_ITEM(newargs, i, swig_obj[i + %d]);\n", num_arguments); + Printf(f->code, " Py_XINCREF(swig_obj[i + %d]);\n", num_arguments); + Printf(f->code, "}\n"); + } else { + 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); Append(f->code, "Py_XDECREF(newargs);\n"); Append(f->code, "Py_XDECREF(varargs);\n"); From 97802ab8c4707079bad123f9c754606d3c2ed213 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Thu, 3 Mar 2011 04:18:58 +0000 Subject: [PATCH 31/56] Changed a bunch of methods from SWIGRUNTIME to SWIGINTERN. Removed a snarky comment. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12513 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/boost_shared_ptr.i | 4 ---- Lib/python/builtin.swg | 30 +++++++++++++++--------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Lib/python/boost_shared_ptr.i b/Lib/python/boost_shared_ptr.i index 129bd9965..b62b2b87f 100644 --- a/Lib/python/boost_shared_ptr.i +++ b/Lib/python/boost_shared_ptr.i @@ -314,10 +314,6 @@ %template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; -// Separate out the code for builtin types, since it's pretty extensive. -// I feel compelled to point out that the functionality provided by -// smart pointers is utterly redundant when using builtin types. - #if defined(SWIGPYTHON_BUILTIN) %typemap(builtin_init, fragment="SWIG_null_deleter") CONST TYPE * { diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index b662acbb7..2811e326b 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -184,13 +184,13 @@ wrapper##_closure (PyObject *a) \ return result; \ } -SWIGRUNTIME int py_builtin_bad_init (PyObject *self, PyObject *args, PyObject *kwds) +SWIGINTERN int py_builtin_bad_init (PyObject *self, PyObject *args, PyObject *kwds) { PyErr_Format(PyExc_TypeError, "Cannot create new instances of type '%.300s'", self->ob_type->tp_name); return -1; } -SWIGRUNTIME void py_builtin_bad_dealloc (PyObject *pyobj) +SWIGINTERN void py_builtin_bad_dealloc (PyObject *pyobj) { SwigPyObject *sobj = (SwigPyObject*) pyobj; if (sobj->own) { @@ -205,7 +205,7 @@ typedef struct { PyCFunction set; } SwigPyGetSet; -SWIGRUNTIME PyObject* +SWIGINTERN PyObject* pyswig_getter_closure (PyObject *obj, void *closure) { if (!closure) @@ -220,7 +220,7 @@ pyswig_getter_closure (PyObject *obj, void *closure) return result; } -SWIGRUNTIME PyObject* +SWIGINTERN PyObject* pyswig_funpack_getter_closure (PyObject *obj, void *closure) { if (!closure) @@ -232,7 +232,7 @@ pyswig_funpack_getter_closure (PyObject *obj, void *closure) return result; } -SWIGRUNTIME int +SWIGINTERN int pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure) { if (!closure) { @@ -254,7 +254,7 @@ pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure) return result ? 0 : -1; } -SWIGRUNTIME int +SWIGINTERN int pyswig_funpack_setter_closure (PyObject *obj, PyObject *val, void *closure) { if (!closure) { @@ -271,7 +271,7 @@ pyswig_funpack_setter_closure (PyObject *obj, PyObject *val, void *closure) return result ? 0 : -1; } -SWIGRUNTIME PyObject* +SWIGINTERN PyObject* pyswig_static_getter_closure (PyObject *obj, void *closure) { if (!closure) @@ -286,7 +286,7 @@ pyswig_static_getter_closure (PyObject *obj, void *closure) return result; } -SWIGRUNTIME int +SWIGINTERN int pyswig_static_setter_closure (PyObject *obj, PyObject *val, void *closure) { if (!closure) { @@ -308,7 +308,7 @@ pyswig_static_setter_closure (PyObject *obj, PyObject *val, void *closure) return result ? 0 : -1; } -SWIGRUNTIME void +SWIGINTERN void SwigPyStaticVar_dealloc(PyDescrObject *descr) { _PyObject_GC_UNTRACK(descr); @@ -317,7 +317,7 @@ SwigPyStaticVar_dealloc(PyDescrObject *descr) PyObject_GC_Del(descr); } -SWIGRUNTIME PyObject * +SWIGINTERN PyObject * SwigPyStaticVar_repr(PyGetSetDescrObject *descr) { #if PY_VERSION_HEX >= 0x03000000 @@ -331,7 +331,7 @@ SwigPyStaticVar_repr(PyGetSetDescrObject *descr) #endif } -SWIGRUNTIME int +SWIGINTERN int SwigPyStaticVar_traverse(PyObject *self, visitproc visit, void *arg) { PyDescrObject *descr = (PyDescrObject *)self; @@ -339,7 +339,7 @@ SwigPyStaticVar_traverse(PyObject *self, visitproc visit, void *arg) return 0; } -SWIGRUNTIME PyObject * +SWIGINTERN PyObject * SwigPyStaticVar_get (PyGetSetDescrObject *descr, PyObject *obj, PyObject *type) { if (descr->d_getset->get != NULL) @@ -356,7 +356,7 @@ SwigPyStaticVar_get (PyGetSetDescrObject *descr, PyObject *obj, PyObject *type) return NULL; } -SWIGRUNTIME int +SWIGINTERN int SwigPyStaticVar_set (PyGetSetDescrObject *descr, PyObject *obj, PyObject *value) { int res; @@ -377,7 +377,7 @@ SwigPyStaticVar_set (PyGetSetDescrObject *descr, PyObject *obj, PyObject *value) return -1; } -SWIGRUNTIME PyTypeObject SwigPyStaticVar_Type = { +SWIGINTERN PyTypeObject SwigPyStaticVar_Type = { #if PY_VERSION_HEX >= 0x03000000 PyVarObject_HEAD_INIT(&PyType_Type, 0) #else @@ -419,7 +419,7 @@ SWIGRUNTIME PyTypeObject SwigPyStaticVar_Type = { (descrsetfunc)SwigPyStaticVar_set, /* tp_descr_set */ }; -SWIGRUNTIME int +SWIGINTERN int SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value) { PyObject *attribute = _PyType_Lookup(type, name); From 908c37cef8cd3770826f9db4d7a6b6541f24d261 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 3 Mar 2011 19:34:18 +0000 Subject: [PATCH 32/56] Coding style fixes for Python builtin changes added on the szager-builtin branch git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12515 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/builtin.swg | 574 +++++++++++++++++--------------------- Lib/python/director.swg | 9 +- Lib/python/pyinit.swg | 4 +- Lib/python/pyrun.swg | 278 +++++++++--------- Lib/python/pyruntime.swg | 1 - Lib/python/std_map.i | 8 +- Source/Modules/python.cxx | 57 ++-- 7 files changed, 425 insertions(+), 506 deletions(-) diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index 2811e326b..69402568e 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -1,15 +1,13 @@ #define PYSWIG_UNARYFUNC_CLOSURE(wrapper) \ -SWIGINTERN PyObject* \ -wrapper##_closure (PyObject *a) \ -{ \ - return wrapper(a, NULL); \ +SWIGINTERN PyObject * \ +wrapper##_closure(PyObject *a) { \ + return wrapper(a, NULL); \ } #define PYSWIG_DESTRUCTOR_CLOSURE(wrapper) \ SWIGINTERN void \ -wrapper##_closure (PyObject *a) \ -{ \ - SwigPyObject *sobj = (SwigPyObject*) a; \ +wrapper##_closure(PyObject *a) { \ + SwigPyObject *sobj = (SwigPyObject *)a; \ if (sobj->own) { \ PyObject *o = wrapper(a, NULL); \ Py_XDECREF(o); \ @@ -18,8 +16,7 @@ wrapper##_closure (PyObject *a) \ #define PYSWIG_INQUIRY_CLOSURE(wrapper) \ SWIGINTERN int \ -wrapper##_closure (PyObject *a) \ -{ \ +wrapper##_closure(PyObject *a) { \ PyObject *pyresult = wrapper(a, NULL); \ int result = pyresult && PyObject_IsTrue(pyresult) ? 1 : 0; \ Py_XDECREF(pyresult); \ @@ -27,9 +24,8 @@ wrapper##_closure (PyObject *a) \ } #define PYSWIG_BINARYFUNC_CLOSURE(wrapper) \ -SWIGINTERN PyObject* \ -wrapper##_closure (PyObject *a, PyObject *b) \ -{ \ +SWIGINTERN PyObject * \ +wrapper##_closure(PyObject *a, PyObject *b) { \ PyObject *tuple = PyTuple_New(1); \ assert(tuple); \ PyTuple_SET_ITEM(tuple, 0, b); \ @@ -40,9 +36,8 @@ wrapper##_closure (PyObject *a, PyObject *b) \ } #define PYSWIG_TERNARYFUNC_CLOSURE(wrapper) \ -SWIGINTERN PyObject* \ -wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \ -{ \ +SWIGINTERN PyObject * \ +wrapper##_closure(PyObject *a, PyObject *b, PyObject *c) { \ PyObject *tuple = PyTuple_New(2); \ assert(tuple); \ PyTuple_SET_ITEM(tuple, 0, b); \ @@ -56,8 +51,7 @@ wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \ #define PYSWIG_LENFUNC_CLOSURE(wrapper) \ SWIGINTERN Py_ssize_t \ -wrapper##_closure (PyObject *a) \ -{ \ +wrapper##_closure(PyObject *a) { \ PyObject *resultobj = wrapper(a, NULL); \ Py_ssize_t result = PyNumber_AsSsize_t(resultobj, NULL); \ Py_DECREF(resultobj); \ @@ -65,9 +59,8 @@ wrapper##_closure (PyObject *a) \ } #define PYSWIG_SSIZESSIZEARGFUNC_CLOSURE(wrapper) \ -SWIGINTERN PyObject* \ -wrapper##_closure (PyObject *a, Py_ssize_t b, Py_ssize_t c) \ -{ \ +SWIGINTERN PyObject * \ +wrapper##_closure(PyObject *a, Py_ssize_t b, Py_ssize_t c) { \ PyObject *tuple = PyTuple_New(2); \ assert(tuple); \ PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \ @@ -79,8 +72,7 @@ wrapper##_closure (PyObject *a, Py_ssize_t b, Py_ssize_t c) \ #define PYSWIG_SSIZESSIZEOBJARGPROC_CLOSURE(wrapper) \ SWIGINTERN int \ -wrapper##_closure (PyObject *a, Py_ssize_t b, Py_ssize_t c, PyObject *d) \ -{ \ +wrapper##_closure(PyObject *a, Py_ssize_t b, Py_ssize_t c, PyObject *d) { \ PyObject *tuple = PyTuple_New(d ? 3 : 2); \ assert(tuple); \ PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \ @@ -97,9 +89,8 @@ wrapper##_closure (PyObject *a, Py_ssize_t b, Py_ssize_t c, PyObject *d) \ } #define PYSWIG_SSIZEARGFUNC_CLOSURE(wrapper) \ -SWIGINTERN PyObject* \ -wrapper##_closure (PyObject *a, Py_ssize_t b) \ -{ \ +SWIGINTERN PyObject * \ +wrapper##_closure(PyObject *a, Py_ssize_t b) { \ PyObject *tuple = PyTuple_New(1); \ assert(tuple); \ PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \ @@ -109,9 +100,8 @@ wrapper##_closure (PyObject *a, Py_ssize_t b) \ } #define PYSWIG_FUNPACK_SSIZEARGFUNC_CLOSURE(wrapper) \ -SWIGINTERN PyObject* \ -wrapper##_closure (PyObject *a, Py_ssize_t b) \ -{ \ +SWIGINTERN PyObject * \ +wrapper##_closure(PyObject *a, Py_ssize_t b) { \ PyObject *arg = _PyLong_FromSsize_t(b); \ PyObject *result = wrapper(a, arg); \ Py_DECREF(arg); \ @@ -120,8 +110,7 @@ wrapper##_closure (PyObject *a, Py_ssize_t b) \ #define PYSWIG_SSIZEOBJARGPROC_CLOSURE(wrapper) \ SWIGINTERN int \ -wrapper##_closure (PyObject *a, Py_ssize_t b, PyObject *c) \ -{ \ +wrapper##_closure(PyObject *a, Py_ssize_t b, PyObject *c) { \ PyObject *tuple = PyTuple_New(2); \ assert(tuple); \ PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \ @@ -136,8 +125,7 @@ wrapper##_closure (PyObject *a, Py_ssize_t b, PyObject *c) \ #define PYSWIG_OBJOBJARGPROC_CLOSURE(wrapper) \ SWIGINTERN int \ -wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \ -{ \ +wrapper##_closure(PyObject *a, PyObject *b, PyObject *c) { \ PyObject *tuple = PyTuple_New(c ? 2 : 1); \ assert(tuple); \ PyTuple_SET_ITEM(tuple, 0, b); \ @@ -154,16 +142,14 @@ wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \ } #define PYSWIG_REPRFUNC_CLOSURE(wrapper) \ -SWIGINTERN PyObject* \ -wrapper##_closure (PyObject *a) \ -{ \ +SWIGINTERN PyObject * \ +wrapper##_closure(PyObject *a) { \ return wrapper(a, NULL); \ } #define PYSWIG_HASHFUNC_CLOSURE(wrapper) \ SWIGINTERN long \ -wrapper##_closure (PyObject *a) \ -{ \ +wrapper##_closure(PyObject *a) { \ PyObject *pyresult = wrapper(a, NULL); \ if (!pyresult || !PyLong_Check(pyresult)) \ return -1; \ @@ -173,9 +159,8 @@ wrapper##_closure (PyObject *a) \ } #define PYSWIG_ITERNEXT_CLOSURE(wrapper) \ -SWIGINTERN PyObject* \ -wrapper##_closure (PyObject *a) \ -{ \ +SWIGINTERN PyObject * \ +wrapper##_closure(PyObject *a) { \ PyObject *result = wrapper(a, NULL); \ if (result && result == Py_None) { \ Py_DECREF(result); \ @@ -184,288 +169,251 @@ wrapper##_closure (PyObject *a) \ return result; \ } -SWIGINTERN int py_builtin_bad_init (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) -{ - 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); - } -} - -typedef struct { - PyCFunction get; - PyCFunction set; -} SwigPyGetSet; - -SWIGINTERN PyObject* -pyswig_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 PyObject* -pyswig_funpack_getter_closure (PyObject *obj, void *closure) -{ - if (!closure) - return SWIG_Py_Void(); - SwigPyGetSet *getset = (SwigPyGetSet*) closure; - if (!getset->get) - return SWIG_Py_Void(); - PyObject *result = (*getset->get)(obj, NULL); - return result; -} - SWIGINTERN int -pyswig_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 member variable assignment in type '%.300s'", obj->ob_type->tp_name); - 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 int -pyswig_funpack_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 member variable assignment in type '%.300s'", obj->ob_type->tp_name); - return -1; - } - PyObject *result = (*getset->set)(obj, val); - Py_XDECREF(result); - 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; +py_builtin_bad_init(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 -SwigPyStaticVar_dealloc(PyDescrObject *descr) -{ - _PyObject_GC_UNTRACK(descr); - Py_XDECREF(descr->d_type); - Py_XDECREF(descr->d_name); - PyObject_GC_Del(descr); +py_builtin_bad_dealloc(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); + } +} + +typedef struct { + PyCFunction get; + PyCFunction set; +} SwigPyGetSet; + +SWIGINTERN PyObject * +pyswig_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 PyObject * -SwigPyStaticVar_repr(PyGetSetDescrObject *descr) -{ -#if PY_VERSION_HEX >= 0x03000000 - 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 +pyswig_funpack_getter_closure(PyObject *obj, void *closure) { + if (!closure) + return SWIG_Py_Void(); + SwigPyGetSet *getset = (SwigPyGetSet *)closure; + if (!getset->get) + return SWIG_Py_Void(); + PyObject *result = (*getset->get)(obj, NULL); + return result; } SWIGINTERN int -SwigPyStaticVar_traverse(PyObject *self, visitproc visit, void *arg) -{ - PyDescrObject *descr = (PyDescrObject *)self; - Py_VISIT(descr->d_type); - return 0; -} - -SWIGINTERN PyObject * -SwigPyStaticVar_get (PyGetSetDescrObject *descr, PyObject *obj, PyObject *type) -{ - if (descr->d_getset->get != NULL) - return descr->d_getset->get(obj, descr->d_getset->closure); -#if PY_VERSION_HEX >= 0x03000000 - PyErr_Format(PyExc_AttributeError, - "attribute '%.300U' of '%.100s' objects is not readable", - descr->d_name, descr->d_type->tp_name); -#else - PyErr_Format(PyExc_AttributeError, - "attribute '%.300s' of '%.100s' objects is not readable", - PyString_AsString(descr->d_name), descr->d_type->tp_name); -#endif - return NULL; -} - -SWIGINTERN int -SwigPyStaticVar_set (PyGetSetDescrObject *descr, PyObject *obj, PyObject *value) -{ - int res; - - if (descr->d_getset->set != NULL) - return descr->d_getset->set(obj, value, descr->d_getset->closure); -#if PY_VERSION_HEX >= 0x03000000 - PyErr_Format(PyExc_AttributeError, - "attribute '%.300U' of '%.100s' objects is not writable", - descr->d_name, - descr->d_type->tp_name); -#else - PyErr_Format(PyExc_AttributeError, - "attribute '%.300s' of '%.100s' objects is not writable", - PyString_AsString(descr->d_name), - descr->d_type->tp_name); -#endif +pyswig_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 member variable assignment in type '%.300s'", obj->ob_type->tp_name); + 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 int +pyswig_funpack_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 member variable assignment in type '%.300s'", obj->ob_type->tp_name); + return -1; + } + PyObject *result = (*getset->set)(obj, val); + Py_XDECREF(result); + 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); + Py_XDECREF(descr->d_type); + Py_XDECREF(descr->d_name); + PyObject_GC_Del(descr); +} + +SWIGINTERN PyObject * +SwigPyStaticVar_repr(PyGetSetDescrObject *descr) { +#if PY_VERSION_HEX >= 0x03000000 + 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 +} + +SWIGINTERN int +SwigPyStaticVar_traverse(PyObject *self, visitproc visit, void *arg) { + PyDescrObject *descr = (PyDescrObject *)self; + Py_VISIT(descr->d_type); + return 0; +} + +SWIGINTERN PyObject * +SwigPyStaticVar_get(PyGetSetDescrObject *descr, PyObject *obj, PyObject *type) { + if (descr->d_getset->get != NULL) + return descr->d_getset->get(obj, descr->d_getset->closure); +#if PY_VERSION_HEX >= 0x03000000 + PyErr_Format(PyExc_AttributeError, "attribute '%.300U' of '%.100s' objects is not readable", descr->d_name, descr->d_type->tp_name); +#else + PyErr_Format(PyExc_AttributeError, "attribute '%.300s' of '%.100s' objects is not readable", PyString_AsString(descr->d_name), descr->d_type->tp_name); +#endif + return NULL; +} + +SWIGINTERN int +SwigPyStaticVar_set(PyGetSetDescrObject *descr, PyObject *obj, PyObject *value) { + int res; + + if (descr->d_getset->set != NULL) + return descr->d_getset->set(obj, value, descr->d_getset->closure); +#if PY_VERSION_HEX >= 0x03000000 + PyErr_Format(PyExc_AttributeError, "attribute '%.300U' of '%.100s' objects is not writable", descr->d_name, descr->d_type->tp_name); +#else + PyErr_Format(PyExc_AttributeError, "attribute '%.300s' of '%.100s' objects is not writable", PyString_AsString(descr->d_name), descr->d_type->tp_name); +#endif + return -1; } SWIGINTERN PyTypeObject SwigPyStaticVar_Type = { #if PY_VERSION_HEX >= 0x03000000 - PyVarObject_HEAD_INIT(&PyType_Type, 0) + PyVarObject_HEAD_INIT(&PyType_Type, 0) #else - PyObject_HEAD_INIT(&PyType_Type) - 0, + PyObject_HEAD_INIT(&PyType_Type) + 0, #endif - "swig_static_var_getset_descriptor", - sizeof(PyGetSetDescrObject), - 0, - (destructor)SwigPyStaticVar_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - (reprfunc)SwigPyStaticVar_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_HAVE_CLASS, /* tp_flags */ - 0, /* tp_doc */ - SwigPyStaticVar_traverse, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - (descrgetfunc)SwigPyStaticVar_get, /* tp_descr_get */ - (descrsetfunc)SwigPyStaticVar_set, /* tp_descr_set */ + "swig_static_var_getset_descriptor", + sizeof(PyGetSetDescrObject), + 0, + (destructor)SwigPyStaticVar_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + (reprfunc)SwigPyStaticVar_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_HAVE_CLASS, /* tp_flags */ + 0, /* tp_doc */ + SwigPyStaticVar_traverse, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + (descrgetfunc)SwigPyStaticVar_get, /* tp_descr_get */ + (descrsetfunc)SwigPyStaticVar_set, /* tp_descr_set */ }; SWIGINTERN int -SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value) -{ - PyObject *attribute = _PyType_Lookup(type, name); - if (attribute != NULL) { - /* Implement descriptor functionality, if any */ - descrsetfunc local_set = attribute->ob_type->tp_descr_set; - if (local_set != NULL) - return local_set(attribute, (PyObject*) type, value); +SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value) { + PyObject *attribute = _PyType_Lookup(type, name); + if (attribute != NULL) { + /* Implement descriptor functionality, if any */ + descrsetfunc local_set = attribute->ob_type->tp_descr_set; + if (local_set != NULL) + return local_set(attribute, (PyObject *)type, value); #if PY_VERSION_HEX >= 0x03000000 - PyErr_Format(PyExc_AttributeError, - "cannot modify read-only attribute '%.50s.%.400U'", - type->tp_name, name); -#else - PyErr_Format(PyExc_AttributeError, - "cannot modify read-only attribute '%.50s.%.400s'", - type->tp_name, PyString_AS_STRING(name)); + PyErr_Format(PyExc_AttributeError, "cannot modify read-only attribute '%.50s.%.400U'", type->tp_name, name); +#else + PyErr_Format(PyExc_AttributeError, "cannot modify read-only attribute '%.50s.%.400s'", type->tp_name, PyString_AS_STRING(name)); #endif - } else { + } else { #if PY_VERSION_HEX >= 0x03000000 - PyErr_Format(PyExc_AttributeError, - "type '%.50s' has no attribute '%.400U'", - type->tp_name, name); + PyErr_Format(PyExc_AttributeError, "type '%.50s' has no attribute '%.400U'", type->tp_name, name); #else - PyErr_Format(PyExc_AttributeError, - "type '%.50s' has no attribute '%.400s'", - type->tp_name, PyString_AS_STRING(name)); + PyErr_Format(PyExc_AttributeError, "type '%.50s' has no attribute '%.400s'", type->tp_name, PyString_AS_STRING(name)); #endif - } + } - return -1; + return -1; } -SWIGINTERN PyGetSetDescrObject* -SwigPyStaticVar_new_getset (PyTypeObject *type, PyGetSetDef *getset) -{ - PyGetSetDescrObject *descr = (PyGetSetDescrObject*) PyType_GenericAlloc(&SwigPyStaticVar_Type, 0); - assert(descr); - Py_XINCREF(type); - descr->d_type = type; - descr->d_name = PyString_InternFromString(getset->name); - descr->d_getset = getset; - if (descr->d_name == NULL) { - Py_DECREF(descr); - descr = NULL; - } - return descr; +SWIGINTERN PyGetSetDescrObject * +SwigPyStaticVar_new_getset(PyTypeObject *type, PyGetSetDef *getset) { + PyGetSetDescrObject *descr = (PyGetSetDescrObject *)PyType_GenericAlloc(&SwigPyStaticVar_Type, 0); + assert(descr); + Py_XINCREF(type); + descr->d_type = type; + descr->d_name = PyString_InternFromString(getset->name); + descr->d_getset = getset; + if (descr->d_name == NULL) { + Py_DECREF(descr); + descr = NULL; + } + return descr; } #ifdef __cplusplus @@ -473,27 +421,25 @@ SwigPyStaticVar_new_getset (PyTypeObject *type, PyGetSetDef *getset) #include SWIGINTERN void -pyswig_builtin_init_bases (PyTypeObject *type, std::vector& bases) -{ - if (!bases.size()) - bases.push_back(SwigPyObject_type()); - 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) { - PyTuple_SET_ITEM(tuple, i, (PyObject*) bases[i]); - Py_INCREF((PyObject*) bases[i]); - } - type->tp_bases = tuple; +pyswig_builtin_init_bases(PyTypeObject *type, std::vector &bases) { + if (!bases.size()) + bases.push_back(SwigPyObject_type()); + 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) { + PyTuple_SET_ITEM(tuple, i, (PyObject *)bases[i]); + Py_INCREF((PyObject *)bases[i]); + } + type->tp_bases = tuple; } -SWIGINTERN PyObject* -pyswig_this_closure (PyObject *self, void *closure) -{ - PyObject *result = (PyObject*) SWIG_Python_GetSwigThis(self); - Py_XINCREF(result); - return result; -} +SWIGINTERN PyObject * +pyswig_this_closure(PyObject *self, void *closure) { + PyObject *result = (PyObject *)SWIG_Python_GetSwigThis(self); + Py_XINCREF(result); + return result; +} #endif diff --git a/Lib/python/director.swg b/Lib/python/director.swg index 95dc991cd..5749ee74b 100644 --- a/Lib/python/director.swg +++ b/Lib/python/director.swg @@ -461,12 +461,13 @@ namespace Swig { } template - static PyObject* pyobj_disown (PyObject *pyobj, PyObject *SWIGUNUSEDPARM(args)) + static PyObject* pyobj_disown(PyObject *pyobj, PyObject *SWIGUNUSEDPARM(args)) { - SwigPyObject *sobj = (SwigPyObject *) pyobj; + SwigPyObject *sobj = (SwigPyObject *)pyobj; sobj->own = 0; - Director *d = SWIG_DIRECTOR_CAST(reinterpret_cast<_Tp*>(sobj->ptr)); - if (d) d->swig_disown(); + Director *d = SWIG_DIRECTOR_CAST(reinterpret_cast<_Tp *>(sobj->ptr)); + if (d) + d->swig_disown(); return PyWeakref_NewProxy(pyobj, NULL); } diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index bc19c33fb..5f777894b 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -352,7 +352,7 @@ SWIG_init(void) { // 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); + PyTypeObject *metatype = (PyTypeObject *) PyType_Type.tp_call((PyObject *) &PyType_Type, metatype_args, NULL); assert(metatype); Py_DECREF(metatype_args); metatype->tp_setattro = (setattrofunc) &SwigPyObjectType_setattro; @@ -386,7 +386,7 @@ SWIG_init(void) { // All objects have a 'this' attribute static PyGetSetDef this_getset_def = { - const_cast("this"), pyswig_this_closure, NULL, NULL, NULL + const_cast("this"), pyswig_this_closure, NULL, NULL, NULL }; PyObject *this_descr = PyDescr_NewGetSet(SwigPyObject_type(), &this_getset_def); diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 8957b3192..393bc6ddd 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -74,7 +74,7 @@ SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) { #if defined(SWIGPYTHON_BUILTIN) SWIGINTERN void -pyswig_add_public_symbol (PyObject *seq, const char *key) { +pyswig_add_public_symbol(PyObject *seq, const char *key) { PyObject *s = PyString_InternFromString(key); PyList_Append(seq, s); Py_DECREF(s); @@ -82,7 +82,7 @@ pyswig_add_public_symbol (PyObject *seq, const char *key) { SWIGINTERN void SWIG_Python_SetConstant(PyObject *d, PyObject *public_interface, const char *name, PyObject *obj) { - PyDict_SetItemString(d, (char*) name, obj); + PyDict_SetItemString(d, (char *)name, obj); Py_DECREF(obj); if (public_interface) pyswig_add_public_symbol(public_interface, name); @@ -92,7 +92,7 @@ SWIG_Python_SetConstant(PyObject *d, PyObject *public_interface, const char *nam SWIGINTERN void SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) { - PyDict_SetItemString(d, (char*) name, obj); + PyDict_SetItemString(d, (char *)name, obj); Py_DECREF(obj); } @@ -338,8 +338,7 @@ SwigPyClientData_New(PyObject* obj) } SWIGRUNTIME void -SwigPyClientData_Del(SwigPyClientData* data) -{ +SwigPyClientData_Del(SwigPyClientData *data) { Py_XDECREF(data->newraw); Py_XDECREF(data->newargs); Py_XDECREF(data->destroy); @@ -1127,106 +1126,84 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int return SWIG_OK; } - /* - if (ty && ty->clientdata && ((SwigPyClientData*) ty->clientdata)->pytype) { - PyTypeObject *target_tp = ((SwigPyClientData*) ty->clientdata)->pytype; - SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj); - for (; sobj; sobj = (SwigPyObject*) sobj->next) { - if (!sobj->ty->clientdata) - continue; - PyTypeObject *candidate_tp = ((SwigPyClientData*) sobj->ty->clientdata)->pytype; - if (candidate_tp && PyType_IsSubtype(candidate_tp, target_tp)) { - if (own) - *own = *own | sobj->own; - if (flags & SWIG_POINTER_DISOWN) - sobj->own = 0; - if (ptr) - *ptr = sobj->ptr; - return SWIG_OK; - } - } - return SWIG_ERROR; - } - */ - int res = SWIG_ERROR; SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj); if (own) - *own = 0; + *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 { - if (ptr) *ptr = vptr; - break; - } + 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 { + if (ptr) *ptr = vptr; + break; + } } if (sobj) { - if (own) - *own = *own | sobj->own; - if (flags & SWIG_POINTER_DISOWN) { - sobj->own = 0; - } - res = SWIG_OK; + 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); - } - } - } - } + 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); + } + } + } + } } return res; } @@ -1399,35 +1376,35 @@ SWIG_Python_InitShadowInstance(PyObject *args) { SWIGRUNTIME PyObject * SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) { - if (!ptr) - return SWIG_Py_Void(); + if (!ptr) + return SWIG_Py_Void(); - SwigPyClientData *clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0; - int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; - if (clientdata && clientdata->pytype) { - SwigPyObject *newobj = PyObject_New(SwigPyObject, clientdata->pytype); - if (newobj) { - newobj->ptr = ptr; - newobj->ty = type; - newobj->own = own; - newobj->next = 0; + SwigPyClientData *clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0; + int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; + if (clientdata && clientdata->pytype) { + SwigPyObject *newobj = PyObject_New(SwigPyObject, clientdata->pytype); + if (newobj) { + newobj->ptr = ptr; + newobj->ty = type; + newobj->own = own; + newobj->next = 0; #ifdef SWIGPYTHON_BUILTIN - newobj->dict = 0; + newobj->dict = 0; #endif - return (PyObject*) newobj; - } - return SWIG_Py_Void(); + return (PyObject*) newobj; } + return SWIG_Py_Void(); + } - PyObject *robj = SwigPyObject_New(ptr, type, own); - if (clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { - PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); - if (inst) { - Py_DECREF(robj); - robj = inst; - } + PyObject *robj = SwigPyObject_New(ptr, type, own); + if (clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { + PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); + if (inst) { + Py_DECREF(robj); + robj = inst; } - return robj; + } + return robj; } /* Create a new packed object */ @@ -1444,12 +1421,12 @@ SWIG_Python_NewBuiltinObj(PyObject *self, void *ptr, swig_type_info *type, int f assert(clientdata); assert(clientdata->pytype); int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; - SwigPyObject *newobj = (SwigPyObject*) self; + SwigPyObject *newobj = (SwigPyObject *)self; if (newobj->ptr) { PyObject *next_self = clientdata->pytype->tp_alloc(clientdata->pytype, 0); - while (newobj->next) newobj = (SwigPyObject*) newobj->next; + while (newobj->next) newobj = (SwigPyObject *)newobj->next; newobj->next = next_self; - newobj = (SwigPyObject*) next_self; + newobj = (SwigPyObject *)next_self; } newobj->ptr = ptr; newobj->own = own; @@ -1696,55 +1673,52 @@ SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) // 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; - PyObject *descr; - descrsetfunc f; - int res = -1; +SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { + PyTypeObject *tp = obj->ob_type; + PyObject *descr; + descrsetfunc f; + int res = -1; #ifdef Py_USING_UNICODE - if (PyString_Check(name)) { - name = PyUnicode_Decode(PyString_AsString(name), PyString_Size(name), NULL, NULL); - if (name == NULL) - return -1; - } else if (!PyUnicode_Check(name)) { + if (PyString_Check(name)) { + name = PyUnicode_Decode(PyString_AsString(name), PyString_Size(name), NULL, NULL); + if (!name) + return -1; + } else if (!PyUnicode_Check(name)) { #else if (!PyString_Check(name)) { #endif - PyErr_Format(PyExc_TypeError, - "attribute name must be string, not '%.200s'", - name->ob_type->tp_name); - return -1; + PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", name->ob_type->tp_name); + return -1; } else { - Py_INCREF(name); + Py_INCREF(name); } - if (tp->tp_dict == NULL) { - if (PyType_Ready(tp) < 0) - goto done; + if (!tp->tp_dict) { + if (PyType_Ready(tp) < 0) + goto done; } descr = _PyType_Lookup(tp, name); f = NULL; if (descr != NULL) - f = descr->ob_type->tp_descr_set; - if (f == NULL) { - PyErr_Format(PyExc_AttributeError, + f = descr->ob_type->tp_descr_set; + if (!f) { + PyErr_Format(PyExc_AttributeError, #ifdef Py_USING_UNICODE - "'%.100s' object has no attribute '%.200U'", + "'%.100s' object has no attribute '%.200U'", #else - "'%.100s' object has no attribute '%.200S'", + "'%.100s' object has no attribute '%.200S'", #endif - tp->tp_name, name); + tp->tp_name, name); } else { - res = f(descr, obj, value); + res = f(descr, obj, value); } - - done: + +done: Py_DECREF(name); return res; - } + } #ifdef __cplusplus diff --git a/Lib/python/pyruntime.swg b/Lib/python/pyruntime.swg index 77abd47bd..c20ed964f 100644 --- a/Lib/python/pyruntime.swg +++ b/Lib/python/pyruntime.swg @@ -10,5 +10,4 @@ %insert(runtime) "pythreads.swg"; /* Python thread code */ %insert(runtime) "pyapi.swg"; /* Python API */ %insert(runtime) "pyrun.swg"; /* Python run-time code */ - %insert(runtime) "builtin.swg"; /* Specialization for classes with single inheritance */ diff --git a/Lib/python/std_map.i b/Lib/python/std_map.i index 8dcb90fe5..2b3a90747 100644 --- a/Lib/python/std_map.i +++ b/Lib/python/std_map.i @@ -291,10 +291,10 @@ #endif %extend { - // This will be called through the mp_ass_subscript slot to delete an entry. - void __setitem__(const key_type& key) { - self->erase(key); - } + // This will be called through the mp_ass_subscript slot to delete an entry. + void __setitem__(const key_type& key) { + self->erase(key); + } } %extend { diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 693ac0f98..14fdb52b0 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -240,9 +240,11 @@ public: } /* ------------------------------------------------------------ * Thread Implementation - * ------------------------------------------------------------ */ int threads_enable(Node *n) const { + * ------------------------------------------------------------ */ + int threads_enable(Node *n) const { return threads && !GetFlagAttr(n, "feature:nothread"); } + int initialize_threads(String *f_init) { if (!threads) { return SWIG_OK; @@ -510,7 +512,7 @@ public: } } - } /* for */ + } if (py3) { /* force disable features that not compatible with Python 3.x */ @@ -882,11 +884,11 @@ public: * But don't sure wether this would broken old Python? */ Printv(f_shadow, - // "import types\n", +// "import types\n", "try:\n", - // " _object = types.ObjectType\n", +// " _object = types.ObjectType\n", " _object = object\n", " _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n", - // "del types\n", +// "del types\n", "\n\n", NIL); } } @@ -995,8 +997,6 @@ public: } Dump(f_wrappers, f_begin); - //if (builtin) - //Dump(f_builtins, f_begin); Wrapper_pretty_print(f_init, f_begin); Delete(f_header); @@ -3186,7 +3186,7 @@ public: String *mname = SwigType_manglestr(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 = (PyTypeObject *)&SwigPyBuiltin_%s_type;\n", mname); Printf(f_init, " builtin_pytype->tp_dict = d = PyDict_New();\n"); Delete(rname); @@ -3277,38 +3277,37 @@ public: // Rich compare function Hash *richcompare = Getattr(n, "richcompare"); assert(richcompare); - Printf(f, "SWIGINTERN PyObject*\n"); - Printf(f, "%s_richcompare (PyObject *self, PyObject *other, int op)\n", templ); - Printf(f, "{\n"); - Printf(f, " PyObject *result = NULL;\n"); + Printf(f, "SWIGINTERN PyObject *\n"); + Printf(f, "%s_richcompare(PyObject *self, PyObject *other, int op) {\n", templ); + Printf(f, " PyObject *result = NULL;\n"); if (!funpack) { - Printf(f, " PyObject *tuple = PyTuple_New(1);\n"); - Printf(f, " assert(tuple);\n"); - Printf(f, " PyTuple_SET_ITEM(tuple, 0, other);\n"); - Printf(f, " Py_XINCREF(other);\n"); + Printf(f, " PyObject *tuple = PyTuple_New(1);\n"); + Printf(f, " assert(tuple);\n"); + Printf(f, " PyTuple_SET_ITEM(tuple, 0, other);\n"); + Printf(f, " Py_XINCREF(other);\n"); } - Printf(f, " switch (op) {\n"); + Printf(f, " switch (op) {\n"); for (Iterator i = First(richcompare); i.item; i = Next(i)) Printf(f, " case %s : result = %s(self, %s); break;\n", i.key, i.item, funpack ? "other" : "tuple"); Printv(f, " default : break;\n", NIL); - Printf(f, " }\n"); - Printv(f, " if (result == NULL) {\n", NIL); - Printv(f, " if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) {\n", NIL); - Printv(f, " result = SwigPyObject_richcompare((SwigPyObject*) self, (SwigPyObject*) other, op);\n", NIL); - Printv(f, " } else {\n", NIL); - Printv(f, " result = Py_NotImplemented;\n", NIL); - Printv(f, " Py_INCREF(result);\n", NIL); - Printv(f, " }\n", NIL); + Printf(f, " }\n"); + Printv(f, " if (!result) {\n", NIL); + Printv(f, " if (SwigPyObject_Check(self) && SwigPyObject_Check(other)) {\n", NIL); + Printv(f, " result = SwigPyObject_richcompare((SwigPyObject *)self, (SwigPyObject *)other, op);\n", NIL); + Printv(f, " } else {\n", NIL); + Printv(f, " result = Py_NotImplemented;\n", NIL); + Printv(f, " Py_INCREF(result);\n", NIL); Printv(f, " }\n", NIL); + Printv(f, " }\n", NIL); if (!funpack) - Printf(f, " Py_DECREF(tuple);\n"); - Printf(f, " return result;\n"); + Printf(f, " Py_DECREF(tuple);\n"); + Printf(f, " return result;\n"); Printf(f, "}\n\n"); // Methods Printf(f, "SWIGINTERN PyMethodDef %s_methods[] = {\n", templ); Dump(builtin_methods, f); - Printf(f, " {NULL} // Sentinel\n};\n\n"); + Printf(f, " {NULL} // Sentinel\n};\n\n"); // No instance dict for nondynamic objects if (GetFlag(n, "feature:python:nondynamic")) @@ -3502,7 +3501,7 @@ public: Printf(clientdata_klass, "(PyObject*) &%s_type", templ); } - Printf(f, "SWIGINTERN SwigPyClientData %s_clientdata = {%s, 0, 0, 0, 0, 0, (PyTypeObject*) &%s_type};\n\n", templ, clientdata_klass, templ); + Printf(f, "SWIGINTERN SwigPyClientData %s_clientdata = {%s, 0, 0, 0, 0, 0, (PyTypeObject *)&%s_type};\n\n", templ, clientdata_klass, templ); Printv(f_init, " if (PyType_Ready(builtin_pytype) < 0) {\n", NIL); Printf(f_init, " PyErr_SetString(PyExc_TypeError, \"Couldn't create type '%s'\");\n", symname); From cca5a76d91c983cde001fc0ee5b655f4ca59077a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 3 Mar 2011 19:39:48 +0000 Subject: [PATCH 33/56] Minor rewrites of some recent builtin changes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12516 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/python.cxx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 14fdb52b0..7dea183aa 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -931,7 +931,8 @@ public: add_pyinstancemethod_new(); if (builtin) { - String *s = NewString("p.SwigPyObject"); + SwigType *s = NewString("SwigPyObject"); + SwigType_add_pointer(s); SwigType_remember(s); Delete(s); } @@ -2126,7 +2127,7 @@ public: for (Node *sibling = n; sibling; sibling = Getattr(sibling, "sym:nextSibling")) Setattr(sibling, "sym:over_varargs", over_varargs_attr); } - if (strcmp(Char(over_varargs_attr), "0")) + if (Strcmp(over_varargs_attr, "0") != 0) over_varargs = true; } @@ -3249,7 +3250,7 @@ public: Printv(f_init, "PyDict_SetItemString(d, \"thisown\", thisown_descr);\n", NIL); // Now, the rest of the attributes - for (DohIterator member_iter = First(builtin_getset); member_iter.item; member_iter = Next(member_iter)) { + for (Iterator member_iter = First(builtin_getset); member_iter.item; member_iter = Next(member_iter)) { String *memname = member_iter.key; Hash *mgetset = member_iter.item; String *getter = Getattr(mgetset, "getter"); @@ -4169,10 +4170,13 @@ public: * ------------------------------------------------------------ */ virtual int destructorHandler(Node *n) { + String *symname = Getattr(n, "sym:name"); + int oldshadow = shadow; + if (builtin && in_class) { Node *cls = Swig_methodclass(n); if (!Getattr(cls, "feature:tp_dealloc")) { - String *dealloc = Swig_name_destroy(NSPACE_TODO, Getattr(cls, "sym:name")); + String *dealloc = Swig_name_destroy(NSPACE_TODO, symname); String *wdealloc = Swig_name_wrapper(dealloc); Setattr(cls, "feature:tp_dealloc", wdealloc); Delete(wdealloc); @@ -4180,9 +4184,6 @@ public: } } - String *symname = Getattr(n, "sym:name"); - int oldshadow = shadow; - if (shadow) shadow = shadow | PYSHADOW_MEMBER; //Setattr(n,"emit:dealloc","1"); From d008ab2bc6c3a10f78a86368aebee73e5c0338ad Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 3 Mar 2011 19:42:43 +0000 Subject: [PATCH 34/56] Remove local mode editor setting - editors should be set up correctly for the whole of SWIG git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12517 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/python.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 7dea183aa..c04f98913 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -1,4 +1,3 @@ -/* mode: c++; c-basic-offset: 2 */ /* ----------------------------------------------------------------------------- * This file is part of SWIG, which is licensed as a whole under version 3 * (or any later version) of the GNU General Public License. Some additional From 5f935225ec4689316faa7082d5a7553d63a6eb4c Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Mon, 28 Mar 2011 22:16:44 +0000 Subject: [PATCH 35/56] Merged from trunk. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12560 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/varargs_overload.i | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Examples/test-suite/varargs_overload.i diff --git a/Examples/test-suite/varargs_overload.i b/Examples/test-suite/varargs_overload.i new file mode 100644 index 000000000..1ba00ba65 --- /dev/null +++ b/Examples/test-suite/varargs_overload.i @@ -0,0 +1,44 @@ +// Tests SWIG's *default* handling of overloading varargs (function varargs, not preprocessor varargs). +// The default behavior is to simply ignore the varargs. +%module varargs_overload + +%inline %{ +const char *vararg_over1(const char *fmt, ...) { + return fmt; +} +const char *vararg_over1(int i) { + static char buffer[256]; + sprintf(buffer, "%d", i); + return buffer; +} + +const char *vararg_over2(const char *fmt, ...) { + return fmt; +} +const char *vararg_over2(int i, double j) { + static char buffer[256]; + sprintf(buffer, "%d %g", i, j); + return buffer; +} + +const char *vararg_over3(const char *fmt, ...) { + return fmt; +} +const char *vararg_over3(int i, double j, const char *s) { + static char buffer[256]; + sprintf(buffer, "%d %g %s", i, j, s); + return buffer; +} +%} + +%varargs(int mode = 0) vararg_over4; +%inline %{ +const char *vararg_over4(const char *fmt, ...) { + return fmt; +} +const char *vararg_over4(int i) { + static char buffer[256]; + sprintf(buffer, "%d", i); + return buffer; +} +%} From 39921e87d92d8f86c9b780133cd49de75b31b485 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Mon, 28 Mar 2011 22:18:07 +0000 Subject: [PATCH 36/56] Merge from trunk. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12561 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../python/varargs_overload_runme.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Examples/test-suite/python/varargs_overload_runme.py diff --git a/Examples/test-suite/python/varargs_overload_runme.py b/Examples/test-suite/python/varargs_overload_runme.py new file mode 100644 index 000000000..a3b2068b5 --- /dev/null +++ b/Examples/test-suite/python/varargs_overload_runme.py @@ -0,0 +1,31 @@ +import varargs_overload + +if varargs_overload.vararg_over1("Hello") != "Hello": + raise RuntimeError, "Failed" + +if varargs_overload.vararg_over1(2) != "2": + raise RuntimeError, "Failed" + + +if varargs_overload.vararg_over2("Hello") != "Hello": + raise RuntimeError, "Failed" + +if varargs_overload.vararg_over2(2, 2.2) != "2 2.2": + raise RuntimeError, "Failed" + + +if varargs_overload.vararg_over3("Hello") != "Hello": + raise RuntimeError, "Failed" + +if varargs_overload.vararg_over3(2, 2.2, "hey") != "2 2.2 hey": + raise RuntimeError, "Failed" + +if varargs_overload.vararg_over4("Hello") != "Hello": + raise RuntimeError, "Failed" + +if varargs_overload.vararg_over4(123) != "123": + raise RuntimeError, "Failed" + +if varargs_overload.vararg_over4("Hello", 123) != "Hello": + raise RuntimeError, "Failed" + From 3d444101d114ca5e462558277b0fc7f3f7eb651b Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Tue, 29 Mar 2011 06:57:02 +0000 Subject: [PATCH 37/56] 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); From 0aa8729d500932e60afcbb50e8b2de623fba9db9 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Wed, 30 Mar 2011 07:59:52 +0000 Subject: [PATCH 38/56] Added more documentation of -builtin. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12571 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Python.html | 159 ++++++++++++++++++++++++++++++++++++++--- Lib/python/pyopers.swg | 56 +++++++++++++++ 2 files changed, 204 insertions(+), 11 deletions(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 3ee140c59..04cf0a1e1 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -2306,15 +2306,56 @@ by Python built-in types until Python 2.2).

    33.4.2 Built-in Classes

    -The -builtin option gives a significant performance improvement -in the wrapped code. More information about python built-in extensions is available -here. +The -builtin option provides a significant performance improvement +in the wrapped code. To understand the difference between proxy classes +and built-in types, let's take a look at what a wrapped object looks like +under both circumstances. +

    + +

    When proxy classes are used, each wrapped object in python is an instance +of a pure python class. As a reminder, here is what the __init__ method looks +like in a proxy class: +

    + +
    +
    +class Foo(object):
    +     def __init__(self):
    +         self.this = _example.new_Foo()
    +         self.thisown = 1
    +
    +
    + +

    When a Foo instance is created, the call to _example.new_Foo() +creates a new C++ Foo instance; wraps that C++ instance inside an instance of +a python built-in type called SwigPyObject; and stores the SwigPyObject +instance in the 'this' field of the python Foo object. Did you get all that? So, the +python Foo object is composed of three parts:

    + +
      +
    • The python Foo instance, which contains...
    • +
    • ... an instance of struct SwigPyObject, which contains...
    • +
    • ... a C++ Foo instance
    • +
    + +

    When -builtin is used, the pure python layer is stripped off. Each +wrapped class is turned into a new python built-in type which inherits from +SwigPyObject, and SwigPyObject instances are returned directly +from the wrapped methods. For more information about python built-in extensions, +please refer to the python documentation:

    +

    docs.python.org/extending/extending.html.

    33.4.2.1 Limitations

    Use of the -builtin option implies a couple of limitations:

      +
    • Some legacy syntax is no longer supported; in particular:
    • +
        +
      • The functional interface is no longer exposed. For example, you may no longer call Whizzo.new_CrunchyFrog(). Instead, you must use Whizzo.CrunchyFrog().
      • +
      • Static member variables are no longer accessed through the 'cvar' field (e.g., Dances.cvar.FishSlap). +They are instead accessed in the idiomatic way (Dances.FishSlap).
      • +
    • Wrapped types may not be thrown as python exceptions
    • Reverse operators are not supported.
    @@ -2331,7 +2372,7 @@ strings, you can define an 'operator+ (const char*)' method : class MyString { public: MyString (const char *init); - MyString operator+ (const char *other); + MyString operator+ (const char *other) const; ... }; @@ -2341,21 +2382,21 @@ public: swig will automatically create an operator overload in python that will allow this:

    -
    +
     from MyModule import MyString
     
    -mystr = MyString("Nobody expects")
    +mystr = MyString("No one expects")
     episode = mystr + " the Spanish Inquisition"
     

    This works because the first operand -- the instance of MyString -- defines a way -to add a MyString and a native string. However, the following will not work: +to add a native string to itself. However, the following will not work:

    -
    +
     from MyModule import MyString
     
    @@ -2366,12 +2407,108 @@ episode = "Dead " + mystr
     
     

    The above code fails, because the first operand -- a native python string -- -doesn't know how to add itself to an instance of MyString. +doesn't know how to add an instance of MyString to itself.

    -

    33.4.2.2 Getting the most out of builtin-types

    +

    33.4.2.2 Operator overloads -- use them!

    + +

    The entire justification for the -builtin option is improved +performance. To that end, the best way to squeeze maximum performance out +of your wrappers is to use operator overloads. +Named method dispatch is slow in python, even when compared to other scripting languages. +However, python built-in types have a large number of "slots", +analogous to C++ operator overloads, which allow you to short-circuit name method dispatch +for certain common operations. +

    + +

    By default, swig will translate most C++ arithmetic operator overloads into python +slot entries. For example, suppose you have this class: + +

    +
    +class DeadParrot {
    +public:
    +    DeadParrot operator+ (const DeadParrot& dp) const;
    +
    +    // Dispatch to operator+
    +    DeadParrot add (const DeadParrot& dp) const
    +    { return *this + dp; }
    +};
    +
    +
    + +

    ... then you may write python code like this:

    + +
    +
    +from MyModule import DeadParrot
    +
    +dp1 = DeadParrot()
    +dp2 = DeadParrot()
    +dp3 = dp1 + dp2
    +dp4 = dp1.add(dp2)
    +
    +
    + +

    The last two lines of the python code are equivalent, +but the line that uses the '+' operator is much faster. +

    + +

    In-place operators (e.g., operator+=) and comparison operators +(operator==, operator<, etc.) are also converted to python +slot operators. For a complete list of C++ operators that are +automatically converted to python slot operators, refer to the file +python/pyopers.swig in the SWIG library. +

    + +

    There are other very useful python slots that you +may explicitly define using %feature directives. For example, +suppose you want to use instances of a wrapped class as keys in a native python +dict. That will work as long as you define a hash function for +instances of your class, and use it to define the python tp_hash +slot: +

    + +
    +
    +class Cheese {
    +public:
    +    Cheese (const char *name);
    +    long cheeseHashFunc () const;
    +};
    +
    +%feature("python:slot", "tp_hash", functype="hashfunc") Cheese::cheeseHashFunc;
    +
    +
    + +

    This will allow you to write python code like this:

    + +
    +
    +from my MyPackage import Cheese
    +
    +inventory = {
    +    Cheese("cheddar") : 0,
    +    Cheese("gouda") : 0,
    +    Cheese("camembert") : 0
    +}
    +
    +
    + +

    Because you defined the tp_hash slot, Cheese objects may +be used as hash keys; and when the cheeseHashFunc method is invoked +by a python dict, it will not go through named method dispatch. +A more detailed discussion about %feature("python:slot") can be found +in the file python/pyopers.swig in the SWIG library. +You can read about all of the available python slots here:

    + +

    docs.python.org/c-api/typeobj.html

    + +

    You may override (almost) all of the slots defined in the PyTypeObject, +PyNumberMethods, PyMappingMethods, PySequenceMethods, and PyBufferProcs +structs. +

    -

    TODO

    33.4.3 Memory management

    diff --git a/Lib/python/pyopers.swg b/Lib/python/pyopers.swg index 2dbaba41e..1ce4f0980 100644 --- a/Lib/python/pyopers.swg +++ b/Lib/python/pyopers.swg @@ -1,5 +1,61 @@ /* ------------------------------------------------------------ * Overloaded operator support + + The directives in this file apply whether or not you use the + -builtin option to swig, but operator overloads are particularly + attractive when using -builtin, because they are much faster + than named methods. + + If you're using the -builtin option to swig, and you want to define + python operator overloads beyond the defaults defined in this file, + here's what you need to know: + + There are two ways to define a python slot function: dispatch to a + statically defined function; or dispatch to a method defined on the + operand. + + To dispatch to a statically defined function, use %feature("python:"), + where is the name of a field in a PyTypeObject, PyNumberMethods, + PyMappingMethods, PySequenceMethods, or PyBufferProcs. For example: + + %{ + + static long myHashFunc (PyObject *pyobj) { + MyClass *cobj; + // Convert pyobj to cobj + return (cobj->field1 * (cobj->field2 << 7)); + } + + %} + + %feature("python:tp_hash") MyClass "myHashFunc"; + + NOTE: It is the responsibility of the programmer (that's you) to ensure + that a statically defined slot function has the correct signature. + + If, instead, you want to dispatch to an instance method, you can + use %feature("python:slot"). For example: + + class MyClass { + public: + long myHashFunc () const; + ... + }; + + %feature("python:slot", "tp_hash", functype="hashfunc") MyClass::myHashFunc; + + NOTE: Some python slots use a method signature which does not + match the signature of swig-wrapped methods. For those slots, + swig will automatically generate a "closure" function to re-marshall + the arguments before dispatching to the wrapped method. Setting + the "functype" attribute of the feature enables swig to generate + a correct closure function. + + For more information about python slots, including their names and + signatures, you may refer to the python documentation : + + http://docs.python.org/c-api/typeobj.html + * ------------------------------------------------------------ */ From f2b0d2ef40df54328083745a9d86ba3429bc1931 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Wed, 30 Mar 2011 08:15:16 +0000 Subject: [PATCH 39/56] Added comment about -builtin in Memory Management section. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12572 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Python.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 04cf0a1e1..7add2a458 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -2512,6 +2512,8 @@ structs.

    33.4.3 Memory management

    +

    NOTE: Although this section refers to proxy objects, everything here also applies +when the -builtin option is used.

    Associated with proxy object, is an ownership flag .thisown The value of this From 99dc5893d85684ba1a586319a3a06adcfb44c7d0 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Wed, 30 Mar 2011 19:17:54 +0000 Subject: [PATCH 40/56] Style fixes, and switch %U to %S git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12573 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/builtin.swg | 8 ++--- Lib/python/pyrun.swg | 79 +++++++++++++----------------------------- 2 files changed, 28 insertions(+), 59 deletions(-) diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index aa7dbbe89..ffd3fbd1c 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -279,7 +279,7 @@ SwigPyStaticVar_get(PyGetSetDescrObject *descr, PyObject *obj, PyObject *type) { if (descr->d_getset->get != NULL) return descr->d_getset->get(obj, descr->d_getset->closure); #if PY_VERSION_HEX >= 0x03000000 - PyErr_Format(PyExc_AttributeError, "attribute '%.300U' of '%.100s' objects is not readable", descr->d_name, descr->d_type->tp_name); + PyErr_Format(PyExc_AttributeError, "attribute '%.300S' of '%.100s' objects is not readable", descr->d_name, descr->d_type->tp_name); #else PyErr_Format(PyExc_AttributeError, "attribute '%.300s' of '%.100s' objects is not readable", PyString_AsString(descr->d_name), descr->d_type->tp_name); #endif @@ -293,7 +293,7 @@ SwigPyStaticVar_set(PyGetSetDescrObject *descr, PyObject *obj, PyObject *value) if (descr->d_getset->set != NULL) return descr->d_getset->set(obj, value, descr->d_getset->closure); #if PY_VERSION_HEX >= 0x03000000 - PyErr_Format(PyExc_AttributeError, "attribute '%.300U' of '%.100s' objects is not writable", descr->d_name, descr->d_type->tp_name); + PyErr_Format(PyExc_AttributeError, "attribute '%.300S' of '%.100s' objects is not writable", descr->d_name, descr->d_type->tp_name); #else PyErr_Format(PyExc_AttributeError, "attribute '%.300s' of '%.100s' objects is not writable", PyString_AsString(descr->d_name), descr->d_type->tp_name); #endif @@ -351,13 +351,13 @@ SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value) { if (local_set != NULL) return local_set(attribute, (PyObject *)type, value); #if PY_VERSION_HEX >= 0x03000000 - PyErr_Format(PyExc_AttributeError, "cannot modify read-only attribute '%.50s.%.400U'", type->tp_name, name); + PyErr_Format(PyExc_AttributeError, "cannot modify read-only attribute '%.50s.%.400S'", type->tp_name, name); #else PyErr_Format(PyExc_AttributeError, "cannot modify read-only attribute '%.50s.%.400s'", type->tp_name, PyString_AS_STRING(name)); #endif } else { #if PY_VERSION_HEX >= 0x03000000 - PyErr_Format(PyExc_AttributeError, "type '%.50s' has no attribute '%.400U'", type->tp_name, name); + PyErr_Format(PyExc_AttributeError, "type '%.50s' has no attribute '%.400S'", type->tp_name, name); #else PyErr_Format(PyExc_AttributeError, "type '%.50s' has no attribute '%.400s'", type->tp_name, PyString_AS_STRING(name)); #endif diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 84b552a72..2621c4269 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1448,32 +1448,6 @@ 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); - SwigPyClientData *clientdata = (SwigPyClientData *)(type->clientdata); - assert(clientdata); - assert(clientdata->pytype); - int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; - SwigPyObject *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; - } - newobj->ptr = ptr; - newobj->own = own; - newobj->ty = type; - newobj->next = 0; -#ifdef SWIGPYTHON_BUILTIN - newobj->dict = 0; -#endif - return 0; -} -*/ - /* -----------------------------------------------------------------------------* * Get type list * -----------------------------------------------------------------------------*/ @@ -1712,7 +1686,7 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { PyTypeObject *tp = obj->ob_type; PyObject *descr; descrsetfunc f; - int res = -1; + int res; #ifdef Py_USING_UNICODE if (PyString_Check(name)) { @@ -1721,40 +1695,35 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { return -1; } else if (!PyUnicode_Check(name)) { #else - if (!PyString_Check(name)) { + if (!PyString_Check(name)) { #endif PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", name->ob_type->tp_name); return -1; - } else { + } else { Py_INCREF(name); - } - - if (!tp->tp_dict) { - if (PyType_Ready(tp) < 0) - goto done; - } - - descr = _PyType_Lookup(tp, name); - f = NULL; - if (descr != NULL) - f = descr->ob_type->tp_descr_set; - if (!f) { - PyErr_Format(PyExc_AttributeError, -#ifdef Py_USING_UNICODE - "'%.100s' object has no attribute '%.200U'", -#else - "'%.100s' object has no attribute '%.200S'", -#endif - tp->tp_name, name); - } else { - res = f(descr, obj, value); - } - -done: - Py_DECREF(name); - return res; } + if (!tp->tp_dict) { + if (PyType_Ready(tp) < 0) + goto done; + } + + res = -1; + descr = _PyType_Lookup(tp, name); + f = NULL; + if (descr != NULL) + f = descr->ob_type->tp_descr_set; + if (!f) { + PyErr_Format(PyExc_AttributeError, "'%.100s' object has no attribute '%.200S'", tp->tp_name, name); + } else { + res = f(descr, obj, value); + } + + done: + Py_DECREF(name); + return res; +} + #ifdef __cplusplus #if 0 From bc200998b188106538e18c3071fd3becb354c96f Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Wed, 30 Mar 2011 19:51:22 +0000 Subject: [PATCH 41/56] Added usage message for -builtin, and tweaked -builtin docs. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12574 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Python.html | 38 +++++++++++++++++++------------------- Source/Modules/python.cxx | 1 + 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 7add2a458..5714eb243 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -2204,10 +2204,10 @@ of low-level details were omitted. This section provides a brief overview of how the proxy classes work.

    -

    New in swig version 2.0.3: +

    New in SWIG version 2.0.3: The use of Python proxy classes has performance implications that may be unacceptable for a high-performance library. The new -builtin -option instructs swig to forego the use of proxy classes, and instead +option instructs SWIG to forego the use of proxy classes, and instead create wrapped types as new built-in Python types. When this option is used, the following section ("Proxy classes") does not apply. Details on the use of the -builtin option are in the Built-in Classes @@ -2343,8 +2343,8 @@ wrapped class is turned into a new python built-in type which inherits from SwigPyObject, and SwigPyObject instances are returned directly from the wrapped methods. For more information about python built-in extensions, please refer to the python documentation:

    -

    docs.python.org/extending/extending.html. -

    + +

    docs.python.org/extending/newtypes.html

    33.4.2.1 Limitations

    @@ -2362,7 +2362,7 @@ They are instead accessed in the idiomatic way (Dances.FishSlap).
  • -To illustrate the second point, if you have a wrapped class called MyString, +To illustrate the last point, if you have a wrapped class called MyString, and you want to use instances of MyString interchangeably with native python strings, you can define an 'operator+ (const char*)' method :

    @@ -2379,7 +2379,7 @@ public:

    -swig will automatically create an operator overload in python that will allow this: +SWIG will automatically create an operator overload in python that will allow this:

    @@ -2392,7 +2392,7 @@ episode = mystr + " the Spanish Inquisition"

    -This works because the first operand -- the instance of MyString -- defines a way +This works because the first operand (mystr) defines a way to add a native string to itself. However, the following will not work:

    @@ -2417,36 +2417,36 @@ performance. To that end, the best way to squeeze maximum performance out of your wrappers is to use operator overloads. Named method dispatch is slow in python, even when compared to other scripting languages. However, python built-in types have a large number of "slots", -analogous to C++ operator overloads, which allow you to short-circuit name method dispatch +analogous to C++ operator overloads, which allow you to short-circuit named method dispatch for certain common operations.

    -

    By default, swig will translate most C++ arithmetic operator overloads into python +

    By default, SWIG will translate most C++ arithmetic operator overloads into python slot entries. For example, suppose you have this class:

    -class DeadParrot {
    +class Twit {
     public:
    -    DeadParrot operator+ (const DeadParrot& dp) const;
    +    Twit operator+ (const Twit& twit) const;
     
         // Dispatch to operator+
    -    DeadParrot add (const DeadParrot& dp) const
    -    { return *this + dp; }
    +    Twit add (const Twit& twit) const
    +    { return *this + twit; }
     };
     
    -

    ... then you may write python code like this:

    +

    SWIG will automatically register operator+ as a python slot operator for addition. You may write python code like this:

    -from MyModule import DeadParrot
    +from MyModule import Twit
     
    -dp1 = DeadParrot()
    -dp2 = DeadParrot()
    -dp3 = dp1 + dp2
    -dp4 = dp1.add(dp2)
    +nigel = Twit()
    +emily = Twit()
    +william = nigel + emily
    +william = nigel.add(emily)
     
    diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 2c89dab10..836f87d8b 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -110,6 +110,7 @@ static const char *usage1 = (char *) "\ Python Options (available with -python)\n\ -aliasobj0 - Alias obj0 when using fastunpack, needed for some old typemaps \n\ -buildnone - Use Py_BuildValue(" ") to obtain Py_None (default in Windows)\n\ + -builtin - Create new python built-in types, rather than proxy classes, for better performance\n\ -castmode - Enable the casting mode, which allows implicit cast between types in python\n\ -classic - Use classic classes only\n\ -classptr - Generate shadow 'ClassPtr' as in older swig versions\n\ From e43d328c6191b66b5e8d2244471bd530ff6ffbe7 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Wed, 30 Mar 2011 21:41:59 +0000 Subject: [PATCH 42/56] Eliminate -Wformat compiler warning. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12575 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pyrun.swg | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 2621c4269..4403a73b9 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1685,6 +1685,7 @@ SWIGRUNTIME int SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { PyTypeObject *tp = obj->ob_type; PyObject *descr; + PyObject *encoded_name; descrsetfunc f; int res; @@ -1714,7 +1715,14 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { if (descr != NULL) f = descr->ob_type->tp_descr_set; if (!f) { - PyErr_Format(PyExc_AttributeError, "'%.100s' object has no attribute '%.200S'", tp->tp_name, name); + if (PyString_Check(name)) { + encoded_name = name; + Py_INCREF(name); + } else { + encoded_name = PyUnicode_AsUTF8String(name); + } + PyErr_Format(PyExc_AttributeError, "'%.100s' object has no attribute '%.200s'", tp->tp_name, PyString_AsString(encoded_name)); + Py_DECREF(encoded_name); } else { res = f(descr, obj, value); } From 0e57a29a27fad297f8f21febdc60e9c3798e7901 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Wed, 30 Mar 2011 22:01:25 +0000 Subject: [PATCH 43/56] More tweaking of -builtin docs. More judicious selection of names in the operator overload example. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12576 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Python.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 5714eb243..bb1f71e94 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -2313,7 +2313,7 @@ under both circumstances.

    When proxy classes are used, each wrapped object in python is an instance -of a pure python class. As a reminder, here is what the __init__ method looks +of a pure python class. As a reminder, here is what the __init__ method looks like in a proxy class:

    @@ -2362,8 +2362,8 @@ They are instead accessed in the idiomatic way (Dances.FishSlap).

    -To illustrate the last point, if you have a wrapped class called MyString, -and you want to use instances of MyString interchangeably with native python +To illustrate the last point, if you have a wrapped class called MyString, +and you want to use instances of MyString interchangeably with native python strings, you can define an 'operator+ (const char*)' method :

    @@ -2407,7 +2407,7 @@ episode = "Dead " + mystr

    The above code fails, because the first operand -- a native python string -- -doesn't know how to add an instance of MyString to itself. +doesn't know how to add an instance of MyString to itself.

    33.4.2.2 Operator overloads -- use them!

    @@ -2430,7 +2430,7 @@ class Twit { public: Twit operator+ (const Twit& twit) const; - // Dispatch to operator+ + // Forward to operator+ Twit add (const Twit& twit) const { return *this + twit; } }; @@ -2445,8 +2445,8 @@ from MyModule import Twit nigel = Twit() emily = Twit() -william = nigel + emily -william = nigel.add(emily) +percival = nigel + emily +percival = nigel.add(emily) From 769f6648c85b8b979f926f8a976d1e093f709553 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Thu, 31 Mar 2011 03:55:42 +0000 Subject: [PATCH 44/56] Added test case for python richcompare operators. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12577 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/python/Makefile.in | 1 + .../python/python_richcompare_runme.py | 100 ++++++++++++++++++ Examples/test-suite/python_richcompare.i | 60 +++++++++++ 3 files changed, 161 insertions(+) create mode 100644 Examples/test-suite/python/python_richcompare_runme.py create mode 100644 Examples/test-suite/python_richcompare.i diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index a05542b70..3b0769019 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -61,6 +61,7 @@ CPP_TEST_CASES += \ python_kwargs \ python_nondynamic \ python_overload_simple_cast \ + python_richcompare \ std_containers \ swigobject \ template_matrix \ diff --git a/Examples/test-suite/python/python_richcompare_runme.py b/Examples/test-suite/python/python_richcompare_runme.py new file mode 100644 index 000000000..e077989cc --- /dev/null +++ b/Examples/test-suite/python/python_richcompare_runme.py @@ -0,0 +1,100 @@ +import python_richcompare + +base1 = python_richcompare.BaseClass(1) +base2 = python_richcompare.BaseClass(2) +base3 = python_richcompare.BaseClass(3) +a1 = python_richcompare.SubClassA(1) +a2 = python_richcompare.SubClassA(2) +a3 = python_richcompare.SubClassA(3) +b1 = python_richcompare.SubClassB(1) +b2 = python_richcompare.SubClassB(2) +b3 = python_richcompare.SubClassB(3) + +# Check == and != within a single type +#------------------------------------------------------------------------------- + +if not (base1 == base1) : + raise RuntimeError("Object not == to itself") + +if not (base1 == python_richcompare.BaseClass(1)) : + raise RuntimeError("Object not == to an equivalent object") + +if (base1 == base2) : + raise RuntimeError("Comparing non-equivalent objects of the same type, == returned True") + +if (base1 != base1) : + raise RuntimeError("Object is != itself") + +if (base1 != python_richcompare.BaseClass(1)) : + raise RuntimeError("Object is != an equivalent object") + +if not (base1 != base2) : + raise RuntimeError("Comparing non-equivalent objects of the same type, != returned False") + + +# Check redefined operator== in SubClassA +#------------------------------------------------------------------------------- + +if (a2 == base2) : + raise RuntimeError("Redefined operator== in SubClassA failed") + +if (a2 == b2) : + raise RuntimeError("Redefined operator== in SubClassA failed") + +if not (a1 == a2) : + raise RuntimeError("Redefined operator== in SubClassA failed") + +# Check up-casting of subclasses +#------------------------------------------------------------------------------- + +if (base2 != a2) : + raise RuntimeError("Comparing equivalent base and subclass instances, != returned True") + +if (a2 == base2) : + raise RuntimeError("Comparing non-equivalent base and subclass instances, == returned True") + +if (a1 == b1) : + raise RuntimeError("Comparing equivalent instances of different subclasses, == returned True") + +if (b1 == a1) : + raise RuntimeError("Comparing equivalent instances of different subclasses, == returned True") + +# Check inequalities +#------------------------------------------------------------------------------- + +if (a2 > b2) : + raise RuntimeError("operator> failed") + +if (a2 < b2) : + raise RuntimeError("operator< failed") + +if not (a2 >= b2) : + raise RuntimeError("operator>= failed") + +if not (a2 <= b2) : + raise RuntimeError("operator<= failed") + +# Check inequalities used for ordering +#------------------------------------------------------------------------------- + +x = sorted([a2, a3, a1]) + +if not (x[0] is a1) : + raise RuntimeError("Ordering failed") + +if not (x[1] is a2) : + raise RuntimeError("Ordering failed") + +if not (x[2] is a3) : + raise RuntimeError("Ordering failed") + +x = sorted([base2, a3, b1]) + +if not (x[0] is b1) : + raise RuntimeError("Ordering failed") + +if not (x[1] is base2) : + raise RuntimeError("Ordering failed") + +if not (x[2] is a3) : + raise RuntimeError("Ordering failed") diff --git a/Examples/test-suite/python_richcompare.i b/Examples/test-suite/python_richcompare.i new file mode 100644 index 000000000..142d0594b --- /dev/null +++ b/Examples/test-suite/python_richcompare.i @@ -0,0 +1,60 @@ +/* Test the tp_richcompare functions generated with the -builtin option */ + +%module python_richcompare + +%inline { + +class BaseClass { +public: + BaseClass (int i_) : i(i_) {} + ~BaseClass () {} + + int getValue () const + { return i; } + + bool operator< (const BaseClass& x) const + { return this->i < x.i; } + + bool operator> (const BaseClass& x) const + { return this->i > x.i; } + + bool operator<= (const BaseClass& x) const + { return this->i <= x.i; } + + bool operator>= (const BaseClass& x) const + { return this->i >= x.i; } + + bool operator== (const BaseClass& x) const + { return this->i == x.i; } + + bool operator!= (const BaseClass& x) const + { return this->i != x.i; } + + int i; +}; + +class SubClassA : public BaseClass { +public: + SubClassA (int i_) : BaseClass(i_) {} + ~SubClassA () {} + + bool operator== (const SubClassA& x) const + { return true; } + + bool operator== (const BaseClass& x) const + { return false; } +}; + +class SubClassB : public BaseClass { +public: + SubClassB (int i_) : BaseClass(i_) {} + ~SubClassB () {} + + bool operator== (const SubClassB& x) const + { return true; } + + bool operator== (const SubClassA& x) const + { return false; } +}; + +} From 6cecfe4fcf9999bed46aa411587986565fc24850 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Thu, 31 Mar 2011 04:12:29 +0000 Subject: [PATCH 45/56] Added documentation about tp_richcompare. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12578 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pyopers.swg | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/Lib/python/pyopers.swg b/Lib/python/pyopers.swg index 1ce4f0980..4d7a575dd 100644 --- a/Lib/python/pyopers.swg +++ b/Lib/python/pyopers.swg @@ -2,11 +2,11 @@ * Overloaded operator support The directives in this file apply whether or not you use the - -builtin option to swig, but operator overloads are particularly + -builtin option to SWIG, but operator overloads are particularly attractive when using -builtin, because they are much faster than named methods. - If you're using the -builtin option to swig, and you want to define + If you're using the -builtin option to SWIG, and you want to define python operator overloads beyond the defaults defined in this file, here's what you need to know: @@ -45,12 +45,39 @@ %feature("python:slot", "tp_hash", functype="hashfunc") MyClass::myHashFunc; NOTE: Some python slots use a method signature which does not - match the signature of swig-wrapped methods. For those slots, - swig will automatically generate a "closure" function to re-marshall + match the signature of SWIG-wrapped methods. For those slots, + SWIG will automatically generate a "closure" function to re-marshall the arguments before dispatching to the wrapped method. Setting - the "functype" attribute of the feature enables swig to generate + the "functype" attribute of the feature enables SWIG to generate a correct closure function. + -------------------------------------------------------------- + + The tp_richcompare slot is a special case: SWIG automatically generates + a rich compare function for all wrapped types. If a type defines C++ + operator overloads for comparison (operator==, operator<, etc.), they + will be called from the generated rich compare function. If you + want to explicitly choose a method to handle a certain comparison + operation, you may use %feature("python:slot") like this: + + class MyClass { + public: + bool lessThan (const MyClass& x) const; + ... + }; + + %feature("python:slot", "Py_LT") MyClass::lessThan; + + ... where "Py_LT" is one of rich comparison opcodes defined in the + python header file object.h. + + If there's no method defined to handle a particular comparsion operation, + the default behavior is to compare pointer values of the wrapped + C++ objects. + + -------------------------------------------------------------- + + For more information about python slots, including their names and signatures, you may refer to the python documentation : From e4f434173da709c135210b21c97554c865b17067 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 31 Mar 2011 20:29:35 +0000 Subject: [PATCH 46/56] Minor html changes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12580 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Python.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index bb1f71e94..e766baaf0 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -43,7 +43,7 @@
  • Further details on the Python class interface @@ -2210,7 +2210,7 @@ unacceptable for a high-performance library. The new -builtin option instructs SWIG to forego the use of proxy classes, and instead create wrapped types as new built-in Python types. When this option is used, the following section ("Proxy classes") does not apply. Details on the use of -the -builtin option are in the Built-in Classes +the -builtin option are in the Built-in Classes section.

    @@ -2303,7 +2303,7 @@ you can attach new Python methods to the class and you can even inherit from it by Python built-in types until Python 2.2).

    -

    33.4.2 Built-in Classes

    +

    33.4.2 Built-in Classes

    The -builtin option provides a significant performance improvement @@ -2344,7 +2344,7 @@ wrapped class is turned into a new python built-in type which inherits from from the wrapped methods. For more information about python built-in extensions, please refer to the python documentation:

    -

    docs.python.org/extending/newtypes.html

    +

    http://docs.python.org/extending/newtypes.html

    33.4.2.1 Limitations

    @@ -2502,7 +2502,7 @@ A more detailed discussion about %feature("python:slot") can be found in the file python/pyopers.swig in the SWIG library. You can read about all of the available python slots here:

    -

    docs.python.org/c-api/typeobj.html

    +

    http://docs.python.org/c-api/typeobj.html

    You may override (almost) all of the slots defined in the PyTypeObject, PyNumberMethods, PyMappingMethods, PySequenceMethods, and PyBufferProcs From a46e1f6c31a26f24e5145cd10c1717ab80ba70a0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 31 Mar 2011 20:30:13 +0000 Subject: [PATCH 47/56] unused warning fix git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12581 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pyapi.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/python/pyapi.swg b/Lib/python/pyapi.swg index d980f9263..6f53676ed 100644 --- a/Lib/python/pyapi.swg +++ b/Lib/python/pyapi.swg @@ -32,7 +32,7 @@ typedef struct swig_const_info { * Wrapper of PyInstanceMethod_New() used in Python 3 * It is exported to the generated module, used for -fastproxy * ----------------------------------------------------------------------------- */ -SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *self, PyObject *func) +SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func) { #if PY_VERSION_HEX >= 0x03000000 return PyInstanceMethod_New(func); From f1cb5b7ca6a8d40a0e6fdfcecae9c224d89c5b33 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Thu, 31 Mar 2011 20:37:23 +0000 Subject: [PATCH 48/56] Bug fix: missing quotation mark on autodoc string git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12582 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/python.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 836f87d8b..50c376a63 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -3916,7 +3916,7 @@ public: if (check_kwargs(n)) { 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); + 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 { From 51ef340eedb11bd330c4791c40b4f423526051fa Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Thu, 31 Mar 2011 21:26:12 +0000 Subject: [PATCH 49/56] Converted rest of slot outputting to use printSlot. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12583 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/python.cxx | 40 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 50c376a63..0b6f968e1 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -3473,42 +3473,42 @@ public: // PySequenceMethods as_sequence; Printf(f, " {\n"); - 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")); + printSlot(f, getSlot(n, "feature:python:sq_length"), "sq_length", "lenfunc"); + printSlot(f, getSlot(n, "feature:python:sq_concat"), "sq_concat", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:sq_repeat"), "sq_repeat", "ssizeargfunc"); + printSlot(f, getSlot(n, "feature:python:sq_item"), "sq_item", "ssizeargfunc"); Printv(f, "#if PY_VERSION_HEX >= 0x03000000\n", NIL); - Printf(f, " (void*) %s, // was_sq_slice\n", getSlot(n, "feature:was_sq_slice")); + printSlot(f, getSlot(n, "feature:was_sq_slice"), "was_sq_slice", "void*"); Printv(f, "#else\n", NIL); - Printf(f, " (ssizessizeargfunc) %s, // sq_slice\n", getSlot(n, "feature:python:sq_slice")); + printSlot(f, getSlot(n, "feature:python:sq_slice"), "sq_slice", "ssizessizeargfunc"); Printv(f, "#endif\n", NIL); - Printf(f, " (ssizeobjargproc) %s, // sq_ass_item\n", getSlot(n, "feature:python:sq_ass_item")); + printSlot(f, getSlot(n, "feature:python:sq_ass_item"), "sq_ass_item", "ssizeobjargproc"); 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")); + printSlot(f, getSlot(n, "feature:was_sq_ass_slice"), "was_sq_ass_slice", "void*"); Printv(f, "#else\n", NIL); - Printf(f, " (ssizessizeobjargproc) %s, // sq_ass_slice\n", getSlot(n, "feature:python:sq_ass_slice")); + printSlot(f, getSlot(n, "feature:python:sq_ass_slice"), "sq_ass_slice", "ssizessizeobjargproc"); Printv(f, "#endif\n", NIL); - 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")); + printSlot(f, getSlot(n, "feature:python:sq_contains"), "sq_contains", "objobjproc"); + printSlot(f, getSlot(n, "feature:python:sq_inplace_concat"), "sq_inplace_concat", "binaryfunc"); + printSlot(f, getSlot(n, "feature:python:sq_inplace_repeat"), "sq_inplace_repeat", "ssizeargfunc"); 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:python:bf_getbuffer")); - Printf(f, " (releasebufferproc) %s, // bf_releasebuffer\n", getSlot(n, "feature:python:bf_releasebuffer")); + printSlot(f, getSlot(n, "feature:python:bf_getbuffer"), "bf_getbuffer", "getbufferproc"); + printSlot(f, getSlot(n, "feature:python:bf_releasebuffer"), "bf_releasebuffer", "releasebufferproc"); Printv(f, "#else\n", NIL); - 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")); + printSlot(f, getSlot(n, "feature:python:bf_getreadbuffer"), "bf_getreadbuffer", "readbufferproc"); + printSlot(f, getSlot(n, "feature:python:bf_getwritebuffer"), "bf_getwritebuffer", "writebufferproc"); + printSlot(f, getSlot(n, "feature:python:bf_getsegcount"), "bf_getsegcount", "segcountproc"); + printSlot(f, getSlot(n, "feature:python:bf_getcharbuffer"), "bf_getcharbuffer", "charbufferproc"); Printv(f, "#endif\n", NIL); Printf(f, " },\n"); // PyObject *ht_name, *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")); + printSlot(f, getSlot(n, "feature:python:ht_name"), "ht_name", "PyObject*"); + printSlot(f, getSlot(n, "feature:python:ht_slots"), "ht_slots", "PyObject*"); Printf(f, "};\n\n"); String *clientdata = NewString(""); From 960b503a7268f65b5bb23884bf952bce98515db3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 1 Apr 2011 06:46:14 +0000 Subject: [PATCH 50/56] Python warning fixes for gcc -Wall -Wextra git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12584 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pyapi.swg | 2 +- Lib/python/pyinit.swg | 8 ++-- Lib/python/pyrun.swg | 94 +++++++++++++++++++++++-------------------- 3 files changed, 57 insertions(+), 47 deletions(-) diff --git a/Lib/python/pyapi.swg b/Lib/python/pyapi.swg index 6f53676ed..6d794a67b 100644 --- a/Lib/python/pyapi.swg +++ b/Lib/python/pyapi.swg @@ -32,7 +32,7 @@ typedef struct swig_const_info { * Wrapper of PyInstanceMethod_New() used in Python 3 * It is exported to the generated module, used for -fastproxy * ----------------------------------------------------------------------------- */ -SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func) +SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *SWIGUNUSEDPARM(func)) { #if PY_VERSION_HEX >= 0x03000000 return PyInstanceMethod_New(func); diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index 1027695f0..88d2d3f16 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -138,7 +138,7 @@ SWIGINTERN PyTypeObject* swig_varlink_type(void) { static char varlink__doc__[] = "Swig var link object"; static PyTypeObject varlink_type; - static int type_init = 0; + static int type_init = 0; if (!type_init) { const PyTypeObject tmp = { @@ -152,7 +152,7 @@ swig_varlink_type(void) { (char *)"swigvarlink", /* Type name (tp_name) */ sizeof(swig_varlinkobject), /* Basic size (tp_basicsize) */ 0, /* Itemsize (tp_itemsize) */ - (destructor) swig_varlink_dealloc, /* Deallocator (tp_dealloc) */ + (destructor) swig_varlink_dealloc, /* Deallocator (tp_dealloc) */ (printfunc) swig_varlink_print, /* Print (tp_print) */ (getattrfunc) swig_varlink_getattr, /* get attr (tp_getattr) */ (setattrfunc) swig_varlink_setattr, /* Set attr (tp_setattr) */ @@ -179,6 +179,9 @@ swig_varlink_type(void) { #if PY_VERSION_HEX >= 0x02030000 0, /* tp_del */ #endif +#if PY_VERSION_HEX >= 0x02060000 + 0, /* tp_version */ +#endif #ifdef COUNT_ALLOCS 0,0,0,0 /* tp_alloc -> tp_next */ #endif @@ -321,7 +324,6 @@ SWIGEXPORT #endif SWIG_init(void) { PyObject *m, *d, *md; - PyTypeObject *builtin_type; #if PY_VERSION_HEX >= 0x03000000 static struct PyModuleDef SWIG_module = { PyModuleDef_HEAD_INIT, diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 4403a73b9..53eaf8163 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -416,7 +416,7 @@ SwigPyObject_repr(SwigPyObject *v, PyObject *args) #endif { const char *name = SWIG_TypePrettyName(v->ty); - PyObject *repr = SWIG_Python_str_FromFormat("", name, v); + PyObject *repr = SWIG_Python_str_FromFormat("", name, (void *)v); if (v->next) { # ifdef METH_NOARGS PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next); @@ -688,7 +688,7 @@ SwigPyObject_getattr(SwigPyObject *sobj,char *name) SWIGRUNTIME PyTypeObject* SwigPyObject_TypeOnce(void) { static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer"; - + static PyNumberMethods SwigPyObject_as_number = { (binaryfunc)0, /*nb_add*/ (binaryfunc)0, /*nb_subtract*/ @@ -735,7 +735,7 @@ SwigPyObject_TypeOnce(void) { #endif }; - static PyTypeObject swigpyobject_type; + static PyTypeObject swigpyobject_type; static int type_init = 0; if (!type_init) { const PyTypeObject tmp @@ -743,7 +743,7 @@ SwigPyObject_TypeOnce(void) { /* PyObject header changed in Python 3 */ #if PY_VERSION_HEX >= 0x03000000 PyVarObject_HEAD_INIT(&PyType_Type, 0) -#else +#else PyObject_HEAD_INIT(NULL) 0, /* ob_size */ #endif @@ -753,17 +753,17 @@ SwigPyObject_TypeOnce(void) { (destructor)SwigPyObject_dealloc, /* tp_dealloc */ (printfunc)SwigPyObject_print, /* tp_print */ #if PY_VERSION_HEX < 0x02020000 - (getattrfunc)SwigPyObject_getattr, /* tp_getattr */ + (getattrfunc)SwigPyObject_getattr, /* tp_getattr */ #else - (getattrfunc)0, /* tp_getattr */ + (getattrfunc)0, /* tp_getattr */ #endif - (setattrfunc)0, /* tp_setattr */ + (setattrfunc)0, /* tp_setattr */ #if PY_VERSION_HEX >= 0x03000000 0, /* tp_reserved in 3.0.1, tp_compare in 3.0.0 but not used */ #else (cmpfunc)SwigPyObject_compare, /* tp_compare */ #endif - (reprfunc)SwigPyObject_repr, /* tp_repr */ + (reprfunc)SwigPyObject_repr, /* tp_repr */ &SwigPyObject_as_number, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ @@ -774,7 +774,7 @@ SwigPyObject_TypeOnce(void) { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ - swigobject_doc, /* tp_doc */ + swigobject_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ (richcmpfunc)SwigPyObject_richcompare, /* tp_richcompare */ @@ -782,28 +782,31 @@ SwigPyObject_TypeOnce(void) { #if PY_VERSION_HEX >= 0x02020000 0, /* tp_iter */ 0, /* tp_iternext */ - swigobject_methods, /* tp_methods */ + swigobject_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0, /* tp_free */ - 0, /* tp_is_gc */ - 0, /* tp_bases */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ + 0, /* tp_bases */ 0, /* tp_mro */ - 0, /* tp_cache */ + 0, /* tp_cache */ 0, /* tp_subclasses */ 0, /* tp_weaklist */ #endif #if PY_VERSION_HEX >= 0x02030000 0, /* tp_del */ #endif +#if PY_VERSION_HEX >= 0x02060000 + 0, /* tp_version */ +#endif #ifdef COUNT_ALLOCS 0,0,0,0 /* tp_alloc -> tp_next */ #endif @@ -915,7 +918,7 @@ SWIGRUNTIME PyTypeObject* SwigPyPacked_TypeOnce(void) { static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer"; static PyTypeObject swigpypacked_type; - static int type_init = 0; + static int type_init = 0; if (!type_init) { const PyTypeObject tmp = { @@ -957,28 +960,31 @@ SwigPyPacked_TypeOnce(void) { #if PY_VERSION_HEX >= 0x02020000 0, /* tp_iter */ 0, /* tp_iternext */ - 0, /* tp_methods */ + 0, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0, /* tp_free */ - 0, /* tp_is_gc */ - 0, /* tp_bases */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ + 0, /* tp_bases */ 0, /* tp_mro */ - 0, /* tp_cache */ - 0, /* tp_subclasses */ + 0, /* tp_cache */ + 0, /* tp_subclasses */ 0, /* tp_weaklist */ #endif #if PY_VERSION_HEX >= 0x02030000 0, /* tp_del */ #endif +#if PY_VERSION_HEX >= 0x02060000 + 0, /* tp_version */ +#endif #ifdef COUNT_ALLOCS 0,0,0,0 /* tp_alloc -> tp_next */ #endif @@ -1136,10 +1142,12 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int int res; SwigPyObject *sobj; - if (!obj) return SWIG_ERROR; + if (!obj) + return SWIG_ERROR; if (obj == Py_None) { - if (ptr) *ptr = 0; - return SWIG_OK; + if (ptr) + *ptr = 0; + return SWIG_OK; } res = SWIG_ERROR; @@ -1667,7 +1675,7 @@ SWIG_Python_TypeError(const char *type, PyObject *obj) /* Convert a pointer value, signal an exception on a type mismatch */ SWIGRUNTIME void * -SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) { +SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int SWIGUNUSEDPARM(argnum), int flags) { void *result; if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) { PyErr_Clear(); From cd7fc2047b88d87a7d394c03da2a01a101510093 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Fri, 1 Apr 2011 19:35:30 +0000 Subject: [PATCH 51/56] Factored some #ifdef noise out of the initialization function by adding SwigPyBuiltin_SetMetaType. For %import statements, move the runtime import out of SWIG_init and into the .py file. The reason for this is that the import must be executed within the python execution frame of the module, which is true in the .py file, but *not* true in the initialization function. Had to re-order the .py file slightly to put the 'import' statements at the top; that's necessary to make sure base types from an imported module are initialized first. If -builtin isn't used, then the .py code is not re-ordered. Added an explanation and workaround for the limitation that wrapped types are not raise-able. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12585 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Python.html | 63 +++++++++++++++++++++++++++++++++++++-- Lib/python/builtin.swg | 10 +++++++ Lib/python/pyinit.swg | 3 -- Source/Modules/python.cxx | 56 ++++++++-------------------------- 4 files changed, 83 insertions(+), 49 deletions(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index e766baaf0..0c88185cb 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -2350,14 +2350,71 @@ please refer to the python documentation:

    Use of the -builtin option implies a couple of limitations:

      -
    • Some legacy syntax is no longer supported; in particular:
    • +
    • Some legacy syntax is no longer supported; in particular:

      • The functional interface is no longer exposed. For example, you may no longer call Whizzo.new_CrunchyFrog(). Instead, you must use Whizzo.CrunchyFrog().
      • Static member variables are no longer accessed through the 'cvar' field (e.g., Dances.cvar.FishSlap). They are instead accessed in the idiomatic way (Dances.FishSlap).
      -
    • Wrapped types may not be thrown as python exceptions
    • -
    • Reverse operators are not supported.
    • +
    • Wrapped types may not be thrown as python exceptions. Here's why: the python internals expect that all sub-classes of Exception will have this struct layout:

      + +
      +
      +typedef struct {
      +    PyObject_HEAD
      +    PyObject *dict;
      +    PyObject *args;
      +    PyObject *message;
      +} PyBaseExceptionObject;
      +
      +
      + +

      But swig-generated wrappers expect that all swig-wrapped classes will have this struct layout:

      + +
      +
      +typedef struct {
      +    PyObject_HEAD
      +    void *ptr;
      +    swig_type_info *ty;
      +    int own;
      +    PyObject *next;
      +    PyObject *dict;
      +} SwigPyObject;
      +
      +
      + +

      There are workarounds for this. For example, if you wrap this class: + +

      +
      +class MyException {
      +public:
      +    MyException (const char *msg_);
      +    ~MyException ();
      +
      +    const char *what () const;
      +
      +private:
      +    char *msg;
      +};
      +
      +
      + +

      ... you can define this python class, which may be raised as an exception:

      + +
      +
      +class MyPyException (Exception, MyException) :
      +    def __init__(self, msg, *args) :
      +        Exception.__init__(self, *args)
      +        self.myexc = MyException(msg)
      +    def what (self) :
      +        return self.myexc.what()
      +
      +
      +
    • +
    • Reverse binary operators (e.g., __radd__) are not supported.

    diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index ffd3fbd1c..876bcd1cc 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -409,3 +409,13 @@ SwigPyBuiltin_ThisClosure (PyObject *self, void *closure) { Py_XINCREF(result); return result; } + +SWIGINTERN void +SwigPyBuiltin_SetMetaType (PyTypeObject *type, PyTypeObject *metatype) +{ +#if PY_VERSION_HEX >= 0x03000000 + type->ob_base.ob_base.ob_type = metatype; +#else + type->ob_type = metatype; +#endif +} diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index 88d2d3f16..088eb0ab0 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -355,9 +355,6 @@ SWIG_init(void) { Py_DECREF(metatype_args); metatype->tp_setattro = (setattrofunc) &SwigPyObjectType_setattro; assert(PyType_Ready(metatype) >= 0); - - SWIG_Python_builtin_imports(); - #endif /* Fix SwigMethods to carry the callback ptrs when needed */ diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 0b6f968e1..fe63a3dbc 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -44,8 +44,8 @@ static File *f_directors_h = 0; static File *f_init = 0; static File *f_shadow_py = 0; static String *f_shadow = 0; -static String *f_shadow_imports = 0; -static String *f_shadow_import_stmts = 0; +static Hash *f_shadow_imports = 0; +static String *f_shadow_builtin_imports = 0; static String *f_shadow_stubs = 0; static Hash *builtin_getset = 0; static Hash *class_members = 0; @@ -782,24 +782,13 @@ public: filen = NULL; f_shadow = NewString(""); - f_shadow_imports = NewString(""); - f_shadow_import_stmts = NewString(""); + f_shadow_imports = NewHash(); + f_shadow_builtin_imports = NewString(""); f_shadow_stubs = NewString(""); - Printv(f_shadow_import_stmts, "SWIGINTERN void\n", NIL); - Printv(f_shadow_import_stmts, "SWIG_Python_builtin_imports()\n", NIL); - Printv(f_shadow_import_stmts, "{\n", NIL); - Printv(f_shadow_import_stmts, tab4 "PyObject *import_str = NULL;\n", NIL); - Swig_register_filebyname("shadow", f_shadow); Swig_register_filebyname("python", f_shadow); - Swig_banner_target_lang(f_shadow, "#"); - - if (!modern) { - Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL); - } - if (mod_docstring && Len(mod_docstring)) { Printv(f_shadow, "\"\"\"\n", mod_docstring, "\n\"\"\"\n\n", NIL); Delete(mod_docstring); @@ -982,13 +971,13 @@ public: Printf(f_init, "}\n"); if (shadow) { - if (builtin) { - Printv(f_shadow_import_stmts, "}\n", NIL); - Printv(f_header, f_shadow_import_stmts, NIL); + Swig_banner_target_lang(f_shadow_py, "#"); + if (!modern) { + Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL); } + Printv(f_shadow_py, "\n", f_shadow_builtin_imports, "\n", NIL); Printv(f_shadow_py, f_shadow, "\n", NIL); Printv(f_shadow_py, f_shadow_stubs, "\n", NIL); - Close(f_shadow_py); Delete(f_shadow_py); } @@ -1066,25 +1055,13 @@ public: if (shadowimport) { if (!options || (!Getattr(options, "noshadow") && !Getattr(options, "noproxy"))) { Printf(import, "_%s\n", modname); - if (!Strstr(f_shadow_imports, import)) { + if (!GetFlagAttr(f_shadow_imports, import)) { if (pkg && (!package || Strcmp(pkg, package) != 0)) { - if (builtin) { - Printf(f_shadow_import_stmts, tab4 "import_str = PyString_FromString(\"%s.%s\");\n", pkg, modname); - Printf(f_shadow_import_stmts, tab4 "PyImport_Import(import_str);\n"); - Printf(f_shadow_import_stmts, tab4 "Py_XDECREF(import_str);\n"); - } else { - Printf(f_shadow, "import %s.%s\n", pkg, modname); - } + Printf(builtin ? f_shadow_builtin_imports : f_shadow, "import %s.%s\n", pkg, modname); } else { - if (builtin) { - Printf(f_shadow_import_stmts, tab4 "import_str = PyString_FromString(\"%s\");\n", modname); - Printf(f_shadow_import_stmts, tab4 "PyImport_Import(import_str);\n"); - Printf(f_shadow_import_stmts, tab4 "Py_XDECREF(import_str);\n"); - } else { - Printf(f_shadow, "import %s\n", modname); - } + Printf(builtin ? f_shadow_builtin_imports : f_shadow, "import %s\n", modname); } - Printv(f_shadow_imports, import, NULL); + SetFlag(f_shadow_imports, import); } } } @@ -3227,11 +3204,7 @@ public: String *templ = NewStringf("SwigPyBuiltin_%s", mname); int funpack = modernargs && fastunpack; - Printv(f_init, "#if PY_VERSION_HEX >= 0x03000000\n", NIL); - Printf(f_init, " builtin_pytype->ob_base.ob_base.ob_type = metatype;\n"); - Printv(f_init, "#else\n", NIL); - Printf(f_init, " builtin_pytype->ob_type = metatype;\n"); - Printv(f_init, "#endif\n", NIL); + Printv(f_init, " SwigPyBuiltin_SetMetaType(builtin_pytype, metatype);\n", NIL); Printf(f_init, " builtin_pytype->tp_new = PyType_GenericNew;\n"); Printv(f_init, " builtin_base_count = 0;\n", NIL); List *baselist = Getattr(n, "bases"); @@ -3848,9 +3821,6 @@ public: } if (builtin) { - //Dump(f_shadow, f_builtins); - //Printf(f_builtins, " {NULL} // Sentinel\n};\n\n"); - //Dump(builtin_methods, f_builtins); Clear(class_members); Clear(builtin_getset); Clear(builtin_methods); From da1fc2ff6ab8ff512ace983375d0c65597616722 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Fri, 1 Apr 2011 19:39:14 +0000 Subject: [PATCH 52/56] Fixed exception example git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12586 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Python.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 0c88185cb..cc10eb58c 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -2356,7 +2356,7 @@ please refer to the python documentation:

  • Static member variables are no longer accessed through the 'cvar' field (e.g., Dances.cvar.FishSlap). They are instead accessed in the idiomatic way (Dances.FishSlap).
  • -
  • Wrapped types may not be thrown as python exceptions. Here's why: the python internals expect that all sub-classes of Exception will have this struct layout:

    +
  • Wrapped types may not be raised as python exceptions. Here's why: the python internals expect that all sub-classes of Exception will have this struct layout:

    @@ -2405,7 +2405,7 @@ private:
     
     
    -class MyPyException (Exception, MyException) :
    +class MyPyException (Exception) :
         def __init__(self, msg, *args) :
             Exception.__init__(self, *args)
             self.myexc = MyException(msg)
    
    From 48faf209345c632e9823fe62f0bd315e52a21617 Mon Sep 17 00:00:00 2001
    From: Stefan Zager 
    Date: Sat, 2 Apr 2011 21:35:34 +0000
    Subject: [PATCH 53/56] Added python version support to the built-in section.
    
    git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12589 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    ---
     Doc/Manual/Python.html | 6 ++++++
     1 file changed, 6 insertions(+)
    
    diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html
    index cc10eb58c..165b84bf9 100644
    --- a/Doc/Manual/Python.html
    +++ b/Doc/Manual/Python.html
    @@ -2350,6 +2350,12 @@ please refer to the python documentation:

    Use of the -builtin option implies a couple of limitations:

      +
    • python version support:

    • +
        +
      • Versions 2.5 and up are fully supported
      • +
      • Versions 2.3 and 2.4 are mostly supported; there are problems with director classes and/or sub-classing a wrapped type in python.
      • +
      • Versions older than 2.3 are not supported.
      • +
    • Some legacy syntax is no longer supported; in particular:

      • The functional interface is no longer exposed. For example, you may no longer call Whizzo.new_CrunchyFrog(). Instead, you must use Whizzo.CrunchyFrog().
      • From 90fe22acf7b02111db8799b608c4189efa9b280c Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Sat, 2 Apr 2011 21:40:00 +0000 Subject: [PATCH 54/56] Fix for METH_O and -compactdefaultargs, in two parts: - Don't mark a method as METH_O if it has compactdefaultargs - In SWIG_Python_UnpackTuple, allow for a non-tuple 'args'. Added compatibility for python versions 2.3 and 2.4. These are only partially supported; inheriting from wrapped types looks problematic. Versions older that 2.3 are unlikely ever to work. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12590 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 3 ++- Lib/python/builtin.swg | 2 +- Lib/python/pyhead.swg | 45 +++++++++++++++++++++++++++++++++++ Lib/python/pyrun.swg | 8 +++++++ Lib/python/std_pair.i | 8 +++---- Source/Modules/python.cxx | 4 +++- 6 files changed, 63 insertions(+), 7 deletions(-) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 5423542f7..f85eed491 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -156,7 +156,6 @@ CPP_TEST_CASES += \ destructor_reprotected \ director_abstract \ director_alternating \ - director_basic \ director_classes \ director_classic \ director_constructor \ @@ -439,6 +438,8 @@ CPP_TEST_CASES += \ wallkw \ wrapmacro +# director_basic \ + # # Put all the heavy STD/STL cases here, where they can be skipped if needed # diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index 876bcd1cc..ca9d8ab15 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -270,7 +270,7 @@ SwigPyStaticVar_repr(PyGetSetDescrObject *descr) { SWIGINTERN int SwigPyStaticVar_traverse(PyObject *self, visitproc visit, void *arg) { PyDescrObject *descr = (PyDescrObject *)self; - Py_VISIT(descr->d_type); + Py_VISIT((PyObject*) descr->d_type); return 0; } diff --git a/Lib/python/pyhead.swg b/Lib/python/pyhead.swg index 2ce0fb194..d38b4d91f 100644 --- a/Lib/python/pyhead.swg +++ b/Lib/python/pyhead.swg @@ -153,4 +153,49 @@ PyObject *PyBool_FromLong(long ok) typedef int Py_ssize_t; # define PY_SSIZE_T_MAX INT_MAX # define PY_SSIZE_T_MIN INT_MIN +typedef inquiry lenfunc; +typedef intargfunc ssizeargfunc; +typedef intintargfunc ssizessizeargfunc; +typedef intobjargproc ssizeobjargproc; +typedef intintobjargproc ssizessizeobjargproc; +typedef getreadbufferproc readbufferproc; +typedef getwritebufferproc writebufferproc; +typedef getsegcountproc segcountproc; +typedef getcharbufferproc charbufferproc; +static inline long PyNumber_AsSsize_t (PyObject *x, void*) +{ + long result = 0; + PyObject *i = PyNumber_Int(x); + if (i) { + result = PyInt_AsLong(i); + Py_DECREF(i); + } + return result; +} +#endif + +#if PY_VERSION_HEX < 0x02040000 +#define Py_VISIT(op) \ + do { \ + if (op) { \ + int vret = visit((op), arg); \ + if (vret) \ + return vret; \ + } \ + } while (0) +#endif + +#if PY_VERSION_HEX < 0x02030000 +typedef struct { + PyTypeObject type; + PyNumberMethods as_number; + PyMappingMethods as_mapping; + PySequenceMethods as_sequence; + PyBufferProcs as_buffer; + PyObject *name, *slots; +} PyHeapTypeObject; +#endif + +#if PY_VERSION_HEX < 0x02030000 +typedef destructor freefunc; #endif diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 53eaf8163..d6e273df1 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -166,6 +166,14 @@ SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssi } } if (!PyTuple_Check(args)) { + if (min <= 1 && max >= 1) { + objs[0] = args; + register int i; + for (i = 1; i < max; ++i) { + objs[i] = 0; + } + return 2; + } PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple"); return 0; } else { diff --git a/Lib/python/std_pair.i b/Lib/python/std_pair.i index 386fbdab7..782969574 100644 --- a/Lib/python/std_pair.i +++ b/Lib/python/std_pair.i @@ -129,8 +129,8 @@ SwigPython_std_pair_repr (PyObject *o) { PyObject *tuple = PyTuple_New(2); assert(tuple); - PyTuple_SET_ITEM(tuple, 0, PyObject_GetAttrString(o, "first")); - PyTuple_SET_ITEM(tuple, 1, PyObject_GetAttrString(o, "second")); + PyTuple_SET_ITEM(tuple, 0, PyObject_GetAttrString(o, (char*) "first")); + PyTuple_SET_ITEM(tuple, 1, PyObject_GetAttrString(o, (char*) "second")); PyObject *result = PyObject_Repr(tuple); Py_DECREF(tuple); return result; @@ -139,14 +139,14 @@ SwigPython_std_pair_repr (PyObject *o) SWIGINTERN PyObject* SwigPython_std_pair_getitem (PyObject *a, Py_ssize_t b) { - PyObject *result = PyObject_GetAttrString(a, b % 2 ? "second" : "first"); + PyObject *result = PyObject_GetAttrString(a, b % 2 ? (char*) "second" : (char*) "first"); return result; } SWIGINTERN int SwigPython_std_pair_setitem (PyObject *a, Py_ssize_t b, PyObject *c) { - int result = PyObject_SetAttrString(a, b % 2 ? "second" : "first", c); + int result = PyObject_SetAttrString(a, b % 2 ? (char*) "second" : (char*) "first", c); return result; } #endif diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index fe63a3dbc..b26e75433 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -2129,7 +2129,7 @@ public: int noargs = funpack && (tuple_required == 0 && tuple_arguments == 0); int onearg = funpack && (tuple_required == 1 && tuple_arguments == 1); - if (builtin && funpack && !overname && !builtin_ctor) { + if (builtin && funpack && !overname && !builtin_ctor && !GetFlag(n, "feature:compactdefaultargs")) { String *argattr = NewStringf("%d", tuple_arguments); Setattr(n, "python:argcount", argattr); Delete(argattr); @@ -3434,7 +3434,9 @@ public: 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"); + Printv(f, "#if PY_VERSION_HEX >= 0x02050000\n", NIL); printSlot(f, getSlot(n, "feature:python:nb_index"), "nb_index", "unaryfunc"); + Printv(f, "#endif\n", NIL); Printf(f, " },\n"); // PyMappingMethods as_mapping; From a403518d03afce2b74139b004f6ea1dddc6aca37 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Sat, 2 Apr 2011 21:40:39 +0000 Subject: [PATCH 55/56] Restore director_basic test git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12591 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index f85eed491..5423542f7 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -156,6 +156,7 @@ CPP_TEST_CASES += \ destructor_reprotected \ director_abstract \ director_alternating \ + director_basic \ director_classes \ director_classic \ director_constructor \ @@ -438,8 +439,6 @@ CPP_TEST_CASES += \ wallkw \ wrapmacro -# director_basic \ - # # Put all the heavy STD/STL cases here, where they can be skipped if needed # From c95cc724548f76449c41b4472dda65f4dbcdc04c Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Sun, 3 Apr 2011 05:15:48 +0000 Subject: [PATCH 56/56] Merged %pythonnondynamic fix git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12594 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/python.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index b26e75433..b98793e0c 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -858,9 +858,9 @@ public: #endif tab4, tab8, "return\n", tab4, "method = class_type.__swig_setmethods__.get(name,None)\n", tab4, "if method: return method(self,value)\n", #ifdef USE_THISOWN - tab4, "if (not static) or hasattr(self,name) or (name == \"thisown\"):\n", + tab4, "if (not static) or (name == \"thisown\"):\n", #else - tab4, "if (not static) or hasattr(self,name):\n", + tab4, "if (not static):\n", #endif tab4, tab4, "self.__dict__[name] = value\n", tab4, "else:\n",