summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-08-12 17:03:09 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2006-08-12 17:03:09 (GMT)
commit8a87f5d37e6aab91ddc4c6491877b6cbd48a12cf (patch)
tree330bb4b553958f129b31e31ccea2a2c835b19de0 /Include
parentf3e304297e94b9b1956a4ed95debd1b163958d71 (diff)
downloadcpython-8a87f5d37e6aab91ddc4c6491877b6cbd48a12cf.zip
cpython-8a87f5d37e6aab91ddc4c6491877b6cbd48a12cf.tar.gz
cpython-8a87f5d37e6aab91ddc4c6491877b6cbd48a12cf.tar.bz2
Patch #1538606, Patch to fix __index__() clipping.
I modified this patch some by fixing style, some error checking, and adding XXX comments. This patch requires review and some changes are to be expected. I'm checking in now to get the greatest possible review and establish a baseline for moving forward. I don't want this to hold up release if possible.
Diffstat (limited to 'Include')
-rw-r--r--Include/abstract.h20
-rw-r--r--Include/object.h2
2 files changed, 18 insertions, 4 deletions
diff --git a/Include/abstract.h b/Include/abstract.h
index f96b297..9b0b3f0 100644
--- a/Include/abstract.h
+++ b/Include/abstract.h
@@ -758,13 +758,27 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
*/
- PyAPI_FUNC(Py_ssize_t) PyNumber_Index(PyObject *);
+#define PyIndex_Check(obj) \
+ ((obj)->ob_type->tp_as_number != NULL && \
+ PyType_HasFeature((obj)->ob_type, Py_TPFLAGS_HAVE_INDEX) && \
+ (obj)->ob_type->tp_as_number->nb_index != NULL)
+
+ PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o);
/*
- Returns the object converted to Py_ssize_t on success
- or -1 with an error raised on failure.
+ Returns the object converted to a Python long or int
+ or NULL with an error raised on failure.
*/
+ PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc);
+
+ /*
+ Returns the object converted to Py_ssize_t by going through
+ PyNumber_Index first. If an overflow error occurs while
+ converting the int-or-long to Py_ssize_t, then the second argument
+ is the error-type to return. If it is NULL, then the overflow error
+ is cleared and the value is clipped.
+ */
PyAPI_FUNC(PyObject *) PyNumber_Int(PyObject *o);
diff --git a/Include/object.h b/Include/object.h
index 4b0e080..b0817e6 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -208,7 +208,7 @@ typedef struct {
binaryfunc nb_inplace_true_divide;
/* Added in release 2.5 */
- lenfunc nb_index;
+ unaryfunc nb_index;
} PyNumberMethods;
typedef struct {