summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'Modules')
-rw-r--r--Modules/arraymodule.c12
-rw-r--r--Modules/mmapmodule.c30
-rw-r--r--Modules/operator.c12
3 files changed, 14 insertions, 40 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 14e5e5d..efa7835 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1572,14 +1572,11 @@ array_repr(arrayobject *a)
return s;
}
-#define HASINDEX(o) PyType_HasFeature((o)->ob_type, Py_TPFLAGS_HAVE_INDEX)
-
static PyObject*
array_subscr(arrayobject* self, PyObject* item)
{
- PyNumberMethods *nb = item->ob_type->tp_as_number;
- if (nb != NULL && HASINDEX(item) && nb->nb_index != NULL) {
- Py_ssize_t i = nb->nb_index(item);
+ if (PyIndex_Check(item)) {
+ Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
if (i==-1 && PyErr_Occurred()) {
return NULL;
}
@@ -1627,9 +1624,8 @@ array_subscr(arrayobject* self, PyObject* item)
static int
array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
{
- PyNumberMethods *nb = item->ob_type->tp_as_number;
- if (nb != NULL && HASINDEX(item) && nb->nb_index != NULL) {
- Py_ssize_t i = nb->nb_index(item);
+ if (PyIndex_Check(item)) {
+ Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
if (i==-1 && PyErr_Occurred())
return -1;
if (i < 0)
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index b2dd675..53df275 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -808,8 +808,6 @@ static PyTypeObject mmap_object_type = {
};
-#define HASINDEX(o) PyType_HasFeature((o)->ob_type, Py_TPFLAGS_HAVE_INDEX)
-
/* extract the map size from the given PyObject
Returns -1 on error, with an appropriate Python exception raised. On
@@ -817,31 +815,19 @@ static PyTypeObject mmap_object_type = {
static Py_ssize_t
_GetMapSize(PyObject *o)
{
- PyNumberMethods *nb = o->ob_type->tp_as_number;
- if (nb != NULL && HASINDEX(o) && nb->nb_index != NULL) {
- Py_ssize_t i = nb->nb_index(o);
+ if (PyIndex_Check(o)) {
+ Py_ssize_t i = PyNumber_AsSsize_t(o, PyExc_OverflowError);
if (i==-1 && PyErr_Occurred())
return -1;
- if (i < 0)
- goto onnegoverflow;
- if (i==PY_SSIZE_T_MAX)
- goto onposoverflow;
+ if (i < 0) {
+ PyErr_SetString(PyExc_OverflowError,
+ "memory mapped size must be positive");
+ return -1;
+ }
return i;
}
- else {
- PyErr_SetString(PyExc_TypeError,
- "map size must be an integral value");
- return -1;
- }
-
- onnegoverflow:
- PyErr_SetString(PyExc_OverflowError,
- "memory mapped size must be positive");
- return -1;
- onposoverflow:
- PyErr_SetString(PyExc_OverflowError,
- "memory mapped size is too large (limited by C int)");
+ PyErr_SetString(PyExc_TypeError, "map size must be an integral value");
return -1;
}
diff --git a/Modules/operator.c b/Modules/operator.c
index 7fc1f8a..7479a53 100644
--- a/Modules/operator.c
+++ b/Modules/operator.c
@@ -139,15 +139,7 @@ op_ipow(PyObject *s, PyObject *a)
static PyObject *
op_index(PyObject *s, PyObject *a)
{
- Py_ssize_t i;
- PyObject *a1;
- if (!PyArg_UnpackTuple(a,"index", 1, 1, &a1))
- return NULL;
- i = PyNumber_Index(a1);
- if (i == -1 && PyErr_Occurred())
- return NULL;
- else
- return PyInt_FromSsize_t(i);
+ return PyNumber_Index(a);
}
static PyObject*
@@ -249,7 +241,7 @@ spam1o(isMappingType,
spam1(is_, "is_(a, b) -- Same as a is b.")
spam1(is_not, "is_not(a, b) -- Same as a is not b.")
-spam2(index, __index__, "index(a) -- Same as a.__index__()")
+spam2o(index, __index__, "index(a) -- Same as a.__index__()")
spam2(add,__add__, "add(a, b) -- Same as a + b.")
spam2(sub,__sub__, "sub(a, b) -- Same as a - b.")
spam2(mul,__mul__, "mul(a, b) -- Same as a * b.")