mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* struct.c (make_struct): allow non local-id field
names. [ruby-core:04575] * struct.c (inspect_struct): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8171 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b547538e68
commit
56b9f4da43
3 changed files with 26 additions and 16 deletions
|
@ -1,3 +1,10 @@
|
|||
Thu Mar 17 17:42:13 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* struct.c (make_struct): allow non local-id field
|
||||
names. [ruby-core:04575]
|
||||
|
||||
* struct.c (inspect_struct): ditto.
|
||||
|
||||
Wed Mar 16 23:39:13 2005 Shugo Maeda <shugo@ruby-lang.org>
|
||||
|
||||
* test/ruby/test_settracefunc.rb: added test for c-return.
|
||||
|
|
1
parse.y
1
parse.y
|
@ -8942,4 +8942,3 @@ Init_ripper()
|
|||
rb_intern("&&");
|
||||
}
|
||||
#endif /* RIPPER */
|
||||
|
||||
|
|
34
struct.c
34
struct.c
|
@ -210,17 +210,15 @@ make_struct(name, members, klass)
|
|||
rb_define_singleton_method(nstr, "members", rb_struct_s_members_m, 0);
|
||||
for (i=0; i< RARRAY(members)->len; i++) {
|
||||
ID id = SYM2ID(RARRAY(members)->ptr[i]);
|
||||
if (!rb_is_local_id(id)) {
|
||||
rb_raise(rb_eNameError, "`%s' is not proper name for a struct member",
|
||||
rb_id2name(id));
|
||||
if (rb_is_local_id(id)) {
|
||||
if (i<sizeof(ref_func)) {
|
||||
rb_define_method_id(nstr, id, ref_func[i], 0);
|
||||
}
|
||||
else {
|
||||
rb_define_method_id(nstr, id, rb_struct_ref, 0);
|
||||
}
|
||||
rb_define_method_id(nstr, rb_id_attrset(id), rb_struct_set, 1);
|
||||
}
|
||||
if (i<sizeof(ref_func)) {
|
||||
rb_define_method_id(nstr, id, ref_func[i], 0);
|
||||
}
|
||||
else {
|
||||
rb_define_method_id(nstr, id, rb_struct_ref, 0);
|
||||
}
|
||||
rb_define_method_id(nstr, rb_id_attrset(id), rb_struct_set, 1);
|
||||
}
|
||||
|
||||
return nstr;
|
||||
|
@ -489,18 +487,24 @@ inspect_struct(s, dummy, recur)
|
|||
rb_str_cat2(str, cname);
|
||||
rb_str_cat2(str, " ");
|
||||
for (i=0; i<RSTRUCT(s)->len; i++) {
|
||||
VALUE str2, slot;
|
||||
VALUE slot;
|
||||
ID id;
|
||||
char *p;
|
||||
|
||||
if (i > 0) {
|
||||
rb_str_cat2(str, ", ");
|
||||
}
|
||||
slot = RARRAY(members)->ptr[i];
|
||||
p = rb_id2name(SYM2ID(slot));
|
||||
rb_str_cat2(str, p);
|
||||
id = SYM2ID(slot);
|
||||
if (rb_is_local_id(id)) {
|
||||
p = rb_id2name(id);
|
||||
rb_str_cat2(str, p);
|
||||
}
|
||||
else {
|
||||
rb_str_append(str, rb_inspect(slot));
|
||||
}
|
||||
rb_str_cat2(str, "=");
|
||||
str2 = rb_inspect(RSTRUCT(s)->ptr[i]);
|
||||
rb_str_append(str, str2);
|
||||
rb_str_append(str, rb_inspect(RSTRUCT(s)->ptr[i]));
|
||||
}
|
||||
rb_str_cat2(str, ">");
|
||||
OBJ_INFECT(str, s);
|
||||
|
|
Loading…
Add table
Reference in a new issue