[Cython] bytearray tests fail with default unsigned char

Julian Taylor jtaylor.debian at googlemail.com
Wed Jan 22 00:03:20 CET 2014


hi,
the bytearray tests are broken when chars are unsigned.

tests/run/bytearraymethods.pyx defines following function:
def bytearray_append(b, char c, int i, object o):

this gets converted to an effective __Pyx_PyInt_AsUnsignedChar which
then errors out when -1 is passed in.
chars are unsigned like they are by default on arm, s390x and powerpc.
This causes a couple build failures in debian:
https://buildd.debian.org/status/package.php?p=cython
https://buildd.debian.org/status/fetch.php?pkg=cython&arch=armel&ver=0.20-1&stamp=1390316252

the tests can be fixed by adding signed char to the interface.

to reproduce on x86 with gcc (note the -funsigned-char to change the
default):

cython tests/run/bytearraymethods.pyx
gcc -funsigned-char bytearraymethods.c -fPIC $(python-config --includes)
$(python-config --libs) -shared -O2 -o bytearraymethods.so

python -c "import doctest; import bytearraymethods;
doctest.testmod(bytearraymethods)"

Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'bytearraymethods' is not defined
root at ubuntu:/# python -c "import doctest; import bytearraymethods;
doctest.testmod(bytearraymethods)"
**********************************************************************
File "bytearraymethods.so", line ?, in
bytearraymethods.__test__.bytearray_append (line 202)
Failed example:
    b = bytearray_append(b, -1, ord('y'), ord('z'))  # doctest: +ELLIPSIS
Expected:
    Traceback (most recent call last):
    ValueError: ...
Got:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest bytearraymethods.__test__.bytearray_append (line
202)[14]>", line 1, in <module>
        b = bytearray_append(b, -1, ord('y'), ord('z'))  # doctest:
+ELLIPSIS
      File "bytearraymethods.pyx", line 202, in
bytearraymethods.bytearray_append (bytearraymethods.c:1339)
        def bytearray_append(bytearray b, char c, int i, object o):
    OverflowError: can't convert negative value to char
**********************************************************************



More information about the cython-devel mailing list