You hit the nail right on the head... I had the second, but Dumper \@a instead of Dumper $a[0], and my test code was assuming I was returning a list. Hate it when that happens ;-)

OK, so now at least I have it returning something sensible, which is always good. In which case, the question is why does this:

AV * readdir_inode(dirname) char* dirname INIT: struct dirent *ent; DIR* dir; SV* record[2]; AV *entry, *ret_val; CODE: RETVAL = newAV(); dir = opendir(dirname); if (!dir) perror("Cannot open dir"); while ((ent=readdir(dir))) { printf("%ld %x\n", ent->d_ino, ent->d_name); record[0] = newSVpv(ent->d_name, 0); record[1] = newSViv((IV)ent->d_ino); entry = av_make(2, record); av_push(RETVAL, newRV_inc((SV*) entry)); } closedir(dir); /*RETVAL=*ret_val;*/ /*RETVAL=newRV_inc((SV*) ret_val);*/ OUTPUT: RETVAL

Return an extra level of arrays?

The calling code:

my @ents = readdir_inode("."); print Dumper @ents;

The output:

$VAR1 = [ [ '.', 67586 ], [ '..', 255604
...

In reply to Re: Re: XS routine returns an extra depth of array refs by mugwumpjism
in thread XS routine returns an extra depth of array refs by mugwumpjism

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.