summaryrefslogtreecommitdiff
path: root/struct.c
diff options
context:
space:
mode:
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/struct.c b/struct.c
index 76187c09b4..f09c697273 100644
--- a/struct.c
+++ b/struct.c
@@ -136,11 +136,17 @@ make_struct(name, member, klass)
ID id;
int i;
- id = rb_intern(RSTRING(name)->ptr);
- if (!rb_is_const_id(id)) {
- NameError("identifier %s needs to be constant", RSTRING(name)->ptr);
+ if (NIL_P(name)) {
+ nstr = class_new(klass);
+ }
+ else {
+ char *cname = STR2CSTR(name);
+ id = rb_intern(cname);
+ if (!rb_is_const_id(id)) {
+ NameError("identifier %s needs to be constant", cname);
+ }
+ nstr = rb_define_class_under(klass, cname, klass);
}
- nstr = rb_define_class_under(klass, RSTRING(name)->ptr, klass);
rb_iv_set(nstr, "__size__", INT2FIX(RARRAY(member)->len));
rb_iv_set(nstr, "__member__", member);
@@ -206,7 +212,6 @@ struct_s_def(argc, argv, klass)
VALUE st;
rb_scan_args(argc, argv, "1*", &name, &rest);
- Check_Type(name, T_STRING);
for (i=0; i<rest->len; i++) {
ID id = rb_to_id(rest->ptr[i]);
rest->ptr[i] = INT2FIX(id);