]> granicus.if.org Git - python/commitdiff
Related to SF bug 132008 (PyList_Reverse blows up).
authorTim Peters <tim.peters@gmail.com>
Mon, 12 Feb 2001 22:13:26 +0000 (22:13 +0000)
committerTim Peters <tim.peters@gmail.com>
Mon, 12 Feb 2001 22:13:26 +0000 (22:13 +0000)
_testcapimodule.c
    make sure PyList_Reverse doesn't blow up again
getargs.c
    assert args isn't NULL at the top of vgetargs1 instead of
    waiting for a NULL-pointer dereference at the end

Modules/_testcapimodule.c
Python/getargs.c

index 1b3b596aed21f07955324314dab5f8d7c3bddcc7..0ffdc17669852a8e9eceae5dc4af03d5229db757 100644 (file)
@@ -50,8 +50,54 @@ test_config(PyObject *self, PyObject *args)
        return Py_None;
 }
 
+static PyObject*
+test_list_api(PyObject *self, PyObject *args)
+{
+       PyObject* list;
+       int i;
+        if (!PyArg_ParseTuple(args, ":test_list_api"))
+                return NULL;
+
+       /* SF bug 132008:  PyList_Reverse segfaults */
+#define NLIST 30
+       list = PyList_New(NLIST);
+       if (list == (PyObject*)NULL)
+               return (PyObject*)NULL;
+       /* list = range(NLIST) */
+       for (i = 0; i < NLIST; ++i) {
+               PyObject* anint = PyInt_FromLong(i);
+               if (anint == (PyObject*)NULL) {
+                       Py_DECREF(list);
+                       return (PyObject*)NULL;
+               }
+               PyList_SET_ITEM(list, i, anint);
+       }
+       /* list.reverse(), via PyList_Reverse() */
+       i = PyList_Reverse(list);   /* should not blow up! */
+       if (i != 0) {
+               Py_DECREF(list);
+               return (PyObject*)NULL;
+       }
+       /* Check that list == range(29, -1, -1) now */
+       for (i = 0; i < NLIST; ++i) {
+               PyObject* anint = PyList_GET_ITEM(list, i);
+               if (PyInt_AS_LONG(anint) != NLIST-1-i) {
+                       PyErr_SetString(TestError,
+                                       "test_list_api: reverse screwed up");
+                       Py_DECREF(list);
+                       return (PyObject*)NULL;
+               }
+       }
+       Py_DECREF(list);
+#undef NLIST
+
+       Py_INCREF(Py_None);
+       return Py_None;
+}
+
 static PyMethodDef TestMethods[] = {
        {"test_config", test_config, METH_VARARGS},
+       {"test_list_api", test_list_api, METH_VARARGS},
        {NULL, NULL} /* sentinel */
 };
 
index aa4a22828d26d947d7ea3ae4e2d472898ebd5ae9..00f298a62794a824fa879013b7eff11fa30a5a10 100644 (file)
@@ -84,6 +84,8 @@ vgetargs1(PyObject *args, char *format, va_list *p_va, int compat)
        int i, len;
        char *msg;
        
+       assert(compat || (args != (PyObject*)NULL));
+
        for (;;) {
                int c = *format++;
                if (c == '(' /* ')' */) {