Vivek Dasmohapatra <[EMAIL PROTECTED]> writes:
>Hi - I'm trying to write an XS Function which returns a list of values:
>Following the examples in the perlxs/perlguts/perlxstut pages, I tried:
>
>void
>j_random_ids(zp, ...)
> J_Random * zp
> PREINIT:
> int i;
> int j;
> int p;
> int n = 0;
> PPCODE:
>
> [ some code to mangle some data structures here
> and put the number of return values in n ]
>
> if( zp->id[ID_OVERFLOW] )
> {
> XSRETURN_EMPTY;
> }
> else
> {
> EXTEND( SP, n );
> for(i = 0; i < MAX_IDS; i++)
> {
> if(zp->id[i]) { PUSHi(i); }
> }
> }
>
>I've also tried:
>
> else
> {
> for(i = 0; i < MAX_IDS; i++)
> {
> if(zp->id[i]) { XPUSHi(i); }
> }
> }
PUSHi() and XPUSHi() are weird internal macros which use the 'target'
of the current "op". They are not really suitable for use in XS code.
Saddly you need something like:
XPUSHs(sv_2mortal(newSViv((IV) i)));
If you do use EXTEND() then your 'n' should match the number of things
you are going to push - your code has 'n' in one place and
perhaps MAX_IDS in the other.
--
Nick Ing-Simmons
who is looking for a new job see http://www.ni-s.u-net.com/