From ad29fe856c7df1bab98109ad241205c7ffdf24ea Mon Sep 17 00:00:00 2001 From: akr Date: Fri, 17 Jul 2009 09:13:29 +0000 Subject: * struct.c (recursive_hash): extracted from rb_struct_hash. reject recursive key. (rb_struct_hash): use recursive_hash. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@24166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ struct.c | 25 +++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index c87714005..42ee98d73 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Jul 17 18:11:32 2009 Tanaka Akira + + * struct.c (recursive_hash): extracted from rb_struct_hash. reject + recursive key. + (rb_struct_hash): use recursive_hash. + Fri Jul 17 16:45:22 2009 Tanaka Akira * array.c (recursive_hash): reject recursive key. diff --git a/struct.c b/struct.c index a93ed65f7..e4b6da0e7 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]); @@ -825,6 +821,19 @@ rb_struct_hash(VALUE s) return INT2FIX(h); } +/* + * 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 -- cgit