[PyKDE] Help on wrapping a C library
Phil Thompson
phil at riverbankcomputing.co.uk
Tue May 24 08:45:04 BST 2005
On Monday 23 May 2005 7:38 pm, huaicai wrote:
> Hi all,
>
> I was trying to use SIP to wrap a C library GTS(gnu triangular surface). I
> am new to the SIP tool, so before wrapping GTS, I am learning to wrap a
> simple C libary just like the C example(word) in the SIP reference guide.
>
> I implemented the "Word" libary in C and a C test program works fine by
> using the libary. I got a "segmentation fault" error when I call the
> reverse() in python as follows:
> import word
> w = word.create_word("How are you?")
> print word.reverse(w)
> I added another reverse function into the "word" library like: "char
> *myReverse(const char *w);". It works fine in python when I do this:
> print word.myReverse("How are you?")
>
> Please see the C source/header file and SIP specification file in the
> attachments. Can any one tell me what's wrong?
>
> Thank you very much! I really appreciate your help.
In your implementation of reverse() you are freeing the memory allocated to
the Word structure and the word itself. Because the wrapper has ownership it
will also try to free the memory which will result in the seg fault.
Either remove the calls to free() or add /Transfer/ to the argument to
reverse().
Phil
More information about the PyQt
mailing list