slim has asked for the wisdom of the Perl Monks concerning the following question:

Wise monks, what could be wrong in:
for $i (1..100) { $r=C($i); print $r."\n" } use Inline C => <<'C_CODE'; int C (int i) { Inline_Stack_Vars; return i; Inline_Stack_Void; } C_CODE
to produce:
... 94 95 96 97 98 99 100 Segmentation fault
I have also tryied the following version of C_CODE:
SV* C (SV* param) { Inline_Stack_Vars; int i = atoi(SvPV(Inline_Stack_Item(0), PL_na)); return newSVpvf("%i",i); Inline_Stack_Void; }
getting:
1 0 0 Segmentation fault
But if I declare SV* C (SV* param,...) it seems to work...

Replies are listed 'Best First'.
Re: Inline::C parameters
by dbp (Pilgrim) on Feb 24, 2003 at 01:37 UTC
    Without looking at your code too carfully, I notice that you're trying to do something after the return in your C function. Inline_Stack_Void won't be called; could this be causing your segfault?
      Take a look at the Inline C Cookbook section on variable argument lists. The link above should take you to the correct anchor. You're going to have undefined behavior if you use Inline_Stack_Vars in functions that don't have variable length arg lists.