I am trying to build a embedded Perl interpreter in a C application in a non-persistent manner. The example code below works fine with a simple Perl script. If I add "use Tk;" to the simple script, it will get executed once and die the second time on the perl_parse call. I have tried this on LINUX, Windows XP, VMS, and HP-UX with the same results. What have I done wrong?
#include <EXTERN.h>
#include <perl.h>
#include <stdio.h>
static void xs_init (pTHX);
EXTERN_C void xs_init (pTHX);
EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
EXTERN_C void boot_Win32CORE (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);
newXS("Win32CORE::bootstrap", boot_Win32CORE, file);
}
#define BUFFER_SIZE 1024
static PerlInterpreter *my_perl = NULL;
STRLEN n_a;
int
main()
{
char plfile [BUFFER_SIZE];
char *embedding [] = { "", plfile };
int exitstatus = 0;
int stripchars = 1;
while(printf("Enter file name: ") &&
fgets(plfile, BUFFER_SIZE, stdin)) {
plfile[strlen(plfile) - stripchars] = '\0'; /* strip \n */
if ((my_perl = perl_alloc()) == NULL) {
fprintf (stderr, "no memory!");
exit (1);
}
PL_perl_destruct_level = 2;
perl_construct (my_perl);
exitstatus = perl_parse (my_perl, xs_init, 2, embedding, NULL);
if (!exitstatus) {
exitstatus = perl_run (my_perl);
}
PL_perl_destruct_level = 2;
perl_destruct (my_perl);
PL_perl_destruct_level = 2;
perl_free (my_perl);
stripchars = 2;
}
exit (exitstatus);
}
Thanks,
Randy
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.