[Python-Dev] index clipping (original) (raw)
Travis E. Oliphant oliphant.travis at ieee.org
Fri Aug 11 09:51:04 CEST 2006
- Previous message: [Python-Dev] __index__ clipping
- Next message: [Python-Dev] __index__ clipping
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Here is my C-API proposal
PyIndex_Check(obj)
Similar to PyIter_Check(obj) as it just checks for whether or not the
object can call nb_index. Actually implemented as a macro.
PyObject* PyNumber_Index(obj)
Simple interface around nb_index that calls it if possible and returns TypeError if not (or if the result does not end up in an exact int-or-long
Py_ssize_t PyNumber_AsSsize_t(obj, err)
This converts the object to a Py_ssize_t by using the nb_index call if possible. The err argument is a Python error object and specifies what error should be raised should the conversion from Int-or-Long to Py_ssize_t cause Overflow.
If err is NULL, then no error will be raised and the result will be
clipped. Other-wise the corresponding error will be set. Internally PyExc_IndexError and PyExc_OverflowError will be the errors used.
-Travis
- Previous message: [Python-Dev] __index__ clipping
- Next message: [Python-Dev] __index__ clipping
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]