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");
 vector_length = av_len(array) + 1;
 printf("vector_length %d\n", vector_length);
 for (i = 0; i < vector_length; i++) {
   svp = av_fetch(array, i, 0);
   if (SvOK(*svp))
    printf("element SvOK\n");
   printf("element %d: %d\n", i, SvIV(*svp));
 }
}

which prints:

array reference
vector_length 2
element 0: 0
Segmentation fault (core dumped)

Can anyone spot my mistake? Obviously vector_length should be 3, so it
is something fairly fundamental I am missing.

Thanks

Jeff

Reply via email to