* 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
This commit is contained in:
parent
0101958745
commit
2cdcc564fd
@ -1,3 +1,9 @@
|
|||||||
|
Fri Jul 17 18:11:32 2009 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* 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 <akr@fsij.org>
|
Fri Jul 17 16:45:22 2009 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* array.c (recursive_hash): reject recursive key.
|
* array.c (recursive_hash): reject recursive key.
|
||||||
|
31
struct.c
31
struct.c
@ -802,6 +802,25 @@ rb_struct_equal(VALUE s, VALUE s2)
|
|||||||
return Qtrue;
|
return Qtrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
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]);
|
||||||
|
h = rb_hash_uint(h, NUM2LONG(n));
|
||||||
|
}
|
||||||
|
h = rb_hash_end(h);
|
||||||
|
return INT2FIX(h);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* struct.hash => fixnum
|
* struct.hash => fixnum
|
||||||
@ -812,17 +831,7 @@ rb_struct_equal(VALUE s, VALUE s2)
|
|||||||
static VALUE
|
static VALUE
|
||||||
rb_struct_hash(VALUE s)
|
rb_struct_hash(VALUE s)
|
||||||
{
|
{
|
||||||
long i;
|
return rb_exec_recursive(recursive_hash, s, 0);
|
||||||
unsigned long h;
|
|
||||||
VALUE n;
|
|
||||||
|
|
||||||
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]);
|
|
||||||
h = rb_hash_uint(h, NUM2LONG(n));
|
|
||||||
}
|
|
||||||
h = rb_hash_end(h);
|
|
||||||
return INT2FIX(h);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user