[issue5186] Reduce hash collisions for objects with no __hash__ method
report at bugs.python.org
Thu Feb 12 12:54:26 CET 2009
Mark Dickinson <dickinsm at gmail.com> added the comment:
> Well, I had memories of a weird signed/unsigned problem (issue4935) and
> I wasn't sure whether it could raise its head in the present case or
I'm 99.9% sure that it's not a problem here. If it is a problem then it
needs to be fixed in long_hash in longobject.c as well, which uses
exactly the same code.
The relevant section of the C99 standard is 126.96.36.199, para. 1 (try
googling for 'n1256' if you don't have a copy of the standard). The
only really nasty cases are those of the form unsigned_int +
signed_long, or more generally,
low_rank_unsigned_integer binary_op higher_rank_signed_integer
where the type of the expression depends on the relative sizes (not just
ranks) of the integer types, giving potential portability problems. And
there are similar problems with the integer promotions (188.8.131.52, para. 2).
I guess it comes down to personal taste, but my own preference is to
leave out casts where the conversion they describe is already implied by
the C language rules, adding them back in to silence compiler warnings
if necessary. I find it reduces noise in the code and makes the
important casts more visible, but chacun à son goût.
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list