tikets 704: segfault if change print message before "@values[name] = value"
(gdb) r
Starting program: /Users/watson/src/macruby-trunk-svn/miniruby /Users/watson/tmp/test_singleton.rb
Reading symbols for shared libraries .++++++++................... done
Reading symbols for shared libraries . done
method : 2.12264622838802e-314
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x00007fff81d2f700 in _class_getSuperclass ()
(gdb) bt
#0 0x00007fff81d2f700 in _class_getSuperclass ()
#1 0x00000001000280c8 in foundation_type (k=0x28508b48f8458b48) at class.c:1302
#2 0x0000000100028146 in rb_objc_type (obj=4295664350) at class.c:1322
#3 0x00000001000438dd in rb_type (obj=4295664350) at ruby.h:933
#4 0x0000000100045347 in rhash_aset (hash=8590551168, sel=0x0, key=4295664350, val=4621819117588971523) at hash.c:912
#5 0x0000000101701d14 in ?? ()
#6 0x0000000101701ad7 in ?? ()
#7 0x000000010013c503 in __rb_vm_bcall [inlined] () at /Users/watson/src/macruby-trunk-svn/dispatcher.cpp:100
#8 0x000000010013c503 in vm_block_eval [inlined] () at /Users/watson/src/macruby-trunk-svn/dispatcher.cpp:1198
#9 0x000000010013c503 in rb_vm_block_eval2 (b=0x20000d920, self=8590077760, sel=0x101289490, argc=1, argv=0x7fff5fbfdd58) at dispatcher.cpp:1214
#10 0x0000000101702195 in ?? ()
#11 0x0000000100137146 in __rb_vm_rcall [inlined] () at /Users/watson/src/macruby-trunk-svn/dispatcher.cpp:161
#12 0x0000000100137146 in ruby_dispatch [inlined] () at /Users/watson/src/macruby-trunk-svn/dispatcher.cpp:466
#13 0x0000000100137146 in rb_vm_dispatch () at dispatcher.cpp:849
#14 0x00000001017004b6 in ?? ()
#15 0x0000000101700154 in ?? ()
#16 0x00000001001515d1 in rb_vm_run (fname=0x20000d2c0 "/Users/watson/tmp/test_singleton.rb", node=0x20000cc80, binding=0x0, inside_eval=false) at vm.cpp:3942
#17 0x0000000100036102 in ruby_run_node (n=0x20000cc80) at eval.c:211
#18 0x00000001000dbaef in main (argc=2, argv=0x100f1ddd0, envp=0x7fff5fbfee68) at main.cpp:40
(gdb) Quit
# http://www.macruby.org/trac/ticket/704
class SingletonTest
attr_reader :values
def initialize
@values = {}
end
def addMethod(name)
singleton = class << self
self
end
singleton.instance_exec(name) do |name|
define_method("#{name}=") do |value|
puts "method : #{name}" # changed
@values[name] = value # segfault
end
define_method("#{name}") do
return @values[name]
end
end
end
end
singleton_test = SingletonTest.new()
singleton_test.addMethod('foo')
singleton_test.foo = 10.0
p singleton_test.foo