On Wed, Aug 13, 2008 at 7:08 PM, Brian Bird
<Brian.Bird@...> wrote:
> I'm getting a Segmentation fault on a 64-bit Ubuntu machine when using
> Swig1.3.36 and Python2.5.
>
>
>
> When compiling my example_wrap.c I get a warning about "casting to pointer
> from integer of different size". I assume this is the cause of the segfault.
>
>
>
> Everything works on a 32-bit machine. There is no warning (since pointers
> and integers are the same size).
>
>
>
> However the wrapper works fine when generated from swig version 1.3.16 (on
> both 32-bit and 64-bit machines).
>
>
>
> I tried Swig1.3.33 and it fails in the same way. Has something broken in
> Swig since version 1.3.16 when returning strings (char *) to Python? Or is
> there a better way to return a string from a C function to python which will
> ensure the latest versions of swig will generate wrappers which work on
> 64-bit machines? Most of the documentation/forums I've read seem to be aimed
> either at Swig1.1 or using typedefs/structs which seems (IMHO) to be
> overcomplicated just to return a string to Python – isn't it?
>
>
>
> Any suggestions would be appreciated!
>
>
>
> Below is the simplest example I could create which shows the problem.
> Thanks!
>
>
>
> /* file /tmp/example.i */
>
> %module example
>
> extern char *test(char *, char *);
>
>
>
> /* file /tmp/example.c */
>
> char *test(char *param1, char *param2) {
>
> return param2;
>
> }
>
>
>
> % cd /tmp
>
> % tar -xzf swig-1.3.36.tar.gz
>
> % cd swig-1.3.36/
>
> % ./configure --with-python=/usr/bin/python2.5 --prefix=/tmp/swig && make &&
> make install
>
> % cd ..
>
> % /tmp/swig/bin/swig -python example.i # Creates example_wrap.c and
> example.py
>
> % gcc -c -fpic example_wrap.c example.c -I/usr/include/python2.5
>
> example_wrap.c: In function '_wrap_test':
>
> example_wrap.c:2631: warning: cast to pointer from integer of different size
>
> % gcc -shared example.o example_wrap.o -o _example.so # Creates _example.so
>
> % python
>
> Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30)
>
> [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
>
> Type "help", "copyright", "credits" or "license" for more information.
>
>>>> import example
>
>>>> print example.test("Hello","World") # Should print "World" on the
>>>> screen. It works on 32-bit machines and with SWIG-1.3.16
>
> Segmentation fault
>
Could you provide more information likes the line of the code
generated the compile warning, or the trace back of the segmentation
fault? I havn't a 64-bit Linux so I can't debug it.However, I believe
it is somewhere the pointer of a 32-bit int casted to a 64-bit size_t.
--
Haoyu Bai
|