summaryrefslogtreecommitdiff
path: root/struct.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-05-12 05:27:35 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-05-12 05:27:35 +0000
commitc6ac6cb4542b845eb4c18a9e80e15f8deab4f54a (patch)
treef39e1fd249686fc7a6946d88c65e944ccdc59a43 /struct.c
parent039a94478ee4f8b3154e99812223614e03ac186c (diff)
$/, Struct subclassing
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@465 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/struct.c b/struct.c
index 794b587..681abe0 100644
--- a/struct.c
+++ b/struct.c
@@ -29,13 +29,30 @@ class_of(obj)
}
static VALUE
+iv_get(obj, name)
+ VALUE obj;
+ char *name;
+{
+ ID id;
+
+ id = rb_intern(name);
+ for (;;) {
+ if (rb_ivar_defined(obj, id))
+ return rb_ivar_get(obj, id);
+ obj = RCLASS(obj)->super;
+ if (obj == 0 || obj == rb_cStruct)
+ return Qnil;
+ }
+}
+
+static VALUE
rb_struct_s_members(obj)
VALUE obj;
{
VALUE member, ary;
VALUE *p, *pend;
- member = rb_iv_get(obj, "__member__");
+ member = iv_get(obj, "__member__");
if (NIL_P(member)) {
rb_bug("non-initialized struct");
}
@@ -64,7 +81,7 @@ rb_struct_getmember(obj, id)
VALUE member, slot;
int i;
- member = rb_iv_get(class_of(obj), "__member__");
+ member = iv_get(class_of(obj), "__member__");
if (NIL_P(member)) {
rb_bug("non-initialized struct");
}
@@ -116,7 +133,7 @@ rb_struct_set(obj, val)
VALUE member, slot;
int i;
- member = rb_iv_get(class_of(obj), "__member__");
+ member = iv_get(class_of(obj), "__member__");
if (NIL_P(member)) {
rb_bug("non-initialized struct");
}
@@ -231,7 +248,7 @@ rb_struct_initialize(self, values)
VALUE size;
int n;
- size = rb_iv_get(klass, "__size__");
+ size = iv_get(klass, "__size__");
n = FIX2INT(size);
if (n != RARRAY(values)->len) {
rb_raise(rb_eArgError, "struct size differs");
@@ -252,7 +269,7 @@ struct_alloc(argc, argv, klass)
NEWOBJ(st, struct RStruct);
OBJSETUP(st, klass, T_STRUCT);
- size = rb_iv_get(klass, "__size__");
+ size = iv_get(klass, "__size__");
n = FIX2INT(size);
st->len = 0; /* avoid GC crashing */
@@ -284,7 +301,7 @@ rb_struct_new(klass, va_alist)
int size, i;
va_list args;
- sz = rb_iv_get(klass, "__size__");
+ sz = iv_get(klass, "__size__");
size = FIX2INT(sz);
mem = ALLOCA_N(VALUE, size);
va_init_list(args, klass);
@@ -327,7 +344,7 @@ inspect_struct(s)
VALUE str, member;
int i;
- member = rb_iv_get(CLASS_OF(s), "__member__");
+ member = iv_get(CLASS_OF(s), "__member__");
if (NIL_P(member)) {
rb_bug("non-initialized struct");
}
@@ -397,7 +414,7 @@ rb_struct_aref_id(s, id)
VALUE member;
int i, len;
- member = rb_iv_get(CLASS_OF(s), "__member__");
+ member = iv_get(CLASS_OF(s), "__member__");
if (NIL_P(member)) {
rb_bug("non-initialized struct");
}
@@ -441,7 +458,7 @@ rb_struct_aset_id(s, id, val)
VALUE member;
int i, len;
- member = rb_iv_get(CLASS_OF(s), "__member__");
+ member = iv_get(CLASS_OF(s), "__member__");
if (NIL_P(member)) {
rb_bug("non-initialized struct");
}