From: Christoph Date: 2002-09-04T02:58:49+09:00 Subject: Allocate crash loop hole. Hi, Ruby's current (admittedly pointless) ability to instantiate ``higher order'' meta classes bunches a hole in the new defenses around the allocate frame work. The following script segfaults on ruby 1.7.3 (2002-08-29) [i386-mswin32]. (Also see [ruby-talk: 38612]). Maybe this is a good enough reason to to identify Class and Object.meta(1)? --- class Object def meta(n) n.zero? ? self : \ class << self; self end.meta(n-1) end end Odd = 19 Even = 12 CrashClass = Class.meta(Odd).allocate Class.meta(Even).allocate rescue puts "bad" # bad CrashClass.allocate rescue puts "bad" # bad p CrashClass.type # Class p CrashClass.superclass # nil # CrashClass can instantiate working classes - weird! A = CrashClass.new B = CrashClass.new class A def okay; 'okay' end end p A.superclass == Object # true p A == B # false p A.new.okay # okay def CrashClass.okay20; p 'fine' end A.meta(18).okay20 rescue p 'bad' # bad A.meta(21).okay20 rescue p 'bad' # bad A.meta(30).okay20 # fine begin class CrashClass end rescue TypeError => mes p mes # end # however this will crash CrashClass.class_eval { def crash; end } --- /Christoph