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

* 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
This commit is contained in:
matz 2008-05-05 10:52:44 +00:00
parent 50c2a48b85
commit 0fb8126bbf
2 changed files with 15 additions and 5 deletions

View file

@ -1,3 +1,11 @@
Mon May 5 19:49:59 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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.
Mon May 5 17:17:40 2008 Tanaka Akira <akr@fsij.org>
* eval.c (ruby_cleanup): wrap ruby_finalize_0 by SAVE_ROOT_JMPBUF to

View file

@ -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);