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

Hi , I am using a sample code provided in C for embedding perl interpreter
/////////////////////////////////////////// static void call_Subtract(a, b) int a; int b; { dSP; int count; ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSViv(a))); XPUSHs(sv_2mortal(newSViv(b))); PUTBACK; printf("PL_errgv2 = %p\n", PL_errgv); //count = call_pv("Subtract", G_EVAL|G_SCALAR); count = call_pv("Subtract", G_SCALAR); SPAGAIN; printf("PL_errgv3 = %p\n", PL_errgv); /* Check the eval first */ if (SvTRUE(ERRSV)) //crashes here { STRLEN n_a; printf ("Uh oh - %s\n", SvPV(ERRSV, n_a)); POPs; } /* else { if (count != 1) croak("call_Subtract: wanted 1 value from 'Subtract', g +ot %d\n", count); printf ("%d - %d = %d\n", a, b, POPi); }*/ PUTBACK; FREETMPS; LEAVE; } 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 ); printf("PL_errgv1 = %p\n", PL_errgv); perl_parse(my_perl, NULL, 2, my_argv, (char **)NULL); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; perl_run(my_perl); call_Subtract(10,5); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }

I am using the VC 2005 form tetsing the code. This code works fine for Perl 5.8. But it crashes for perl 5.10.

Please help.
Best Regards
Manoj

Replies are listed 'Best First'.
Re: SvTRUE(ERRSV) crsahes in Perl 5.10
by roboticus (Chancellor) on Nov 11, 2010 at 12:18 UTC

    mcalsuca:

    If you had actual information on the error[1] in your post, perhaps someone could point you to the error. As it is, someone would have to download your code, build the project and compile it themselves to see the error message(s) that you should have provided.

    I'm not that motivated to go downstairs and fire up the windows box to give it a try.

    Please update your node and give some more details...

    Notes:

    [1] Including compiler messages, linker messages, messages while executing the code, stack dumps, etc. can be pretty helpful for remote diagnosis of problems...

    ...roboticus

Re: SvTRUE(ERRSV) crsahes in Perl 5.10
by syphilis (Archbishop) on Nov 12, 2010 at 06:44 UTC
    You can use inline::C to provide test/demo scripts that we can all run (if Inline::C is installed).
    The following runs fine for me on both perl-5.8.9 and perl-5.10. Do you still get the crash ?
    use warnings; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'EOC'; void call_Subtract(int a , int b) { dSP; int count; ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSViv(a))); XPUSHs(sv_2mortal(newSViv(b))); PUTBACK; printf("PL_errgv2 = %p\n", PL_errgv); //count = call_pv("Subtract", G_EVAL|G_SCALAR); count = call_pv("Subtract", G_SCALAR); SPAGAIN; printf("PL_errgv3 = %p\n", PL_errgv); /* Check the eval first */ if (SvTRUE(ERRSV)) /* crashes here */ { STRLEN n_a; printf ("Uh oh - %s\n", SvPV(ERRSV, n_a)); POPs; } else { if (count != 1) croak("call_Subtract: wanted 1 value from 'Subtract', g +ot %d\n", count); printf ("%d - %d = %d\n", a, b, POPi); } PUTBACK; FREETMPS; LEAVE; } EOC call_Subtract(25, 12); sub Subtract { my $ret = $_[0] - $_[1]; return $ret; }
    It ouptuts, for me:
    PL_errgv2 = 002E3F20 PL_errgv3 = 002E3F20 25 - 12 = 13
    Cheers,
    Rob
      Hi , Thanks for the replies
      Just like to mention , i am using VC8 (VC2005) compiler then it crashes
      --------------------------- perl10.exe - Application Error --------------------------- The exception unknown software exception (0xc0000005) occurred in the application at location 0x00401064. Click on OK to terminate the program Click on CANCEL to debug the program --------------------------- OK Cancel ---------------------------
      But this works fine for VC6 compiler.
      And it crashes at the if (SvTRUE(ERRSV)) line.
      Please help
      Best Regards Manoj
        Google produces lots (probably far too many) of hits for '0xc0000005'.

        My best guess is that afoken's post is closest to the mark.

        That is, you've come up against some sort of wtf - probably a handle allocated by msvcr80.dll is passed to msvcrt.dll, and msvcrt.dll doesn't know what to do with this handle (... nor should it).

        Cheers,
        Rob
Re: SvTRUE(ERRSV) crsahes in Perl 5.10
by afoken (Chancellor) on Nov 11, 2010 at 15:59 UTC
    I am using the VC 2005 form tetsing the code. This code works fine for Perl 5.8. But it crashes for perl 5.10.

    Are you sure both perls were compiled using VC 2005? As far as I know, very ugly things can happen to perl when you mix compilers and linkers. If you want to play safe, use the compiler, linker, and make utility that were used to compile perl.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)