diff --git a/Lib/python/pymacros.swg b/Lib/python/pymacros.swg index 4b7fb6f8b..ab7bace5b 100644 --- a/Lib/python/pymacros.swg +++ b/Lib/python/pymacros.swg @@ -1,13 +1,4 @@ %include -/* - adding backward compatibility macros - please move to the macros names defined in - - Lib/typemaps/swigmacros.swg -*/ - -#define SWIG_arg(x...) %arg(x) -#define SWIG_Mangle(x...) %mangle(x) diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 5a48cec2f..8495c67b0 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -77,9 +77,6 @@ #define SWIG_POINTER_IMPLICIT_CONV (SWIG_POINTER_DISOWN << 1) -/* For backward compatibility only */ -#define SWIG_POINTER_EXCEPTION 0 - #ifdef __cplusplus extern "C" { #if 0 @@ -1211,6 +1208,104 @@ SWIG_Python_SetModule(swig_module_info *swig_module) { } } + +/* + For backward compatibility only +*/ +#define SWIG_POINTER_EXCEPTION 0 +#define SWIG_arg_fail(arg) SWIG_Python_ArgFail(arg) +#define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags) + +SWIGRUNTIME int +SWIG_Python_AddErrMesg(const char* mesg, int infront) +{ + if (PyErr_Occurred()) { + PyObject *type = 0; + PyObject *value = 0; + PyObject *traceback = 0; + PyErr_Fetch(&type, &value, &traceback); + if (value) { + PyObject *old_str = PyObject_Str(value); + Py_XINCREF(type); + PyErr_Clear(); + if (infront) { + PyErr_Format(type, "%s %s", mesg, PyString_AsString(old_str)); + } else { + PyErr_Format(type, "%s %s", PyString_AsString(old_str), mesg); + } + Py_DECREF(old_str); + } + return 1; + } else { + return 0; + } +} + +SWIGRUNTIME int +SWIG_Python_ArgFail(int argnum) +{ + if (PyErr_Occurred()) { + /* add information about failing argument */ + char mesg[256]; + PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum); + return SWIG_Python_AddErrMesg(mesg, 1); + } else { + return 0; + } +} + +SWIGRUNTIME void +SWIG_Python_TypeError(const char *type, PyObject *obj) +{ + if (type) { +#if defined(SWIG_COBJECT_TYPES) + if (obj && PySwigObject_Check(obj)) { + const char *otype = (const char *) PySwigObject_GetDesc(obj); + if (otype) { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'PySwigObject(%s)' is received", + type, otype); + return; + } + } else +#endif + { + const char *otype = (obj ? obj->ob_type->tp_name : 0); + if (otype) { + PyObject *str = PyObject_Str(obj); + const char *cstr = str ? PyString_AsString(str) : 0; + if (cstr) { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received", + type, otype, cstr); + } else { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received", + type, otype); + } + Py_XDECREF(str); + return; + } + } + PyErr_Format(PyExc_TypeError, "a '%s' is expected", type); + } else { + PyErr_Format(PyExc_TypeError, "unexpected type is received"); + } +} + + +/* Convert a pointer value, signal an exception on a type mismatch */ +SWIGRUNTIME void * +SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) { + void *result; + if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) { + PyErr_Clear(); + if (flags & SWIG_POINTER_EXCEPTION) { + SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj); + SWIG_Python_ArgFail(argnum); + } + } + return result; +} + + #ifdef __cplusplus #if 0 { /* cc-mode */ diff --git a/Lib/python/python.swg b/Lib/python/python.swg index 052bd0696..5b8c56d96 100644 --- a/Lib/python/python.swg +++ b/Lib/python/python.swg @@ -55,4 +55,9 @@ %include +/* ------------------------------------------------------------ + * For backward compatibility + * ------------------------------------------------------------ */ +%include +