perl データ構造を使用しようとしています (部分的には C で連想配列をサポートする方法として) が、次のプログラムがクラッシュし続けます。正常にコンパイルされますが、newSVpv() の行でクラッシュします。理由がわからない。
#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;
}
それをコンパイルする行は
gcc -g -o interp te1.c `perl -MExtUtils::Embed -e ccopts -e ldopts`
私が持っている perl は、Ubuntu 12.04.4 LTS で実行されている 5.14.2 です。
ヒントをありがとう!
更新: gdb トレースを追加しました。質問してくれてありがとう。gdb トレース:
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)