Menu

#935 segfault on inclusion of std_vector.i [ruby]

closed-works-for-me
ruby (61)
5
2010-02-13
2008-07-18
Alex Norman
No

I have tested this with the most recent version of swig (1.3.36) as well as the ubuntu package.

If I include std_vector.i in my swig wrapper and make a ruby wrapper, I get a segfault right when I start my app. I am not building the swig wrapper into a library, I am building it directly into my application and calling Foo_init(); I have attached a small example which works fine with out std_vector.i but segfaults when starting the app if I include std_vector.i. By the way, I am building under ubuntu/linux hardy (8.04LTS).

when I include std_vector.i i also get these errors while building:

swig -Wall -c++ -ruby foo.i
/usr/local/share/swig/1.3.36/ruby/rubycontainer_extended.swg:136: Warning(322): Redundant redeclaration of 'map_bang',
/usr/local/share/swig/1.3.36/ruby/rubycontainer_extended.swg:136: Warning(322): previous declaration of 'map_bang'.
/usr/local/share/swig/1.3.36/ruby/rubycontainer_extended.swg:136: Warning(322): Redundant redeclaration of '__delete__',
/usr/local/share/swig/1.3.36/ruby/rubycontainer_extended.swg:136: Warning(322): previous declaration of '__delete__'.
/usr/local/share/swig/1.3.36/ruby/rubycontainer_extended.swg:137: Warning(322): Redundant redeclaration of 'map_bang',
/usr/local/share/swig/1.3.36/ruby/rubycontainer_extended.swg:137: Warning(322): previous declaration of 'map_bang'.
/usr/local/share/swig/1.3.36/ruby/rubycontainer_extended.swg:137: Warning(322): Redundant redeclaration of '__delete__',
/usr/local/share/swig/1.3.36/ruby/rubycontainer_extended.swg:137: Warning(322): previous declaration of '__delete__'.
/usr/local/share/swig/1.3.36/ruby/rubycontainer_extended.swg:138: Warning(322): Redundant redeclaration of 'map_bang',
/usr/local/share/swig/1.3.36/ruby/rubycontainer_extended.swg:138: Warning(322): previous declaration of 'map_bang'.
/usr/local/share/swig/1.3.36/ruby/rubycontainer_extended.swg:138: Warning(322): Redundant redeclaration of '__delete__',
/usr/local/share/swig/1.3.36/ruby/rubycontainer_extended.swg:138: Warning(322): previous declaration of '__delete__'.
g++ -g foo.cpp main.cpp foo_wrap.cxx -o foo_test -I/usr/lib/ruby/1.8/i486-linux/ -lruby1.8

here is the backtrace from gdb:

09:16:46 $ gdb ./foo_test
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
(gdb) run
Starting program: /home/alex/projects/swig_vector_segfault/foo_test
[Thread debugging using libthread_db enabled]
[New Thread 0xb7c026c0 (LWP 30045)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7c026c0 (LWP 30045)]
0xb7f570de in st_lookup () from /usr/lib/libruby1.8.so.1.8
(gdb) bt
#0 0xb7f570de in st_lookup () from /usr/lib/libruby1.8.so.1.8
#1 0xb7f2b312 in rb_intern () from /usr/lib/libruby1.8.so.1.8
#2 0x0804a623 in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at foo_wrap.cxx:2067
#3 0x0804a776 in global constructors keyed to _ZN4swig8GC_VALUE7hash_idE () at foo_wrap.cxx:4163
#4 0x080504b5 in __do_global_ctors_aux ()
#5 0x08049654 in _init ()
#6 0x08050459 in __libc_csu_init ()
#7 0xb7c683f1 in __libc_start_main () from /lib/tls/i686/cmov/libc.so.6
#8 0x08049b51 in _start ()
(gdb)

Discussion

  • Alex Norman

    Alex Norman - 2008-07-18

    A very simple example project which shows this bug.

     
  • Alex Norman

    Alex Norman - 2008-07-18
    • labels: --> ruby
     
  • Evan Wies

    Evan Wies - 2008-08-12

    Logged In: YES
    user_id=774353
    Originator: NO

    you might want to see my bug #2048064, which is related to stl and ruby... i discovered it while migrating from Dapper to Hardy.

     
  • William Fulton

    William Fulton - 2010-02-13
    • assigned_to: nobody --> wsfulton
    • status: open --> closed-works-for-me
     
  • William Fulton

    William Fulton - 2010-02-13

    This works with the fixes to your tarball below using latest SWIG and probably 1.3.36 too.

    --- swig_vector_segfault/foo.i 2008-07-18 17:11:33.000000000 +0100
    +++ swig_vector_segfault_fixed/foo.i 2010-02-13 16:35:41.000000000 +0000
    @@ -1,4 +1,4 @@
    -%module Foo
    +%module foo_test
    %{
    #include "foo.hpp"
    %}
    diff -Naur swig_vector_segfault/foo.rb swig_vector_segfault_fixed/foo.rb
    --- swig_vector_segfault/foo.rb 2008-07-04 15:32:13.000000000 +0100
    +++ swig_vector_segfault_fixed/foo.rb 2010-02-13 16:34:45.000000000 +0000
    @@ -1,2 +1,4 @@
    -f = Foo::Foo.new
    +require 'foo_test'
    +
    +f = Foo_test::Foo.new()
    puts "YES!"
    diff -Naur swig_vector_segfault/Makefile swig_vector_segfault_fixed/Makefile
    --- swig_vector_segfault/Makefile 2008-07-04 15:39:09.000000000 +0100
    +++ swig_vector_segfault_fixed/Makefile 2010-02-13 16:31:58.000000000 +0000
    @@ -2,14 +2,15 @@
    INCLUDES += -I/usr/lib/ruby/1.8/i486-linux/
    LIBS += -lruby1.8

    -current: foo_test
    +current: foo_test.so

    foo_wrap.cxx: foo.i
    - swig -Wall -c++ -ruby foo.i
    + ../../../preinst-swig -Wall -c++ -ruby foo.i

    -foo_test: foo_wrap.cxx main.cpp foo.cpp
    - g++ -g foo.cpp main.cpp foo_wrap.cxx -o $@ ${INCLUDES} ${LIBS}
    +foo_test.so: foo_wrap.cxx main.cpp foo.cpp
    + g++ -c -g -fpic -fPIC foo.cpp main.cpp foo_wrap.cxx ${INCLUDES}
    + g++ -shared -g foo.o main.o foo_wrap.o -o $@ ${INCLUDES} ${LIBS}

    clean:
    - rm -f foo_wrap.cxx foo_test
    + rm -f foo_wrap.cxx foo_test.so

     

Log in to post a comment.