[Python-3000] int-long unification

"Martin v. Löwis" martin at v.loewis.de
Sun Aug 20 18:30:23 CEST 2006


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?

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

Regards,
Martin


More information about the Python-3000 mailing list