Tugger the SLUGger!SLUG Mailing List Archives

[SLUG] segfault setting perl variables in C code


ok perl gurus:

I have a C program that starts a perl interpreter and runs
a perl script using perl_alloc, construct, parse and finally
perl_run.  I'm trying to set a perl variable in the C code
before starting the perl script.  This variable is then
accessible from the perl script.  That's the idea anyway.

I reckon it should be possible using something like either
of these (from reading 'man perlguts'):

SV *sv = newSVpv("MYID", 4);

or:

SV *sv = get_sv("MYID", TRUE|GV_ADDMULTI);
sv_setpv(sv, 42);
SvPOK_on(sv);

But either way just segfaults on the first call.

Do I have the wrong end of the stick about how this is supposed
to work?  Any ideas?

thanks,
Dave.