|
Re: naive question about passing in a NULL via Python: msg#00187programming.swig
Scott Koranda wrote: > Suppose I have this simple C function declaration: > > void myfunc(char *mystring); ... > What is the most "elegant", "easy" and "proper SWIG" way to have this > function wrapped so that in Python I can simply do > > import mymodule > mymodule.myfunc(<something>) > > and have the C code called with mystring == NULL? > > I think it would be "natural" to call in Python > > mymodule.myfunc(None) The default string typemap isn't doing everything that you want. Try the following in your .i file: %module module %typemap(in) char * { if ($input == Py_None) { $1 = NULL; } else if (PyString_Check($input)) { $1 = PyString_AsString($input); } else { SWIG_fail; } } void myfunc(char *mystring); Then module.myfunc(None) and module.myfunc("string") will act as you expect. -Jerry _______________________________________________ Swig maillist - Swig@xxxxxxxxxxxxxxx http://mailman.cs.uchicago.edu/mailman/listinfo/swig |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: AW: typemaps for python lists (double,int) as function arguments: 00187, Luigi Ballabio |
|---|---|
| Next by Date: | __swig__slots__ on shadowed Python classes?: 00187, Lars Immisch |
| Previous by Thread: | Re: AW: typemaps for python lists (double,int) as function argumentsi: 00187, Luigi Ballabio |
| Next by Thread: | [Newbie]:swig wrappers for bootstrapped classes: 00187, Sharma K M |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |