diff --git a/Examples/test-suite/friends.i b/Examples/test-suite/friends.i index 874b92783..65db63046 100644 --- a/Examples/test-suite/friends.i +++ b/Examples/test-suite/friends.i @@ -1,6 +1,6 @@ %module friends %{ -#include +#include %} %warnfilter(503); diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index b34c54b03..e1a43dc67 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -4,7 +4,7 @@ ####################################################################### LANGUAGE = python -PYTHON = python +PYTHON = @PYTHON@ SCRIPTSUFFIX = _runme.py srcdir = @srcdir@ top_srcdir = @top_srcdir@ diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index 5c633f0a9..d0fbdde16 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -254,38 +254,6 @@ SWIG_Python_FixMethods(PyMethodDef *methods, * Initialize type list * -----------------------------------------------------------------------------*/ -#if PY_MAJOR_VERSION < 2 -/* PyModule_AddObject function was introduced in Python 2.0. The following function -is copied out of Python/modsupport.c in python version 2.3.4 */ -SWIGINTERN int -PyModule_AddObject(PyObject *m, char *name, PyObject *o) -{ - PyObject *dict; - if (!PyModule_Check(m)) { - PyErr_SetString(PyExc_TypeError, - "PyModule_AddObject() needs module as first arg"); - return -1; - } - if (!o) { - PyErr_SetString(PyExc_TypeError, - "PyModule_AddObject() needs non-NULL value"); - return -1; - } - - dict = PyModule_GetDict(m); - if (dict == NULL) { - /* Internal error -- modules must have a dict! */ - PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__", - PyModule_GetName(m)); - return -1; - } - if (PyDict_SetItemString(dict, name, o)) - return -1; - Py_DECREF(o); - return 0; -} -#endif - #ifdef __cplusplus } #endif diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 0b2c2ce54..49d23572d 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -70,7 +70,7 @@ PyString_FromFormat(const char *fmt, ...) { #endif #if PY_VERSION_HEX < 0x01060000 -#define PyObject_Del(op) PyMem_Del((op)) +#define PyObject_Del(op) PyMem_DEL((op)) #endif #if defined(SWIG_COBJECT_TYPES) @@ -788,6 +788,38 @@ SWIG_Python_GetModule(void) { return (swig_module_info *) type_pointer; } +#if PY_MAJOR_VERSION < 2 +/* PyModule_AddObject function was introduced in Python 2.0. The following function +is copied out of Python/modsupport.c in python version 2.3.4 */ +SWIGINTERN int +PyModule_AddObject(PyObject *m, char *name, PyObject *o) +{ + PyObject *dict; + if (!PyModule_Check(m)) { + PyErr_SetString(PyExc_TypeError, + "PyModule_AddObject() needs module as first arg"); + return -1; + } + if (!o) { + PyErr_SetString(PyExc_TypeError, + "PyModule_AddObject() needs non-NULL value"); + return -1; + } + + dict = PyModule_GetDict(m); + if (dict == NULL) { + /* Internal error -- modules must have a dict! */ + PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__", + PyModule_GetName(m)); + return -1; + } + if (PyDict_SetItemString(dict, name, o)) + return -1; + Py_DECREF(o); + return 0; +} +#endif + SWIGRUNTIME void SWIG_Python_SetModule(swig_module_info *swig_module) { static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} };/* Sentinel */ diff --git a/Lib/std/std_common.i b/Lib/std/std_common.i index 945e5e74a..a412f5e5e 100644 --- a/Lib/std/std_common.i +++ b/Lib/std/std_common.i @@ -16,6 +16,14 @@ #define SWIG_STD_NOINSERT_TEMPLATE_STL #endif + +#if defined(__GNUC__) +# if __GNUC__ == 2 && __GNUC_MINOR <= 96 +# define SWIG_STD_NOMODERN_STL +# endif +#endif + + %} // diff --git a/Lib/std/std_ios.i b/Lib/std/std_ios.i index 87ca38d00..75484f3de 100644 --- a/Lib/std/std_ios.i +++ b/Lib/std/std_ios.i @@ -2,7 +2,11 @@ %include %include %{ -#include +#ifndef SWIG_STD_NOMODERN_STL +# include +#else +# include +#endif %} namespace std { diff --git a/Lib/std/std_streambuf.i b/Lib/std/std_streambuf.i index 14265eb8f..3583cf28f 100644 --- a/Lib/std/std_streambuf.i +++ b/Lib/std/std_streambuf.i @@ -1,6 +1,10 @@ %include %{ +#ifndef SWIG_STD_NOMODERN_STL #include +#else +#include +#endif %} namespace std { diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 223b6c12d..d7a06916a 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -390,7 +390,8 @@ public: // Try loading weakref.proxy, which is only available in Python 2.1 and higher Printv(f_shadow, "try:\n", - tab4, "from weakref import proxy as weakref_proxy\n", + tab4, "import weakref\n", + tab4, "weakref_proxy = weakref.proxy\n", "except:\n", tab4, "weakref_proxy = lambda x: x\n", "\n\n",