From 769b26d5754e64ddc37be1e546e1951c94e082d9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 6 May 2011 20:56:42 +0000 Subject: [PATCH 01/59] Fix %varargs when used with a numerical argument, which was emitting one more optional argument than documented git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12657 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 5 +++++ Examples/test-suite/python/varargs_runme.py | 16 ++++++++++++++++ Examples/test-suite/varargs.i | 5 +++++ Source/CParse/parser.y | 3 +-- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index f928203d8..bc347308e 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.4 (in progress) =========================== +2011-05-05: wsfulton + Fix %varargs when used with a numerical argument, eg %varargs(3, char *arg = NULL). + It was possible to use one extra optional argument than document. Now the above only + generates 3 optional char * arguments. Reported by Karl Wette. + 2011-05-05: wsfulton [Lua, Python, Tcl] C/C++ prototypes shown in error message when calling an overloaded method with incorrect arguments improved to show always show fully qualified name diff --git a/Examples/test-suite/python/varargs_runme.py b/Examples/test-suite/python/varargs_runme.py index 301de78a7..a55f0630e 100644 --- a/Examples/test-suite/python/varargs_runme.py +++ b/Examples/test-suite/python/varargs_runme.py @@ -16,3 +16,19 @@ if varargs.test_def("Hello",1) != "Hello": if varargs.test_def("Hello") != "Hello": raise RuntimeError, "Failed" + +### +if varargs.test_plenty("Hello") != "Hello": + raise RuntimeError, "Failed" + +if varargs.test_plenty("Hello", 1) != "Hello": + raise RuntimeError, "Failed" + +if varargs.test_plenty("Hello", 1, 2) != "Hello": + raise RuntimeError, "Failed" + +try: + varargs.test_plenty("Hello", 1, 2, 3) + raise RuntimeError +except NotImplementedError: + pass diff --git a/Examples/test-suite/varargs.i b/Examples/test-suite/varargs.i index c7931fed2..dd56cb073 100644 --- a/Examples/test-suite/varargs.i +++ b/Examples/test-suite/varargs.i @@ -5,6 +5,7 @@ %varargs(int mode = 0) test_def; %varargs(int mode = 0) Foo::Foo; %varargs(int mode = 0) Foo::statictest(const char*fmt, ...); +%varargs(2, int mode = 0) test_plenty(const char*fmt, ...); %inline %{ char *test(const char *fmt, ...) { @@ -36,4 +37,8 @@ public: } }; +const char *test_plenty(const char *fmt, ...) { + return fmt; +} + %} diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index d95390892..2ee117506 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2628,8 +2628,7 @@ varargs_parms : parms { $$ = $1; } $$ = 0; } else { $$ = Copy($3); - Setattr($$,"name","VARARGS_SENTINEL"); - for (i = 0; i < n; i++) { + for (i = 0; i < n-1; i++) { p = Copy($3); set_nextSibling(p,$$); Delete($$); From cba65bd5248076c67d63d5b773b1b22c410b4592 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 6 May 2011 21:10:01 +0000 Subject: [PATCH 02/59] revert 12657 - incorrect changes made git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12658 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 5 ----- Examples/test-suite/python/varargs_runme.py | 5 ++++- Source/CParse/parser.y | 3 ++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index bc347308e..f928203d8 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,11 +4,6 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.4 (in progress) =========================== -2011-05-05: wsfulton - Fix %varargs when used with a numerical argument, eg %varargs(3, char *arg = NULL). - It was possible to use one extra optional argument than document. Now the above only - generates 3 optional char * arguments. Reported by Karl Wette. - 2011-05-05: wsfulton [Lua, Python, Tcl] C/C++ prototypes shown in error message when calling an overloaded method with incorrect arguments improved to show always show fully qualified name diff --git a/Examples/test-suite/python/varargs_runme.py b/Examples/test-suite/python/varargs_runme.py index a55f0630e..f96a43d85 100644 --- a/Examples/test-suite/python/varargs_runme.py +++ b/Examples/test-suite/python/varargs_runme.py @@ -27,8 +27,11 @@ if varargs.test_plenty("Hello", 1) != "Hello": if varargs.test_plenty("Hello", 1, 2) != "Hello": raise RuntimeError, "Failed" +if varargs.test_plenty("Hello", 1, 2, 3) != "Hello": + raise RuntimeError, "Failed" + try: - varargs.test_plenty("Hello", 1, 2, 3) + varargs.test_plenty("Hello", 1, 2, 3, 4) raise RuntimeError except NotImplementedError: pass diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 2ee117506..d95390892 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2628,7 +2628,8 @@ varargs_parms : parms { $$ = $1; } $$ = 0; } else { $$ = Copy($3); - for (i = 0; i < n-1; i++) { + Setattr($$,"name","VARARGS_SENTINEL"); + for (i = 0; i < n; i++) { p = Copy($3); set_nextSibling(p,$$); Delete($$); From a52612f84563cb623e720b176a7e80a6ef70cf79 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Sun, 8 May 2011 06:54:21 +0000 Subject: [PATCH 03/59] Fixed PyGetSetDescr for python3.2. Fixed memory management in special_variable_macros test. Don't define asdict() for multimap. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12659 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Examples/test-suite/python/Makefile.in | 3 ++- Examples/test-suite/special_variable_macros.i | 16 ++++++++++-- Lib/python/builtin.swg | 25 +++++++++++-------- Lib/python/pyhead.swg | 5 ++++ Lib/python/pyinit.swg | 9 +++++++ Lib/python/std_map.i | 11 ++++---- 7 files changed, 53 insertions(+), 19 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index f928203d8..dca3acdd6 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.4 (in progress) =========================== +2011-05-07: szager + [python] Fixed PyGetSetDescr for python3.2. + 2011-05-05: wsfulton [Lua, Python, Tcl] C/C++ prototypes shown in error message when calling an overloaded method with incorrect arguments improved to show always show fully qualified name diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index 06ae7ef24..108cb60eb 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -93,7 +93,8 @@ BUILTIN_BROKEN = \ default_constructor.cpptest \ director_exception.cpptest \ exception_order.cpptest \ - threads_exception.cpptest + threads_exception.cpptest \ + python_abstractbase.cpptest BUILTIN_NOT_BROKEN = $(filter-out $(BUILTIN_BROKEN),$(NOT_BROKEN_TEST_CASES)) diff --git a/Examples/test-suite/special_variable_macros.i b/Examples/test-suite/special_variable_macros.i index 1ad673b41..ba9889d7a 100644 --- a/Examples/test-suite/special_variable_macros.i +++ b/Examples/test-suite/special_variable_macros.i @@ -5,13 +5,25 @@ %warnfilter(SWIGWARN_GO_NAME_CONFLICT); /* Ignoring 'NewName' due to Go name ('NewName') conflict with 'Name' */ +%ignore Name::operator=; + %inline %{ struct Name { - Name(const char *n="none") : name(n) {} + Name(const char *n="none") : name(strdup(n ? n : "")) {} + Name(const Name& x) : name(strdup(x.name)) {} + Name& operator= (const Name& x) + { + if (this != &x) { + free(this->name); + this->name = strdup(x.name); + } + return *this; + } + ~Name () { free(this->name); } const char *getName() const { return name; }; Name *getNamePtr() { return this; }; private: - const char *name; + char *name; }; struct NameWrap { NameWrap(const char *n="casternone") : name(n) {} diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index 8852832d1..de1457c41 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -285,17 +285,22 @@ SwigPyBuiltin_FunpackSetterClosure (PyObject *obj, PyObject *val, void *closure) SWIGINTERN void SwigPyStaticVar_dealloc(PyDescrObject *descr) { _PyObject_GC_UNTRACK(descr); + /* Py_XDECREF(descr->d_type); Py_XDECREF(descr->d_name); + */ + Py_XDECREF(PyDescr_TYPE(descr)); + Py_XDECREF(PyDescr_NAME(descr)); 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); + + return PyUnicode_FromFormat("", PyDescr_NAME(descr), PyDescr_TYPE(descr)->tp_name); #else - return PyString_FromFormat("", PyString_AsString(descr->d_name), descr->d_type->tp_name); + return PyString_FromFormat("", PyString_AsString(PyDescr_NAME(descr)), PyDescr_TYPE(descr)->tp_name); #endif } @@ -303,7 +308,7 @@ SWIGINTERN int SwigPyStaticVar_traverse(PyObject *self, visitproc visit, void *arg) { PyDescrObject *descr; descr = (PyDescrObject *)self; - Py_VISIT((PyObject*) descr->d_type); + Py_VISIT((PyObject*) PyDescr_TYPE(descr)); return 0; } @@ -312,9 +317,9 @@ SwigPyStaticVar_get(PyGetSetDescrObject *descr, PyObject *obj, PyObject *SWIGUNU 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 '%.300S' 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", PyDescr_NAME(descr), PyDescr_TYPE(descr)->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); + PyErr_Format(PyExc_AttributeError, "attribute '%.300s' of '%.100s' objects is not readable", PyString_AsString(PyDescr_NAME(descr)), PyDescr_TYPE(descr)->tp_name); #endif return NULL; } @@ -324,9 +329,9 @@ 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 '%.300S' 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", PyDescr_NAME(descr), PyDescr_TYPE(descr)->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); + PyErr_Format(PyExc_AttributeError, "attribute '%.300s' of '%.100s' objects is not writable", PyString_AsString(PyDescr_NAME(descr)), PyDescr_TYPE(descr)->tp_name); #endif return -1; } @@ -425,10 +430,10 @@ SwigPyStaticVar_new_getset(PyTypeObject *type, PyGetSetDef *getset) { descr = (PyGetSetDescrObject *)PyType_GenericAlloc(&SwigPyStaticVar_Type, 0); assert(descr); Py_XINCREF(type); - descr->d_type = type; - descr->d_name = PyString_InternFromString(getset->name); + PyDescr_TYPE(descr) = type; + PyDescr_NAME(descr) = PyString_InternFromString(getset->name); descr->d_getset = getset; - if (descr->d_name == NULL) { + if (PyDescr_NAME(descr) == NULL) { Py_DECREF(descr); descr = NULL; } diff --git a/Lib/python/pyhead.swg b/Lib/python/pyhead.swg index dacf2d713..803cd0745 100644 --- a/Lib/python/pyhead.swg +++ b/Lib/python/pyhead.swg @@ -206,3 +206,8 @@ typedef destructor freefunc; # define SWIGPY_USE_CAPSULE # define SWIGPY_CAPSULE_NAME ((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION ".type_pointer_capsule" SWIG_TYPE_TABLE_NAME) #endif + +#if PY_VERSION_HEX < 0x03020000 +#define PyDescr_TYPE(x) (((PyDescrObject *)(x))->d_type) +#define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name) +#endif diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index 4682912c8..d5de1f8a6 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -325,7 +325,16 @@ SWIG_init(void) { PyObject *m, *d, *md; #if PY_VERSION_HEX >= 0x03000000 static struct PyModuleDef SWIG_module = { +# if PY_VERSION_HEX >= 0x03020000 PyModuleDef_HEAD_INIT, +# else + { + PyObject_HEAD_INIT(NULL) + NULL, /* m_init */ + 0, /* m_index */ + NULL, /* m_copy */ + }, +# endif (char *) SWIG_name, NULL, -1, diff --git a/Lib/python/std_map.i b/Lib/python/std_map.i index 42f565908..fec816222 100644 --- a/Lib/python/std_map.i +++ b/Lib/python/std_map.i @@ -168,10 +168,6 @@ swig::SwigPyIterator* iteritems(PyObject **PYTHON_SELF) { return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF); } - - PyObject* asdict() { - return swig::traits_from< Map >::asdict(*self); - } } #else @@ -292,14 +288,17 @@ void __setitem__(const key_type& key) { self->erase(key); } - } - %extend { void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) { (*self)[key] = x; } + + PyObject* asdict() { + return swig::traits_from< Map >::asdict(*self); + } } + %enddef From 63f21af8d01a38cbefcaae87fe8746ba744eb80d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 12 May 2011 20:20:36 +0000 Subject: [PATCH 04/59] PyVarObject_HEAD_INIT to conform to C standard - pointers cannot be used in static initializers git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12660 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pyinit.swg | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index d5de1f8a6..7a32a5046 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -143,7 +143,7 @@ swig_varlink_type(void) { const PyTypeObject tmp = { /* PyObject header changed in Python 3 */ #if PY_VERSION_HEX >= 0x03000000 - PyVarObject_HEAD_INIT(&PyType_Type, 0) + PyVarObject_HEAD_INIT(NULL, 0) #else PyObject_HEAD_INIT(NULL) 0, /* ob_size */ @@ -186,11 +186,13 @@ swig_varlink_type(void) { #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; +#if PY_VERSION_HEX < 0x02020000 + varlink_type.ob_type = &PyType_Type; +#else + if (PyType_Ready(&varlink_type) < 0) + return NULL; +#endif } return &varlink_type; } From 1aa65e2220b99e204c5f4e83f7f7b56904849815 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 12 May 2011 21:07:57 +0000 Subject: [PATCH 05/59] PyVarObject_HEAD_INIT to conform to C standard - pointers cannot be used in static initializers git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12661 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/builtin.swg | 144 +++++++++++++++++++++++------------------ 1 file changed, 81 insertions(+), 63 deletions(-) diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index de1457c41..b6f0c4ce0 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -336,68 +336,6 @@ SwigPyStaticVar_set(PyGetSetDescrObject *descr, PyObject *obj, PyObject *value) return -1; } -SWIGINTERN 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 */ - 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 */ -#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 -}; - SWIGINTERN int SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value) { PyObject *attribute; @@ -424,10 +362,90 @@ SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value) { return -1; } +SWIGINTERN PyTypeObject* +SwigPyStaticVar_Type(void) { + static PyTypeObject staticvar_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(&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 */ + 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 */ +#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 + }; + staticvar_type = tmp; + type_init = 1; +#if PY_VERSION_HEX < 0x02020000 + staticvar_type.ob_type = &PyType_Type; +#else + if (PyType_Ready(&staticvar_type) < 0) + return NULL; +#endif + } + return &staticvar_type; +} + SWIGINTERN PyGetSetDescrObject * SwigPyStaticVar_new_getset(PyTypeObject *type, PyGetSetDef *getset) { + PyGetSetDescrObject *descr; - descr = (PyGetSetDescrObject *)PyType_GenericAlloc(&SwigPyStaticVar_Type, 0); + descr = (PyGetSetDescrObject *)PyType_GenericAlloc(SwigPyStaticVar_Type(), 0); assert(descr); Py_XINCREF(type); PyDescr_TYPE(descr) = type; From 34e7c826317db2a38e8a6e9a2ab3c4b860078723 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 13 May 2011 05:58:58 +0000 Subject: [PATCH 06/59] Remove a compiler warning for builtin git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12662 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pyrun.swg | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index c9b772e4b..d730a2dbe 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1070,6 +1070,7 @@ SWIG_Python_GetSwigThis(PyObject *pyobj) return (SwigPyObject *) pyobj; #ifdef SWIGPYTHON_BUILTIN + (void)obj; # ifdef PyWeakref_CheckProxy if (PyWeakref_CheckProxy(pyobj)) { pyobj = PyWeakref_GET_OBJECT(pyobj); From d2dd14e6280083392c6a47b5ac65ffeb5a42dc9b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 13 May 2011 06:01:07 +0000 Subject: [PATCH 07/59] Python 3.2 portability fixes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12663 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Varargs.html | 41 ++++++++---- Examples/test-suite/python_varargs_typemap.i | 67 +++++++++++++------- 2 files changed, 71 insertions(+), 37 deletions(-) diff --git a/Doc/Manual/Varargs.html b/Doc/Manual/Varargs.html index fb34a3ad9..eb14363af 100644 --- a/Doc/Manual/Varargs.html +++ b/Doc/Manual/Varargs.html @@ -461,23 +461,36 @@ like this:
 %typemap(in) (...)(char *args[10]) {
-    int i;
-    int argc;
-    for (i = 0; i < 10; i++) args[i] = 0;
-    argc = PyTuple_Size(varargs);
-    if (argc > 10) {
-       PyErr_SetString(PyExc_ValueError,"Too many arguments");
+  int i;
+  int argc;
+  for (i = 0; i < 10; i++) args[i] = 0;
+  argc = PyTuple_Size(varargs);
+  if (argc > 10) {
+    PyErr_SetString(PyExc_ValueError, "Too many arguments");
+    return NULL;
+  }
+  for (i = 0; i < argc; i++) {
+    PyObject *pyobj = PyTuple_GetItem(varargs, i);
+    char *str = 0;
+%#if PY_VERSION_HEX>=0x03000000
+    PyObject *pystr;
+    if (!PyUnicode_Check(pyobj)) {
+       PyErr_SetString(PyExc_ValueError, "Expected a string");
        return NULL;
     }
-    for (i = 0; i < argc; i++) {
-       PyObject *o = PyTuple_GetItem(varargs,i);
-       if (!PyString_Check(o)) {
-           PyErr_SetString(PyExc_ValueError,"Expected a string");
-           return NULL;
-       }
-       args[i] = PyString_AsString(o);
+    pystr = PyUnicode_AsUTF8String(pyobj);
+    str = PyBytes_AsString(pystr);
+    Py_XDECREF(pystr);
+%#else  
+    if (!PyString_Check(pyobj)) {
+       PyErr_SetString(PyExc_ValueError, "Expected a string");
+       return NULL;
     }
-    $1 = (void *) args;
+    str = PyString_AsString(pyobj);
+%#endif
+    args[i] = str;
+  }
+  $1 = (void *) args;
 }
 
diff --git a/Examples/test-suite/python_varargs_typemap.i b/Examples/test-suite/python_varargs_typemap.i index 3fdf8d4d5..4bc6f3fbd 100644 --- a/Examples/test-suite/python_varargs_typemap.i +++ b/Examples/test-suite/python_varargs_typemap.i @@ -4,40 +4,61 @@ * chapter of the SWIG manual. */ +%{ +%} + %typemap(in) (...)(char *args[10]) { - int i; - int argc; - for (i = 0; i < 10; i++) args[i] = 0; - argc = PyTuple_Size(varargs); - if (argc > 10) { - PyErr_SetString(PyExc_ValueError,"Too many arguments"); + int i; + int argc; + for (i = 0; i < 10; i++) args[i] = 0; + argc = PyTuple_Size(varargs); + if (argc > 10) { + PyErr_SetString(PyExc_ValueError, "Too many arguments"); + return NULL; + } + for (i = 0; i < argc; i++) { + PyObject *pyobj = PyTuple_GetItem(varargs, i); + char *str = 0; +%#if PY_VERSION_HEX>=0x03000000 + PyObject *pystr; + if (!PyUnicode_Check(pyobj)) { + PyErr_SetString(PyExc_ValueError, "Expected a string"); return NULL; } - for (i = 0; i < argc; i++) { - PyObject *o = PyTuple_GetItem(varargs,i); - if (!PyString_Check(o)) { - PyErr_SetString(PyExc_ValueError,"Expected a string"); - return NULL; - } - args[i] = PyString_AsString(o); + pystr = PyUnicode_AsUTF8String(pyobj); + str = PyBytes_AsString(pystr); + Py_XDECREF(pystr); +%#else + if (!PyString_Check(pyobj)) { + PyErr_SetString(PyExc_ValueError, "Expected a string"); + return NULL; } - $1 = (void *) args; + str = PyString_AsString(pyobj); +%#endif + args[i] = str; + } + $1 = (void *) args; } %feature("action") testfunc { - char **args = (char **) arg3; - result = testfunc(arg1, arg2, args[0], args[1], args[2], args[3], args[4], - args[5],args[6],args[7],args[8],args[9], NULL); + char **args = (char **) arg3; + result = testfunc(arg1, arg2, args[0], args[1], args[2], args[3], args[4], + args[5],args[6],args[7],args[8],args[9], NULL); } %inline { char* testfunc (int arg1, double arg2, ...) { - va_list ap; - char *c; - va_start(ap, arg2); - c = va_arg(ap, char*); - va_end(ap); - return c; + va_list ap; + char *c; + va_start(ap, arg2); + c = va_arg(ap, char*); + va_end(ap); + return c; } } + +%inline %{ +char *doublecheck(char *inputval) { return inputval; } +%} + From ef1546a287851ddea8eeb515bc925b557ebf8063 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 14 May 2011 00:10:10 +0000 Subject: [PATCH 08/59] cosmetic - cleanup git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12664 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/builtin.swg | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index b6f0c4ce0..97150dc5c 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -285,10 +285,6 @@ SwigPyBuiltin_FunpackSetterClosure (PyObject *obj, PyObject *val, void *closure) SWIGINTERN void SwigPyStaticVar_dealloc(PyDescrObject *descr) { _PyObject_GC_UNTRACK(descr); - /* - Py_XDECREF(descr->d_type); - Py_XDECREF(descr->d_name); - */ Py_XDECREF(PyDescr_TYPE(descr)); Py_XDECREF(PyDescr_NAME(descr)); PyObject_GC_Del(descr); From 6e87b73c40b427dc7591a197cb5b615cf5423f54 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 14 May 2011 00:11:40 +0000 Subject: [PATCH 09/59] reorder tests alphabetically git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12665 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/python/Makefile.in | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index 108cb60eb..0e600b16f 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -31,42 +31,42 @@ PY2TO3 = 2to3 -x import CPP_TEST_CASES += \ argcargvtest \ - python_autodoc \ - python_append \ callback \ complextest \ director_stl \ director_wstring \ file_test \ iadd \ - inout \ - input \ - inplaceadd \ implicittest \ + inout \ + inplaceadd \ + input \ li_cstring \ li_cwstring \ li_factory \ li_implicit \ - li_std_vectora \ - li_std_vector_extra \ li_std_map_member \ li_std_multimap \ li_std_pair_extra \ li_std_set \ li_std_stream \ li_std_string_extra \ + li_std_vectora \ + li_std_vector_extra \ li_std_wstream \ li_std_wstring \ primitive_types \ python_abstractbase \ + python_append \ + python_autodoc \ python_kwargs \ python_nondynamic \ python_overload_simple_cast \ python_richcompare \ + simutry \ std_containers \ swigobject \ - template_matrix \ - simutry + template_matrix # li_std_carray # director_profile @@ -88,13 +88,13 @@ C_TEST_CASES += \ include $(srcdir)/../common.mk BUILTIN_BROKEN = \ - li_std_string_extra.cpptest \ - li_std_wstring.cpptest \ default_constructor.cpptest \ director_exception.cpptest \ exception_order.cpptest \ - threads_exception.cpptest \ - python_abstractbase.cpptest + li_std_string_extra.cpptest \ + li_std_wstring.cpptest \ + python_abstractbase.cpptest \ + threads_exception.cpptest BUILTIN_NOT_BROKEN = $(filter-out $(BUILTIN_BROKEN),$(NOT_BROKEN_TEST_CASES)) From 74aa3f218f47ae49faf58a2073f5425e7aa61033 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 14 May 2011 00:13:43 +0000 Subject: [PATCH 10/59] %varargs - better documentation and remove additional argument generation which didn't work properly as a sentinel git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12666 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 8 ++++ Doc/Manual/Varargs.html | 49 ++++++++++++++++----- Examples/test-suite/python/varargs_runme.py | 7 ++- Source/CParse/parser.y | 9 +++- 4 files changed, 57 insertions(+), 16 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index dca3acdd6..464a9579a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,14 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.4 (in progress) =========================== +2011-05-14: wsfulton + %varargs when used with a numeric argument used to create an additional argument + which was intended to provide a guaranteed sentinel value. This never worked and now + the additional argument is not generated. + +2011-05-13: wsfulton + [python] Additional fixes for python3.2 support. + 2011-05-07: szager [python] Fixed PyGetSetDescr for python3.2. diff --git a/Doc/Manual/Varargs.html b/Doc/Manual/Varargs.html index eb14363af..ed52001e8 100644 --- a/Doc/Manual/Varargs.html +++ b/Doc/Manual/Varargs.html @@ -331,33 +331,62 @@ int open(const char *path, int oflags, int mode = 0);

In this case, %varargs is simply providing more specific information about the extra arguments that might be passed to a function. -If the parameters to a varargs function are of uniform type, %varargs can also +If the arguments to a varargs function are of uniform type, %varargs can also accept a numerical argument count as follows:

-%varargs(10,char *arg = NULL) execlp;
+%varargs(3, char *str = NULL) execlp;
 ...
-int execlp(const char *path, const char *arg1, ...);
+int execlp(const char *path, const char *arg, ...);
 

-This would wrap execlp() as a function that accepted up to 10 optional arguments. +and is effectively seen as: +

+ +
+
+int execlp(const char *path, const char *arg, 
+           char *str1 = NULL, 
+           char *str2 = NULL, 
+           char *str3 = NULL);
+
+
+ +

+This would wrap execlp() as a function that accepted up to 3 optional arguments. Depending on the application, this may be more than enough for practical purposes.

-Argument replacement is most appropriate in cases where the types of -the extra arguments is uniform and the maximum number of arguments is -known. When replicated argument replacement is used, at least one extra -argument is added to the end of the arguments when making the function call. -This argument serves as a sentinel to make sure the list is properly terminated. -It has the same value as that supplied to the %varargs directive. +The handling of default arguments can be changed via the +compactdefaultargs feature. If this feature is used, for example +

+ +
+
+%feature("compactdefaultargs") execlp;
+%varargs(3, char *str = NULL) execlp;
+...
+int execlp(const char *path, const char *arg, ...);
+
+
+ +

+a call from the target language which does not provide the maximum number of arguments, such as, +execlp("a", "b", "c") +will generate C code which includes the missing default values, that is, execlp("a", "b", "c", NULL, NULL). +If compactdefaultargs is not used, then the generated code will be +execlp("a", "b", "c"). The former is useful for helping providing a sentinel to terminate the argument list.

+Argument replacement is most appropriate in cases where the types of +the extra arguments are uniform and the maximum number of arguments are +known. Argument replacement is not as useful when working with functions that accept mixed argument types such as printf(). Providing general purpose wrappers to such functions presents special problems (covered shortly). diff --git a/Examples/test-suite/python/varargs_runme.py b/Examples/test-suite/python/varargs_runme.py index f96a43d85..2c68f4e06 100644 --- a/Examples/test-suite/python/varargs_runme.py +++ b/Examples/test-suite/python/varargs_runme.py @@ -27,11 +27,10 @@ if varargs.test_plenty("Hello", 1) != "Hello": if varargs.test_plenty("Hello", 1, 2) != "Hello": raise RuntimeError, "Failed" -if varargs.test_plenty("Hello", 1, 2, 3) != "Hello": - raise RuntimeError, "Failed" - try: - varargs.test_plenty("Hello", 1, 2, 3, 4) + varargs.test_plenty("Hello", 1, 2, 3) raise RuntimeError except NotImplementedError: pass +except TypeError: + pass diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index d95390892..2ac0c1916 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2627,10 +2627,15 @@ varargs_parms : parms { $$ = $1; } Swig_error(cparse_file, cparse_line,"Argument count in %%varargs must be positive.\n"); $$ = 0; } else { + String *name = Getattr($3, "name"); $$ = Copy($3); - Setattr($$,"name","VARARGS_SENTINEL"); - for (i = 0; i < n; i++) { + if (name) + Setattr($$, "name", NewStringf("%s%d", name, n)); + for (i = 1; i < n; i++) { p = Copy($3); + name = Getattr(p, "name"); + if (name) + Setattr(p, "name", NewStringf("%s%d", name, n-i)); set_nextSibling(p,$$); Delete($$); $$ = p; From 830e019a09673cce6b80948c4a7b8fd3beca7a22 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 14 May 2011 01:09:36 +0000 Subject: [PATCH 11/59] HTML fixes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12667 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Contents.html | 5 ++++ Doc/Manual/Python.html | 50 +++++++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 74a201bc6..736bd08a8 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -1332,6 +1332,11 @@

  • Further details on the Python class interface diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index fac680825..c7a083701 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -43,7 +43,11 @@
  • Further details on the Python class interface @@ -2210,7 +2214,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 +2307,8 @@ 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 @@ -2346,23 +2351,25 @@ please refer to the python documentation:

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

    -

    33.4.2.1 Limitations

    +

    33.4.2.1 Limitations

    +

    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().
      • -
      • 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 raised as python exceptions. Here's why: the python internals expect that all sub-classes of Exception will have this struct layout:

      +
    • 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().
      • +
      • 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 raised as python exceptions. Here's why: the python internals expect that all sub-classes of Exception will have this struct layout:

      @@ -2422,7 +2429,6 @@ class MyPyException (Exception) :
       
    • Reverse binary operators (e.g., __radd__) are not supported.

    -

    To illustrate the last point, if you have a wrapped class called MyString, @@ -2473,7 +2479,8 @@ The above code fails, because the first operand -- a native python string -- doesn't know how to add an instance of MyString to itself.

    -

    33.4.2.2 Operator overloads -- use them!

    +

    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 @@ -2491,10 +2498,10 @@ slot entries. For example, suppose you have this class:

     class Twit {
     public:
    -    Twit operator+ (const Twit& twit) const;
    +    Twit operator+ (const Twit& twit) const;
     
         // Forward to operator+
    -    Twit add (const Twit& twit) const
    +    Twit add (const Twit& twit) const
         { return *this + twit; }
     };
     
    @@ -2575,6 +2582,7 @@ structs.

    33.4.3 Memory management

    +

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

    From aac2b5d2e16bba3866b6643473f68a7a82d91594 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 14 May 2011 23:54:09 +0000 Subject: [PATCH 12/59] Remove VARARGS_SENTINEL typemaps further to revision 12666. Note that the idea of having a named typemap for sentinels is flawed unless the named typemap is provided for every single type in the typemap library. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12668 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Varargs.html | 20 ++++++++++++++++++++ Lib/swig.swg | 6 ------ Lib/typemaps/swigtype.swg | 5 ----- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Doc/Manual/Varargs.html b/Doc/Manual/Varargs.html index ed52001e8..c27db603d 100644 --- a/Doc/Manual/Varargs.html +++ b/Doc/Manual/Varargs.html @@ -381,6 +381,26 @@ a call from the target language which does not provide the maximum number of arg will generate C code which includes the missing default values, that is, execlp("a", "b", "c", NULL, NULL). If compactdefaultargs is not used, then the generated code will be execlp("a", "b", "c"). The former is useful for helping providing a sentinel to terminate the argument list. +However, this is not guaranteed, for example when a user passes a non-NULL value for all the parameters. +When using compactdefaultargs it is possible to guarantee the NULL sentinel is passed through the, +numinputs=0 'in' typemap attribute, naming the last parameter. +For example, +

    + +
    +
    +%feature("compactdefaultargs") execlp;
    +%varargs(3, char *str = NULL) execlp;
    +%typemap(in, numinputs=0) char *str3 ""
    +...
    +int execlp(const char *path, const char *arg, ...);
    +
    +
    + +

    +Note that str3 is the name of the last argument, as we have used %vargars with 3. +Now execlp("a", "b", "c", "d", "e") will result in an error as one too many arguments has been passed, +as now only 2 additional 'str' arguments can be passed with the 3rd one always using the specified default NULL.

    diff --git a/Lib/swig.swg b/Lib/swig.swg index e7c01823e..a6fef0257 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -500,12 +500,6 @@ namespace std { } } -/* Typemap for variable length arguments sentinel value. Used - by the %varargs directive. */ - -%typemap(in,numinputs=0) SWIGTYPE *VARARGS_SENTINEL, SWIGTYPE VARARGS_SENTINEL ""; - - /* ----------------------------------------------------------------------------- * Overloading support * ----------------------------------------------------------------------------- */ diff --git a/Lib/typemaps/swigtype.swg b/Lib/typemaps/swigtype.swg index bd113e278..47baabf52 100644 --- a/Lib/typemaps/swigtype.swg +++ b/Lib/typemaps/swigtype.swg @@ -559,11 +559,6 @@ * --- Special typemaps --- * ------------------------------------------------------------ */ -/* VARARGS_SENTINEL typemap. Used by the %varargs directive. */ - -%typemap(in,numinputs=0) SWIGTYPE *VARARGS_SENTINEL, SWIGTYPE VARARGS_SENTINEL ""; - - /* DISOWN typemap */ %typemap(in, noblock=1) SWIGTYPE *DISOWN (int res = 0) { From cb0a9752064e0cd64ed82656f02daacbbeec5fc0 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Mon, 16 May 2011 06:12:15 +0000 Subject: [PATCH 13/59] Documented non-looping dependency graph requirement for -builtin. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12669 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Python.html | 90 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 8 deletions(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index c7a083701..0ca6796af 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -2369,7 +2369,8 @@ 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 raised 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:

    @@ -2427,14 +2428,10 @@ class MyPyException (Exception) :
     
  • -
  • Reverse binary operators (e.g., __radd__) are not supported.

  • - - -

    -To illustrate the last point, if you have a wrapped class called MyString, +

  • Reverse binary operators (e.g., __radd__) are not supported.

    +

    To illustrate this 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 : -

    +strings, you can define an 'operator+ (const char*)' method :

    @@ -2478,6 +2475,83 @@ 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.
     

    +
  • + +
  • If you have multiple SWIG modules that share type information (more info), +the -builtin option requiress a bit of extra discipline to ensure that base classes are initialized before derived classes. Specifically:

    +
      +
    • There must be an unambiguous non-looping dependency graph for the modules.
    • +
    • Module dependencies must be explicitly stated with %import statements in the SWIG interface file.
    • + +
    + +

    As an example, suppose module A has this interface in A.i :

    + +
    +%module "A";
    +
    +class Base {
    +...
    +};
    +
    + +

    If you want to wrap another module containing a class that inherits from A, this is how it would look :

    + +
    +%module "B";
    +
    +%import "A.i"
    +
    +class Derived : public Base {
    +...
    +};
    +
    + +

    The import "A.i" statement is required, because module B depends on module A.

    + +

    As long as you obey these requirements, your python code may import the modules in any order :

    + +
    +import B
    +import A
    +
    +d = B.Derived()
    +
    + +

    Here's an example of two interface files that have a dependency loop:

    + +

    A.i:

    + +
    +%module "A";
    +
    +class BaseA {
    +...
    +};
    +
    +class DerivedA : public BaseB {
    +...
    +};
    +
    + +

    B.i:

    + +
    +%module "B";
    +
    +class BaseB {
    +...
    +};
    +
    +class DerivedB : public BaseA {
    +...
    +};
    +
    + +

    These modules are incompatible with the -builtin option.

    + +
  • +

    33.4.2.2 Operator overloads -- use them!

    From 8848b16e01af1b90c01d1c9e3fc6d92259df4d61 Mon Sep 17 00:00:00 2001 From: Xavier Delacour Date: Tue, 17 May 2011 01:56:43 +0000 Subject: [PATCH 14/59] Octave changes by Karl Wette: It's currently not possible to tell SWIG whether or not symbols should be loaded into the global namespace by default. In fact, it's not even possible to make the generated .oct module *not* load all symbols globally, due to a bug in Lib/octave/octruntime.swg (line 37: "noglobal" should be "global"). It's also not possible to change the name of the symbol used to access global variables/constants from the default "cvar". This patch adds 3 Octave-specific command-line options: * -global/-noglobal tell SWIG whether the generated .oct module should load symbols into the global namespace by default. The default option is -global to preserve existing behaviour. * -globals sets the name of the symbol used to access global variables/constants. It is set to "cvar" by default. These options are parsed in Source/Modules/octave.cxx, and written to the wrapping code as the macros SWIG_global_load and SWIG_global_name. In Lib/octave/octruntime.swg, the Octave entry point DEFUN_DLD function now contains a expanded input argument parser, which uses the same command-line arguments (-global/-noglobal, -globals) as can be passed to SWIG itself; this allows the module user to change the default loading behaviour of the module user at load time. The parser checks for non-string and unrecognised arguments, and also checks that the argument to -globals is a valid Octave identifier. A -help option prints a short usage message. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12670 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/octave/octruntime.swg | 51 ++++++++++++++++++++++++++++++++------- Source/Modules/octave.cxx | 33 ++++++++++++++++++++++--- 2 files changed, 72 insertions(+), 12 deletions(-) diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index e19b781c2..48da0cf48 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -1,4 +1,5 @@ %insert(runtime) %{ +#include #include #include #include @@ -20,6 +21,45 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) { static bool already_init=false; if (already_init) return octave_value_list(); + + // parse command line + const char* usage="usage: " SWIG_name_d " [-global|-noglobal] [-globals ]"; + bool global_load=SWIG_global_load; + std::string global_name=SWIG_global_name; + for (int j=0;jassign(swig_globals[j].name,&swig_globals[j]); octave_swig_type* module_ns=new octave_swig_type(0, 0, 0, true); - module_ns->assign("cvar",Swig::swig_value_ref(cvar_ns)); + module_ns->assign(global_name,Swig::swig_value_ref(cvar_ns)); for (int j=0;swig_globals[j].name;++j) if (swig_globals[j].method) module_ns->assign(swig_globals[j].name,&swig_globals[j]); @@ -68,7 +101,7 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) { // the incref is necessary so install_global doesn't destroy module_ns, // as it would if it installed something with the same name as the module. module_ns->incref(); - if (global_option) + if (global_load) module_ns->install_global(); module_ns->decref(); diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index ab53340fe..dcd690844 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -15,9 +15,14 @@ char cvsroot_octave_cxx[] = "$Id$"; #include "swigmod.h" +static bool global_load = true; +static String *global_name = 0; + static const char *usage = (char *) "\ Octave Options (available with -octave)\n\ - [no additional options]\n\ + -global - Load all symbols into the global namespace [default]\n\ + -globals - Set used to access C global variables [default: 'cvar']\n\ + -noglobal - Do not load all symbols into the global namespace\n\ \n"; @@ -64,11 +69,29 @@ public: for (int i = 1; i < argc; i++) { if (argv[i]) { if (strcmp(argv[i], "-help") == 0) { - fputs(usage, stdout); - } + fputs(usage, stderr); + } else if (strcmp(argv[i], "-global") == 0) { + global_load = true; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-noglobal") == 0) { + global_load = false; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-globals") == 0) { + if (argv[i + 1]) { + global_name = NewString(argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } } } + if (!global_name) + global_name = NewString("cvar"); + SWIG_library_directory("octave"); Preprocessor_define("SWIGOCTAVE 1", 0); SWIG_config_file("octave.swg"); @@ -131,6 +154,10 @@ public: Printf(f_runtime, "#define SWIG_name_d \"%s\"\n", module); Printf(f_runtime, "#define SWIG_name %s\n", module); + Printf(f_runtime, "\n"); + Printf(f_runtime, "#define SWIG_global_load %s\n", global_load ? "true" : "false"); + Printf(f_runtime, "#define SWIG_global_name \"%s\"\n", global_name); + if (directorsEnabled()) { Printf(f_runtime, "#define SWIG_DIRECTORS\n"); Swig_banner(f_directors_h); From a3689a02fc646162259465fb102061fb9499f398 Mon Sep 17 00:00:00 2001 From: Xavier Delacour Date: Tue, 17 May 2011 01:57:46 +0000 Subject: [PATCH 15/59] Fixes to two bugs in Lib/octave/octcomplex.swg (by Karl Wette) * replace PyObject with octave_value in the SWIG_AsVal(float) fragment * modify %swig_fromcplx_conv to use the correct Octave constructor for double (Complex) and float (FloatComplex) Also remove an unneeded %ifcplusplus (Octave wrapping code is always in C++). Checked that %swig_cplxflt_convn now compiles correctly for single-precision complex values, and that make check-octave-examples passes. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12671 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/octave/octcomplex.swg | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Lib/octave/octcomplex.swg b/Lib/octave/octcomplex.swg index 7eb373ae4..a3e9ebf77 100644 --- a/Lib/octave/octcomplex.swg +++ b/Lib/octave/octcomplex.swg @@ -4,17 +4,17 @@ the complex Constructor method, and the Real and Imag complex accesor methods. - See the std_complex.i and ccomplex.i for concret examples. + See the std_complex.i and ccomplex.i for concrete examples. */ /* the common from conversor */ -%define %swig_fromcplx_conv(Type, Real, Imag) +%define %swig_fromcplx_conv(Type, OctConstructor, Real, Imag) %fragment(SWIG_From_frag(Type),"header") { SWIGINTERNINLINE octave_value - SWIG_From(Type)(%ifcplusplus(const Type&, Type) c) + SWIG_From(Type)(const Type& c) { - return octave_value(Complex(Real(c), Imag(c))); + return octave_value(OctConstructor(Real(c), Imag(c))); } } %enddef @@ -45,7 +45,7 @@ return SWIG_TypeError; } } -%swig_fromcplx_conv(Type, Real, Imag); +%swig_fromcplx_conv(Type, Complex, Real, Imag); %enddef // the float case @@ -53,7 +53,7 @@ %fragment(SWIG_AsVal_frag(Type),"header", fragment=SWIG_AsVal_frag(float)) { SWIGINTERN int - SWIG_AsVal(Type)(PyObject *o, Type *val) + SWIG_AsVal(Type) (const octave_value& ov, Type* val) { if (ov.is_complex_scalar()) { if (val) { @@ -81,7 +81,7 @@ } } -%swig_fromcplx_conv(Type, Real, Imag); +%swig_fromcplx_conv(Type, FloatComplex, Real, Imag); %enddef #define %swig_cplxflt_convn(Type, Constructor, Real, Imag) \ @@ -90,6 +90,3 @@ #define %swig_cplxdbl_convn(Type, Constructor, Real, Imag) \ %swig_cplxdbl_conv(Type, Constructor, Real, Imag) - - - From e22eb835742606b3911956a344a66f3780dd0338 Mon Sep 17 00:00:00 2001 From: Xavier Delacour Date: Tue, 17 May 2011 01:59:19 +0000 Subject: [PATCH 16/59] Minor improvement to the printing of Octave SWIG classes (by Karl Wette) Uses Octave's indentation functions to make sure the classes are printed at the correct indentation level, e.g. for a cell array containing SWIG-wrapped classes. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12672 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/octave/octrun.swg | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 5b90d91b3..657223f7a 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -849,26 +849,32 @@ namespace Swig { member_map tmp; load_members(tmp); - os << "{" << std::endl; + indent(os); + os << "{"; newline(os); + increment_indent_level(); for (unsigned int j = 0; j < types.size(); ++j) { + indent(os); if (types[j].first->clientdata) { const swig_octave_class *c = (const swig_octave_class *) types[j].first->clientdata; - os << " " << c->name << ", ptr = " << types[j].second.ptr << std::endl; + os << c->name << ", ptr = " << types[j].second.ptr; newline(os); } else { - os << " " << types[j].first->name << ", ptr = " << types[j].second.ptr << std::endl; + os << types[j].first->name << ", ptr = " << types[j].second.ptr; newline(os); } } for (member_map::const_iterator it = tmp.begin(); it != tmp.end(); ++it) { + indent(os); if (it->second.first) { const char *objtype = it->second.first->method ? "method" : "variable"; const char *modifier = (it->second.first->flags &1) ? "static " : (it->second.first->flags &2) ? "global " : ""; - os << " " << it->second.first->name << " (" << modifier << objtype << ")" << std::endl; + os << it->second.first->name << " (" << modifier << objtype << ")"; newline(os); assert(it->second.first->name == it->first); } else { - os << " " << it->first << std::endl; + os << it->first; newline(os); } } - os << "}" << std::endl; + decrement_indent_level(); + indent(os); + os << "}"; newline(os); } }; @@ -998,7 +1004,8 @@ namespace Swig { } void print(std::ostream &os, bool pr_as_read_syntax = false) const { - os << "swig packed type: name = " << (type ? type->name : std::string()) << ", len = " << buf.size() << std::endl; + indent(os); + os << "swig packed type: name = " << (type ? type->name : std::string()) << ", len = " << buf.size(); newline(os); } From 360c1aaa1b82aa49a4270fccf29f6ed2d6e2cd83 Mon Sep 17 00:00:00 2001 From: Xavier Delacour Date: Tue, 17 May 2011 01:59:53 +0000 Subject: [PATCH 17/59] Fix an incompatibility with never versions of Octave (by Karl Wette) According to the Octave changelog (ChangeLog and src/ChangeLog in the Octave 3.4.0 source), octave_base_value::map_value() now returns an octave_map instead of an Octave_map; this change dates from Octave API version 40 onward. This patch makes the necessary changes to the SWIG runtime while remaining backward-compatible. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12673 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/octave/octrun.swg | 11 +++++++++++ Lib/octave/octtypemaps.swg | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 657223f7a..81c10d528 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -715,9 +715,15 @@ namespace Swig { return outarg(0).string_value(); } +#if OCTAVE_API_VERSION_NUMBER >= 40 + virtual octave_map map_value() const { + return octave_map(); + } +#else virtual Octave_map map_value() const { return Octave_map(); } +#endif virtual string_vector map_keys() const { member_map tmp; @@ -929,8 +935,13 @@ namespace Swig { virtual std::string string_value(bool force = false) const { return ptr->string_value(force); } +#if OCTAVE_API_VERSION_NUMBER >= 40 + virtual octave_map map_value() const + { return ptr->map_value(); } +#else virtual Octave_map map_value() const { return ptr->map_value(); } +#endif virtual string_vector map_keys() const { return ptr->map_keys(); } diff --git a/Lib/octave/octtypemaps.swg b/Lib/octave/octtypemaps.swg index cc5fce346..e331cf4b3 100644 --- a/Lib/octave/octtypemaps.swg +++ b/Lib/octave/octtypemaps.swg @@ -61,7 +61,7 @@ %typemap(out) octave_value_list { _outp->append($1); } -%typemap(out,noblock=1) Octave_map { +%typemap(out,noblock=1) octave_map, Octave_map { $result=$1; } %typemap(out,noblock=1) NDArray { From 2d5c4302b0f27e7e23145b2eaa937cd0c2b73845 Mon Sep 17 00:00:00 2001 From: Xavier Delacour Date: Tue, 17 May 2011 02:00:25 +0000 Subject: [PATCH 18/59] Adds support for Python __r*__ operators (by Karl Wette) The Python operator model, when evaluating e.g. x + y, is to call x.__add__(y), then y.__radd__(x) if the former does not exist, etc. This patch adds similar functionality to the SWIG runtime code. For the special case of the comparison operators __l*__ and __g*__, the reverse operators are __g*__ and __l*__ respectively. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12674 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/octave/octrun.swg | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 81c10d528..c4c01ed82 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -809,6 +809,16 @@ namespace Swig { octave_value ret; if (lhs_ost && lhs_ost->dispatch_binary_op(std::string("__") + op_name + std::string("__"), rhs, ret)) return ret; + if (rhs_ost) { + if (strlen(op_name) == 2 && (op_name[1] == 't' || op_name[1] == 'e')) { + if (op_name[0] == 'l' && rhs_ost->dispatch_binary_op(std::string("__g") + op_name[1] + std::string("__"), lhs, ret)) + return ret; + if (op_name[0] == 'g' && rhs_ost->dispatch_binary_op(std::string("__l") + op_name[1] + std::string("__"), lhs, ret)) + return ret; + } + if (rhs_ost->dispatch_binary_op(std::string("__r") + op_name + std::string("__"), lhs, ret)) + return ret; + } std::string symbol; octave_value_list args; From 06221dacaef9d5708532ed7cca0077cba4efc77d Mon Sep 17 00:00:00 2001 From: Xavier Delacour Date: Tue, 17 May 2011 02:02:15 +0000 Subject: [PATCH 19/59] Allow global operators to be SWIG-wrapped functions (by Karl Wette) The Octave run-time allows global operators to be implemented, e.g. op_scalar_add_X for adding a scalar and a wrapped struct X. However it doesn't currently seem possible for these operators to map to SWIG-wrapped functions. This is because dispatch_global_op() looks for the operators to be installed as global variables, whereas install_global() installs SWIG-wrapped functions as builtin functions; the two appear to be separate symbol tables in Octave. This patch modifies install_global() to install global operator functions as both builtin functions and as global variables, where the value of the global variable is a function handle to the operator function. It decides if a function is a global operator if it begins with the prefix "op_"; this prefix can be modified through a new command-line variable. It also always installs the operators globally, regardless of whether the rest of the module is being loaded globally. To accomplish this, install_global() is now always called, but takes a bool argument specifying whether it should load symbols globally. If a function is not a global operator, install_global() should behave as before. Tested that this compiles and works on Octave 3.2.4 and 3.4.0. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12675 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/octave/octrun.swg | 26 +++++++++++++++----------- Lib/octave/octruntime.swg | 3 +-- Source/Modules/octave.cxx | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index c4c01ed82..49b032fc9 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -457,22 +457,26 @@ namespace Swig { rhs.members.clear(); } - void install_global() { + void install_global(bool global_load) { for (member_map::const_iterator it = members.begin(); it != members.end(); ++it) { - if (it->second.first && it->second.first->method) + bool is_global_op = (it->first.substr(0, strlen(SWIG_op_prefix)) == SWIG_op_prefix); + bool is_func_defined = (it->second.first && it->second.first->method); + if (is_func_defined && (is_global_op || global_load)) { install_builtin_function(it->second.first->method, it->first, - it->second.first->doc?it->second.first->doc:std::string()); - else if (it->second.second.is_defined()) { + it->second.first->doc ? it->second.first->doc : std::string()); + } + octave_value global_val = is_global_op ? make_fcn_handle(it->first) : it->second.second; + if (global_val.is_defined() && (is_global_op || global_load)) { #if OCTAVE_API_VERSION_NUMBER<37 link_to_global_variable(curr_sym_tab->lookup(it->first, true)); #else symbol_table::varref(it->first); symbol_table::mark_global(it->first); #endif - set_global_value(it->first, it->second.second); + set_global_value(it->first, global_val); #if OCTAVE_API_VERSION_NUMBER<37 - octave_swig_type *ost = Swig::swig_value_deref(it->second.second); + octave_swig_type *ost = Swig::swig_value_deref(global_val); if (ost) { const char* h = ost->help_text(); if (h) { @@ -775,7 +779,7 @@ namespace Swig { } static bool dispatch_global_op(const std::string &symbol, const octave_value_list &args, octave_value &ret) { - // we assume that "op_"-prefixed functions are installed in global namespace + // we assume that SWIG_op_prefix-prefixed functions are installed in global namespace // (rather than any module namespace). octave_value fcn = get_global_value(symbol, true); @@ -792,7 +796,7 @@ namespace Swig { octave_value ret; if (ost->dispatch_unary_op(std::string("__") + op_name + std::string("__"), ret)) return ret; - std::string symbol = "op_" + ost->swig_type_name() + "_" + op_name; + std::string symbol = SWIG_op_prefix + ost->swig_type_name() + "_" + op_name; octave_value_list args; args.append(make_value_hack(x)); if (dispatch_global_op(symbol, args, ret)) @@ -825,7 +829,7 @@ namespace Swig { args.append(make_value_hack(lhs)); args.append(make_value_hack(rhs)); - symbol = "op_"; + symbol = SWIG_op_prefix; symbol += lhs_ost ? lhs_ost->swig_type_name() : lhs.type_name(); symbol += "_"; symbol += op_name; @@ -834,7 +838,7 @@ namespace Swig { if (dispatch_global_op(symbol, args, ret)) return ret; - symbol = "op_"; + symbol = SWIG_op_prefix; symbol += lhs_ost ? lhs_ost->swig_type_name() : lhs.type_name(); symbol += "_"; symbol += op_name; @@ -843,7 +847,7 @@ namespace Swig { if (dispatch_global_op(symbol, args, ret)) return ret; - symbol = "op_"; + symbol = SWIG_op_prefix; symbol += "any"; symbol += "_"; symbol += op_name; diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index 48da0cf48..da5b9c512 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -101,8 +101,7 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) { // the incref is necessary so install_global doesn't destroy module_ns, // as it would if it installed something with the same name as the module. module_ns->incref(); - if (global_load) - module_ns->install_global(); + module_ns->install_global(global_load); module_ns->decref(); #if OCTAVE_API_VERSION_NUMBER<37 diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index dcd690844..b46214463 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -17,12 +17,14 @@ char cvsroot_octave_cxx[] = "$Id$"; static bool global_load = true; static String *global_name = 0; +static String *op_prefix = 0; static const char *usage = (char *) "\ Octave Options (available with -octave)\n\ -global - Load all symbols into the global namespace [default]\n\ -globals - Set used to access C global variables [default: 'cvar']\n\ -noglobal - Do not load all symbols into the global namespace\n\ + -opprefix - Prefix for global operator functions [default: 'op_']\n\ \n"; @@ -85,12 +87,23 @@ public: } else { Swig_arg_error(); } + } else if (strcmp(argv[i], "-opprefix") == 0) { + if (argv[i + 1]) { + op_prefix = NewString(argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } } } } if (!global_name) global_name = NewString("cvar"); + if (!op_prefix) + op_prefix = NewString("op_"); SWIG_library_directory("octave"); Preprocessor_define("SWIGOCTAVE 1", 0); @@ -157,6 +170,7 @@ public: Printf(f_runtime, "\n"); Printf(f_runtime, "#define SWIG_global_load %s\n", global_load ? "true" : "false"); Printf(f_runtime, "#define SWIG_global_name \"%s\"\n", global_name); + Printf(f_runtime, "#define SWIG_op_prefix \"%s\"\n", op_prefix); if (directorsEnabled()) { Printf(f_runtime, "#define SWIG_DIRECTORS\n"); From 1756036825b7994917132b96de81912974fdc02f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 17 May 2011 05:47:23 +0000 Subject: [PATCH 20/59] Help goes to stdout not stderr git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12676 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/octave.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index b46214463..11fbc46fd 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -15,7 +15,7 @@ char cvsroot_octave_cxx[] = "$Id$"; #include "swigmod.h" -static bool global_load = true; +static bool global_load = true; static String *global_name = 0; static String *op_prefix = 0; @@ -71,7 +71,7 @@ public: for (int i = 1; i < argc; i++) { if (argv[i]) { if (strcmp(argv[i], "-help") == 0) { - fputs(usage, stderr); + fputs(usage, stdout); } else if (strcmp(argv[i], "-global") == 0) { global_load = true; Swig_mark_arg(i); From df75ceb87018d0d05b7cd1290be057eddfeb8b88 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 17 May 2011 06:38:53 +0000 Subject: [PATCH 21/59] begin section was missing in some of the docs git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12677 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Extending.html | 11 ++++++----- Doc/Manual/SWIG.html | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index c6e006033..ff666791c 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -2754,15 +2754,16 @@ int Python::top(Node *n) {

    -Within SWIG wrappers, there are four main sections. These are (in order) +Within SWIG wrappers, there are five main sections. These are (in order)

      -
    • runtime: This section has most of the common SWIG runtime code -
    • header: This section holds declarations and inclusions from the .i file -
    • wrapper: This section holds all the wrappering code +
    • begin: This section is a placeholder for users to put code at the beginning of the C/C++ wrapper file. +
    • runtime: This section has most of the common SWIG runtime code. +
    • header: This section holds declarations and inclusions from the .i file. +
    • wrapper: This section holds all the wrappering code.
    • init: This section holds the module initalisation function -(the entry point for the interpreter) +(the entry point for the interpreter).

    Different parts of the SWIG code will fill different sections, diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index fd510f2a4..bcfcc60f5 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -3034,14 +3034,15 @@ output of SWIG is structured first.

    -When SWIG creates its output file, it is broken up into four sections +When SWIG creates its output file, it is broken up into five sections corresponding to runtime code, headers, wrapper functions, and module initialization code (in that order).

    • Begin section.
      -A placeholder to put code at the beginning of the C/C++ wrapper file. +A placeholder for users to put code at the beginning of the C/C++ wrapper file. +This is most often used to define preprocessor macros that are used in later sections.
    • Runtime code.
      From e45ba03570ba91fe22bd48fb2e56e1ed5416a155 Mon Sep 17 00:00:00 2001 From: Xavier Delacour Date: Tue, 17 May 2011 16:06:42 +0000 Subject: [PATCH 22/59] Add CHANGES.current note about octave API>=40 compatability change git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12678 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 464a9579a..581b1f7b0 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.4 (in progress) =========================== +2011-05-16: xavier98 + [octave] Fix an incompatibility with never versions of Octave. Case on Octave + API >= 40 to handle rename of Octave_map to octave_map. + 2011-05-14: wsfulton %varargs when used with a numeric argument used to create an additional argument which was intended to provide a guaranteed sentinel value. This never worked and now From 7e5fa23c5f6641c6051cb3f14640398d52b26748 Mon Sep 17 00:00:00 2001 From: Xavier Delacour Date: Tue, 17 May 2011 16:11:26 +0000 Subject: [PATCH 23/59] more CHANGES.current edits git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12679 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 581b1f7b0..762cb17bf 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,10 @@ Version 2.0.4 (in progress) 2011-05-16: xavier98 [octave] Fix an incompatibility with never versions of Octave. Case on Octave API >= 40 to handle rename of Octave_map to octave_map. + [octave] Add support for y.__rop__(x) operators when x.__op__(y) doesn't exist. + [octave] Allow global operators to be defined by SWIG-wrapped functions. + [octave] Fix several bugs around module namespaces; add -global, -noglobal, + -globals command line options to the module. 2011-05-14: wsfulton %varargs when used with a numeric argument used to create an additional argument From f35dd29dffac35899aa7e4d473a48ac39d126650 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 17 May 2011 18:12:53 +0000 Subject: [PATCH 24/59] Apply #3300072 from Christian Delbaere to fix multiple module loading not always sharing variables across modules. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12680 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Examples/test-suite/tcl/imports_runme.tcl | 19 +++++++++++-------- Lib/tcl/tclrun.swg | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 762cb17bf..76f9ad671 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.4 (in progress) =========================== +2011-05-17: wsfulton + [Tcl] Apply #3300072 from Christian Delbaere to fix multiple module loading not + always sharing variables across modules. + 2011-05-16: xavier98 [octave] Fix an incompatibility with never versions of Octave. Case on Octave API >= 40 to handle rename of Octave_map to octave_map. diff --git a/Examples/test-suite/tcl/imports_runme.tcl b/Examples/test-suite/tcl/imports_runme.tcl index 85abe49ed..6b2e77bde 100644 --- a/Examples/test-suite/tcl/imports_runme.tcl +++ b/Examples/test-suite/tcl/imports_runme.tcl @@ -1,14 +1,17 @@ # This is the imports runtime testcase. +proc import {} { + if [ catch { load ./imports_b[info sharedlibextension] imports_b} err_msg ] { + puts stderr "Could not load shared object:\n$err_msg" + exit 1 + } + if [ catch { load ./imports_a[info sharedlibextension] imports_a} err_msg ] { + puts stderr "Could not load shared object:\n$err_msg" + exit 1 + } +} -if [ catch { load ./imports_b[info sharedlibextension] imports_b} err_msg ] { - puts stderr "Could not load shared object:\n$err_msg" - exit 1 -} -if [ catch { load ./imports_a[info sharedlibextension] imports_a} err_msg ] { - puts stderr "Could not load shared object:\n$err_msg" -exit 1 -} +import set x [new_B] A_hello $x diff --git a/Lib/tcl/tclrun.swg b/Lib/tcl/tclrun.swg index 240560b80..66bb4d201 100644 --- a/Lib/tcl/tclrun.swg +++ b/Lib/tcl/tclrun.swg @@ -277,7 +277,7 @@ SWIG_Tcl_SetModule(Tcl_Interp *interp, swig_module_info *module) { /* create a new pointer */ data = SWIG_PackData(buf, &module, sizeof(swig_type_info **)); *data = 0; - Tcl_SetVar(interp, (char *)"swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, buf, 0); + Tcl_SetVar(interp, (char *)"swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, buf, TCL_GLOBAL_ONLY); } /* -----------------------------------------------------------------------------* From e71624749a8464c2ad1769b991601ff69d8e8b0c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 17 May 2011 19:15:50 +0000 Subject: [PATCH 25/59] Apply #3289851 to fix memory leak in directors when checking for pending exceptions. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12681 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Source/Modules/java.cxx | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 76f9ad671..2ca012599 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.4 (in progress) =========================== +2011-05-17: wsfulton + [Java] Apply #3289851 from Alan Harder to fix memory leak in directors when checking + for pending exceptions. + 2011-05-17: wsfulton [Tcl] Apply #3300072 from Christian Delbaere to fix multiple module loading not always sharing variables across modules. diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 6cdf26fe3..bf7098b7a 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -3990,7 +3990,7 @@ public: Printf(w->code, "jenv->%s(Swig::jclass_%s, Swig::director_methids[%s], %s);\n", methop, imclass_name, methid, jupcall_args); - Printf(w->code, "if (jenv->ExceptionOccurred()) return $null;\n"); + Printf(w->code, "if (jenv->ExceptionCheck() == JNI_TRUE) return $null;\n"); if (!is_void) { String *jresult_str = NewString("jresult"); From d4ac9ba49d5d650322734b5665ac4732ea3bd27f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 17 May 2011 19:47:47 +0000 Subject: [PATCH 26/59] Add release summary git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12682 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- RELEASENOTES | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/RELEASENOTES b/RELEASENOTES index ea2f0c5b6..a9ee792b8 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -4,6 +4,14 @@ and CHANGES files. Release Notes ============= +SWIG-2.0.4 summary: +This is mainly a Python oriented release including support for Python +built-in types for superior performance with the new -builtin option. +Python 3.2 support has also been added and various Python bugs have +been fixed. There are also the usual minor generic improvements, as +well as bug fixes and enhancements for D, Lua, Octave, and Tcl. +Octave 3.4 support has also been added. + SWIG-2.0.3 summary: - A bug fix release including a couple of fixes for regressions in the 2.0 series. From 90d20c7fe8c3b7467f4ad2330442e61908ca95b6 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Tue, 17 May 2011 21:53:39 +0000 Subject: [PATCH 27/59] Cleaned up section about dependency requirements for -builtin. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12683 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Python.html | 37 ++----------------------------------- 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 0ca6796af..863c088d5 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -2480,7 +2480,7 @@ doesn't know how to add an instance of MyString to itself.
    • If you have multiple SWIG modules that share type information (more info), the -builtin option requiress a bit of extra discipline to ensure that base classes are initialized before derived classes. Specifically:

        -
      • There must be an unambiguous non-looping dependency graph for the modules.
      • +
      • There must be an unambiguous dependency graph for the modules.
      • Module dependencies must be explicitly stated with %import statements in the SWIG interface file.
      @@ -2515,41 +2515,8 @@ class Derived : public Base { import B import A -d = B.Derived() +assert(issubclass(B.Derived, A.Base)) - -

      Here's an example of two interface files that have a dependency loop:

      - -

      A.i:

      - -
      -%module "A";
      -
      -class BaseA {
      -...
      -};
      -
      -class DerivedA : public BaseB {
      -...
      -};
      -
      - -

      B.i:

      - -
      -%module "B";
      -
      -class BaseB {
      -...
      -};
      -
      -class DerivedB : public BaseA {
      -...
      -};
      -
      - -

      These modules are incompatible with the -builtin option.

      -
    From 2946576efb1bb076d7567f4cd0e0453ac06ab624 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 18 May 2011 00:29:36 +0000 Subject: [PATCH 28/59] Workaround for Octave crashing at extit in the mods and multi_import testcases git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12684 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/octave/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/octave/Makefile.in b/Examples/test-suite/octave/Makefile.in index 0dbb6a1e5..f12047e74 100644 --- a/Examples/test-suite/octave/Makefile.in +++ b/Examples/test-suite/octave/Makefile.in @@ -3,7 +3,7 @@ ####################################################################### LANGUAGE = octave -OCTAVE = @OCTAVE@ -q +OCTAVE = @OCTAVE@ -qf SCRIPTSUFFIX = _runme.m srcdir = @srcdir@ top_srcdir = @top_srcdir@ From af858d846ecadb7e5c79b6e0898df4691d981b08 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Wed, 18 May 2011 03:25:35 +0000 Subject: [PATCH 29/59] Fixes for -builtin docs. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12685 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Python.html | 6 +++--- RELEASENOTES | 16 ++++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 863c088d5..d179d3beb 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -43,7 +43,7 @@
  • Further details on the Python class interface
    • Proxy classes -
    • Built-in Classes +
    • Built-in Types
      • Limitations
      • Operator overloads -- use them! @@ -2214,7 +2214,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 Types section.

        @@ -2307,7 +2307,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 Types

        diff --git a/RELEASENOTES b/RELEASENOTES index a9ee792b8..36feb6ddf 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -5,12 +5,16 @@ and CHANGES files. Release Notes ============= SWIG-2.0.4 summary: -This is mainly a Python oriented release including support for Python -built-in types for superior performance with the new -builtin option. -Python 3.2 support has also been added and various Python bugs have -been fixed. There are also the usual minor generic improvements, as -well as bug fixes and enhancements for D, Lua, Octave, and Tcl. -Octave 3.4 support has also been added. +- This is mainly a Python oriented release including support for Python + built-in types for superior performance with the new -builtin option. + The -builtin option is especially suitable for performance-critical + libraries and applications that call wrapped methods repeatedly. + See the python-specific chapter of the SWIG manual for more info. + +- Python 3.2 support has also been added and various Python bugs have + been fixed. There are also the usual minor generic improvements, as + well as bug fixes and enhancements for D, Lua, Octave, and Tcl. + Octave 3.4 support has also been added. SWIG-2.0.3 summary: - A bug fix release including a couple of fixes for regressions in the From fe7a09c04afb977cf92bae8d2abb3eaa386ca8fc Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 19 May 2011 06:37:41 +0000 Subject: [PATCH 30/59] html fixes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12686 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Contents.html | 2 +- Doc/Manual/Python.html | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 736bd08a8..04cbbcf2a 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -1332,7 +1332,7 @@

      • Further details on the Python class interface
        • Proxy classes -
        • Built-in Classes +
        • Built-in Types
          • Limitations
          • Operator overloads -- use them! diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index d179d3beb..81b2fe04e 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -2480,9 +2480,8 @@ doesn't know how to add an instance of MyString to itself.
          • If you have multiple SWIG modules that share type information (more info), the -builtin option requiress a bit of extra discipline to ensure that base classes are initialized before derived classes. Specifically:

              -
            • There must be an unambiguous dependency graph for the modules.
            • -
            • Module dependencies must be explicitly stated with %import statements in the SWIG interface file.
            • - +
            • There must be an unambiguous dependency graph for the modules.

            • +
            • Module dependencies must be explicitly stated with %import statements in the SWIG interface file.

            As an example, suppose module A has this interface in A.i :

            From f0c0e9462ef87c1dd6879872bd61436408398238 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 19 May 2011 06:38:59 +0000 Subject: [PATCH 31/59] Label Python entries in CHANGES.current git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12687 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 2ca012599..f2c130cff 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,7 +2,7 @@ This file contains the changes for the current release. See the CHANGES file for changes in older releases. See the RELEASENOTES file for a summary of changes in each release. -Version 2.0.4 (in progress) +Version 2.0.4 (17 May 2011) =========================== 2011-05-17: wsfulton [Java] Apply #3289851 from Alan Harder to fix memory leak in directors when checking @@ -43,18 +43,18 @@ Version 2.0.4 (in progress) Bug 2635919: Convenience method to convert std::map to a python dict. 2011-04-29: szager - Fixed bug 2811549: return non-const iterators from STL + [Python] Fixed bug 2811549: return non-const iterators from STL methods begin(), end(), rbegin(), rend(). 2011-04-25: szager - Fixed bug 1498929: Access to member fields in map elements + [Python] Fixed bug 1498929: Access to member fields in map elements 2011-04-23: klickverbot [D] nspace: Correctly generate identifiers for base classes when not in split proxy mode. 2011-04-13: szager - Fixed bug 3286333: infite recursion with mutual 'using namespace' clauses. + Fixed bug 3286333: infinite recursion with mutual 'using namespace' clauses. 2011-04-12: szager Fixed bug 1163440: vararg typemaps. @@ -64,14 +64,14 @@ Version 2.0.4 (in progress) test case to demonstrate. 2011-04-11: szager - Fixed PyVarObject_HEAD_INIT to eliminate VC++ compiler errors about + [Python] Fixed PyVarObject_HEAD_INIT to eliminate VC++ compiler errors about static initialization of struct members with pointers. 2011-04-11: wsfulton [Tcl] Apply patch #3284326 from Colin McDonald to fix some compiler warnings. 2011-04-11: szager - Fixed PyVarObject_HEAD_INIT to eliminate VC++ compiler errors about + [Python] Fixed PyVarObject_HEAD_INIT to eliminate VC++ compiler errors about static initialization of struct members with pointers. 2011-04-10: klickverbot @@ -83,10 +83,10 @@ Version 2.0.4 (in progress) not in split proxy mode. 2011-04-09: szager - Applied patch #1932484: migrate PyCObject to PyCapsule. + [Python] Applied patch #1932484: migrate PyCObject to PyCapsule. 2011-04-09: szager - Added preprocessor guards for python functions PyUnicode_AsWideChar and + [Python] Added preprocessor guards for python functions PyUnicode_AsWideChar and PySlice_GetIndices, which changed signatures in python3.2. 2011-04-07: wsfulton @@ -94,10 +94,10 @@ Version 2.0.4 (in progress) reported by Karl Wette. 2011-04-03: szager - Fixed the behavior of %pythonnondynamic to conform to the spec in Lib/pyuserdir.swg. + [Python] Fixed the behavior of %pythonnondynamic to conform to the spec in Lib/pyuserdir.swg. 2011-04-03: szager - Merged in the szager-python-builtin branch, adding the -builtin feature + [Python] Merged in the szager-python-builtin branch, adding the -builtin feature for python. The -builtin option may provide a significant performance gain in python wrappers. For full details and limitations, refer to Doc/Manual/Python.html. A small test suite designed to demonstrate the performance gain is in From dfa13b658e537a3366fc3e3b8cd41892ed7aa077 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 19 May 2011 06:42:56 +0000 Subject: [PATCH 32/59] Fix import_stl testcase git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12688 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 6 +- Lib/ruby/rubyclasses.swg | 109 ++++++++++++++++++----------------- Lib/ruby/rubycontainer.swg | 3 +- Lib/ruby/rubyiterators.swg | 2 +- Lib/ruby/rubystdfunctors.swg | 2 +- 5 files changed, 64 insertions(+), 58 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index f2c130cff..d0dc7e4da 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,8 +2,12 @@ This file contains the changes for the current release. See the CHANGES file for changes in older releases. See the RELEASENOTES file for a summary of changes in each release. -Version 2.0.4 (17 May 2011) +Version 2.0.4 (in progress) =========================== +2011-05-19: wsfulton + [Ruby] Fix %import where one of the imported files %include one of the STL include + files such as std_vector.i. + 2011-05-17: wsfulton [Java] Apply #3289851 from Alan Harder to fix memory leak in directors when checking for pending exceptions. diff --git a/Lib/ruby/rubyclasses.swg b/Lib/ruby/rubyclasses.swg index db5482694..2048b1f5f 100644 --- a/Lib/ruby/rubyclasses.swg +++ b/Lib/ruby/rubyclasses.swg @@ -34,52 +34,7 @@ */ -namespace swig { - - %nodirector GC_VALUE; - - // We ignore the constructor so that user can never create a GC_VALUE - // manually - %ignore GC_VALUE::GC_VALUE; - - struct GC_VALUE { - VALUE inspect() const; - VALUE to_s() const; - GC_VALUE(); - protected: - GC_VALUE( const GC_VALUE& ); - ~GC_VALUE(); - }; - - %exception GC_VALUE {}; - - - %apply VALUE {GC_VALUE}; - - // Make sure this is the last typecheck done - %typecheck(999999,noblock=1) GC_VALUE, GC_VALUE&, - const GC_VALUE& { $1 = 1; }; - - /* For input */ - %typemap(in,noblock=1) GC_VALUE* (GC_VALUE r), GC_VALUE& (GC_VALUE r) { - r = $input; $1 = &r; - } - - /* For output */ - %typemap(out,noblock=1) GC_VALUE { - $result = (VALUE)$1; - } - - %typemap(out,noblock=1) GC_VALUE*, GC_VALUE const & { - $result = (VALUE)*$1; - } - - %ignore LANGUAGE_OBJ; - typedef GC_VALUE LANGUAGE_OBJ; -} - - -%{ +%fragment("GC_VALUE_definition","header") { namespace swig { class GC_VALUE { protected: @@ -213,7 +168,7 @@ namespace swig { } -#define GC_VALUE_CMP( op_id, op, cmp, cmpval ) \ +%#define GC_VALUE_CMP( op_id, op, cmp, cmpval ) \ bool op( const GC_VALUE& other ) const \ { \ if ( FIXNUM_P(_obj) && FIXNUM_P(other._obj) ) \ @@ -253,14 +208,14 @@ namespace swig { GC_VALUE_CMP( le_id, operator<=, <=, <= 0 ) GC_VALUE_CMP( gt_id, operator>, > , > 0 ) GC_VALUE_CMP( ge_id, operator>=, >=, >= 0 ) -#undef GC_VALUE_CMP +%#undef GC_VALUE_CMP bool operator!=( const GC_VALUE& other ) { return !(this->operator==(other)); } -#define GC_VALUE_UNARY( proc_id, op ) \ +%#define GC_VALUE_UNARY( proc_id, op ) \ GC_VALUE op() const \ { \ VALUE ret = Qnil; \ @@ -280,9 +235,9 @@ namespace swig { GC_VALUE_UNARY( pos_id, operator+ ) GC_VALUE_UNARY( neg_id, operator- ) GC_VALUE_UNARY( inv_id, operator~ ) -#undef GC_VALUE_BINARY +%#undef GC_VALUE_BINARY -#define GC_VALUE_BINARY( proc_id, op ) \ +%#define GC_VALUE_BINARY( proc_id, op ) \ GC_VALUE op( const GC_VALUE& other ) const \ { \ VALUE ret = Qnil; \ @@ -311,7 +266,7 @@ namespace swig { GC_VALUE_BINARY( lshift_id, operator<< ); GC_VALUE_BINARY( rshift_id, operator>> ); -#undef GC_VALUE_BINARY +%#undef GC_VALUE_BINARY }; @@ -345,7 +300,53 @@ namespace swig { } // namespace swig -%} +} // %fragment(GC_VALUE_definition) + + + +namespace swig { + + %apply VALUE {GC_VALUE}; + + // Make sure this is the last typecheck done + %typecheck(999999,fragment="GC_VALUE_definition",noblock=1) GC_VALUE, GC_VALUE&, + const GC_VALUE& { $1 = 1; }; + + /* For input */ + %typemap(in,fragment="GC_VALUE_definition",noblock=1) GC_VALUE* (GC_VALUE r), GC_VALUE& (GC_VALUE r) { + r = $input; $1 = &r; + } + + /* For output */ + %typemap(out,fragment="GC_VALUE_definition",noblock=1) GC_VALUE { + $result = (VALUE)$1; + } + + %typemap(out,fragment="GC_VALUE_definition",noblock=1) GC_VALUE*, GC_VALUE const & { + $result = (VALUE)*$1; + } + + %nodirector GC_VALUE; + + // We ignore the constructor so that user can never create a GC_VALUE + // manually + %ignore GC_VALUE::GC_VALUE; + + struct GC_VALUE { + VALUE inspect() const; + VALUE to_s() const; + GC_VALUE(); + protected: + GC_VALUE( const GC_VALUE& ); + ~GC_VALUE(); + }; + + %exception GC_VALUE {}; + + + %ignore LANGUAGE_OBJ; + typedef GC_VALUE LANGUAGE_OBJ; +} %init { @@ -359,7 +360,7 @@ namespace swig { // These functions may be invoked as a need of the from(), asval(), // asptr() and as() template functors, usually used in %typemaps. // -%fragment(SWIG_Traits_frag(swig::GC_VALUE),"header",fragment="StdTraits") { +%fragment(SWIG_Traits_frag(swig::GC_VALUE),"header",fragment="StdTraits",fragment="GC_VALUE_definition") { namespace swig { template <> struct traits { typedef value_category category; diff --git a/Lib/ruby/rubycontainer.swg b/Lib/ruby/rubycontainer.swg index f643e84b3..0f8d1e3a5 100644 --- a/Lib/ruby/rubycontainer.swg +++ b/Lib/ruby/rubycontainer.swg @@ -972,7 +972,8 @@ namespace swig %fragment("StdSequenceTraits","header", fragment="StdTraits", - fragment="RubySequence_Cont") + fragment="RubySequence_Cont", + fragment="GC_VALUE_definition") { namespace swig { template diff --git a/Lib/ruby/rubyiterators.swg b/Lib/ruby/rubyiterators.swg index aba156a2b..f4df4af9a 100644 --- a/Lib/ruby/rubyiterators.swg +++ b/Lib/ruby/rubyiterators.swg @@ -12,7 +12,7 @@ %include -%fragment("ConstIterator","header") { +%fragment("ConstIterator","header",fragment="GC_VALUE_definition") { namespace swig { struct stop_iteration { }; diff --git a/Lib/ruby/rubystdfunctors.swg b/Lib/ruby/rubystdfunctors.swg index 82093823d..f2050b6f2 100644 --- a/Lib/ruby/rubystdfunctors.swg +++ b/Lib/ruby/rubystdfunctors.swg @@ -83,7 +83,7 @@ namespace swig { } -%fragment("StdFunctors","header",fragment="StdTraits") +%fragment("StdFunctors","header",fragment="StdTraits",fragment="GC_VALUE_definition") { namespace swig { From f8270079ebb71afd7221c2b4d5854054bb7e9951 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 19 May 2011 06:44:17 +0000 Subject: [PATCH 33/59] remove unused macro git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12689 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/ruby/rubystdcommon.swg | 63 -------------------------------------- 1 file changed, 63 deletions(-) diff --git a/Lib/ruby/rubystdcommon.swg b/Lib/ruby/rubystdcommon.swg index 4e1b9d967..b4ae3a3cc 100644 --- a/Lib/ruby/rubystdcommon.swg +++ b/Lib/ruby/rubystdcommon.swg @@ -200,66 +200,3 @@ namespace swig { } } - -// Define GC marking template traits for a container type -%define %create_mark_traits(Type) -%{ - namespace swig { - template - struct mark_traits { - typedef typename Type::const_iterator const_iterator; - - inline void operator()(const Type& c ) const - { - const_iterator i = c.begin(); - const_iterator e = c.end(); - for ( ; i != e; ++i ) - { - rb_gc_mark( swig::from( &(*i) ) ); - } - } - }; - - // Partial specializations for classes that requires no GC marking - // or a special GC marking algorithm. - template< > - struct mark_traits { - inline void operator()(const Type& c ) const {} - }; - - template< > - struct mark_traits { - inline void operator()(const Type& c ) const {} - }; - - template< > - struct mark_traits { - inline void operator()(const Type& c ) const {} - }; - - template< > - struct mark_traits { - inline void operator()(const Type& c ) const {} - }; - - template< > - struct mark_traits { - typedef Type::const_iterator const_iterator; - - inline void operator()(const Type& c ) const { - const_iterator i = c.begin(); - const_iterator e = c.end(); - for ( ; i != e; ++i ) - { - VALUE v = *i; - if ( FIXNUM_P(v) || SPECIAL_CONST_P(v) || SYMBOL_P(v) || - ( BUILTIN_TYPE(v) == T_NONE ) ) continue; - - rb_gc_mark( v ); - } - } - }; - - } -%} -%enddef From 527c3e0552a01f87911333f09fbc66b5bea4b34b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 19 May 2011 18:48:57 +0000 Subject: [PATCH 34/59] Test modifications of changed behaviour in perl 5.12 and 5.14 in reporting errors git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12690 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/perl5/default_args_runme.pl | 14 +++++++------- Examples/test-suite/perl5/li_std_string_runme.pl | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Examples/test-suite/perl5/default_args_runme.pl b/Examples/test-suite/perl5/default_args_runme.pl index 8d0d2689b..45f10b37e 100644 --- a/Examples/test-suite/perl5/default_args_runme.pl +++ b/Examples/test-suite/perl5/default_args_runme.pl @@ -41,11 +41,11 @@ ok(not($@), '%rename handling'); # exception specifications eval { default_args::exceptionspec() }; -is($@, "ciao", "exceptionspec 1"); +like($@, qr/^ciao/, "exceptionspec 1"); eval { default_args::exceptionspec(-1) }; -is($@, "ciao", "exceptionspec 2"); +like($@, qr/^ciao/, "exceptionspec 2"); eval { default_args::exceptionspec(100) }; -is($@, '100', "exceptionspec 3"); +like($@, qr/^100/, "exceptionspec 3"); my $ex = new default_args::Except($false); @@ -54,13 +54,13 @@ eval { $ex->exspec(); $hit = 1; }; # a zero was thrown, an exception occured, but $@ is false is($hit, 0, "exspec 1"); eval { $ex->exspec(-1) }; -is($@, "ciao", "exspec 2"); +like($@, qr/^ciao/, "exspec 2"); eval { $ex->exspec(100) }; -is($@, 100, "exspec 3"); +like($@, qr/^100/, "exspec 3"); eval { $ex = default_args::Except->new($true) }; -is($@, -1, "Except constructor 1"); +like($@, qr/-1/, "Except constructor 1"); eval { $ex = default_args::Except->new($true, -2) }; -is($@, -2, "Except constructor 2"); +like($@, qr/-2/, "Except constructor 2"); #Default parameters in static class methods is(default_args::Statics::staticmethod(), 60, "staticmethod 1"); diff --git a/Examples/test-suite/perl5/li_std_string_runme.pl b/Examples/test-suite/perl5/li_std_string_runme.pl index 9ec7dd08c..e6358ff1f 100644 --- a/Examples/test-suite/perl5/li_std_string_runme.pl +++ b/Examples/test-suite/perl5/li_std_string_runme.pl @@ -48,7 +48,7 @@ li_std_string::test_reference($stringPtr); # Check throw exception specification eval { li_std_string::test_throw() }; -is($@, "test_throw message", "Test 5"); +like($@, qr/^test_throw message/, "Test 5"); { local $TODO = "why is the error not a Perl string?"; eval { li_std_string::test_const_reference_throw() }; is($@, "", "Test 6"); From ea00ff974fa7dd0e33768d96d5293fd4061c7786 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 19 May 2011 19:31:39 +0000 Subject: [PATCH 35/59] Patch #3260265 fixing overloading of non-primitive types and integers in Perl 5.12 and later git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12691 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Examples/test-suite/overload_simple.i | 6 ++++++ Examples/test-suite/perl5/overload_simple_runme.pl | 9 ++++++++- Lib/perl5/perlrun.swg | 10 ++++++++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index d0dc7e4da..e8b145673 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.4 (in progress) =========================== +2011-05-19: wsfulton + [Perl] Patch #3260265 fixing overloading of non-primitive types and integers in + Perl 5.12 and later. + 2011-05-19: wsfulton [Ruby] Fix %import where one of the imported files %include one of the STL include files such as std_vector.i. diff --git a/Examples/test-suite/overload_simple.i b/Examples/test-suite/overload_simple.i index d23807641..6bedf6cef 100644 --- a/Examples/test-suite/overload_simple.i +++ b/Examples/test-suite/overload_simple.i @@ -208,3 +208,9 @@ long long ll(long long ull) { return ull; } } #endif + +%inline %{ + int int_object(Spam *s) { return 999; } + int int_object(int c) { return c; } +%} + diff --git a/Examples/test-suite/perl5/overload_simple_runme.pl b/Examples/test-suite/perl5/overload_simple_runme.pl index 27719aa00..624d428c6 100644 --- a/Examples/test-suite/perl5/overload_simple_runme.pl +++ b/Examples/test-suite/perl5/overload_simple_runme.pl @@ -2,7 +2,7 @@ use overload_simple; use vars qw/$DOWARN/; use strict; -use Test::More tests => 71; +use Test::More tests => 75; pass("loaded"); @@ -189,3 +189,10 @@ is(overload_simple::fid("3", 3), "fid:intint", "fid:fid(int,int)"); isnt(overload_simple::fbool(0), overload_simple::fbool(1), "fbool(bool)"); is(2, overload_simple::fbool(2), "fbool(int)"); + +# int and object overload + +is(overload_simple::int_object(1), 1, "int_object(1)"); +is(overload_simple::int_object(0), 0, "int_object(0)"); +is(overload_simple::int_object(undef), 999, "int_object(Spam*)"); +is(overload_simple::int_object($s), 999, "int_object(Spam*)"); diff --git a/Lib/perl5/perlrun.swg b/Lib/perl5/perlrun.swg index ecb1f5cd2..d89865665 100644 --- a/Lib/perl5/perlrun.swg +++ b/Lib/perl5/perlrun.swg @@ -274,8 +274,14 @@ SWIG_Perl_ConvertPtrAndOwn(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_ return SWIG_OK; } else if (SvTYPE(sv) == SVt_RV) { /* Check for NULL pointer */ if (!SvROK(sv)) { - *(ptr) = (void *) 0; - return SWIG_OK; + /* In Perl 5.12 and later, SVt_RV == SVt_IV, so sv could be a valid integer value. */ + if (SvIOK(sv)) { + return SWIG_ERROR; + } else { + /* NULL pointer (reference to undef). */ + *(ptr) = (void *) 0; + return SWIG_OK; + } } else { return SWIG_ERROR; } From ac06518319ae5b7454f55cc4f3ca5a8cf56c54b3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 19 May 2011 19:49:48 +0000 Subject: [PATCH 36/59] Patch #3191625 fixing overloading of integer types. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12692 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Lib/guile/typemaps.i | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index e8b145673..f510bd82a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.4 (in progress) =========================== +2011-05-19: wsfulton + [Guile] Patch #3191625 fixing overloading of integer types. + 2011-05-19: wsfulton [Perl] Patch #3260265 fixing overloading of non-primitive types and integers in Perl 5.12 and later. diff --git a/Lib/guile/typemaps.i b/Lib/guile/typemaps.i index c31f1463f..4eda6eeeb 100644 --- a/Lib/guile/typemaps.i +++ b/Lib/guile/typemaps.i @@ -406,7 +406,7 @@ typedef unsigned long SCM; const std::size_t &, const std::ptrdiff_t &, enum SWIGTYPE { - $1 = SCM_NFALSEP(scm_integer_p($input)) ? 1 : 0; + $1 = SCM_NFALSEP(scm_integer_p($input)) && SCM_NFALSEP(scm_exact_p($input))? 1 : 0; } %typecheck(SWIG_TYPECHECK_BOOL) From 315dd8fb2f405ec17ceb3bc21895355eb98381b8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 20 May 2011 05:58:05 +0000 Subject: [PATCH 37/59] Add in error handling in the even of not being able to find a base when initializing a builtin type - should the base not be loaded git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12693 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/python.cxx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 2d6274869..00f6ebfff 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -3233,6 +3233,13 @@ public: 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, " } else {\n", NIL); + Printf(f_init, " PyErr_SetString(PyExc_TypeError, \"Could not create type '%s' as base '%s' has not been initialized.\\n\");\n", symname, bname); + 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); Delete(base_name); Delete(base_mname); @@ -3538,7 +3545,7 @@ public: 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); + Printf(f_init, " PyErr_SetString(PyExc_TypeError, \"Could not 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); From ecc64bc6708d6f82147e949faff8002c1cfdf166 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 20 May 2011 06:14:26 +0000 Subject: [PATCH 38/59] More language modules for release notes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12694 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- RELEASENOTES | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/RELEASENOTES b/RELEASENOTES index 36feb6ddf..f517b9db2 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -10,11 +10,11 @@ SWIG-2.0.4 summary: The -builtin option is especially suitable for performance-critical libraries and applications that call wrapped methods repeatedly. See the python-specific chapter of the SWIG manual for more info. - - Python 3.2 support has also been added and various Python bugs have - been fixed. There are also the usual minor generic improvements, as - well as bug fixes and enhancements for D, Lua, Octave, and Tcl. - Octave 3.4 support has also been added. + been fixed. +- Octave 3.4 support has also been added. +- There are also the usual minor generic improvements, as well as bug + fixes and enhancements for D, Guile, Lua, Octave, Perl and Tcl. SWIG-2.0.3 summary: - A bug fix release including a couple of fixes for regressions in the From 34340677119c382ac021f697d4de9a3e2d8281e9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 21 May 2011 20:52:49 +0000 Subject: [PATCH 39/59] Add swig-2.0.4 release date git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12701 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- ANNOUNCE | 2 +- Doc/Manual/Sections.html | 2 +- README | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 1a13e074f..fc9a47a71 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,4 +1,4 @@ -*** ANNOUNCE: SWIG 2.0.4 (29 March 2011) *** +*** ANNOUNCE: SWIG 2.0.4 (21 May 2011) *** http://www.swig.org diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index 62305b9ed..e6dcd0e67 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

            SWIG-2.0 Documentation

            -Last update : SWIG-2.0.4 (in progress) +Last update : SWIG-2.0.4 (21 May 2011)

            Sections

            diff --git a/README b/README index 2626f0bef..658ff4ca1 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 2.0.4 (in progress) +Version: 2.0.4 (21 May 2011) Tagline: SWIG is a compiler that integrates C and C++ with languages including Perl, Python, Tcl, Ruby, PHP, Java, Ocaml, Lua, From 262ba47521fcee7cd3bd50e413557ae550732ebd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 21 May 2011 21:22:05 +0000 Subject: [PATCH 40/59] Add missing swig-2.0.4 release date git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12703 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index f510bd82a..d3e3d9f4a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,7 +2,7 @@ This file contains the changes for the current release. See the CHANGES file for changes in older releases. See the RELEASENOTES file for a summary of changes in each release. -Version 2.0.4 (in progress) +Version 2.0.4 (21 May 2011) =========================== 2011-05-19: wsfulton [Guile] Patch #3191625 fixing overloading of integer types. From c077d83803c8f8953d5ac3f3713b964cdb037489 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 21 May 2011 22:33:36 +0000 Subject: [PATCH 41/59] bump version to 2.0.5 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12704 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- ANNOUNCE | 8 +-- CHANGES | 116 ++++++++++++++++++++++++++++++++++++++ CHANGES.current | 117 +-------------------------------------- Doc/Manual/Sections.html | 2 +- README | 2 +- configure.in | 2 +- 6 files changed, 125 insertions(+), 122 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index fc9a47a71..6f0247f56 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,8 +1,8 @@ -*** ANNOUNCE: SWIG 2.0.4 (21 May 2011) *** +*** ANNOUNCE: SWIG 2.0.5 (in progress) *** http://www.swig.org -We're pleased to announce SWIG-2.0.4, the latest SWIG release. +We're pleased to announce SWIG-2.0.5, the latest SWIG release. What is SWIG? ============= @@ -21,11 +21,11 @@ Availability ============ The release is available for download on Sourceforge at - http://prdownloads.sourceforge.net/swig/swig-2.0.4.tar.gz + http://prdownloads.sourceforge.net/swig/swig-2.0.5.tar.gz A Windows version is also available at - http://prdownloads.sourceforge.net/swig/swigwin-2.0.4.zip + http://prdownloads.sourceforge.net/swig/swigwin-2.0.5.zip Please report problems with this release to the swig-devel mailing list, details at http://www.swig.org/mail.html. diff --git a/CHANGES b/CHANGES index 7e930159e..9bc2f5718 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,122 @@ SWIG (Simplified Wrapper and Interface Generator) See the CHANGES.current file for changes in the current version. See the RELEASENOTES file for a summary of changes in each release. +Version 2.0.4 (21 May 2011) +=========================== +2011-05-19: wsfulton + [Guile] Patch #3191625 fixing overloading of integer types. + +2011-05-19: wsfulton + [Perl] Patch #3260265 fixing overloading of non-primitive types and integers in + Perl 5.12 and later. + +2011-05-19: wsfulton + [Ruby] Fix %import where one of the imported files %include one of the STL include + files such as std_vector.i. + +2011-05-17: wsfulton + [Java] Apply #3289851 from Alan Harder to fix memory leak in directors when checking + for pending exceptions. + +2011-05-17: wsfulton + [Tcl] Apply #3300072 from Christian Delbaere to fix multiple module loading not + always sharing variables across modules. + +2011-05-16: xavier98 + [octave] Fix an incompatibility with never versions of Octave. Case on Octave + API >= 40 to handle rename of Octave_map to octave_map. + [octave] Add support for y.__rop__(x) operators when x.__op__(y) doesn't exist. + [octave] Allow global operators to be defined by SWIG-wrapped functions. + [octave] Fix several bugs around module namespaces; add -global, -noglobal, + -globals command line options to the module. + +2011-05-14: wsfulton + %varargs when used with a numeric argument used to create an additional argument + which was intended to provide a guaranteed sentinel value. This never worked and now + the additional argument is not generated. + +2011-05-13: wsfulton + [python] Additional fixes for python3.2 support. + +2011-05-07: szager + [python] Fixed PyGetSetDescr for python3.2. + +2011-05-05: wsfulton + [Lua, Python, Tcl] C/C++ prototypes shown in error message when calling an overloaded + method with incorrect arguments improved to show always show fully qualified name + and if a const method. + + Also fixed other Lua error messages in generated code which weren't consistently + using the fully qualified C++ name - requested by Gedalia Pasternak. + +2011-04-29: szager + Bug 2635919: Convenience method to convert std::map to a python dict. + +2011-04-29: szager + [Python] Fixed bug 2811549: return non-const iterators from STL + methods begin(), end(), rbegin(), rend(). + +2011-04-25: szager + [Python] Fixed bug 1498929: Access to member fields in map elements + +2011-04-23: klickverbot + [D] nspace: Correctly generate identifiers for base classes when + not in split proxy mode. + +2011-04-13: szager + Fixed bug 3286333: infinite recursion with mutual 'using namespace' clauses. + +2011-04-12: szager + Fixed bug 1163440: vararg typemaps. + +2011-04-12: szager + Fixed bug #3285386: parse error from 'operator T*&()'. Added operator_pointer_ref + test case to demonstrate. + +2011-04-11: szager + [Python] Fixed PyVarObject_HEAD_INIT to eliminate VC++ compiler errors about + static initialization of struct members with pointers. + +2011-04-11: wsfulton + [Tcl] Apply patch #3284326 from Colin McDonald to fix some compiler warnings. + +2011-04-11: szager + [Python] Fixed PyVarObject_HEAD_INIT to eliminate VC++ compiler errors about + static initialization of struct members with pointers. + +2011-04-10: klickverbot + [D] Fixed wrapping of enums that are type char, for example: + enum { X = 'X'; } (this was already in 2.0.3 for C# and Java) + +2011-04-10: klickverbot + [D] nspace: Fixed referencing types in the root namespace when + not in split proxy mode. + +2011-04-09: szager + [Python] Applied patch #1932484: migrate PyCObject to PyCapsule. + +2011-04-09: szager + [Python] Added preprocessor guards for python functions PyUnicode_AsWideChar and + PySlice_GetIndices, which changed signatures in python3.2. + +2011-04-07: wsfulton + Fix wrapping of const array typedefs which were generating uncompileable code as + reported by Karl Wette. + +2011-04-03: szager + [Python] Fixed the behavior of %pythonnondynamic to conform to the spec in Lib/pyuserdir.swg. + +2011-04-03: szager + [Python] Merged in the szager-python-builtin branch, adding the -builtin feature + for python. The -builtin option may provide a significant performance gain + in python wrappers. For full details and limitations, refer to Doc/Manual/Python.html. + A small test suite designed to demonstrate the performance gain is in + Examples/python/performance. + +2011-04-01: wsfulton + Add in missing wrappers for friend functions for some target languages, mostly + the non-scripting languages like Java and C#. + Version 2.0.3 (29 March 2011) ============================= diff --git a/CHANGES.current b/CHANGES.current index d3e3d9f4a..203f3c7d7 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,119 +1,6 @@ -This file contains the changes for the current release. +Below are the changes for the current release. See the CHANGES file for changes in older releases. See the RELEASENOTES file for a summary of changes in each release. -Version 2.0.4 (21 May 2011) +Version 2.0.5 (in progress) =========================== -2011-05-19: wsfulton - [Guile] Patch #3191625 fixing overloading of integer types. - -2011-05-19: wsfulton - [Perl] Patch #3260265 fixing overloading of non-primitive types and integers in - Perl 5.12 and later. - -2011-05-19: wsfulton - [Ruby] Fix %import where one of the imported files %include one of the STL include - files such as std_vector.i. - -2011-05-17: wsfulton - [Java] Apply #3289851 from Alan Harder to fix memory leak in directors when checking - for pending exceptions. - -2011-05-17: wsfulton - [Tcl] Apply #3300072 from Christian Delbaere to fix multiple module loading not - always sharing variables across modules. - -2011-05-16: xavier98 - [octave] Fix an incompatibility with never versions of Octave. Case on Octave - API >= 40 to handle rename of Octave_map to octave_map. - [octave] Add support for y.__rop__(x) operators when x.__op__(y) doesn't exist. - [octave] Allow global operators to be defined by SWIG-wrapped functions. - [octave] Fix several bugs around module namespaces; add -global, -noglobal, - -globals command line options to the module. - -2011-05-14: wsfulton - %varargs when used with a numeric argument used to create an additional argument - which was intended to provide a guaranteed sentinel value. This never worked and now - the additional argument is not generated. - -2011-05-13: wsfulton - [python] Additional fixes for python3.2 support. - -2011-05-07: szager - [python] Fixed PyGetSetDescr for python3.2. - -2011-05-05: wsfulton - [Lua, Python, Tcl] C/C++ prototypes shown in error message when calling an overloaded - method with incorrect arguments improved to show always show fully qualified name - and if a const method. - - Also fixed other Lua error messages in generated code which weren't consistently - using the fully qualified C++ name - requested by Gedalia Pasternak. - -2011-04-29: szager - Bug 2635919: Convenience method to convert std::map to a python dict. - -2011-04-29: szager - [Python] Fixed bug 2811549: return non-const iterators from STL - methods begin(), end(), rbegin(), rend(). - -2011-04-25: szager - [Python] Fixed bug 1498929: Access to member fields in map elements - -2011-04-23: klickverbot - [D] nspace: Correctly generate identifiers for base classes when - not in split proxy mode. - -2011-04-13: szager - Fixed bug 3286333: infinite recursion with mutual 'using namespace' clauses. - -2011-04-12: szager - Fixed bug 1163440: vararg typemaps. - -2011-04-12: szager - Fixed bug #3285386: parse error from 'operator T*&()'. Added operator_pointer_ref - test case to demonstrate. - -2011-04-11: szager - [Python] Fixed PyVarObject_HEAD_INIT to eliminate VC++ compiler errors about - static initialization of struct members with pointers. - -2011-04-11: wsfulton - [Tcl] Apply patch #3284326 from Colin McDonald to fix some compiler warnings. - -2011-04-11: szager - [Python] Fixed PyVarObject_HEAD_INIT to eliminate VC++ compiler errors about - static initialization of struct members with pointers. - -2011-04-10: klickverbot - [D] Fixed wrapping of enums that are type char, for example: - enum { X = 'X'; } (this was already in 2.0.3 for C# and Java) - -2011-04-10: klickverbot - [D] nspace: Fixed referencing types in the root namespace when - not in split proxy mode. - -2011-04-09: szager - [Python] Applied patch #1932484: migrate PyCObject to PyCapsule. - -2011-04-09: szager - [Python] Added preprocessor guards for python functions PyUnicode_AsWideChar and - PySlice_GetIndices, which changed signatures in python3.2. - -2011-04-07: wsfulton - Fix wrapping of const array typedefs which were generating uncompileable code as - reported by Karl Wette. - -2011-04-03: szager - [Python] Fixed the behavior of %pythonnondynamic to conform to the spec in Lib/pyuserdir.swg. - -2011-04-03: szager - [Python] Merged in the szager-python-builtin branch, adding the -builtin feature - for python. The -builtin option may provide a significant performance gain - in python wrappers. For full details and limitations, refer to Doc/Manual/Python.html. - A small test suite designed to demonstrate the performance gain is in - Examples/python/performance. - -2011-04-01: wsfulton - Add in missing wrappers for friend functions for some target languages, mostly - the non-scripting languages like Java and C#. diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html index e6dcd0e67..6f6f18bed 100644 --- a/Doc/Manual/Sections.html +++ b/Doc/Manual/Sections.html @@ -6,7 +6,7 @@

            SWIG-2.0 Documentation

            -Last update : SWIG-2.0.4 (21 May 2011) +Last update : SWIG-2.0.5 (in progress)

            Sections

            diff --git a/README b/README index 658ff4ca1..9eb3bc90c 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ SWIG (Simplified Wrapper and Interface Generator) -Version: 2.0.4 (21 May 2011) +Version: 2.0.5 (in progress) Tagline: SWIG is a compiler that integrates C and C++ with languages including Perl, Python, Tcl, Ruby, PHP, Java, Ocaml, Lua, diff --git a/configure.in b/configure.in index 3c9f8f9c3..1953e19ee 100644 --- a/configure.in +++ b/configure.in @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. dnl The macros which aren't shipped with the autotools are stored in the dnl Tools/config directory in .m4 files. -AC_INIT([swig],[2.0.4],[http://www.swig.org]) +AC_INIT([swig],[2.0.5],[http://www.swig.org]) dnl NB: When this requirement is increased to 2.60 or later, AC_PROG_SED dnl definition below can be removed From f38530b4900f39213d277f880deee2ff7df1974b Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 24 May 2011 03:59:35 +0000 Subject: [PATCH 42/59] Make a char * pointer we don't modify through const. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12710 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/php/phprun.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 006921703..ef521c857 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -192,7 +192,7 @@ SWIG_ZTS_ConvertResourcePtr(zval *z, swig_type_info *ty, int flags TSRMLS_DC) { swig_object_wrapper *value; void *p; int type; - char *type_name; + const char *type_name; value = (swig_object_wrapper *) zend_list_find(z->value.lval, &type); if ( flags & SWIG_POINTER_DISOWN ) { From 1d7f309a8a3b46582334ac0846b8981425d313b5 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 24 May 2011 14:51:59 +0000 Subject: [PATCH 43/59] [PHP] Fix handling of methods of classes with a virtual base class (SF#3124665). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12711 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Source/Modules/php.cxx | 34 ++++++++++++---------------------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 203f3c7d7..1ef7e4907 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,3 +4,7 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.5 (in progress) =========================== + +2011-05-24: olly + [PHP] Fix handling of methods of classes with a virtual base class (SF#3124665). + diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index a304946e7..09d6c5730 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1682,36 +1682,26 @@ public: if (Cmp(invoke, "$r") != 0) Printf(output, "\t\t$r=%s;\n", invoke); if (Len(ret_types) == 1) { - /* If it has an abstract base, then we can't create a new - * base object. */ - int hasabstractbase = 0; - Node *bases = Getattr(Swig_methodclass(n), "bases"); - if (bases) { - Iterator i = First(bases); - while(i.item) { - if (Getattr(i.item, "abstract")) { - hasabstractbase = 1; - break; - } - i = Next(i); - } + /* If d is abstract we can't create a new wrapper type d. */ + Node * d_class = classLookup(d); + int is_abstract = 0; + if (Getattr(d_class, "abstract")) { + is_abstract = 1; } - if (newobject || !hasabstractbase) { - /* - * _p_Foo -> Foo, _p_ns__Bar -> Bar - * TODO: do this in a more elegant way - */ + if (newobject || !is_abstract) { Printf(output, "\t\tif (is_resource($r)) {\n"); if (Getattr(classLookup(Getattr(n, "type")), "module")) { + /* + * _p_Foo -> Foo, _p_ns__Bar -> Bar + * TODO: do this in a more elegant way + */ if (Len(prefix) == 0) { Printf(output, "\t\t\t$c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));\n"); } else { Printf(output, "\t\t\t$c='%s'.substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));\n", prefix); } - Printf(output, "\t\t\tif (!class_exists($c)) {\n"); - Printf(output, "\t\t\t\treturn new %s%s($r);\n", prefix, Getattr(classLookup(d), "sym:name")); - Printf(output, "\t\t\t}\n"); - Printf(output, "\t\t\treturn new $c($r);\n"); + Printf(output, "\t\t\tif (class_exists($c)) return new $c($r);\n"); + Printf(output, "\t\t\treturn new %s%s($r);\n", prefix, Getattr(classLookup(d), "sym:name")); } else { Printf(output, "\t\t\t$c = new stdClass();\n"); Printf(output, "\t\t\t$c->"SWIG_PTR" = $r;\n"); From 14d5f8ff46b07bf384cf7ffaccbbad9e5806728b Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 24 May 2011 14:54:46 +0000 Subject: [PATCH 44/59] Add blank line after 2.0.4 release heading to match previous releases. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12712 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index 9bc2f5718..185d57d45 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,7 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.4 (21 May 2011) =========================== + 2011-05-19: wsfulton [Guile] Patch #3191625 fixing overloading of integer types. From 18174ed370b4104f20a1889a8c9886c461893ccb Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 24 May 2011 23:53:59 +0000 Subject: [PATCH 45/59] Add link to PEP 3119. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12713 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Python.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 81b2fe04e..13b20d953 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -5497,7 +5497,8 @@ used to define an abstract base class for your own C++ class:

            -For details of abstract base class, please see PEP 3119. +For details of abstract base class, please see +PEP 3119.

            From c44249f32cdc10cd13bc4de59f2a5b79aa22f69c Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 24 May 2011 23:55:35 +0000 Subject: [PATCH 46/59] Add link to PEP 3107. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12714 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Python.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 13b20d953..07f9e87d7 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -5305,7 +5305,8 @@ all overloaded functions share the same function in SWIG generated proxy class.

            -For detailed usage of function annotation, see PEP 3107. +For detailed usage of function annotation, see +PEP 3107.

            33.12.2 Buffer interface

            From 748e951e7e1b159c83ac93f4332e08ce608aaaa4 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 25 May 2011 05:19:48 +0000 Subject: [PATCH 47/59] Add testcase virtual_vs_nonvirtual_base as a regression test for SF#3124665. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12715 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 1 + .../php/virtual_vs_nonvirtual_base_runme.php | 11 +++++ .../test-suite/virtual_vs_nonvirtual_base.i | 48 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 Examples/test-suite/php/virtual_vs_nonvirtual_base_runme.php create mode 100644 Examples/test-suite/virtual_vs_nonvirtual_base.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 3b0efd1eb..52a551a56 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -437,6 +437,7 @@ CPP_TEST_CASES += \ varargs_overload \ virtual_destructor \ virtual_poly \ + virtual_vs_nonvirtual_base \ voidtest \ wallkw \ wrapmacro diff --git a/Examples/test-suite/php/virtual_vs_nonvirtual_base_runme.php b/Examples/test-suite/php/virtual_vs_nonvirtual_base_runme.php new file mode 100644 index 000000000..0d4aa3d5f --- /dev/null +++ b/Examples/test-suite/php/virtual_vs_nonvirtual_base_runme.php @@ -0,0 +1,11 @@ +getInner()->get(), $fail->getInner()->get(), "should both be 10"); + +?> diff --git a/Examples/test-suite/virtual_vs_nonvirtual_base.i b/Examples/test-suite/virtual_vs_nonvirtual_base.i new file mode 100644 index 000000000..9e8bc5eab --- /dev/null +++ b/Examples/test-suite/virtual_vs_nonvirtual_base.i @@ -0,0 +1,48 @@ +%module virtual_vs_nonvirtual_base; +// Regression test for SF#3124665. +%inline { + +class SimpleVirtual +{ + public: + virtual int implementMe() = 0; +}; + +class SimpleNonVirtual +{ + public: + int dummy() { return 0; } +}; + +class SimpleReturnClass +{ + public: + SimpleReturnClass(int i) : value(i) {}; + int get() const { return value; } + private: + int value; +}; + +class SimpleClassFail : public SimpleVirtual +{ + public: + SimpleClassFail() : inner(10) {} + SimpleReturnClass getInner() { return inner; } + + virtual int implementMe() { return 0; } + private: + SimpleReturnClass inner; +}; + +class SimpleClassWork : public SimpleNonVirtual +{ + public: + SimpleClassWork() : inner(10) {} + SimpleReturnClass getInner() { return inner; } + + virtual int implementMe() { return 0; } + private: + SimpleReturnClass inner; +}; + +} From 924be5044d2ec82ffa4d05ce5d8418aea378f1ff Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 25 May 2011 17:13:45 +0000 Subject: [PATCH 48/59] cosmetic style fix on pointer declarations git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12716 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/guile/typemaps.i | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Lib/guile/typemaps.i b/Lib/guile/typemaps.i index 4eda6eeeb..edf227d46 100644 --- a/Lib/guile/typemaps.i +++ b/Lib/guile/typemaps.i @@ -292,18 +292,18 @@ SIMPLE_MAP(unsigned long long, gh_scm2ulong_long, gh_ulong_long2scm, integer); %typemap (varin, doc="NEW-VALUE is a string") char * {$1 = ($1_ltype)SWIG_scm2str($input);} %typemap (out, doc="") char * {$result = gh_str02scm((const char *)$1);} %typemap (varout, doc="") char * {$result = gh_str02scm($1);} - %typemap (in, doc="$NAME is a string") char * *INPUT(char * temp, int must_free = 0) { + %typemap (in, doc="$NAME is a string") char **INPUT(char * temp, int must_free = 0) { temp = (char *) SWIG_scm2str($input); $1 = &temp; must_free = 1; } - %typemap (in,numinputs=0) char * *OUTPUT (char * temp) + %typemap (in,numinputs=0) char **OUTPUT (char * temp) {$1 = &temp;} - %typemap (argout,doc="$NAME (a string)") char * *OUTPUT + %typemap (argout,doc="$NAME (a string)") char **OUTPUT {SWIG_APPEND_VALUE(gh_str02scm(*$1));} - %typemap (in) char * *BOTH = char * *INPUT; - %typemap (argout) char * *BOTH = char * *OUTPUT; - %typemap (in) char * *INOUT = char * *INPUT; - %typemap (argout) char * *INOUT = char * *OUTPUT; + %typemap (in) char **BOTH = char **INPUT; + %typemap (argout) char **BOTH = char **OUTPUT; + %typemap (in) char **INOUT = char **INPUT; + %typemap (argout) char **INOUT = char **OUTPUT; /* SWIG_scm2str makes a malloc'ed copy of the string, so get rid of it after the function call. */ From 49532b718138f7b0188f0e7499010c72a3a89735 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 27 May 2011 00:04:32 +0000 Subject: [PATCH 49/59] Some improvements to the Go documentation. From Gary Holt . git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12719 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Contents.html | 3 +- Doc/Manual/Go.html | 160 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 161 insertions(+), 2 deletions(-) diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 04cbbcf2a..b53923c17 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -764,6 +764,8 @@
          • Go Templates
          • Go Director Classes
          • Default Go primitive type mappings +
          • Output arguments +
          • Adding additional go code
        @@ -1689,4 +1691,3 @@ - diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index 8681927c3..8c072e00a 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -28,6 +28,8 @@
      • Go Templates
      • Go Director Classes
      • Default Go primitive type mappings +
      • Output arguments +
      • Adding additional go code
    @@ -273,7 +275,7 @@ class.

    SWIG will represent static methods of C++ classes as ordinary Go -functions. SWIG will use names like ClassName_MethodName. +functions. SWIG will use names like ClassNameMethodName. SWIG will give static members getter and setter functions with names like GetClassName_VarName.

    @@ -289,6 +291,37 @@ to reinterpret_cast. This should only be used for very special cases, such as where C++ would use a dynamic_cast.

    +

    Note that C++ pointers to compound objects are represented in go as objects +themselves, not as go pointers. So, for example, if you wrap the following +function:

    +
    +
    +class MyClass {
    +  int MyMethod();
    +  static MyClass *MyFactoryFunction();
    +};
    +
    +
    +
    +

    You will get go code that looks like this:

    +
    +
    +type MyClass interface {
    +  Swigcptr() uintptr
    +  SwigIsMyClass()
    +  MyMethod() int
    +}
    +
    +MyClassMyFactoryFunction() MyClass {
    +  // swig magic here
    +}
    +
    +
    +

    Note that the factory function does not return a go pointer; it actually +returns a go interface. If the returned pointer can be null, you can check +for this by calling the Swigcptr() method. +

    +

    21.3.5.1 Go Class Inheritance

    @@ -459,5 +492,130 @@ that typemap, or add new values, to control how C/C++ types are mapped into Go types.

    +

    21.3.9 Output arguments

    + + +

    Because of limitations in the way output arguments are processed in swig, +a function with output arguments will not have multiple return values. +Instead, you must pass a pointer into the C++ function to tell it where to +store the ouput value. In go, you supply a slice in the place of the output +argument.

    + +

    For example, suppose you were trying to wrap the modf() function in the +C math library which splits x into integral and fractional parts (and +returns the integer part in one of its parameters):

    +

    +
    +double modf(double x, double *ip);
    +
    +
    +

    You could wrap it with SWIG as follows:

    +
    +
    +%include <typemaps.i>
    +double modf(double x, double *OUTPUT);
    +
    +
    +

    or you can use the %apply directive:

    +
    +
    +%include <typemaps.i>
    +%apply double *OUTPUT { double *ip };
    +double modf(double x, double *ip);
    +
    +
    +

    In Go you would use it like this:

    +
    +
    +ptr := []float64{0.0}
    +fraction := modulename.Modf(5.0, ptr)
    +
    +
    +

    Since this is ugly, you may want to wrap the swig-generated API with +some additional functions written in go that +hide the ugly details.

    + +

    There are no char *OUTPUT typemaps. However you can +apply the signed char * typemaps instead:

    +

    +
    +%include <typemaps.i>
    +%apply signed char *OUTPUT {char *output};
    +void f(char *output);
    +
    +
    + +

    21.3.10 Adding additional go code

    + +

    Often the APIs generated by swig are not very natural in go, especially if +there are output arguments. You can +insert additional go wrapping code to add new APIs +with %insert(go_wrapper), like this:

    +
    +
    +%include <typemaps.i>
    +// Change name of what swig generates to Wrapped_modf.  This function will
    +// have the following signature in go:
    +//   func Wrapped_modf(float64, []float64) float64
    +%rename(wrapped_modf) modf(double x, double *ip);
    +
    +%apply double *OUTPUT { double *ip };
    +double modf(double x, double *ip);
    +
    +%insert(go_wrapper) %{
    +
    +// The improved go interface to this function, which has two return values,
    +// in the more natural go idiom:
    +func Modf(x float64) (fracPart float64, intPart float64) {
    +  ip := []float64{0.0}
    +  fracPart = Wrapped_modf(x, ip)
    +  intPart = ip[0]
    +  return
    +}
    +
    +%}
    +
    +
    + +

    For classes, since swig generates an interface, you can add additional +methods by defining another interface that includes the swig-generated +interface. For example,

    +
    +
    +%rename(Wrapped_MyClass) MyClass;
    +%rename(Wrapped_GetAValue) MyClass::GetAValue(int *x);
    +%apply int *OUTPUT { int *x };
    +
    +class MyClass {
    + public:
    +  MyClass();
    +  int AFineMethod(const char *arg); // Swig's wrapping is fine for this one.
    +  bool GetAValue(int *x);
    +};
    +
    +%insert(go_wrapper) %{
    +
    +type MyClass interface {
    +  Wrapped_MyClass
    +  GetAValue() (int, bool)
    +}
    +
    +func (arg SwigcptrWrapped_MyClass) GetAValue() (int, bool) {
    +  ip := []int{0}
    +  ok := arg.Wrapped_GetAValue(ip)
    +  return ip[0], ok
    +}
    +
    +%}
    +
    +
    +

    Of course, if you have to rewrite most of the methods, instead of just a +few, then you might as well define your own struct that includes the +swig-wrapped object, instead of adding methods to the swig-generated object.

    + +

    This only works if your wrappers do not need to import other go modules. +There is at present no way to insert import statements in the correct place +in swig-generated go. If you need to do that, you must put your go code +in a separate file.

    From 75a317d746ab74d33d9c097a810774286363094c Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 27 May 2011 13:57:42 +0000 Subject: [PATCH 50/59] Fix typo in UEH message git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12720 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/director.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/python/director.swg b/Lib/python/director.swg index c80695ff7..ca46f6dab 100644 --- a/Lib/python/director.swg +++ b/Lib/python/director.swg @@ -250,7 +250,7 @@ namespace Swig { std::cerr << "This exception was caught by the SWIG unexpected exception handler." << std::endl << "Try using %feature(\"director:except\") to avoid reaching this point." << std::endl << std::endl - << "Exception is being re-thrown, program will like abort/terminate." << std::endl; + << "Exception is being re-thrown, program will likely abort/terminate." << std::endl; throw; } From 4c64a731c87681c03af47c26117a46f6eb747497 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 30 May 2011 04:37:49 +0000 Subject: [PATCH 51/59] Avoid pointless creation of a PHP string git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12721 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/php/director.swg | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Lib/php/director.swg b/Lib/php/director.swg index e625f8acb..218a84e3a 100644 --- a/Lib/php/director.swg +++ b/Lib/php/director.swg @@ -107,13 +107,11 @@ namespace Swig { } bool swig_is_overridden_method(char *cname, char *lc_fname) { - zval classname; zend_class_entry **ce; zend_function *mptr; int name_len = strlen(lc_fname); - ZVAL_STRING(&classname, cname, 0); - if (zend_lookup_class(Z_STRVAL_P(&classname), Z_STRLEN_P(&classname), &ce TSRMLS_CC) != SUCCESS) { + if (zend_lookup_class(cname, strlen(cname), &ce TSRMLS_CC) != SUCCESS) { return false; } if (zend_hash_find(&(*ce)->function_table, lc_fname, name_len + 1, (void**) &mptr) != SUCCESS) { From dce3b5bacf9191b3e39504c29df89e284aa0c243 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 30 May 2011 04:49:29 +0000 Subject: [PATCH 52/59] [PHP] Fix handling of directors when -prefix is used. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12722 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Source/Modules/php.cxx | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 1ef7e4907..3fab761b8 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.5 (in progress) =========================== +2011-05-30: olly + [PHP] Fix handling of directors when -prefix is used. + 2011-05-24: olly [PHP] Fix handling of methods of classes with a virtual base class (SF#3124665). diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 09d6c5730..33f5291fb 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -803,8 +803,8 @@ public: Wrapper_add_local(f, "director", "Swig::Director *director = 0"); Printf(f->code, "director = dynamic_cast(arg1);\n"); Wrapper_add_local(f, "upcall", "bool upcall = false"); - Printf(f->code, "upcall = !director->swig_is_overridden_method((char *)\"%s\", (char *)\"%s\");\n", - Swig_class_name(Swig_methodclass(n)), name); + Printf(f->code, "upcall = !director->swig_is_overridden_method((char *)\"%s%s\", (char *)\"%s\");\n", + prefix, Swig_class_name(Swig_methodclass(n)), name); } // This generated code may be called: @@ -1655,7 +1655,7 @@ public: Printf(output, "\t\t$this->%s=%s;\n", SWIG_PTR, invoke); } else { String *classname = Swig_class_name(current_class); - Printf(output, "\t\treturn new %s(%s);\n", classname, invoke); + Printf(output, "\t\treturn new %s%s(%s);\n", prefix, classname, invoke); } } } else { From 29190559f847164a8532711638b49f27462f3a11 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 30 May 2011 06:47:47 +0000 Subject: [PATCH 53/59] SWIG_ZTS_SetPointerZval() now interprets bit 1 in newobject as meaning (wrap in a PHP class wrapper), rather than taking newobject==2 as meaning this, so we can wrap new and existing objects in this way. Handle wrapping classes in a C++ namespace being returned by director methods. No need to force classname to lowercase as zend_lookup_class() does that internally. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12723 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/php/php.swg | 2 +- Lib/php/phprun.swg | 39 ++++++++++++++++++++++++++------------- Source/Modules/php.cxx | 3 +++ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/Lib/php/php.swg b/Lib/php/php.swg index f69761079..2affdd1ac 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -347,7 +347,7 @@ SWIGTYPE [], SWIGTYPE & %{ - SWIG_SetPointerZval($input, (void *)&$1_name, $1_descriptor, $owner); + SWIG_SetPointerZval($input, (void *)&$1_name, $1_descriptor, ($owner)|2); %} %typemap(out, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*) diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index ef521c857..86d242958 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -96,7 +96,6 @@ static ZEND_RSRC_DTOR_FUNC(SWIG_landfill) { (void)rsrc; } static void SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject TSRMLS_DC) { - swig_object_wrapper *value=NULL; /* * First test for Null pointers. Return those as PHP native NULL */ @@ -105,12 +104,13 @@ SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject return; } if (type->clientdata) { + swig_object_wrapper *value; if (! (*(int *)(type->clientdata))) zend_error(E_ERROR, "Type: %s failed to register with zend",type->name); value=(swig_object_wrapper *)emalloc(sizeof(swig_object_wrapper)); value->ptr=ptr; - value->newobject=newobject; - if (newobject <= 1) { + value->newobject=(newobject & 1); + if ((newobject & 2) == 0) { /* Just register the pointer as a resource. */ ZEND_REGISTER_RESOURCE(z, value, *(int *)(type->clientdata)); } else { @@ -119,18 +119,32 @@ SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject * via the "_cPtr" member. This is currently only used by * directorin typemaps. */ - value->newobject = 0; zval *resource; + zend_class_entry **ce = NULL; + const char *type_name = type->name+3; /* +3 so: _p_Foo -> Foo */ + size_t type_name_len; + int result; + const char * p; + + /* Namespace__Foo -> Foo */ + /* FIXME: ugly and goes wrong for classes with __ in their names. */ + while ((p = strstr(type_name, "__")) != NULL) { + type_name = p + 2; + } + type_name_len = strlen(type_name); + MAKE_STD_ZVAL(resource); ZEND_REGISTER_RESOURCE(resource, value, *(int *)(type->clientdata)); - zend_class_entry **ce = NULL; - zval *classname; - MAKE_STD_ZVAL(classname); - /* _p_Foo -> Foo */ - ZVAL_STRING(classname, (char*)type->name+3, 1); - /* class names are stored in lowercase */ - php_strtolower(Z_STRVAL_PP(&classname), Z_STRLEN_PP(&classname)); - if (zend_lookup_class(Z_STRVAL_P(classname), Z_STRLEN_P(classname), &ce TSRMLS_CC) != SUCCESS) { + if (SWIG_PREFIX_LEN > 0) { + char * classname = (char*)emalloc(SWIG_PREFIX_LEN + type_name_len + 1); + strcpy(classname, SWIG_PREFIX); + strcpy(classname + SWIG_PREFIX_LEN, type_name); + result = zend_lookup_class(classname, SWIG_PREFIX_LEN + type_name_len, &ce TSRMLS_CC); + efree(classname); + } else { + result = zend_lookup_class(type_name, type_name_len, &ce TSRMLS_CC); + } + if (result != SUCCESS) { /* class does not exist */ object_init(z); } else { @@ -139,7 +153,6 @@ SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject Z_SET_REFCOUNT_P(z, 1); Z_SET_ISREF_P(z); zend_hash_update(HASH_OF(z), (char*)"_cPtr", sizeof("_cPtr"), (void*)&resource, sizeof(zval), NULL); - FREE_ZVAL(classname); } return; } diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 33f5291fb..b4af248f5 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -328,6 +328,9 @@ public: if (!prefix) prefix = NewStringEmpty(); + Printf(f_runtime, "#define SWIG_PREFIX \"%s\"\n", prefix); + Printf(f_runtime, "#define SWIG_PREFIX_LEN %lu\n", (unsigned long)Len(prefix)); + if (directorsEnabled()) { Swig_banner(f_directors_h); Printf(f_directors_h, "\n"); From a09225e70b4f9d92e0d726b5f12827d7246c054e Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 30 May 2011 06:58:26 +0000 Subject: [PATCH 54/59] Need to cast away const-ness for the PHP API. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12724 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/php/phprun.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 86d242958..623b33705 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -142,7 +142,7 @@ SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject result = zend_lookup_class(classname, SWIG_PREFIX_LEN + type_name_len, &ce TSRMLS_CC); efree(classname); } else { - result = zend_lookup_class(type_name, type_name_len, &ce TSRMLS_CC); + result = zend_lookup_class((char *)type_name, type_name_len, &ce TSRMLS_CC); } if (result != SUCCESS) { /* class does not exist */ From a47da97ffe1e1c0ef91ee821e5bdcb1df315bab5 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 3 Jun 2011 06:07:46 +0000 Subject: [PATCH 55/59] rename python_autodoc testcase to autodoc for use with all languages (note it was once called autodoc.i in the python subdirectory) git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12728 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/{python_autodoc.i => autodoc.i} | 0 Examples/test-suite/common.mk | 1 + Examples/test-suite/python/Makefile.in | 1 - 3 files changed, 1 insertion(+), 1 deletion(-) rename Examples/test-suite/{python_autodoc.i => autodoc.i} (100%) diff --git a/Examples/test-suite/python_autodoc.i b/Examples/test-suite/autodoc.i similarity index 100% rename from Examples/test-suite/python_autodoc.i rename to Examples/test-suite/autodoc.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 52a551a56..10bc24309 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -118,6 +118,7 @@ CPP_TEST_CASES += \ arrays_global \ arrays_global_twodim \ arrays_scope \ + autodoc \ bloody_hell \ bools \ catches \ diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index 0e600b16f..7eb700124 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -58,7 +58,6 @@ CPP_TEST_CASES += \ primitive_types \ python_abstractbase \ python_append \ - python_autodoc \ python_kwargs \ python_nondynamic \ python_overload_simple_cast \ From b0ffa0b48f8cab8d336c97870430b5c46af540b2 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 3 Jun 2011 13:13:44 +0000 Subject: [PATCH 56/59] Fix comment typos git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12729 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/tcl/tcltypemaps.swg | 8 ++++---- Lib/typemaps/primtypes.swg | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Lib/tcl/tcltypemaps.swg b/Lib/tcl/tcltypemaps.swg index d93c8869b..2b4e06e9d 100644 --- a/Lib/tcl/tcltypemaps.swg +++ b/Lib/tcl/tcltypemaps.swg @@ -7,7 +7,7 @@ * ------------------------------------------------------------ */ /* - in Tcl we need to pass the interp value, so, we define the decl/call + In Tcl we need to pass the interp value, so we define the decl/call macros as needed. */ @@ -15,13 +15,13 @@ #define SWIG_AS_CALL_ARGS SWIG_TCL_CALL_ARGS_2 -/* Include fundamental fragemt definitions */ +/* Include fundamental fragment definitions */ %include /* Look for user fragments file. */ %include -/* Tcl fragments for primitve types */ +/* Tcl fragments for primitive types */ %include /* Tcl fragments for char* strings */ @@ -32,7 +32,7 @@ * Unified typemap section * ------------------------------------------------------------ */ -/* No director supported in Tcl */ +/* No director support in Tcl */ #ifdef SWIG_DIRECTOR_TYPEMAPS #undef SWIG_DIRECTOR_TYPEMAPS #endif diff --git a/Lib/typemaps/primtypes.swg b/Lib/typemaps/primtypes.swg index 42728e5fe..cc8a55e6e 100644 --- a/Lib/typemaps/primtypes.swg +++ b/Lib/typemaps/primtypes.swg @@ -22,8 +22,8 @@ which can always be redefined in the swig target language if needed. - The fragments for the following types, however, need to be defined - in the target language always: + The fragments for the following types, however, always need to be + defined in the target language: long unsigned long @@ -40,7 +40,7 @@ %typemaps_primitive(CheckCode, Type) - which generate the typemaps for a primitive type with a given + which generates the typemaps for a primitive type with a given checkcode. It is assumed that the primitive type is 'normalized' and the corresponding SWIG_AsVal(Type) and SWIG_From(Type) methods are provided via fragments. From f9ec0e8f06a8ec06a1623d9edb81e54113a41ce5 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 3 Jun 2011 13:24:28 +0000 Subject: [PATCH 57/59] Fix typo and a few indentation inconsistencies git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12730 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/CParse/parser.y | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 2ac0c1916..e6c6e5143 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -5024,7 +5024,7 @@ notso_direct_declarator : idcolon { $$.have_parms = 0; } -/* This generate a shift-reduce conflict with constructors */ +/* This generates a shift-reduce conflict with constructors */ | LPAREN idcolon RPAREN { $$.id = Char($2); $$.type = 0; @@ -5335,26 +5335,26 @@ direct_abstract_declarator : direct_abstract_declarator LBRACKET RBRACKET { pointer : STAR type_qualifier pointer { - $$ = NewStringEmpty(); - SwigType_add_pointer($$); - SwigType_push($$,$2); - SwigType_push($$,$3); - Delete($3); + $$ = NewStringEmpty(); + SwigType_add_pointer($$); + SwigType_push($$,$2); + SwigType_push($$,$3); + Delete($3); } | STAR pointer { $$ = NewStringEmpty(); SwigType_add_pointer($$); SwigType_push($$,$2); Delete($2); - } + } | STAR type_qualifier { - $$ = NewStringEmpty(); - SwigType_add_pointer($$); - SwigType_push($$,$2); + $$ = NewStringEmpty(); + SwigType_add_pointer($$); + SwigType_push($$,$2); } | STAR { - $$ = NewStringEmpty(); - SwigType_add_pointer($$); + $$ = NewStringEmpty(); + SwigType_add_pointer($$); } ; @@ -5382,7 +5382,7 @@ type : rawtype { } ; -rawtype : type_qualifier type_right { +rawtype : type_qualifier type_right { $$ = $2; SwigType_push($$,$1); } @@ -5400,7 +5400,7 @@ rawtype : type_qualifier type_right { type_right : primitive_type { $$ = $1; /* Printf(stdout,"primitive = '%s'\n", $$);*/ - } + } | TYPE_BOOL { $$ = $1; } | TYPE_VOID { $$ = $1; } | TYPE_TYPEDEF template_decl { $$ = NewStringf("%s%s",$1,$2); } From 21424ecd09b583c4cfa100531c7fa6bb3686a849 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 3 Jun 2011 13:49:18 +0000 Subject: [PATCH 58/59] PHP directors now done. WAD has been removed. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12731 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- TODO | 5 ----- 1 file changed, 5 deletions(-) diff --git a/TODO b/TODO index 879e65f1f..01d9a8d78 100644 --- a/TODO +++ b/TODO @@ -198,8 +198,6 @@ PHP **** Look at moving to using the UTL. -*** Director support. - ** When returning wrapped objects via alternate constructors if that pointer value already exists "out there" as a resource we should use the same resource, we can't have multiple ref-counted resources @@ -373,6 +371,3 @@ Documentation *** Perl, Python, Tcl modules. *** add section for Perl module support for operator overloading - -** Add section on WAD. - From 50425dc95ee551574c8a977a4dfe8e77d8396a8b Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Fri, 3 Jun 2011 18:42:38 +0000 Subject: [PATCH 59/59] For all long integer types, use PyLong_From* rather than PyInt_From* git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12732 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pyprimtypes.swg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/python/pyprimtypes.swg b/Lib/python/pyprimtypes.swg index 63435eee0..a11e87409 100644 --- a/Lib/python/pyprimtypes.swg +++ b/Lib/python/pyprimtypes.swg @@ -28,7 +28,7 @@ SWIG_AsVal_dec(bool)(PyObject *obj, bool *val) /* long */ %fragment(SWIG_From_frag(long),"header") { - %define_as(SWIG_From_dec(long), PyInt_FromLong) + %define_as(SWIG_From_dec(long), PyLong_FromLong) } %fragment(SWIG_AsVal_frag(long),"header", @@ -80,7 +80,7 @@ SWIGINTERNINLINE PyObject* SWIG_From_dec(unsigned long)(unsigned long value) { return (value > LONG_MAX) ? - PyLong_FromUnsignedLong(value) : PyInt_FromLong(%numeric_cast(value,long)); + PyLong_FromUnsignedLong(value) : PyLong_FromLong(%numeric_cast(value,long)); } } @@ -139,7 +139,7 @@ SWIGINTERNINLINE PyObject* SWIG_From_dec(long long)(long long value) { return ((value < LONG_MIN) || (value > LONG_MAX)) ? - PyLong_FromLongLong(value) : PyInt_FromLong(%numeric_cast(value,long)); + PyLong_FromLongLong(value) : PyLong_FromLong(%numeric_cast(value,long)); } } @@ -193,7 +193,7 @@ SWIGINTERNINLINE PyObject* SWIG_From_dec(unsigned long long)(unsigned long long value) { return (value > LONG_MAX) ? - PyLong_FromUnsignedLongLong(value) : PyInt_FromLong(%numeric_cast(value,long)); + PyLong_FromUnsignedLongLong(value) : PyLong_FromLong(%numeric_cast(value,long)); } }