|
From: Arnaud D. <ar...@he...> - 2014-02-10 14:28:49
|
Hello SWIG users,
We just switched to using SWIG 2.0.12 (we were using 2.0.0 before), and
noticed that the "check" code SWIG generates for python, in -modern
mode, is different than it used to be.
For example, if I have the following in :test.hpp":
---
> int foo(void);
> int bar(int b);
---
the following wrappers will be generated (snipped for brevity):
---
> SWIGINTERN PyObject *_wrap_foo(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
> PyObject *resultobj = 0;
> int result;
> {
> SWIG_PYTHON_THREAD_BEGIN_ALLOW;
> [...]
>
> SWIGINTERN PyObject *_wrap_bar(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
>[...]
> if(!PyArg_UnpackTuple(args,(char *)"bar",1,1,&obj0)) SWIG_fail;
> ecode1 = SWIG_AsVal_int(obj0, &val1);
> if (!SWIG_IsOK(ecode1)) {
> SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "bar" "', argument " "1"" of type '" "int""'");
> }
> arg1 = static_cast< int >(val1);
> {
> SWIG_PYTHON_THREAD_BEGIN_ALLOW;
> [...]
> }
---
(the command line was: /opt/swig-2.0.12-install/bin/swig -modern -python
-threads -c++ -shadow -D__GNUC__ -I/tmp -o test.cpp test.i)
Notice how, '_wrap_foo' doesn't validate that the number of arguments is
0 (i.e., no call to 'PyArg_UnpackTuple'), as it used to.
I was wondering why, and tracked the change to this:
http://sourceforge.net/p/swig/code/12332/
More specifically, this piece of the diff:
---
> - } else {
> - Printf(parse_args, "if(!PyArg_UnpackTuple(args,(char *)\"%s\",%d,%d", iname, num_required, num_arguments);
> + } else if (tuple_arguments > 0) {
> + Printf(parse_args, "if(!PyArg_UnpackTuple(args,(char *)\"%s\",%d,%d", iname, tuple_required, tuple_arguments);
---
This is in the "szager-python-builtin" branch, and unfortunately the
commit message doesn't quite explain the decision of adding the
"tuple_arguments > 0" condition.
Then, that branch was brought into the trunk, and the rest is history.
To my SWIG-novice eyes, it looks like a bug, but ... would anyone happen
to know why that condition was added?
Thanks!
Best regards,
Arnaud
--
Arnaud Diederen
Hex-Rays SA: state of the art binary software analysis tools
|