1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* gc.c: __size__ removed. use the length of __members__ instead.

(num_members): new function.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-06-27 12:56:45 +00:00
parent 4bcf877beb
commit dfbf04166a
2 changed files with 20 additions and 11 deletions

View file

@ -1,3 +1,8 @@
Fri Jun 27 21:38:57 2008 Tanaka Akira <akr@fsij.org>
* gc.c: __size__ removed. use the length of __members__ instead.
(num_members): new function.
Fri Jun 27 21:19:08 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* test/inlinetest.rb (InlineTest.in_progname): workaround for frozen

View file

@ -193,7 +193,6 @@ make_struct(VALUE name, VALUE members, VALUE klass)
}
nstr = rb_define_class_under(klass, rb_id2name(id), klass);
}
rb_iv_set(nstr, "__size__", LONG2NUM(RARRAY_LEN(members)));
rb_iv_set(nstr, "__members__", members);
rb_define_alloc_func(nstr, struct_alloc);
@ -249,7 +248,6 @@ rb_struct_define_without_accessor(const char *class_name, VALUE super, rb_alloc_
rb_class_inherited(super, klass);
}
rb_iv_set(klass, "__size__", LONG2NUM(RARRAY_LEN(members)));
rb_iv_set(klass, "__members__", members);
if (alloc)
@ -340,6 +338,17 @@ rb_struct_s_def(int argc, VALUE *argv, VALUE klass)
return st;
}
static size_t
num_members(VALUE klass)
{
VALUE members;
members = rb_struct_iv_get(klass, "__members__");
if (TYPE(members) != T_ARRAY) {
rb_raise(rb_eTypeError, "broken members");
}
return RARRAY_LEN(members);
}
/*
*/
@ -347,12 +356,10 @@ VALUE
rb_struct_initialize(VALUE self, VALUE values)
{
VALUE klass = rb_obj_class(self);
VALUE size;
long n;
rb_struct_modify(self);
size = rb_struct_iv_get(klass, "__size__");
n = FIX2LONG(size);
n = num_members(klass);
if (n < RARRAY_LEN(values)) {
rb_raise(rb_eArgError, "struct size differs");
}
@ -367,13 +374,11 @@ rb_struct_initialize(VALUE self, VALUE values)
static VALUE
struct_alloc(VALUE klass)
{
VALUE size;
long n;
NEWOBJ(st, struct RStruct);
OBJSETUP(st, klass, T_STRUCT);
size = rb_struct_iv_get(klass, "__size__");
n = FIX2LONG(size);
n = num_members(klass);
if (0 < n && n <= RSTRUCT_EMBED_LEN_MAX) {
RBASIC(st)->flags &= ~RSTRUCT_EMBED_LEN_MASK;
@ -398,12 +403,11 @@ rb_struct_alloc(VALUE klass, VALUE values)
VALUE
rb_struct_new(VALUE klass, ...)
{
VALUE sz, *mem;
VALUE *mem;
long size, i;
va_list args;
sz = rb_struct_iv_get(klass, "__size__");
size = FIX2LONG(sz);
size = num_members(klass);
mem = ALLOCA_N(VALUE, size);
va_start(args, klass);
for (i=0; i<size; i++) {