raf has asked for the wisdom of the Perl Monks concerning the following question:

Hi, i'm getting into perl and xs, little example work fine, what i'm trying to do is use the festival api in perl, but the program go in segmentation fault every time i run it. Here follow some code, sure someone else can find some mistake that i didn't see :) The xs file...
...... #include <festival/festival.h> MODULE = festival_test PACKAGE = festival_test void initialize(load_init_file,heap_size) int load_init_file int heap_size CODE: festival_initialize(load_init_file,heap_size); .......
The Makefile.PL
$CC='g++'; WriteMakefile( NAME => 'festival_test', VERSION_FROM => 'lib/festival_test.pm', # finds $VERSION PREREQ_PM => {}, ($] >= 5.005 ? (ABSTRACT_FROM => 'lib/festival_test.pm', AUTHOR => 'A. U. Thor <spike@(none)>') : ()), LIBS => ['-L/usr/lib -lFestival -lestools -lestbase - +leststring -lncurses '], DEFINE => '', INC => '-I. -I/usr/include/speech-tools/', 'CC' => $CC, 'LD' => '$(CC)', );
Two line of perl to use this...
use ExtUtils::testlib; use festival_test; print "\nWrite something you want to be read from me: "; $txt=<>; festival_test::initialize(1,210000);
The segmentation fault come on the initialize call, using perl -d, it just freeze. Suggestions, corrections?, thanks

Replies are listed 'Best First'.
Re: Segfault when using Festival library from XS
by Anonymous Monk on Jul 21, 2008 at 10:31 UTC
      if i understand you say to test the library first, right? I' ve already written a simple c++ class for use the library, a TTS.h, TTS.cpp and a main.c file in which i create a TTS object and call the 'speak' method, i got no problem, it work fine. I've written a little Makefile to simplify the compilation
      #Makefile for TTS VERSION = 0.1 CC = g++ ISEARCHDIR = -I/usr/include/speech-tools/ -I /usr/include/ LSEARCHDIR = -L. -L/usr/lib/ OPTIMIZE = -O3 -s -fomit-frame-pointer CFLAGS = $(DEFINES) $(OPTIMIZE) LFLAGS = -lFestival -lestools -lestbase -leststring -lncurses PROGS = FestivalExposure PROGS_O = TTS.o OBJ_SO = TTS.so all : objs progs progs : $(CC) main.c $(PROGS_O) $(LSEARCHDIR) $(LFLAGS) -o $(PROGS) objs : $(CC) TTS.cpp $(ISEARCHDIR) -c sobjs : $(CC) TTS.cpp $(ISEARCHDIR) $(LSEARCHDIR) $(LFLAGS) --shared - +o $(OBJ_SO) provaOBJ : $(CC) TTS.cpp $(ISEARCHDIR) $(LSEARCHDIR) $(LFLAGS) -o $(PROGS +_O) clean : cleanbin rm -f *.o *~ cleanbin : rm -f $(PROGS)
      Tonight i'll try xs with the TTS class, writing the typemap, etc... P.S.: sorry the my english
Re: Segfault when using Festival library from XS
by Anonymous Monk on Jul 21, 2008 at 10:51 UTC
    Maybe add
    CODE: warn("Cheese file(%s) size(%s)", load_init_file, heap_size); festival_initialize(load_init_file,heap_size);
      nothing to do with the add, but thanks or the suggestion.
      I've done another test too, with a simple c++ class that wrap the festival API, same behavior, it give up with a segmentation fault. I'm starting to think that the problem is not my xs code, i got segmentation fault even with the Speech::eSpeak module.
      I'll investigate that.