develooper Front page | perl.perl5.porters | Postings from December 1999

Returning An Array from an Extension

Aby Paul
December 8, 1999 02:28
Returning An Array from an Extension
Message ID:

I have the following code snippet which should return an array. This doesn't seem to work. 
Could someone tell me what is wrong in this code?

SV *retsv=NULL;
AV *av;
int i = 5;
av = newAV();
retsv = newRV(sv_2mortal((SV*)av));
while(--i >= 0) 
  av_store(av, i, newSViv(i));


When called from the script, the length is always returned as 1. But I am unable to see the contents. When @x and $z = $x[0] are
printed, it shows nothing.

If I replace 
ST(2)=sv_2mortal(retsv); with sv_setsv(ST(returnIndex),sv_2mortal(retsv));
then I get ARRAY(0x....) for @x and "01234" for $z = $x[0] from the script.
Aby Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About