[Cython] Cython 0.16: "eval" problem
Vitja Makarov
vitja.makarov at gmail.com
Sun Apr 22 20:22:44 CEST 2012
2012/4/22 Nathan Dunfield <nmd at illinois.edu>:
> 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
>
Oops, it seems to be a problem with locals() dict creation. Perhaps it
should ignore variables that can't be converted to PyObject
--
vitja.
More information about the cython-devel
mailing list