* proc.c (method_hash, proc_hash): Fix {Unbound}Method#hash

[Bug #6048]. Isolate hash computation for proc

* internal.h: Declaration for above

* vm_method.c (rb_method_definition_hash): Computation for
  hash part of a method definition

* method.h: Declaration for above

* test/ruby/test_method.rb: Test for above

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
marcandre 2012-02-21 00:13:44 +00:00
parent 3052f75db4
commit f12c14d3ef
6 changed files with 63 additions and 4 deletions

16
proc.c
View file

@ -794,6 +794,15 @@ proc_eq(VALUE self, VALUE other)
return Qfalse;
}
st_index_t
rb_hash_proc(st_index_t hash, VALUE prc)
{
const rb_proc_t *proc = (const rb_proc_t *)prc;
hash = rb_hash_uint(hash, (st_index_t)proc->block.iseq);
hash = rb_hash_uint(hash, (st_index_t)proc->envval);
return rb_hash_uint(hash, (st_index_t)proc->block.lfp >> 16);
}
/*
* call-seq:
* prc.hash -> integer
@ -807,9 +816,8 @@ proc_hash(VALUE self)
st_index_t hash;
rb_proc_t *proc;
GetProcPtr(self, proc);
hash = rb_hash_start((st_index_t)proc->block.iseq);
hash = rb_hash_uint(hash, (st_index_t)proc->envval);
hash = rb_hash_uint(hash, (st_index_t)proc->block.lfp >> 16);
hash = rb_hash_start(0);
hash = rb_hash_proc(hash, proc);
hash = rb_hash_end(hash);
return LONG2FIX(hash);
}
@ -1075,7 +1083,7 @@ method_hash(VALUE method)
TypedData_Get_Struct(method, struct METHOD, &method_data_type, m);
hash = rb_hash_start((st_index_t)m->rclass);
hash = rb_hash_uint(hash, (st_index_t)m->recv);
hash = rb_hash_uint(hash, (st_index_t)m->me->def);
hash = rb_hash_method_entry(hash, m->me);
hash = rb_hash_end(hash);
return INT2FIX(hash);