[Python-3000] int-long unification

Guido van Rossum guido at python.org
Sun Aug 20 18:43:05 CEST 2006


On 8/20/06, "Martin v. Löwis" <martin at v.loewis.de> wrote:
> Guido van Rossum schrieb:
> > Are you interested in doing this at the Google sprint next week?
>
> Sure; I hadn't any special plans so far.
>
> > What do you think?
>
> Sounds good. There are two problems I see:
>
> - how to benchmark?

We could possibly do a lot of int allocations and deallocations in a
temporary extension module.

> - there are subtle details in the API that require changes
>   to extension code. In particular, PyInt_AsLong currently
>   cannot fail, but can fail with a range error after the
>   unification.
>
> However, to evaluate the performance, it is possible to work
> around that.
>
> For this specific problem, I would propose to introduce
> another API, say
>
> int PyLong_ToLong(PyObject* val, long* result);
>
> which will return true(1) for success, and set an exception
> in case of a failure. Then, we get
>
> long PyLong_AsLong(PyObj *val)
> {
>   long result;
>   if(!PyLong_ToLong(val, &result))return -1;
>   return result;
> }
>
> and perhaps
>
> long PyInt_AsLong(PyObj* val)
> {
>   long result;
>   if(!PyLong_ToLong(val, &result))
>     Py_FatalError("old-style integer conversion failed");
>   return result;
> }

The fatal error strikes me as unpleasant. Perhaps PyInt_Check[Exact]
should return false if the value won't fit in a C long? Or perhaps we
could just return -sys.maxint-1?

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list