Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Ellipsis in perl XS

by rafl (Friar)
on Sep 04, 2006 at 22:32 UTC ( #571162=note: print w/ replies, xml ) Need Help??


in reply to Ellipsis in perl XS

That's exactly right.

If you want to pass a list of objects (let's say pointers of type foo*) that require a typemap you usually create a typemap that simply calls a function (let's say SvFoo()) to convert a foo pointer to an SV:

TYPEMAP foo* T_FOO INPUT T_FOO $var = ($type)SvFoo($var);

And in your XS code do:

void my_xsub(...) PREINIT: int i; foo **foos = NULL; CODE: foos = (foo**)malloc(sizeof(foo*) * items); for (i = 0; i < items; i++) { foos[i] = SvFoo(ST(i)); } # do something with foos

Now the only thing you need to do is to define a SvFoo function which might look like that:

foo* SvFoo(SV* foo) { SV* ret; IV tmp = SvIV((SV*)SvRV(foo)); ret = INT2PTR(foo*, tmp); }

Cheers, Flo


Comment on Re: Ellipsis in perl XS
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://571162]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2015-07-28 22:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls