From: matz@... (Yukihiro Matsumoto) Date: 1999-05-26T11:58:46+09:00 Subject: [ruby-talk:00343] Re: Struct.new Hi. In message "[ruby-talk:00341] Struct.new" on 99/05/25, "Michael Neumann" writes: |Following code is incompatible between 1.25 and 1.3x | |#version 1.25: |St = Struct.new("St", :first, :second) |s = St.new | |#version 1.3x: |St = Struct.new("St", :first, :second) |s = St.new # error: `initialize': struct size differs (ArgumentError) |a = St.new(3,4) #works | |Perhaps this could be changed? Hmm, it's really easy to relax the member check (with included patch). But I want to discuss whether we should choose this behavior or not. What do you guys (other than Pros) think about this? matz. --- struct.c 1999/05/25 08:26:17 1.1.1.3.2.6 +++ struct.c 1999/05/26 02:35:22 @@ -251,8 +251,12 @@ size = iv_get(klass, "__size__"); n = FIX2INT(size); - if (n != RARRAY(values)->len) { + if (n < RARRAY(values)->len) { rb_raise(rb_eArgError, "struct size differs"); } MEMCPY(RSTRUCT(self)->ptr, RARRAY(values)->ptr, VALUE, RARRAY(values)->len); + if (n > RARRAY(values)->len) { + rb_mem_clear(RSTRUCT(self)->ptr+RARRAY(values)->len, + n-RARRAY(values)->len); + } return Qnil; }