summaryrefslogtreecommitdiff
path: root/struct.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-05 10:52:44 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-05 10:52:44 +0000
commit0fb8126bbf9e458f93ba80caa9adf91a47f6d984 (patch)
treed28d2c2af3482d03b1be2ca5809d82738203e458 /struct.c
parent50c2a48b8502e96cfc399e80bcae939243d95395 (diff)
* struct.c (rb_struct_s_def): Struct.new(0) should not SEGV.
based on the patch from wanabe <s.wanabe at gmail.com> in [ruby-dev:34594]. * struct.c (make_struct): call to_str on name object. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16295 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/struct.c b/struct.c
index 74d20a426c..415032bed4 100644
--- a/struct.c
+++ b/struct.c
@@ -181,7 +181,9 @@ make_struct(VALUE name, VALUE members, VALUE klass)
rb_class_inherited(klass, nstr);
}
else {
- id = SYM2ID(rb_str_intern(name));
+ /* old style: should we warn? */
+ name = rb_str_to_str(name);
+ id = rb_to_id(name);
if (!rb_is_const_id(id)) {
rb_name_error(id, "identifier %s needs to be constant", StringValuePtr(name));
}
@@ -322,14 +324,14 @@ rb_struct_s_def(int argc, VALUE *argv, VALUE klass)
ID id;
rb_scan_args(argc, argv, "1*", &name, &rest);
- for (i=0; i<RARRAY_LEN(rest); i++) {
- id = rb_to_id(RARRAY_PTR(rest)[i]);
- RARRAY_PTR(rest)[i] = ID2SYM(id);
- }
if (!NIL_P(name) && SYMBOL_P(name)) {
rb_ary_unshift(rest, name);
name = Qnil;
}
+ for (i=0; i<RARRAY_LEN(rest); i++) {
+ id = rb_to_id(RARRAY_PTR(rest)[i]);
+ RARRAY_PTR(rest)[i] = ID2SYM(id);
+ }
st = make_struct(name, rest, klass);
if (rb_block_given_p()) {
rb_mod_module_eval(0, 0, st);