From: Jeff Mitchell Date: 2004-05-13T04:00:41+09:00 Subject: [BUG] ruby/dl # dltest.rb require 'dl/import' module DLTest extend DL::Importable dlload "./dltest.so" extern "void* dltest_func()" end srand(2727) ptr = DLTest.dltest_func().to_i puts "[ruby] got pointer: #{ptr}" loop { DL::PtrData.new(ptr) } __END__ # dltest.c #include static const char* data = "konnichiwa" ; void* dltest_func() { printf("[C] sending pointer: %d\n", (unsigned int)data) ; return (void*)data ; } # Makefile all : dltest.so dltest.so : dltest.o gcc -shared -Wall dltest.o -o dltest.so dltest.o : dltest.c gcc -c -fpic -Wall dltest.c -o dltest.o clean : rm -f dltest.o dltest.so run : dltest.so ruby -w dltest.rb .PHONY: all clean run -------------------------------------------------- output: [C] sending pointer: 1073911707 [ruby] got pointer: 1073911707 dltest.rb:18: [BUG] Segmentation fault ruby 1.9.0 (2004-05-12) [i686-linux] -------------------------------------------------- Same result for ruby-1.8.1 and cvs up -r ruby_1_8. For me, the segfault occurs on the 3737th iteration. Results may vary. Changing the program slightly can make it segfault only within a certain range, say 5000-8000 iterations, or cause memory to grow without bound. A simpler yet unorthodox example is: require 'dl' srand(2727) FOO = "foo" loop { DL::PtrData.new(2*FOO.object_id) ; } Thanks to Mauricio for helping to further isolate the bug on #ruby-lang IRC. __________________________________ Do you Yahoo!? Yahoo! Movies - Buy advance tickets for 'Shrek 2' http://movies.yahoo.com/showtimes/movie?mid=1808405861