On Fri, May 1, 2009 at 4:45 AM, Andrew Stone <g.andrew.stone@...> wrote:
> Hi SWIG users,
> I have two questions that I hope you can answer since I haven't found
> anything in the docs or the FAQ. The first is about exceptions and
> return values. My C functions return an error code and return the
> actual result via a pointer parameter.
> For example: int getData(int param, int* result);
> I have figured out how to tell SWIG that "result" is an output
> parameter, and I am checking the return code and raising a Python
> exception using the %exception construct.
> So it correctly raises the exception, however on success it STILL
> returns the error code. It returns a list [err code, result]. How
> can I tell SWIG to NOT return the C function's return code?
You can use %pythonappend to post process the return value. Just
search SWIG manual to find example for this:
> Second, I have a function like:
> typedef struct
> int a;
> int b;
> char* c;
> } MyParams;
> int getData(MyParams* param, int d);
> So MyParams is really just wrapping some function parameters into a
> structure (no, I didn't write this C code!). I'd like the Python
> function to just have a,b, and c as parameters, like this:
> So basically I want to take several python parameters and combine them
> into 1 C parameter. I have done the opposite with typemaps (taken 1
> Python parameter and converted it to several C parameters), so am
> wondering if this is possible?
I think the easiest way for this is write a helper function with (int
a, int b, char *c, int d) as signature, and let SWIG to wrap this
> Thanks for any help!
> Andrew Stone
-- Haoyu Bai