On Fri, Oct 24, 2008 at 09:03:42PM +0200, Jeffrey Ratcliffe wrote: > I seem to be having trouble with an array reference in my xs module. > I've hacked up a simple example using inline c: > > #!/usr/bin/perl > > use Inline C; > > my @array = ( 3, 2, 1 ); > print_array([EMAIL PROTECTED]); > > __END__ > __C__ > void print_array(SV * array) { > int i, vector_length = 0; > SV ** svp; > > if (SvROK(array) && SvTYPE(SvRV(array)) == SVt_PVAV) > printf("array reference\n");
Indeed, array reference, not array. So here: > vector_length = av_len(array) + 1; you need vector_length = av_len(SvRV(array)) + 1; > printf("vector_length %d\n", vector_length); > for (i = 0; i < vector_length; i++) { > svp = av_fetch(array, i, 0); svp = av_fetch(SvRV(array), i, 0); > if (SvOK(*svp)) > printf("element SvOK\n"); > printf("element %d: %d\n", i, SvIV(*svp)); > } > } with the obvious refactoring to do the SvRV(...) only once, and store the result locally. Nicholas Clark