[PyKDE] Help on wrapping a C library

Huaicai Mo huaicai at nanorex.com
Tue May 24 16:40:11 BST 2005


> -----Original Message-----
> From: Phil Thompson [mailto:phil at riverbankcomputing.co.uk]
> Sent: Tuesday, May 24, 2005 3:45 AM
> To: pykde at mats.imk.fraunhofer.de
>..........
> 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

Thank you Phil for the reply. I did try as you suggested by removing the 2
free() calls in the reverse() or just simply implement reverse() by 
                  
		return word->the_word;

I also tried adding the /Transfer/ annotation to the argument of reverse()
in the word.sip file without removing the 2 free() calls. I still get the
segmentation fault. 

BTW, here is one of the generated functions in sipwordWord.c that I guess is
used by the wrapper to free the memory:
    
    static void dealloc_Word(sipWrapper *sipSelf)
    {
		If(sipIsPyOwned(sipSelf))
		  sipFree(sipSelf -> u.cppPtr);
    }

I am not sure if the above function is able to free "the_word" member in the
"Word" structure, so I tried keeping "free(word->the_word);" in the
reverse() too, it doesn't help either. For the whole generated C files,
please see the attachment.

Huaicai


-------------- next part --------------
A non-text attachment was scrubbed...
Name: sipwordWord.c
Type: application/octet-stream
Size: 1534 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20050524/da4aa824/sipwordWord.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sipwordcmodule.c
Type: application/octet-stream
Size: 3438 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20050524/da4aa824/sipwordcmodule.obj


More information about the PyQt mailing list