logo       

Re: Overriding PyArg_ParseTuple arguments: msg#00152

programming.swig

Subject: Re: Overriding PyArg_ParseTuple arguments


On Nov 25, 2003, at 10:13 PM, Tessa Lau wrote:

I'm SWIGging a C library into Python that does a lot of string handling.
One of the functions takes a char * argument, which can be NULL (to get
the default behavior).

If I don't do anything special in my SWIG wrapper, when I try to call
this function with a None argument, I get a TypeError saying the
argument must be a string, not None.

I know that Python's PyArg_ParseTuple function supports the "z" format
character, which converts a Python string into a char *, and converts
Python None into NULL. This functionality has been part of Python since
1.5.2. Yet I don't see any way to achieve this behavior in SWIG except
by using a typemap to explicitly check for PyNone.

Is there any way to override the automatically generated
PyArg_ParseTuple arguments in order to get this behavior?


%typemap(in,parse="z") char * "";

-- Dave

_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise