From: Kyle N. <kyl...@gm...> - 2013-04-15 14:32:47
|
I have a C++ function: string dm_cli::show (char *mode, ...) And the swig.i file says: %varargs(6,char *arg = NULL) show; I was using swig 1.3.21 with python 2.6.6 and didn't have any issues calling show("programs") However, another user was trying from their swig 1.3.39 and it was failing saying the args were incorrect. It no longer seemed to know where the end of the varargs were. I had to manually specify the None: show("programs", None) I am parsing out the args using va_start just as is shown in the swig documentation: va_start(voptargs,mode); s = va_arg(voptargs, char *); while (s) { ... s = va_arg(voptargs, char *); } va_end(voptargs); I searched the release notes and bugs and found this comment on the 2.0.4 changes: 2011-05-14: wsfulton %varargs when used with a numeric argument used to create an additional argument which was intended to provide a guaranteed sentinel value. This never worked and now the additional argument is not generated. So I tried 2.0.4 and that failed but 2.05 worked. However 2,0,6 through 2.0.9 all failed. the pywrap.cxx file generated by 2.0.5 and 2.0.6 looks identical. This issue seems to be specific to python--I did not have any issues with the TCL generated interface. Is there some trick to getting %varargs with a numeric argument working with python so that swig automatically inserts the NULL terminator? Is this a known bug? I couldn't find it in the list of open/closed bugs. |
From: William S F. <ws...@fu...> - 2013-05-23 23:01:26
|
On 15/04/13 15:32, Kyle Nolan wrote: > > I have a C++ function: > string dm_cli::show (char *mode, ...) > And the swig.i file says: > %varargs(6,char *arg = NULL) show; > > I was using swig 1.3.21 with python 2.6.6 and didn't have any issues > calling show("programs") > > However, another user was trying from their swig 1.3.39 and it was > failing saying the args were incorrect. > It no longer seemed to know where the end of the varargs were. I had to > manually specify the None: > show("programs", None) > > I am parsing out the args using va_start just as is shown in the swig > documentation: > va_start(voptargs,mode); > s = va_arg(voptargs, char *); > while (s) { > ... > s = va_arg(voptargs, char *); > } > va_end(voptargs); > > I searched the release notes and bugs and found this comment on the > 2.0.4 changes: > > 2011-05-14: wsfulton > %varargs when used with a numeric argument used to create an > additional argument > which was intended to provide a guaranteed sentinel value. This never > worked and now > the additional argument is not generated. > > So I tried 2.0.4 and that failed but 2.05 worked. However 2,0,6 through > 2.0.9 all failed. > > the pywrap.cxx file generated by 2.0.5 and 2.0.6 looks identical. > This is then indicative of some undefined behaviour problem possibly elsewhere else in your own code. > This issue seems to be specific to python--I did not have any issues > with the TCL generated interface. > > Is there some trick to getting %varargs with a numeric argument working > with python so that swig automatically inserts the NULL terminator? > Is this a known bug? I couldn't find it in the list of open/closed bugs. > Have you read the most up to date documentation, currently at http://www.swig.org/Doc2.0/Varargs.html#Varargs_nn5. In particular are you using the "compactdefaultargs" feature? Please provide a small cutdown test case of your issue if the above information doesn't help. William |