[pypy-dev] hash negotiation

Christian Tismer tismer at tismer.com
Sat Mar 1 20:01:18 CET 2003


Hi,

additional to an integer change, I also saw a change of
the hash implementation:

def int_hash(space, w_int1):
     #/* XXX If this is changed, you also need to change the way
     #   Python's long, float and complex types are hashed. */
##    x = w_int1.intval
##    if x == -1:
##        x = -2
##    return W_IntObject(x)
     # XXX unlike CPython we have no need to special-case the value -1
     return w_int1

I intentionally repeated CPython's implementation, which special
cases -1 as an indicator for "no hash computed yet".

It may negotiable whether we want to preserve an extra flag
in all the hashable objects whether the hash has been computed,
or repeat CPython's way to preserve a single value for this.
This is a part of CPython's object protocol, and I believe
we *have* to decide about this together. It cannot be our
style just to remove something without notice.

How hashes are computed has two impacts which we need decide
upon:
- If we aim at CPython compatibilty at some time, we might
   keep the door open to do exactly the same here.
- If we want to provide *functional* compatibility with CPython's
   hash values, then we need to provide exactly the same values,
   or programs relying on hash values will behave differently.

I have no problem to have different implementations, it might
even make sense to add a config variable, how compatible we want
to be.
But since hash() is an exposed function, we need at least
be aware when we change something visible, and we need to express
whether we care about that or not.
Obviously, my default way of doing things "when in doubt, then
do what the C code does" isn't shared by Armin.
Creating an almost CPython compatible implementation was one
of the targets from the beginning, and I don't remember that
we have dispensed of possible targets, already.

So I'd like to ask for your opinions about stuff like that.

cheers - chris
-- 
Christian Tismer             :^)   <mailto:tismer at tismer.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a     :    *Starship* http://starship.python.net/
14109 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34  home +49 30 802 86 56  pager +49 173 24 18 776
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?   http://www.stackless.com/




More information about the Pypy-dev mailing list