summaryrefslogtreecommitdiff
path: root/struct.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-10-03 07:19:19 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-10-03 07:19:19 +0000
commit1fe40b7cc5e92105f636d670d77b059fe4a4c50b (patch)
tree02dfc7bab198fc494d9d4f1f3bf1072d292fed66 /struct.c
parentd902111a57dfcf3c9b017b0ebd1b49f19142168c (diff)
* marshal.c (r_object): better allocation type check for
TYPE_UCLASS. usage of allocation framework is disabled for now. * variable.c (rb_class_path): Module may have subclass. * string.c (rb_str_update): should maintain original negative offset. * string.c (rb_str_subpat_set): ditto * string.c (rb_str_aset): ditto. * re.c (rb_reg_nth_match): should check negative nth. * re.c (rb_reg_nth_defined): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/struct.c b/struct.c
index d6613d95e0..cfc144757e 100644
--- a/struct.c
+++ b/struct.c
@@ -14,7 +14,7 @@
VALUE rb_cStruct;
-static VALUE struct_alloc _((int, VALUE*, VALUE));
+static VALUE struct_alloc _((VALUE));
VALUE
rb_struct_iv_get(c, name)
@@ -168,8 +168,9 @@ make_struct(name, member, 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, "allocate", struct_alloc, 0);
+ rb_define_singleton_method(nstr, "new", rb_class_new_instance, -1);
+ rb_define_singleton_method(nstr, "[]", rb_class_new_instance, -1);
rb_define_singleton_method(nstr, "members", rb_struct_s_members, 0);
for (i=0; i< RARRAY(member)->len; i++) {
ID id = SYM2ID(RARRAY(member)->ptr[i]);
@@ -269,14 +270,11 @@ rb_struct_initialize(self, values)
}
static VALUE
-struct_alloc(argc, argv, klass)
- int argc;
- VALUE *argv;
+struct_alloc(klass)
VALUE klass;
{
VALUE size;
long n;
-
NEWOBJ(st, struct RStruct);
OBJSETUP(st, klass, T_STRUCT);
@@ -286,7 +284,6 @@ struct_alloc(argc, argv, klass)
st->ptr = ALLOC_N(VALUE, n);
rb_mem_clear(st->ptr, n);
st->len = n;
- rb_obj_call_init((VALUE)st, argc, argv);
return (VALUE)st;
}
@@ -295,7 +292,7 @@ VALUE
rb_struct_alloc(klass, values)
VALUE klass, values;
{
- return struct_alloc(RARRAY(values)->len, RARRAY(values)->ptr, klass);
+ return rb_class_new_instance(RARRAY(values)->len, RARRAY(values)->ptr, klass);
}
VALUE
@@ -320,7 +317,7 @@ rb_struct_new(klass, va_alist)
}
va_end(args);
- return struct_alloc(size, mem, klass);
+ return rb_class_new_instance(size, mem, klass);
}
static VALUE
@@ -409,13 +406,13 @@ static VALUE
rb_struct_clone(s)
VALUE s;
{
- NEWOBJ(clone, struct RStruct);
- CLONESETUP(clone, s);
- clone->ptr = ALLOC_N(VALUE, RSTRUCT(s)->len);
- clone->len = RSTRUCT(s)->len;
- MEMCPY(clone->ptr, RSTRUCT(s)->ptr, VALUE, clone->len);
+ VALUE clone = rb_obj_clone(s);
+
+ RSTRUCT(clone)->ptr = ALLOC_N(VALUE, RSTRUCT(s)->len);
+ RSTRUCT(clone)->len = RSTRUCT(s)->len;
+ MEMCPY(RSTRUCT(clone)->ptr, RSTRUCT(s)->ptr, VALUE, RSTRUCT(clone)->len);
- return (VALUE)clone;
+ return clone;
}
static VALUE