note
syphilis
Hi,<br><br>
With the code you posted, I too get a crash on latest Strawberry Perl (5.18.2).
<br>By inserting a couple of debug printf() statements, I found that it crashed when perl_parse() was executed. Same for you ?
<br><br>However, there's a very similar example given in Strawberry Perl's perlembed (perldoc perlembed) documentation:
<c>
#include <EXTERN.h>
#include <perl.h>
static PerlInterpreter *my_perl;
static void
PerlPower(int a, int b)
{
dSP; /* initialize stack pointer */
ENTER; /* everything created after here */
SAVETMPS; /* ...is a temporary variable. */
PUSHMARK(SP); /* remember the stack pointer */
XPUSHs(sv_2mortal(newSViv(a))); /* push the base onto the stack */
XPUSHs(sv_2mortal(newSViv(b))); /* push the exponent onto stack */
PUTBACK; /* make local stack pointer global */
call_pv("expo", G_SCALAR); /* call the function */
SPAGAIN; /* refresh stack pointer */
/* pop the return value from stack */
printf ("%d to the %dth power is %d.\n", a, b, POPi);
PUTBACK;
FREETMPS; /* free that return value */
LEAVE; /* ...and the XPUSHed "mortal" args.*/
}
int main (int argc, char **argv, char **env)
{
char *my_argv[] = { "", "power.pl" };
PERL_SYS_INIT3(&argc,&argv,&env);
my_perl = perl_alloc();
perl_construct( my_perl );
perl_parse(my_perl, NULL, 2, my_argv, (char **)NULL);
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
perl_run(my_perl);
PerlPower(3, 4); /*** Compute 3 ** 4 ***/
perl_destruct(my_perl);
perl_free(my_perl);
PERL_SYS_TERM();
}
</c>
With the file "power.pl" that contains:
<c>
sub expo {
my ($a, $b) = @_;
return $a ** $b;
}
</c>
That example works fine, for me.<br>
By working through the differences, you should be able to determine the reason(s) that one works, but the other doesn't.
<br>(I'm assuming the version provided by the Strawberry docs works for you.)
<br><br>Cheers,<br>Rob
1074459
1074459