Working on an Inline C module, and having problems appearing to be related
to array elements not being accessible after being passed in via reference.

Wrote a test program, cut and pasted mostly from this newsgroup to isolate
the problem. Program and output are as follows.  Still can't get at
individual array members.

#!/usr/bin/perl -w
use strict;

use Inline C => 'DATA';

my $a = [ 1 .. 10 ];
print "array in:    " . join(" ", @{$a}) . "\n";
dump_arrref($a);

__DATA__

__C__

void dump_arrref(SV* arrref) {
  int i, n, val;
  AV* arr;

  if (!SvROK(arrref))
      croak("dump_arrref did not receive a pointer");

  arr = SvRV(arrref);

  if (SvTYPE(arr) != SVt_PVAV)
    croak("dump_arrref did not receive a pointer to a list");

  n = av_len(arr) + 1;
  printf("array in C:  ");
  for(i = 0 ; i < n ; i++) printf("%d ", SvIVx(av_shift(arr)));
}

Executing this produces: 

% perl5.8.3 inline.pl
array in:    1 2 3 4 5 6 7 8 9 10
array in C:  0 0 0 0 0 0 0 0 0 0 

Whats strange to me is that the SvROK, SvTYPE, and av_len functions all
indicate the array is fine and as expected.  However cant get SvIVx (or
SvIV for that matter and I know it will do the shift twice if I use it) to
return the integers in the array.

Any thoughts anyone? 

Perl 5.8.3 
SunOS dna428 5.7 Generic_106541-29 sun4u sparc SUNW,Ultra-4
Inline-0.44.tar.gz
 

Reply via email to