Forward-port of r52136: a review of overflow-detecting code.
* unified the way intobject, longobject and mystrtoul handle
values around -sys.maxint-1.
* in general, trying to entierely avoid overflows in any computation
involving signed ints or longs is extremely involved. Fixed a few
simple cases where a compiler might be too clever (but that's all
guesswork).
* more overflow checks against bad data in marshal.c.
* 2.5 specific: fixed a number of places that were still confusing int
and Py_ssize_t. Some of them could potentially have caused
"real-world" breakage.
* list.pop(x): fixing overflow issues on x was messy. I just reverted
to PyArg_ParseTuple("n"), which does the right thing. (An obscure
test was trying to give a Decimal to list.pop()... doesn't make
sense any more IMHO)
* trying to write a few tests...
diff --git a/Objects/listobject.c b/Objects/listobject.c
index ad27644..7afea12 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -863,17 +863,12 @@
listpop(PyListObject *self, PyObject *args)
{
Py_ssize_t i = -1;
- PyObject *v, *arg = NULL;
+ PyObject *v;
int status;
- if (!PyArg_UnpackTuple(args, "pop", 0, 1, &arg))
+ if (!PyArg_ParseTuple(args, "|n:pop", &i))
return NULL;
- if (arg != NULL) {
- if (PyInt_Check(arg))
- i = PyInt_AS_LONG((PyIntObject*) arg);
- else if (!PyArg_ParseTuple(args, "|n:pop", &i))
- return NULL;
- }
+
if (self->ob_size == 0) {
/* Special-case most common failure cause */
PyErr_SetString(PyExc_IndexError, "pop from empty list");