永井@知能.九工大です.

From: matz / ruby-lang.org (Yukihiro Matsumoto)
Subject: [ruby-dev:22398] Re: Tk.callback_break causes seg-fault or hang-up
Date: Thu, 25 Dec 2003 07:38:07 +0900
Message-ID: <1072305485.848427.669.nullmailer / picachu.netlab.jp>
> む、Tcl/Tkでpthreadを使ってない時にもsegvですか。
> それは気づいてなかったな。

VineLinux 上で tcl-8.0.5_jp-10vl7 / tk-8.0.5_jp-10vl6 を
使うようにして --enable-pthread を付けずに configure / make を
した ruby 1.8.1 (2003-12-25) [i686-linux] で,
次のスクリプトを実行した結果です.
何文字か入力した時点で segv で落ちます.
---------------------------------------------------
require 'tk'
# Overriding insert in Tktext

class HiText < TkText
# remove any bindings that get in the way
# self.bind_remove "Control-k"

   def insert(index,char,tag1,tag2)
     # set char to preference
     if char =~/[A-Z]/
       flag = super(index,char,tag2)
     elsif
       char =~ /[a-z]/
       flag = super(index,char,tag1)
     end
   end
end

   root = TkRoot.new
   edit = HiText.new(root) {
     width  50
     height 10
     pack
     focus
   }

   # set tags to whatever... colours styles etc
   col2 = TkTextTag.new(edit, 'foreground'=>'red')
   col1 = TkTextTag.new(edit, 'foreground'=>'blue')

   root.title 'HiText : Control-d exits'

   edit.bind("KeyPress") { |event|
     Tk.callback_break if edit.insert('insert', event.char, col1, col2)
   }

   edit.bind "Control-d", proc{root.destroy}

p Tk::TK_VERSION
   Tk.mainloop
---------------------------------------------------
---------------------------------------------------
$ gdb ./ruby
GNU gdb 5.0
Copyright 2000 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux"...
(gdb) r ./xxx.rb
Starting program: /home/nagai/Ruby-CVS/ruby/./ruby ./xxx.rb
"8.0"

Program received signal SIGSEGV, Segmentation fault.
0x40198291 in main_arena () from /lib/libc.so.6
(gdb) bt
#0  0x40198291 in main_arena () from /lib/libc.so.6
#1  0x080a9c46 in st_lookup (table=0x8149360, key=9593, value=0x0) at st.c:258
#2  0x080b6457 in rb_ivar_defined (obj=1076036264, id=9593) at variable.c:1016
#3  0x080c3ca0 in exc_backtrace (exc=1076036264) at error.c:475
#4  0x0805bc81 in rb_call0 (klass=1075627652, recv=1076036264, id=4833, 
    oid=4833, argc=0, argv=0x0, body=0x401cc544, nosuper=0) at eval.c:4944
#5  0x0805c6a6 in rb_call (klass=1075627652, recv=1076036264, mid=4833, 
    argc=0, argv=0x0, scope=1) at eval.c:5287
#6  0x0805c8d9 in rb_funcall (recv=1076036264, mid=4833, n=0) at eval.c:5352
#7  0x08052f8f in get_backtrace (info=1076036264) at eval.c:1062
#8  0x08059623 in rb_longjmp (tag=6, mesg=1076036264) at eval.c:3990
#9  0x0805980b in rb_exc_raise () at eval.c:4041
#10 0x0805d2c3 in eval (self=1075636512, src=1076041864, scope=4, 
    file=0x81eec09 "(eval)", line=762) at eval.c:5649
#11 0x08053c6e in rb_eval_string (
    str=0x8292c28 "TkCore.callback %Q!c00001 283 0x6a 38 0 ?? 1 0 i 38 NotifyNormal 0 PlaceOnTop 0 -1426119423 0 113 46 a 801 38 0 a 97 0x3a 0x0 2 .w00000 801 106!") at eval.c:1490
#12 0x0805ab5e in rb_rescue2 (b_proc=0x8053c20 <rb_eval_string>, 
    data1=136916008, r_proc=0x400193dc <ip_ruby_eval_rescue>, data2=3221214020)
    at eval.c:4629
#13 0x40019444 in ip_ruby_eval_body () at eval.c:88
#14 0x0805adf0 in rb_ensure (b_proc=0x400193f0 <ip_ruby_eval_body>, 
    data1=3221214016, e_proc=0x4001944c <ip_ruby_eval_ensure>, data2=1)
    at eval.c:4717
#15 0x40019555 in ip_ruby () at eval.c:88
#16 0x403cd95c in TclExecuteByteCode () from /usr/lib/libtcl.so
#17 0x403ae53c in Tcl_EvalObj () from /usr/lib/libtcl.so
#18 0x403f0788 in TclObjInterpProc () from /usr/lib/libtcl.so
#19 0x403cd95c in TclExecuteByteCode () from /usr/lib/libtcl.so
#20 0x403ae53c in Tcl_EvalObj () from /usr/lib/libtcl.so
#21 0x403ae2bb in Tcl_Eval () from /usr/lib/libtcl.so
#22 0x403afcef in Tcl_GlobalEval () from /usr/lib/libtcl.so
#23 0x402e5542 in Tk_BindEvent () from /usr/lib/libtk8.0jp.so
#24 0x402ea524 in TkBindEventProc () from /usr/lib/libtk8.0jp.so
#25 0x402ee780 in Tk_HandleEvent () from /usr/lib/libtk8.0jp.so
#26 0x402eeb70 in WindowEventProc () from /usr/lib/libtk8.0jp.so
#27 0x403e92ea in Tcl_ServiceEvent () from /usr/lib/libtcl.so
#28 0x403e961d in Tcl_DoOneEvent () from /usr/lib/libtcl.so
#29 0x40018b2a in lib_eventloop_core () at eval.c:88
#30 0x40018dac in lib_eventloop_main () at eval.c:88
#31 0x0805adf0 in rb_ensure (b_proc=0x40018d74 <lib_eventloop_main>, data1=2, 
    e_proc=0x40018dc0 <lib_eventloop_ensure>, data2=0) at eval.c:4717
#32 0x40018f58 in lib_eventloop_launcher () at eval.c:88
#33 0x40018fb4 in lib_mainloop () at eval.c:88
#34 0x0805bc4e in rb_call0 (klass=1076472684, recv=1076472924, id=10409, 
    oid=10409, argc=1, argv=0xbfffe694, body=0x4029ab58, nosuper=0)
    at eval.c:4938
#35 0x0805c6a6 in rb_call (klass=1076472684, recv=1076472924, mid=10409, 
    argc=1, argv=0xbfffe694, scope=0) at eval.c:5287
#36 0x0805739f in rb_eval (self=1076463844, n=0x401a43a0) at eval.c:3076
#37 0x0805c259 in rb_call0 (klass=1076470204, recv=1076463844, id=10409, 
    oid=10409, argc=0, argv=0x0, body=0x401a43a0, nosuper=0) at eval.c:5194
#38 0x0805c6a6 in rb_call (klass=1076470204, recv=1076463844, mid=10409, 
    argc=0, argv=0x0, scope=0) at eval.c:5287
#39 0x0805739f in rb_eval (self=1075636512, n=0x401beca0) at eval.c:3076
#40 0x08053640 in eval_node (self=1075636512, node=0x401beca0) at eval.c:1267
#41 0x08053b0e in ruby_exec () at eval.c:1436
#42 0x08053b6a in ruby_run () at eval.c:1457
#43 0x08052032 in Letext () at main.c:50
#44 0x4009013f in __libc_start_main (main=0x8052010 <main>, argc=2, 
    ubp_av=0xbffff5d4, init=0x805141c <_init>, fini=0x80c5670 <_fini>, 
    rtld_fini=0x4000c770 <_dl_fini>, stack_end=0xbffff5cc)
    at ../sysdeps/generic/libc-start.c:129
(gdb) 
---------------------------------------------------
-- 
                                         永井 秀利 (九工大 知能情報)
                                             nagai / ai.kyutech.ac.jp