logo       

Re: AW: typemaps for python lists (double,int) as function arguments: msg#00186

programming.swig

Subject: Re: AW: typemaps for python lists (double,int) as function arguments

At 01:45 PM 1/31/03 +0000, Marcus Stojek wrote:
In reality I am using the (double*, int size) solution right now. And I
was just reading the chapter of the doc you referred to :-)

Well, great minds think alike :)

In "real" reality my funcitons look like:

calc(double*, int size, double*, int size, double*, int size)

with the first two lists going in and the last storing the result.
For other functions the number of in and out list changes and some
additional parameters are passed in.

So would you suggest writing a single typemap for each function, maybe
using the parameter names explicitly? Or is there a smarter solution.

No, there's no need to write a typemap for each function. If you write one for (double*, int), it will be applied to each such couple of arguments in your functions.


For the outgoing list I guess I have to use an (argout) typemap that will
create Pythonlist for me.

Yes, I think so---even though I didn't have to wrap such functions myself, so I don't have first-hand experience.

The only way I found for doing this is PyList_New and a PyList_Append loop. Isn't that awfully slow?

Probably. It might help to use PyList_New(size) and PyList_SetItem(list,i,obj) instead of PyList_Append---this way you allocate just once.

Bye,
Luigi

_______________________________________________
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