summaryrefslogtreecommitdiffstats
path: root/Modules/mmapmodule.c
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 /Modules/mmapmodule.c
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 'Modules/mmapmodule.c')
-rw-r--r--Modules/mmapmodule.c30
1 files changed, 8 insertions, 22 deletions
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;
}