Bug in 0.19 (with example)

61 views
Skip to first unread message

Eric Frederich

unread,
May 1, 2013, 12:59:29 PM5/1/13
to cython...@googlegroups.com, cython...@python.org
Hello,

I have discovered a bug in Cython 0.19

This code works in 0.15.1 but not in 0.19.
I haven't tested it anywhere in between.

The following 3 files are listed at the end of this email.
blah.h
blah.pxd
test.pyx

The errors I get are the following:
test.pyx:3:18: Not allowed in a constant expression
test.pyx:3:18: Array dimension not integer
test.pyx:3:20: Variable type 'char []' is incomplete

The line is:
cdef char[blah.FOO] x

If I do:
cdef char[int(blah.FOO)] x
... I get the following error:
test.pyx:3:10: Compiler crash in AnalyseDeclarationsTransform

The workaround that I found to work is to add +0 at the end of the constant:
cdef char[blah.FOO+0] x

I found this because I have a bunch of bindings with character arrays
with some constant +1.
After upgrading from 0.15.1 to 0.19 cython didn't complain about them,
only the ones without the +1.
Putting the +0 seems to work.

My apologies if this is already a known bug.

If this is indeed a genuine new bug please let me know the bug number
so I can comment my workaround code accordingly.

Thanks,
~Eric


##### start blah.h #####
#ifndef BLAH__H
#define BLAH__H

#define FOO 123

#endif
##### end blah.h #####


##### start blah.pxd #####
cdef extern from "blah.h" nogil:
enum: FOO
##### end blah.pxd #####


##### start test.pyx #####
cimport blah

cdef char[blah.FOO] x

s = 'Hello'

# copy
for index, c in enumerate(s):
x[index] = ord(c)
# terminate
x[len(s)] = 0

i = 0
while x[i] != 0:
print '%2d %c' % (i, x[i])
i += 1
##### end test.pyx #####

Stefan Behnel

unread,
May 1, 2013, 1:57:58 PM5/1/13
to cython...@googlegroups.com, cython...@python.org
Eric Frederich, 01.05.2013 18:59:
> I have discovered a bug in Cython 0.19
>
> This code works in 0.15.1 but not in 0.19.
> I haven't tested it anywhere in between.
>
> The following 3 files are listed at the end of this email.
> blah.h
> blah.pxd
> test.pyx
>
> The errors I get are the following:
> test.pyx:3:18: Not allowed in a constant expression
> test.pyx:3:18: Array dimension not integer
> test.pyx:3:20: Variable type 'char []' is incomplete
>
> The line is:
> cdef char[blah.FOO] x
>
> If I do:
> cdef char[int(blah.FOO)] x
> ... I get the following error:

Thanks for the report. Looks like a known bug, however, already reported
and fixed:

http://mail.python.org/pipermail/cython-devel/2013-May/003631.html

Stefan

Eric Frederich

unread,
May 1, 2013, 3:05:50 PM5/1/13
to cython...@googlegroups.com, cython...@python.org
Thanks,

Glad to see it was caught.
... and glad that there is a workaround for me at the moment with the +0

~Eric
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "cython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Stefan Behnel

unread,
May 1, 2013, 4:30:50 PM5/1/13
to cython...@googlegroups.com
Eric Frederich, 01.05.2013 21:05:
> On Wed, May 1, 2013 at 1:57 PM, Stefan Behnel wrote:
>> Eric Frederich, 01.05.2013 18:59:
>>> I have discovered a bug in Cython 0.19
>>>
>>> This code works in 0.15.1 but not in 0.19.
>>> I haven't tested it anywhere in between.
>>>
>>> The following 3 files are listed at the end of this email.
>>> blah.h
>>> blah.pxd
>>> test.pyx
>>>
>>> The errors I get are the following:
>>> test.pyx:3:18: Not allowed in a constant expression
>>> test.pyx:3:18: Array dimension not integer
>>> test.pyx:3:20: Variable type 'char []' is incomplete
>>>
>>> The line is:
>>> cdef char[blah.FOO] x
>>>
>>> If I do:
>>> cdef char[int(blah.FOO)] x
>>> ... I get the following error:
>>
>> Thanks for the report. Looks like a known bug, however, already reported
>> and fixed:
>>
>> http://mail.python.org/pipermail/cython-devel/2013-May/003631.html
>
> Glad to see it was caught.
> ... and glad that there is a workaround for me at the moment with the +0

Well, you could still try the latest master branch from github to see if
that works correctly for your code.

Stefan

Reply all
Reply to author
Forward
0 new messages