On Fri, Apr 17, 2009 at 1:52 PM, Stefan Behnel <[email protected]> wrote:
>
> BTW, in Py3, PyNumber_Int() was replaced in favour of PyNumber_Long(). That
> makes it a bit funny, the C layer uses "long", whereas the Python layer
> uses "int".
>

Of course... They should have to remove nb_int, and mantain nb_long...
I remember there were some recent discussions about this
inconsistencies on Python-Dev...

>
> I don't see a major use case either, but calling nb_int when we convert to
> a C-int or a smaller type might still make sense in Py2.

Well, my implementation first check if nb_long exists, if not, it
checks nb_int. So all this work just fine in Py2.

> Note that Py2 allows __int__() to return a PyLong if the value doesn't fit
> into a PyInt, while __long__() must return a PyLong:
>

Then I would vote for getting rid of "nb_long" at all, and always fill
"nb_int" with these rule:

1) if "__int__()" is implemented, always use it and ignore
"__long__()" if present, then fill the "nb_int" slot in Py2/Py3, and
set "nb_long"/"nb_reserved" to NULL.

2) if only "__long__()" is implemented, then fill the "nb_int" slot in
Py2/Py3, and set "nb_long"/"nb_reserved" to NULL.

BTW, filling only the "nb_long" slot has issues, see for example the
implementation "PyNumber_Check()" in Python 2. A  cdef class only
implementing "__long__()" will likely fail that check, right?


What do you think?


> http://docs.python.org/c-api/number.html#PyNumber_Int
>
> """
> PyObject* PyNumber_Int(PyObject *o)
>    Return value: New reference.
>
>    Returns the o converted to an integer object on success, or NULL on
> failure. If the argument is outside the integer range a long object will be
> returned instead. This is the equivalent of the Python expression int(o).
>
> PyObject* PyNumber_Long(PyObject *o)
>    Return value: New reference.
>
>    Returns the o converted to a long integer object on success, or NULL on
> failure. This is the equivalent of the Python expression long(o).
> """
>
> Stefan
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>



-- 
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