-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
Milestone
Description
If I annotate a function using PEP484/526 syntax
import cython
@cython.cfunc
def fib(n : cython.int) -> cython.int:
if (n<=1):
return n
return fib(n-1) + fib(n-2)cython -c tells me the last line interacts with Python, basically checking PyErr_Occurred().
Whereas if I use decorators, there are no such checks, and Cython generates the same C code as it would with Pyrex syntax:
import cython
@cython.cfunc
@cython.locals(n=cython.int)
@cython.returns(cython.int)
def _fib(n):
if (n<=1):
return n
return _fib(n-1) + _fib(n-2)The return line using PEP484/526 syntax looks like this
+08: return _fib(n-1) + _fib(n-2)
__pyx_t_2 = __pyx_f_46_cython_magic_dd8e3b97486038017346fa36994a0695__fib((__pyx_v_n - 1)); if (unlikely(__pyx_t_2 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L1_error)
__pyx_t_3 = __pyx_f_46_cython_magic_dd8e3b97486038017346fa36994a0695__fib((__pyx_v_n - 2)); if (unlikely(__pyx_t_3 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L1_error)
__pyx_r = (__pyx_t_2 + __pyx_t_3);
goto __pyx_L0;whereas with decorators it looks like this
+11: return _fib(n-1) + _fib(n-2)
__pyx_r = (__pyx_f_46_cython_magic_6c3a15eed3bce3137103a8464b16a811__fib((__pyx_v_n - 1)) + __pyx_f_46_cython_magic_6c3a15eed3bce3137103a8464b16a811__fib((__pyx_v_n - 2)));
goto __pyx_L0;