in reply to Config Module for C and Perl

Follow the first rule of C - always check your return values! I suspect that either get_sv() or SvPV_nolen is returning NULL. Trying to dereference a NULL pointer is a great way to get a Segmentation Fault.

As to why they'd return NULL, my guess is it's because you're not loading the MyConfig module. Try something like this before trying to fetch the variable:

  eval_pv("use MyConfig", 1);

-sam

Replies are listed 'Best First'.
Re^2: Config Module for C and Perl
by Neal_the_real (Initiate) on Feb 21, 2006 at 08:41 UTC
    Hello samtregar. Your suggestion was a step in the right way. But there was also a few lines lacking for the perl-allocation. Now, I can represent a working C code.
    #include <stdio.h> #include <stdlib.h> #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; int main(void) { char *var; char *embedding[] = {"", "-e", "0"}; my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, 3, embedding, NULL); perl_run(my_perl); eval_pv("use MyConfig", TRUE); var = SvPV_nolen(get_sv("MyConfig::var", TRUE)); printf(">%s<\n", var); return(EXIT_SUCCESS); }
Re^2: Config Module for C and Perl
by Neal_the_real (Initiate) on Feb 21, 2006 at 08:44 UTC
    Hello samtregar.

    Your suggestion was a step in the right way. But there was also a few lines lacking for the perl-allocation. Now, I can represent a working C code.

    #include <stdio.h> #include <stdlib.h> #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; int main(void) { char *var; char *embedding[] = {"", "-e", "0"}; my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, 3, embedding, NULL); perl_run(my_perl); eval_pv("use MyConfig", TRUE); var = SvPV_nolen(get_sv("MyConfig::var", TRUE)); printf(">%s<\n", var); return(EXIT_SUCCESS); }