I'm trying to access a list of arrays from IC, but I'm walking off the end of the data. Not too surprising as I'm getting the third element instead of the first, but I'm damned if I can see why that is? Cluebats anyone?

#! perl -sw use 5.010; use strict; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'END_C', NAME => 'LoA', CLEAN_AFTER_BUILD => 0; #include <stdarg.h> SV *test( SV *dummy, ... ) { Inline_Stack_Vars; int i; int n = Inline_Stack_Items; printf( "Got %d items\n", n ); for( i = 0; i < n; ++i ) { int j; SV *sv = Inline_Stack_Item( i ); AV *av = (AV *)SvRV( sv ); if( !SvROK( sv ) || SvTYPE( SvRV( sv ) ) != SVt_PVAV ) croak( "Requires a list of array refs (%d => type %d)\n", i, SvTYPE( SvRV( sv ) ) ); printf( "Item %d has %d elements\n", i, av_len( av ) ); for( j = 0; j <= av_len( av ); ++j ) { SV *sv2 = (SV*)av_fetch( av, j, 0 ); printf( "[%d][%d] %x %d '%s'\n", i, j, sv2, SvTYPE( sv2 ), SvPVX( SvRV( sv2 ) ) ); } } printf( "here\n" ); Inline_Stack_Reset; return &PL_sv_yes; } END_C use Data::Dump qw[ pp ]; my @a = map [ 'A' .. 'J' ], 1 .. 5; pp \@a; test( @a ); __END__ __OUPUT__ [ 0:58:24.60] C:\test>IC-LoA.pl [ ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"], ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"], ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"], ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"], ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"], ] Got 5 items Item 0 has 9 elements [0][0] 3b27918 0 'C' [0][1] 3b27920 0 'D' [0][2] 3b27928 0 'E' [0][3] 3b27930 0 'F' [0][4] 3b27938 0 'G' [0][5] 3b27940 0 'H' [0][6] 3b27948 0 'I' [0][7] 3b27950 0 'J' segfault:Memory violation.

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to LoA from XS by BrowserUk

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.