diff --git a/CHANGES.current b/CHANGES.current index b03e05ffc..cc2ce897d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,25 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.11 (in progress) ============================ + +2013-08-07: wsfulton + [Python] SF Patch #326 from Kris Thielemans - Remove SwigPyObject_print and SwigPyObject_str and + make the generated wrapper use the default python implementations, which will fall back to repr + (for -builtin option). + + Advantages: + - it avoids the swig user having to jump through hoops to get print to work as expected when + redefining repr/str slots. + - typing the name of a variable on the python prompt now prints the result of a (possibly redefined) + repr, without the swig user having to do any extra work. + - when redefining repr, the swig user doesn't necessarily have to redefine str as it will call the + redefined repr + - the behaviour is exactly the same as without the -builtin option while requiring no extra work + by the user (aside from adding the %feature("python:slot...) statements of course) + + Disadvantage: + - default str() will give different (but clearer?) output on swigged classes + 2013-07-30: wsfulton [Python, Ruby] Fix #64 #65: Missing code in std::multimap wrappers. Previously an instantiation of a std::map was erroneously required in addition to an instantiation of std::multimap with the diff --git a/Lib/python/pyname_compat.i b/Lib/python/pyname_compat.i index 4026805ba..96af343ca 100644 --- a/Lib/python/pyname_compat.i +++ b/Lib/python/pyname_compat.i @@ -67,10 +67,8 @@ #define PySwigObject_next SwigPyObject_next #define PySwigObject_oct SwigPyObject_oct #define PySwigObject_own SwigPyObject_own -#define PySwigObject_print SwigPyObject_print #define PySwigObject_repr SwigPyObject_repr #define PySwigObject_richcompare SwigPyObject_richcompare -#define PySwigObject_str SwigPyObject_str #define PySwigObject_type SwigPyObject_type #define PySwigPacked SwigPyPacked #define PySwigPacked_Check SwigPyPacked_Check diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index df87bb317..273c82302 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -448,34 +448,6 @@ SwigPyObject_repr(SwigPyObject *v, PyObject *args) return repr; } -SWIGRUNTIME int -SwigPyObject_print(SwigPyObject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) -{ - char *str; -#ifdef METH_NOARGS - PyObject *repr = SwigPyObject_repr(v); -#else - PyObject *repr = SwigPyObject_repr(v, NULL); -#endif - if (repr) { - str = SWIG_Python_str_AsChar(repr); - fputs(str, fp); - SWIG_Python_str_DelForPy3(str); - Py_DECREF(repr); - return 0; - } else { - return 1; - } -} - -SWIGRUNTIME PyObject * -SwigPyObject_str(SwigPyObject *v) -{ - char result[SWIG_BUFFER_SIZE]; - return SWIG_PackVoidPtr(result, v->ptr, v->ty->name, sizeof(result)) ? - SWIG_Python_str_FromChar(result) : 0; -} - SWIGRUNTIME int SwigPyObject_compare(SwigPyObject *v, SwigPyObject *w) { @@ -761,7 +733,7 @@ SwigPyObject_TypeOnce(void) { sizeof(SwigPyObject), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)SwigPyObject_dealloc, /* tp_dealloc */ - (printfunc)SwigPyObject_print, /* tp_print */ + 0, /* tp_print */ #if PY_VERSION_HEX < 0x02020000 (getattrfunc)SwigPyObject_getattr, /* tp_getattr */ #else @@ -779,7 +751,7 @@ SwigPyObject_TypeOnce(void) { 0, /* tp_as_mapping */ (hashfunc)0, /* tp_hash */ (ternaryfunc)0, /* tp_call */ - (reprfunc)SwigPyObject_str, /* tp_str */ + 0, /* tp_str */ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */