in reply to Re^2: perl xs pass an array by reference
in thread perl xs pass an array by reference
will never work. Is your XS code for yourself, or it is for others to see and use?return para[1]
then$str = pack('ddd', 1.0, 1.1, 1.3);
then after the XS call in perlvoid func(doublearrsv) SV * doublearrsv PREINIT: STRLEN len; double (*doublearr)[3];//I hope this works CODE: doublearr = SvPV(doublearrsv, len);//cast warning here if(len != sizeof(*doublearr)) croak("bad len"); do_nothing(&doublearr[2]); //THIS WILL UPDATE IN PERL LAND
An array of arrays, "$array13", is a SV reference to an AV, and each slice of the AV is a SV reference to another AV, which contains non reference SVs. Since you used AV * as a XS syntax prototype, the first SV reference you didn't see and it was automated away for you. If you do@array = unpack('ddd', $str);
then you didn't get an AV or a SV reference. You would need a vararg XSUB.@arr = ([11,12,13], [21,22,23], [31,32,33]); myxsub(@arr);
All code untested.void myxsub(...) PREINIT: int i; CODE: for(i=0; i< items; i++){ SV * sv = ST(i); //do something }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: perl xs pass an array by reference
by andromedia33 (Novice) on Dec 31, 2012 at 19:18 UTC |