[Swig-user] swig and segfault

10 views
Skip to first unread message

Michelangelo Rodriguez

unread,
Mar 20, 2012, 4:19:08 AM3/20/12
to swig-user
Hi all,
I'm a newbye with swig.
I'm trying to wrap my c++ code in python, but when i refer to a library
function, in this case lame, python goes into segfault.
How ken i to investigate the problem?
Someone have a tip?
Thanks to all and regards.
M

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Swig-user mailing list
Swig...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user

David Froger

unread,
Mar 20, 2012, 5:42:09 AM3/20/12
to swig-user
Excerpts from Michelangelo Rodriguez's message of mar. mars 20 09:19:08 +0100 2012:

> Hi all,
> I'm a newbye with swig.
> I'm trying to wrap my c++ code in python, but when i refer to a library
> function, in this case lame, python goes into segfault.
> How ken i to investigate the problem?
> Someone have a tip?
> Thanks to all and regards.
> M
>


Hi Rodriguez,

What are the type of the function arguments? Could it be because the function
expects a argument that points to allocated memory, but the argument you pass
points to not allocated memory, or a vector that is not long enough, or
something like that?

I've tried to configure and use valgrind and gdb to debug segfault in Python
extension, but currently I still find that the best method is to reduce the bugged
code to the smallest pieces of code and investigate it. I would be interessed to
know if people use gdb or valgrind to debug segfault in Python extension.

Best,
David

Michelangelo Rodriguez

unread,
Mar 20, 2012, 6:16:51 AM3/20/12
to swig-user

On Tue, 20 Mar 2012, David Froger wrote:

>>
>
>
> Hi Rodriguez,
>
> What are the type of the function arguments? Could it be because the function
> expects a argument that points to allocated memory, but the argument you pass
> points to not allocated memory, or a vector that is not long enough, or
> something like that?

Hi Roger,
The C code works properly.
The problem lives in the module swig generates.
Maybe i have to take some cautions for the code that i would to use with
swig?
Thamks.
M

David Froger

unread,
Mar 20, 2012, 11:05:28 AM3/20/12
to swig-user
> Maybe i have to take some cautions for the code that i would to use with
> swig?

Could you post the C function prototype you're wrapping and your Swig file? What
is the target language?

Michelangelo Rodriguez

unread,
Mar 20, 2012, 4:06:56 PM3/20/12
to swig-user
The target language is python.
Here is the code you have requested:
Thanks again!
**code**
%module speech
%{
#define true 1
#define false 0
#define bool short
#include "speech.h"
%}
#define SPEECH_PROGRAM 0
#define SPEECH_CONVERT 1
%include "gtr.h"
typedef enum
{
speech_langerr=-1,
speech_langlocale=0,
speech_langen,
speech_langfr,
speech_langde,
speech_langes,
speech_langit,
speech_langpt
} speech_lang_t;

typedef struct
{
int speech_mode;
int speech_buflength; //not used
char* speech_datapath; //not used
int speech_options; //not used
int speech_synthrate;
int speech_synthvolume;
int speech_synthpitch;
int speech_synthrange;
int speech_synthpunctuation;
int speech_synthcapitals;
int speech_synthwordgap;
int speech_synthrelative;
bool speech_synthparamsinitialized;
bool speech_libinitialized;
speech_lang_t speech_lang;
char speech_outfilename[210]; //name of the mp3 file.;
char speech_author[200];
char speech_title[200];
} speech_options_t;

speech_options_t* speech_init(void);
bool speech_setlibespeak(speech_options_t* options, int mode);
//set the language of audio output.
bool speech_setlang(speech_options_t* options, speech_lang_t lang);
bool speech_setsynthrate(speech_options_t* options, int value);
bool speech_setsynthvolume(speech_options_t* options, int value);
bool speech_setsynthpitch(speech_options_t* options, int value);
bool speech_setsynthrange(speech_options_t* options, int value);
bool speech_setsynthpunctuation(speech_options_t* options, int value);
bool speech_setsynthcapitals(speech_options_t* options, int value);
bool speech_setsynthwordgap(speech_options_t* options, int value);
bool speech_setsynthcallback(int mode);
//end of swig interface
Here is the prototype of function that causes segfault:
int lame_init_params(GFP* gf);
The function allocates authomatically the memory for gfp*.
Regards.
M

Reply all
Reply to author
Forward
0 new messages