Project

General

Profile

Bug #7575 » patch.diff

Glass_saga (Masaki Matsushita), 12/20/2012 10:33 PM

View differences:

struct.c
207 207
    len = RARRAY_LEN(members);
208 208
    for (i=0; i< len; i++) {
209 209
	ID id = SYM2ID(ptr_members[i]);
210
	if (rb_is_local_id(id) || rb_is_const_id(id)) {
211
	    if (i < N_REF_FUNC) {
212
		rb_define_method_id(nstr, id, ref_func[i], 0);
213
	    }
214
	    else {
215
		rb_define_method_id(nstr, id, rb_struct_ref, 0);
216
	    }
217
	    rb_define_method_id(nstr, rb_id_attrset(id), rb_struct_set, 1);
210
	if (i < N_REF_FUNC) {
211
	    rb_define_method_id(nstr, id, ref_func[i], 0);
212
	}
213
	else {
214
	    rb_define_method_id(nstr, id, rb_struct_ref, 0);
218 215
	}
216
	rb_define_method_id(nstr, rb_id_attrset(id), rb_struct_set, 1);
219 217
    }
220 218

  
221 219
    return nstr;
test/ruby/test_struct.rb
227 227
    assert_equal("#<struct Struct::R\u{e9}sum\u{e9} r\u{e9}sum\u{e9}=42>", a.inspect, '[ruby-core:24849]')
228 228
  end
229 229

  
230
  def test_junk
231
    struct_test = Struct.new("Foo", "a\000")
232
    o = struct_test.new(1)
233
    assert_equal(1, o.send("a\000"))
234
    Struct.instance_eval { remove_const(:Foo) }
235
  end
236

  
230 237
  def test_comparison_when_recursive
231 238
    klass1 = Struct.new(:a, :b, :c)
232 239