[Cython] question on Get/SetItemInt*() utility functions

Stefan Behnel stefan_ml at behnel.de
Sat Nov 9 08:20:00 CET 2013


Stefan Behnel, 09.11.2013 07:17:
> Putting it all together, we can use the fast path in these cases:
> 
>     (sizeof(type_of_i) < sizeof(Py_ssize_t))  ||
> 
>     (sizeof(type_of_i) > sizeof(Py_ssize_t) &&
>           (i <= (type_of_i)PY_SSIZE_T_MAX)  &&
>           (!signed || i >= (type_of_i)PY_SSIZE_T_MIN))  ||
> 
>     (sizeof(type_of_i) == sizeof(Py_ssize_t) &&
>           (signed || (i <= (type_of_i)PY_SSIZE_T_MAX)))
> 
> 
> The casts I added should keep the C compiler from complaining about unsafe
> comparisons.
> 
> Then, for builtin container types, the fallback path already knows that the
> index is out of bounds and can always raise an IndexError. For unknown
> types, the existing "Generic" fallback function can be used.

https://github.com/cython/cython/commit/b66981604baf59ea465027cc10baa42af7c76571

https://github.com/cython/cython/commit/0cae66191bfe42657ff0010e4ca13d032cb523b8

Stefan



More information about the cython-devel mailing list