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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.