[Patches] [ python-Patches-1538606 ] Patch to fix __index__() clipping

SourceForge.net noreply at sourceforge.net
Fri Aug 11 13:47:48 CEST 2006


Patches item #1538606, was opened at 2006-08-11 20:51
Message generated for change (Comment added) made by ncoghlan
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1538606&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core (C code)
Group: Python 2.5
Status: Open
Resolution: None
Priority: 9
Submitted By: Travis Oliphant (teoliphant)
Assigned to: Neal Norwitz (nnorwitz)
Summary: Patch to fix __index__() clipping

Initial Comment:
This is a patch that builds off of Nick Coghlan's work
to fix the __index__() clipping problem.  

It defines 3 New C-API calls (1 is a macro):

int PyIndex_Check(obj) -- does this object have nb_index

PyObject* PyNumber_Index(obj) -- return nb_index(obj)
if possible

Py_ssize_t PyNumber_AsSsize_t(obj, err) -- return obj
as Py_ssize_t by frist going through nb_index(obj)
which returns an integer or long integer.  If err is
NULL, then clip on Overflow, otherwise raise err on
Overflow encountered when trying to fit the result of
nb_index into a Py_ssize_t slot. 

With these three C-API calls, I was able to fix all the
problems that have been identified and simplify several
pieces of code. 





----------------------------------------------------------------------

>Comment By: Nick Coghlan (ncoghlan)
Date: 2006-08-11 21:47

Message:
Logged In: YES 
user_id=1038590

The PyNumber_Index docs should explicitly state that it
raises IndexError when overflow occurs.

It may also be worth resurrecting _PyLong_AsClippedSsize_t
in order to clean up the implementation of
PyNumber_AsSsize_t (detecting OverflowError then poking
around in the guts of a long object is a bit ugly).

Other than that, looks good to me (I like this API a lot
better than mine).

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1538606&group_id=5470


More information about the Patches mailing list