Message 119020 - Python tracker (original) (raw)
On Mon, Oct 18, 2010 at 9:59 AM, Antoine Pitrou <report@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.