C program continues to crash when calling perl function newSVpv ()

Trying to use the perl data structure (partly as a way to support an associative array in C), but the following program continues to crash. It compiles fine, but there will be a crash on the line using newSVpv (). I do not know why.

#include <EXTERN.h>               /* from the Perl distribution     */
#include <perl.h>                 /* from the Perl distribution     */
static PerlInterpreter *my_perl;  /***    The Perl interpreter    ***/
int main(int argc, char **argv, char **env) {
    char *proto = "http";
    SV* ret = newSVpv("http", 4);
    sv_catpvn(ret, "://", 3);
    STRLEN len = 1;
    char *result = SvPV(ret, len);
    printf("result: %p %d\n", result, len);
    return 0;
}

The string to compile is -

gcc -g -o interp te1.c `perl -MExtUtils::Embed -e ccopts -e ldopts`

Perl I have 5.14.2 running on Ubuntu 12.04.4 LTS.

Thanks for any tips!

UPDATE: added gdb trace. Thanks for the question. gdb trace:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b235a6 in Perl_newSVpv () from /usr/lib/libperl.so.5.14
(gdb) bt
#0  0x00007ffff7b235a6 in Perl_newSVpv () from /usr/lib/libperl.so.5.14
#1  0x0000000000400927 in main (argc=1, argv=0x7fffffffe1e8, 
    env=0x7fffffffe1f8) at te1.c:7
(gdb) 
+4
source share
1 answer

C Perl, Perl C, , , PERL_SYS_INIT3, perl_alloc perl_construct perlembed example, perl . newSVpv , - .

(perl_destruct, perl_free PERL_SYS_TERM) .

+7

All Articles