[Pyrex] Unsigned int index regression in 0.9.8.3

Christopher Williams christopherw at verizon.net
Wed Jun 11 04:15:30 CEST 2008


The following test case (based on a problem found in the
compizconfig-python bindings) fails with pyrex 0.9.8.3 but works with
0.9.6.4:

cdef class Foo:
    cdef unsigned int num
    
    def __cinit__(self):
        self.num = 0
        print ['foo', 'bar'][self.num]

Using the following setup.py:

from distutils.core import setup
from distutils.extension import Extension
from Pyrex.Distutils import build_ext
setup(
  name = "foo",
  ext_modules=[ 
    Extension("foo", ["foo.pyx"])
    ],
  cmdclass = {'build_ext': build_ext}
)

Example session:

>>> import foo
>>> foo.Foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "foo.pyx", line 6, in foo.Foo.__cinit__
    print ['foo', 'bar'][self.num]
SystemError: null argument to internal routine

The generated C code shows the unsigned int being cast to PyObject *
and passed to PyObject_GetItem (so in this case, python sees it as a
NULL pointer). As a workaround, using an int instead seems to work
correctly. 

This bug appears to have been introduced in mercurial revision 94.



More information about the Pyrex mailing list