Discussion:
Returning an array reference or nothing
(too old to reply)
Florian Weimer
2010-06-07 08:43:10 UTC
Permalink
Is the following the correct code sequence to return an array
reference or nothing (if result is 0) from an XS function?

PPCODE:
AV *result = 0;
if (some_condition) {
result = newAV();
av_push(result, some_value);
}
if (result) {
EXTEND(SP, 1);
PUSHs(newRV_inc((SV*)result));
}

It's not mentioned in perlxs, but some CPAN modules seem to use this.
--
Florian Weimer <***@bfk.de>
BFK edv-consulting GmbH http://www.bfk.de/
Kriegsstraße 100 tel: +49-721-96201-1
D-76133 Karlsruhe fax: +49-721-96201-99
Torsten Schoenfeld
2010-06-07 18:31:29 UTC
Permalink
Post by Florian Weimer
Is the following the correct code sequence to return an array
reference or nothing (if result is 0) from an XS function?
AV *result = 0;
if (some_condition) {
result = newAV();
av_push(result, some_value);
}
if (result) {
EXTEND(SP, 1);
PUSHs(newRV_inc((SV*)result));
}
It's not mentioned in perlxs, but some CPAN modules seem to use this.
Looks correct, yes. And it does appear in `perldoc perlxs'; look under
"Returning Undef And Empty Lists".

Loading...