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)
- the patch simplifies pyrun.swg a tiny bit.
Disadvantage:
- default str() will give different (but clearer?) output on swigged
classes compared to unpatched swig
SF Bug #326
This commit is contained in:
parent
a0af86811d
commit
a495b5a985
3 changed files with 21 additions and 32 deletions
|
|
@ -4,6 +4,25 @@ See the RELEASENOTES file for a summary of changes in each release.
|
||||||
|
|
||||||
Version 2.0.11 (in progress)
|
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
|
2013-07-30: wsfulton
|
||||||
[Python, Ruby] Fix #64 #65: Missing code in std::multimap wrappers. Previously an instantiation
|
[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
|
of a std::map was erroneously required in addition to an instantiation of std::multimap with the
|
||||||
|
|
|
||||||
|
|
@ -67,10 +67,8 @@
|
||||||
#define PySwigObject_next SwigPyObject_next
|
#define PySwigObject_next SwigPyObject_next
|
||||||
#define PySwigObject_oct SwigPyObject_oct
|
#define PySwigObject_oct SwigPyObject_oct
|
||||||
#define PySwigObject_own SwigPyObject_own
|
#define PySwigObject_own SwigPyObject_own
|
||||||
#define PySwigObject_print SwigPyObject_print
|
|
||||||
#define PySwigObject_repr SwigPyObject_repr
|
#define PySwigObject_repr SwigPyObject_repr
|
||||||
#define PySwigObject_richcompare SwigPyObject_richcompare
|
#define PySwigObject_richcompare SwigPyObject_richcompare
|
||||||
#define PySwigObject_str SwigPyObject_str
|
|
||||||
#define PySwigObject_type SwigPyObject_type
|
#define PySwigObject_type SwigPyObject_type
|
||||||
#define PySwigPacked SwigPyPacked
|
#define PySwigPacked SwigPyPacked
|
||||||
#define PySwigPacked_Check SwigPyPacked_Check
|
#define PySwigPacked_Check SwigPyPacked_Check
|
||||||
|
|
|
||||||
|
|
@ -448,34 +448,6 @@ SwigPyObject_repr(SwigPyObject *v, PyObject *args)
|
||||||
return repr;
|
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
|
SWIGRUNTIME int
|
||||||
SwigPyObject_compare(SwigPyObject *v, SwigPyObject *w)
|
SwigPyObject_compare(SwigPyObject *v, SwigPyObject *w)
|
||||||
{
|
{
|
||||||
|
|
@ -761,7 +733,7 @@ SwigPyObject_TypeOnce(void) {
|
||||||
sizeof(SwigPyObject), /* tp_basicsize */
|
sizeof(SwigPyObject), /* tp_basicsize */
|
||||||
0, /* tp_itemsize */
|
0, /* tp_itemsize */
|
||||||
(destructor)SwigPyObject_dealloc, /* tp_dealloc */
|
(destructor)SwigPyObject_dealloc, /* tp_dealloc */
|
||||||
(printfunc)SwigPyObject_print, /* tp_print */
|
0, /* tp_print */
|
||||||
#if PY_VERSION_HEX < 0x02020000
|
#if PY_VERSION_HEX < 0x02020000
|
||||||
(getattrfunc)SwigPyObject_getattr, /* tp_getattr */
|
(getattrfunc)SwigPyObject_getattr, /* tp_getattr */
|
||||||
#else
|
#else
|
||||||
|
|
@ -779,7 +751,7 @@ SwigPyObject_TypeOnce(void) {
|
||||||
0, /* tp_as_mapping */
|
0, /* tp_as_mapping */
|
||||||
(hashfunc)0, /* tp_hash */
|
(hashfunc)0, /* tp_hash */
|
||||||
(ternaryfunc)0, /* tp_call */
|
(ternaryfunc)0, /* tp_call */
|
||||||
(reprfunc)SwigPyObject_str, /* tp_str */
|
0, /* tp_str */
|
||||||
PyObject_GenericGetAttr, /* tp_getattro */
|
PyObject_GenericGetAttr, /* tp_getattro */
|
||||||
0, /* tp_setattro */
|
0, /* tp_setattro */
|
||||||
0, /* tp_as_buffer */
|
0, /* tp_as_buffer */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue