[Python-Dev] __index__ clipping
Nick Coghlan
ncoghlan at gmail.com
Fri Aug 11 13:44:26 CEST 2006
Travis E. Oliphant wrote:
> Travis E. Oliphant wrote:
>> Here is my C-API proposal
>>
>> 1) 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.
>>
>> 2) 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
>>
>> 3) 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.
>>
>
> This proposal is implemented as patch 1538606
> http://sourceforge.net/tracker/index.php?func=detail&aid=1538606&group_id=5470&atid=305470
This interface is a lot simpler to explain and use than the one in my patch,
and more in tune with the rest of the C API.
I had a minor documentation suggestion which I put on the tracker item, but
other than that +1 on using Travis's patch instead of mine (I've already
rejected my own tracker item).
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-Dev
mailing list