Can anyone tell me why this XS routine returns my RETVAL with one extra depth of array refs?
#include <sys/types.h> #include <dirent.h> #include <stdio.h> SV * readdir_inode(dirname) char* dirname INIT: struct dirent *ent; DIR* dir; SV* record[2]; AV *entry, *ret_val; CODE: ret_val = newAV(); dir = opendir(dirname); if (!dir) perror("Cannot open dir"); while ((ent=readdir(dir))) { record[0] = newSVpv(ent->d_name, 0); record[1] = newSViv((IV)ent->d_ino); entry = av_make(2, record); av_push(ret_val, newRV_inc((SV*) entry)); } closedir(dir); RETVAL=newRV_inc((SV*) ret_val); OUTPUT: RETVAL
That is, I'm getting a structure like this:
$VAR1 = [ [ [ '.', 67586 ], [ '..', 255604 ], ...
Instead of something like this:
$VAR1 = [ [ '.', 67586 ], [ '..', 255604 ], ...
Any ideas why, anyone?
Also, does anyone know of a better way of saying "or die "Can't opendir $file; $!"" (or should I bother? perhaps just return undef and let the caller check $!)
In reply to XS routine returns an extra depth of array refs by mugwumpjism
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |