[Pyrex] Bug in PySequence indexing

Robert Bradshaw robertwb at math.washington.edu
Thu May 29 11:33:17 CEST 2008


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





More information about the Pyrex mailing list