I need the first option.

Then do_nothing1() below will get you started:

#! perl -slw use strict; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'END_C', NAME => '_1159002', CLEAN_AFTER_BUILD => 0 +; #define IS_VARS Inline_Stack_Vars #define IS_RESET Inline_Stack_Reset #define IS_ITEMS Inline_Stack_Items #define IS_ITEM( n ) Inline_Stack_Item( n ) #define IS_PUSHS( s ) Inline_Stack_Push( sv_2mortal( s ) ) #define IS_PUSHIV( iv ) Inline_Stack_Push( sv_2mortal( newSViv( iv ) ) + ) #define IS_PUSHUV( uv ) Inline_Stack_Push( sv_2mortal( newSVuv( uv ) ) + ) #define IS_PUSHNV( nv ) Inline_Stack_Push( sv_2mortal( newSVnv( nv ) ) + ) #define IS_DONE Inline_Stack_Done double do_nothing1( AV *x, int sizeOfX ) { int index; for( index=0; index<sizeOfX; index++ ) { av_store( x, index, newSVnv( 1.0 ) ); } return SvNV( *av_fetch( x, 0, NULL ) ); } void do_nothing2( AV *a, SV *size ) { IS_VARS; int index; IS_RESET; for( index = 0; index < SvIV( size ); ++index ) { IS_PUSHNV( 1.0 ); } IS_DONE; } void do_nothing3( SV*dummy, ... ) { IS_VARS; int index; for( index = 0; index < IS_ITEMS; ++index ) { IS_ITEM( index ) = newSVnv( 1.0 ); } return; } AV *do_nothing4( AV *x ) { IS_VARS; AV *r = newAV(); int index; for( index = 0; index < IS_ITEMS; ++index ) { av_push( r, newSVnv( SvNV( *av_fetch( x, index, NULL ) ) + 1.0 + ) ); } return r; } END_C my @a = ( 0 ) x 10; print do_nothing1( \@a, 10 ); print "@a"; my @b = ( 0 ) x 10; print join ' ', do_nothing2( \@b, 10 ); print join ' ', do_nothing3( 1 .. 10 ); my @c = ( 1 .. 10 ); print join ' ', do_nothing4( \@c );

If you have Inline::C installed and you run the above code you'll get this output:

C:\test>1159002.pl 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

If you then look in the _inline directory tree created below the cwd where you run this, and look for the file _Inline/build/_1159002/_1159002.xs you'll see how it all fits together:


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
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". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^3: perl XS - passing array to C and getting it back by BrowserUk
in thread perl XS - passing array to C and getting it back by kopolov

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.