summaryrefslogtreecommitdiff
path: root/struct.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-17 09:13:29 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-17 09:13:29 +0000
commit2cdcc564fd9a15e8f6d7f20c972cdc6e98243b67 (patch)
treefcdbf2b28a8b37f4cb66df91c14c269109d3de5b /struct.c
parent0101958745f8a18679a71f378656f0ed5184e36b (diff)
* struct.c (recursive_hash): extracted from rb_struct_hash. reject
recursive key. (rb_struct_hash): use recursive_hash. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/struct.c b/struct.c
index a93ed65f7d..e4b6da0e76 100644
--- a/struct.c
+++ b/struct.c
@@ -802,20 +802,16 @@ rb_struct_equal(VALUE s, VALUE s2)
return Qtrue;
}
-/*
- * call-seq:
- * struct.hash => fixnum
- *
- * Return a hash value based on this struct's contents.
- */
-
static VALUE
-rb_struct_hash(VALUE s)
+recursive_hash(VALUE s, VALUE dummy, int recur)
{
long i;
unsigned long h;
VALUE n;
+ if (recur) {
+ rb_raise(rb_eArgError, "recursive key for hash");
+ }
h = rb_hash_start(rb_hash(rb_obj_class(s)));
for (i = 0; i < RSTRUCT_LEN(s); i++) {
n = rb_hash(RSTRUCT_PTR(s)[i]);
@@ -826,6 +822,19 @@ rb_struct_hash(VALUE s)
}
/*
+ * call-seq:
+ * struct.hash => fixnum
+ *
+ * Return a hash value based on this struct's contents.
+ */
+
+static VALUE
+rb_struct_hash(VALUE s)
+{
+ return rb_exec_recursive(recursive_hash, s, 0);
+}
+
+/*
* code-seq:
* struct.eql?(other) => true or false
*