perlquestion
jithoosin
Hi monks,<br><br>There is section called "Fiddling with the Perl stack from your C program" in <a href="http://perldoc.perl.org/perlembed.html">perlembed</a>. In it there is a perl code for integer exponentiation which is called from C function. Actually that code works pretty fine. <br>My doubt is that when i just added <c>use DBI; </c> to the perl code and exectuted the C code i am getting error<br><c>free(): invalid pointer 0x804c6b8!</c><br>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<br><c>#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);
}
</c><br><b> PERL FILE </b><br><c>use DBI;
sub expo {
my ($a, $b) = @_;
return $a ** $b;
}
</c><br>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<br><br>
Thanks<br>
Kiran