[Cython] Cython 0.16: "eval" problem

Nathan Dunfield nmd at illinois.edu
Sun Apr 22 19:59:09 CEST 2012


With Cython 0.15, the following works with Python 2.7:

### start file: prob.pyx

def f(x):
    cdef int* p
    return eval(x)

### end file

>>> import pyximport; pyximport.install()
>>> import prob
>>> prob.f("5")
5

but with Cython 0.16 it doesn't even compile:

>>> import prob

Error compiling Cython file:
------------------------------------------------------------
...
def f(x):
    cdef int* p
    return eval(x)
              ^
------------------------------------------------------------

prob.pyx:3:15: Cannot convert 'int *' to Python object

If I comment out the (unused) line "cdef int* p" then it works with Cython 0.16.  The issue is the pointer declaration; something like:

def f(x):
    cdef int p
    p = eval(x)
    return p*p

works fine with Cython 0.16.

	Thanks,

	Nathan

    





More information about the cython-devel mailing list