I have identified a bug in the handling of varargs using the %varargs
feature in python when wrapping varargs of non-primitive (but pointer)
type.
Using Swig 1.3.29, and the following file, I get:
%module(docstring=3D=22Demos Bad Varargs=22) testSwig;
%=7B
typedef struct ST =7B=7D *pST;=20
int demoBadVararg(int, ...);
int demoGoodVararg(int, ...);
%=7D
%varargs(1, int extra=3D0) demoGoodVararg;
int demoGoodVararg(int x, ...);
%varargs(1, pST st =3D NULL) demoBadVararg;
int demoBadVararg(int x, ...);
The warning that it prints out is:
testSwig.interface:14: Warning(509): Overloaded
demoBadVararg(int,pST,pST) is shadowed by demoBadVararg(int,pST) at
testSwig.interface:14.
I believe that the generated code is incorrect, as it does not put the
trailing 'NULL' argument when it calls the function, which will crash
certain code that is expecting it.
As an example, the generated code that I got was:
SWIGINTERN PyObject *_wrap_demoBadVararg(PyObject *self, PyObject *args)
=7B
int argc;
PyObject *argv=5B3=5D;
int ii;
=20
if (=21PyTuple_Check(args)) SWIG_fail;
argc =3D PyObject_Length(args);
for (ii =3D 0; (ii < argc) && (ii < 2); ii++) =7B
argv=5Bii=5D =3D PyTuple_GET_ITEM(args,ii);
=7D
if (argc =3D=3D 1) =7B
int _v;
=7B
int res =3D SWIG_AsVal_int(argv=5B0=5D, NULL);
_v =3D SWIG_CheckState(res);
=7D
if (_v) =7B
return _wrap_demoBadVararg__SWIG_2(self, args);
=7D
=7D
=2E..
Which calls:
SWIGINTERN PyObject *_wrap_demoBadVararg__SWIG_2(PyObject
*SWIGUNUSEDPARM(self), PyObject *args) =7B
PyObject *resultobj =3D 0;
int arg1 ;
int result;
int val1 ;
int ecode1 =3D 0 ;
PyObject * obj0 =3D 0 ;
=20
if (=21PyArg_ParseTuple(args,(char *)=22O:demoBadVararg=22,&obj0))
SWIG_fail;
ecode1 =3D SWIG_AsVal_int(obj0, &val1);
if (=21SWIG_IsOK(ecode1)) =7B
SWIG_exception_fail(SWIG_ArgError(ecode1), =22in method '=22
=22demoBadVararg=22 =22', argument =22 =221=22=22 of type '=22 =
=22int=22=22'=22);
=7D=20
arg1 =3D static_cast< int >(val1);
result =3D (int)demoBadVararg(arg1);
resultobj =3D SWIG_From_int(static_cast< int >(result));
return resultobj;
fail:
return NULL;
=7D
I believe that the underlying call should be demoBadVarArg(arg1, NULL).
Is this correct?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - =
- - - - - - -
This message is intended only for the personal and confidential use of the =
designated recipient(s) named above. If you are not the intended =
recipient of this message you are hereby notified that any review, =
dissemination, distribution or copying of this message is strictly =
prohibited. This communication is for information purposes only and =
should not be regarded as an offer to sell or as a solicitation of an =
offer to buy any financial product, an official confirmation of any =
transaction, or as an official statement of Lehman Brothers. Email =
transmission cannot be guaranteed to be secure or error-free. Therefore, =
we do not represent that this information is complete or accurate and it =
should not be relied upon as such. All information is subject to change =
without notice.
--------
IRS Circular 230 Disclosure:
Please be advised that any discussion of U.S. tax matters contained within =
this communication (including any attachments) is not intended or written =
to be used and cannot be used for the purpose of (i) avoiding U.S. tax =
related penalties or (ii) promoting, marketing or recommending to another =
party any transaction or matter addressed herein.
|