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
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue