Bug in PySequence indexing
Robert Bradshaw <[email protected]> Thu, 29 May 2008 02:33:17 -0700
| Newsgroups | gmane.comp.python.pyrex |
|---|---|
| Message-ID | <[email protected]> |
Greg,
I was looking at your integer indexing optimization and noticed that
there's a potential bug when indexing with unsigned ints. For
example, try
print sizeof(Py_ssize_t), "==", sizeof(unsigned long)
D = { -1: "negative", <unsigned long>-1: "positive" }
print D[<unsigned long>-1]
on a system where Py_ssize_t and unsigned long have the same size.
The fix I came up with was passing an extra argument signifying
whether or not it needed to worry about a sign change (which should
usually get optimized away).
- Robert