[Python-3000] int-long unification (original) (raw)
Guido van Rossum guido at python.org
Sun Aug 20 18:43:05 CEST 2006
- Previous message: [Python-3000] int-long unification
- Next message: [Python-3000] int-long unification
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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, PyIntAsLong 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 PyLongToLong(PyObject* val, long* result); which will return true(1) for success, and set an exception in case of a failure. Then, we get long PyLongAsLong(PyObj *val) { long result; if(!PyLongToLong(val, &result))return -1; return result; } and perhaps long PyIntAsLong(PyObj* val) { long result; if(!PyLongToLong(val, &result)) PyFatalError("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/)
- Previous message: [Python-3000] int-long unification
- Next message: [Python-3000] int-long unification
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]