I am trying to write an interface for a function whose signature looks like
int function(customstruct* arg)
where arg is an "output" parameter. My target language is python.
There are two issues I'm not sure how to solve:
customstruct is defined is the same header file as function, which is
included in the interface, so from Python I can create and work on
objects of type customstruct. However I don't know how to make the
wrapper return a usable python customstruct object.
The only thing I am able to do from the argout typemap is creating a
python-swig "pointer object" that is effectively useless in python as
I cannot dereference it.
My workaround for the previous problem is doing something like (from
the customstruct argout typemap):
PyObject* member_i = PySomeConverterFuction($1->member_i);
for ever member of customstruct, and then packing them in a python
tuple that I assign to $result.
However I don't know how to free the memory allocated this way. I am
confused by the various "free" typemaps and I can't understand which
one applies to this case or what I should put in them.
Thank you for your attention.
- Demetrio Girardi
From: William S Fulton <wsf@fu...> - 2009-05-18 20:40:48
Demetrio Girardi wrote:
> I am trying to write an interface for a function whose signature looks like
> int function(customstruct* arg)
> where arg is an "output" parameter. My target language is python.
You shouldn't have to do anything. Just create a customstruct in Python,
pass it to function and any modifications that the C++ layer does to
this instance will be viewable from Python.