[issue9778] Make hash values the same width as a pointer (or Py_ssize_t)

Alexander Belopolsky report at bugs.python.org
Mon Oct 18 16:09:12 CEST 2010


Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:

On Mon, Oct 18, 2010 at 9:59 AM, Antoine Pitrou <report at bugs.python.org> wrote:
..
>> Why?  As far as I can tell, negative values are only used as sentinels
>> and we can use say (size_t)-1 instead of -1L.
>
> You can, except that changing the sentinel value will probably break a
> lot of code out there (and there's no benefit AFAICT).

AFAICT, a change from (Py_ssize_t)-1 to (size_t)-1 is less likely to
break code than a change from -1L to  (Py_ssize_t)-1.  (Assuming a
sizeof(long) != sizeof(void*) platform.)  The benefit, though is that
hash computations can be performed natively on the hash values without
casting to an unrelated type.  If Py_hash_t needs to be signed, I
would like to see a typedef Py_uhash_t size_t next to that for
Py_hash_t and  Py_uhash_t used in hash computations rather than
explicit size_t.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9778>
_______________________________________


More information about the Python-bugs-list mailing list