[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyKDE] Help on wrapping a C library
From:       Phil Thompson <phil () riverbankcomputing ! co ! uk>
Date:       2005-05-24 7:45:04
Message-ID: 200505240845.04334.phil () riverbankcomputing ! co ! uk
[Download RAW message or body]

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

_______________________________________________
PyKDE mailing list    PyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic