http://qs1969.pair.com?node_id=518299

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

Hi monks,

There is section called "Fiddling with the Perl stack from your C program" in perlembed. In it there is a perl code for integer exponentiation which is called from C function. Actually that code works pretty fine.
My doubt is that when i just added use DBI; to the perl code and exectuted the C code i am getting error
free(): invalid pointer 0x804c6b8!
How could i avoid it. I am also getting this error in some other programs also. The C code and perl code are given below
#include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; EXTERN_C void boot_DynaLoader (pTHX_ CV* cv); EXTERN_C void xs_init(pTHX) { char *file = __FILE__; dXSUB_SYS; /* DynaLoader is a special case */ newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); } static void PerlPower(int a, int b) { dSP; ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSViv(a))); XPUSHs(sv_2mortal(newSViv(b))); PUTBACK; call_pv("expo", G_SCALAR); SPAGAIN; printf ("%d\n", POPi); PUTBACK; FREETMPS; LEAVE; } int main (int argc, char **argv, char **env) { char *my_argv[] = { "", "power.pl" }; my_perl = perl_alloc(); perl_construct( my_perl ); perl_parse(my_perl, xs_init, 2, my_argv, (char **)NULL); perl_run(my_perl); PerlPower(3, 4); perl_destruct(my_perl); perl_free(my_perl); }

PERL FILE
use DBI; sub expo { my ($a, $b) = @_; return $a ** $b; }

You could ask what is the use of "use DBI" ? The reason is i am getting this error in some other files also and also out of curiosity.Could any one find the reason for the error message

Thanks
Kiran