On Monday 23 May 2005 11:38, 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.
>
> Huaicai
It might not strictly be required, but I'd add:
%ModuleHeaderCode
#include <word.h>
%End
after the %CModule line (although it seems like you'd get compile errors if it
was really necessary - might depend on whether sip generated code is
concatenated for compiling or not).
You might also try:
Word *create_word(const char *);
char *reverse(Word *);
char *myReverse(const char *);
removing "struct" in two places (not sure if it's required or makes a
difference as far as sip is concerned - I believe it's not necessary though).
Also, in Python, try printing w.the_word before calling reverse.
You could also try making Word a class:
class Word
{
public:
char *the_word;
};
At one time (long ago) I had problems doing structs with sip, but I think
that's been fixed for quite a while.
Otherwise, I don't see any obvious errors in the sip file. I'd also look at
how the module is linked and if the .so file being wrapped can be found at
runtime.
Jim
_______________________________________________
PyKDE mailing list [email protected]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde