After pushing the changes for the 'size_t' stuff, now I believe that
things were a bit broken before the patch, and they still are.

+ Go Cython.Compiler.PyrexTypes

+ Look at the module-level tuple variable 'rank_to_type_name'. You can
see that 'Py_ssize_t' and 'size_t' are AFTER the type 'PY_LONG_LONG'.

+ Now look at the implementation of the function 'widest_numeric_type()'.

Then, this bit of Cython::

cdef f():
    cdef unsigned long long a = 5
    cdef size_t b = 7
    return a + b

generates C code like this::

  /* "/u/dalcinl/Devel/cython-devel/tmp.pyx":5
 *     cdef unsigned long long a = 5
 *     cdef size_t b = 7
 *     return a + b             # <<<<<<<<<<<<<<
 */
  /* __pyx_t_1 allocated */
  __pyx_t_1 = __pyx_PyInt_FromSize_t((__pyx_v_a + __pyx_v_b)); if
(unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5;
__pyx_clineno = __LINE__; goto __pyx_L1_error;}



This is IMHO totally wrong !!


Could we assume that PY_LONG_LONG is the widest integral?? Should we
assume that 'Py_ssize_t' and 'size_t' are between 'long' and
'PY_LONG_LONG'? In such case, I'll have to fix the 'rank_to_type_name'
tuple, and perhaps the 'sign_and_rank_to_type' dictionary (used as a
fallback in function 'widest_numeric_type()')

However, I'm not sure how to we will handle code like the one below
with the current implementation,

cdef f():
    cdef Py_ssize_t a = 5
    cdef size_t b = 7
    return a + b

I believe the value of 'a+b' should be promoted to 'signed long long',
but it cannot see the way to implent such behavior in the current
Cython codebase.



-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to