>>>>> "Y" == Yukihiro Matsumoto <matz / ruby-lang.org> writes:

Y> This means your marshal data file is corrupted.  Does this information
Y> help you, or not?

 Unfortunately not, the smallest example is given by

pigeon% cat b.rb
#!/usr/bin/ruby
s = Struct.new("Cat", 'a', 'b', 'c')
record = s.new(1, 2, 3)
s = Struct.new("Cat", 'a', 'b', 'c')
GC.start
record = s.new(1, 2, 3)
pigeon%
 
pigeon% b.rb
./b.rb:6: [BUG] unknown node type 0
ruby 1.6.6 (2001-12-26) [i686-linux]
Aborted
pigeon% 

 The problem is here (make_struct() in struct.c)

  ------------------------------------------------------------
	char *cname = STR2CSTR(name);
	id = rb_intern(cname);
	if (!rb_is_const_id(id)) {
	    rb_raise(rb_eNameError, "identifier %s needs to be constant", cname);
	}
	nstr = rb_define_class_under(klass, cname, klass);
    }
    rb_iv_set(nstr, "__size__", INT2NUM(RARRAY(member)->len));
    rb_iv_set(nstr, "__member__", member);

    rb_define_singleton_method(nstr, "new", struct_alloc, -1);
    rb_define_singleton_method(nstr, "[]", struct_alloc, -1);
    rb_define_singleton_method(nstr, "members", rb_struct_s_members, 0);
  ------------------------------------------------------------

 1) rb_define_class_under() return the old class if it exist (in 1.6.5 a new
 class was created)

 2) the (singleton) methods are created

 3) when the GC run, it remove the old methods of Struct (they were
    replaced by new one) *but* the cache is not cleared and they are still
    in the cache.

 4) when ruby try to call `s.new(1, 2, 3)' it retrieve the method from the
    cache but because these nodes are free'd ruby give an error


 One possible solution is to call rb_clear_cache(), when
 rb_define_class_xxx() (same for Module) don't create a new class but
 return an old one but this is a *BIG MODIFICATION*



Guy Decoux