From: Kouhei Sutou Date: 2008-01-07T22:02:21+09:00 Subject: [ruby-dev:32970] rb_thread_create()の中でmodule_eval 須藤です。 以下の拡張ライブラリが落ちるのですが、そういうものでしょうか? ちなみにmodule_evalをpにすると落ちません。 Ruby/GLibというもう少し大きなライブラリの中での話だと module_evalのままでもrb_str_new2("")だと落ちて、 rb_str_new2("def ...")だと落ちませんでした。 でも、↓だと""でもそうでなくても落ちます。 a.c: #include static VALUE eval(void *string) { rb_funcall(rb_cObject, rb_intern("module_eval"), 1, rb_str_new2(string ? string : "p 1")); } void Init_a(void) { eval("p 100"); rb_thread_create(eval, NULL); eval("p 123"); } extconf.rb: require 'mkmf' create_makefile("a") コマンドライン: % /tmp/local/bin/ruby extconf.rb creating Makefile % make gcc -I. -I/tmp/local/include/ruby-1.9.0/x86_64-linux -I/tmp/local/include/ruby-1.9.0 -I. -fPIC -g -o a.o -c a.c gcc -shared -o a.so a.o -L. -L/tmp/local/lib -Wl,-R/tmp/local/lib -L. -rdynamic -Wl,-export-dynamic -lpthread -lrt -ldl -lcrypt -lm -lc % /tmp/local/bin/ruby -e 'require "a"; sleep 1' 100 123 [BUG] Segmentation fault ruby 1.9.0 (2008-01-07 revision 0) [x86_64-linux] -- control frame ---------- c:0002 p:---- s:0004 b:0004 l:000003 d:000003 CFUNC :module_eval c:0001 p:---- s:0002 b:0002 l:000001 d:000001 TOP --------------------------- -- backtrace of native function call (Use addr2line) -- 0x4d79ee 0x4fbc9a 0x4fbd8a 0x494b7d 0x2b579912e7d0 0x41cf53 0x41d1b2 0x41d316 0x41d409 0x4cc20c 0x4cbc98 0x41c120 0x41c194 0x41c56b 0x2aaaaaab2744 0x4d89eb 0x4d7dbe 0x2b57991263f7 0x2b5799cd991d ------------------------------------------------------- zsh: abort /tmp/local/bin/ruby -e 'require "a"; sleep 1' % gdb --args /tmp/local/bin/ruby -e 'require "a"; sleep 1' GNU gdb 6.7.1-debian Copyright (C) 2007 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later 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 "x86_64-linux-gnu"... Using host libthread_db library "/lib/libthread_db.so.1". (gdb) r Starting program: /tmp/local/bin/ruby -e require\ \"a\"\;\ sleep\ 1 [Thread debugging using libthread_db enabled] [New Thread 0x2ab6615f7dc0 (LWP 21874)] [New Thread 0x40003950 (LWP 21881)] 100 [New Thread 0x40084950 (LWP 21882)] 123 Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x40084950 (LWP 21882)] 0x000000000041cf53 in exec_under (func=0x41d0e5 , under=46962807518120, self=46962807518120, args=1074281200) at eval.c:1856 1856 while (!RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { (gdb) bt #0 0x000000000041cf53 in exec_under (func=0x41d0e5 , under=46962807518120, self=46962807518120, args=1074281200) at eval.c:1856 #1 0x000000000041d1b2 in eval_under (under=46962807518120, self=46962807518120, src=46962807166400, file=0x519bb1 "(eval)", line=1) at eval.c:1920 #2 0x000000000041d316 in specific_eval (argc=1, argv=0x40083e60, klass=46962807518120, self=46962807518120) at eval.c:1959 #3 0x000000000041d409 in rb_mod_module_eval (argc=1, argv=0x40083e60, mod=46962807518120) at eval.c:2059 #4 0x00000000004cc20c in call_cfunc (func=0x41d3e2 , recv=46962807518120, len=-1, argc=1, argv=0x40083e60) at vm_insnhelper.c:280 #5 0x00000000004cbc98 in vm_call0 (th=0x85f040, klass=46962807518040, recv=46962807518120, id=2976, oid=0, argc=1, argv=0x40083e60, body=0x2ab66174c768, nosuper=0) at vm.c:457 #6 0x000000000041c120 in rb_call0 (klass=46962807518040, recv=46962807518120, mid=2976, argc=1, argv=0x40083e60, scope=3, self=4) at eval.c:1438 #7 0x000000000041c194 in rb_call (klass=46962807517800, recv=46962807518120, mid=2976, argc=1, argv=0x40083e60, scope=3) at eval.c:1452 #8 0x000000000041c56b in rb_funcall (recv=46962807518120, mid=2976, n=1) at eval.c:1544 #9 0x00002aaaaaab2744 in eval (string=0x0) at a.c:6 #10 0x00000000004d89eb in thread_start_func_2 (th=0x85f040, stack_start=0x40084130) at thread.c:316 #11 0x00000000004d7dbe in thread_start_func_1 (th_ptr=0x85f040) at thread_pthread.c:175 #12 0x00002ab6607bd3f7 in start_thread () from /lib/libpthread.so.0 #13 0x00002ab66137091d in clone () from /lib/libc.so.6 #14 0x0000000000000000 in ?? () (gdb) quit The program is running. Exit anyway? (y or n) y %