[Python-checkins] CVS: python/dist/src/Modules _testcapimodule.c,1.1,1.2

Tim Peters tim_one@users.sourceforge.net
Mon, 12 Feb 2001 14:13:28 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv1516/python/dist/src/Modules

Modified Files:
	_testcapimodule.c 
Log Message:
Related to SF bug 132008 (PyList_Reverse blows up).
_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


Index: _testcapimodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_testcapimodule.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** _testcapimodule.c	2001/02/04 03:09:53	1.1
--- _testcapimodule.c	2001/02/12 22:13:26	1.2
***************
*** 51,56 ****
--- 51,102 ----
  }
  
+ 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 */
  };