summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-03-17 08:50:26 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-03-17 08:50:26 +0000
commit8edf8442e46496cbf89165901e54413be1f03cde (patch)
tree086e45007ed8b6777eb78824ea55d71df8f8b6f1
parentc37188578acd5e9437014259f58fd2b30d83decd (diff)
* 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/branches/ruby_1_8@8170 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--struct.c34
2 files changed, 26 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 5f1793ab47..a06f20a903 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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:36:02 2005 Shugo Maeda <shugo@ruby-lang.org>
* eval.c (rb_call0): call_cfunc() should be protected.
diff --git a/struct.c b/struct.c
index 55f9c8aac1..8521195b71 100644
--- a/struct.c
+++ b/struct.c
@@ -212,17 +212,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<10) {
+ 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<10) {
- 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;
@@ -481,18 +479,24 @@ inspect_struct(s)
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);