[Python-checkins] CVS: python/dist/src/Modules _testcapimodule.c,1.3,1.4
Tim Peters
tim_one@users.sourceforge.net
Tue, 12 Jun 2001 13:10:04 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv21117/python/dist/src/Modules
Modified Files:
_testcapimodule.c
Log Message:
The merest start of a test for the PyLong_{As,From}{Unsigned,}LongLong()
functions. I intend to replace their guts with calls to the new
_PyLong_{As,From}ByteArray() functions, but AFAICT there's no tests for
them at all now; I also suspect PyLong_AsLongLong() isn't catching all
overflow cases, but without a std test to demonstrate that why should you
believe me <wink>.
Also added a raiseTestError() utility function.
Index: _testcapimodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_testcapimodule.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** _testcapimodule.c 2001/04/13 17:08:15 1.3
--- _testcapimodule.c 2001/06/12 20:10:01 1.4
***************
*** 10,13 ****
--- 10,29 ----
static PyObject *TestError; /* set to exception object in init */
+ /* Raise TestError with test_name + ": " + msg, and return NULL. */
+
+ static PyObject *
+ raiseTestError(const char* test_name, const char* msg)
+ {
+ char buf[2048];
+
+ if (strlen(test_name) + strlen(msg) > sizeof(buf) - 50)
+ PyErr_SetString(TestError, "internal error msg too large");
+ else {
+ sprintf(buf, "%s: %s", test_name, msg);
+ PyErr_SetString(TestError, buf);
+ }
+ return NULL;
+ }
+
/* Test #defines from config.h (particularly the SIZEOF_* defines).
***************
*** 146,150 ****
if (!PyArg_ParseTuple(args, ":test_dict_iteration"))
return NULL;
!
for (i = 0; i < 200; i++) {
if (test_dict_inner(i) < 0) {
--- 162,166 ----
if (!PyArg_ParseTuple(args, ":test_dict_iteration"))
return NULL;
!
for (i = 0; i < 200; i++) {
if (test_dict_inner(i) < 0) {
***************
*** 157,164 ****
}
static PyMethodDef TestMethods[] = {
! {"test_config", test_config, METH_VARARGS},
! {"test_list_api", test_list_api, METH_VARARGS},
! {"test_dict_iteration", test_dict_iteration, METH_VARARGS},
{NULL, NULL} /* sentinel */
};
--- 173,217 ----
}
+ #ifdef HAVE_LONG_LONG
+
+ /* Basic sanity checks for PyLong_{As, From}{Unsigned,}LongLong(). */
+
+ static PyObject *
+ test_longlong_api(PyObject* self, PyObject* args)
+ {
+ /* unsigned LONG_LONG uinput, uoutput; */
+ LONG_LONG input, output;
+ PyObject *pyresult;
+
+ if (!PyArg_ParseTuple(args, ":test_longlong_api"))
+ return NULL;
+
+ input = 0;
+ pyresult = PyLong_FromLongLong(input);
+ if (pyresult == NULL)
+ return raiseTestError("test_longlong_api",
+ "unexpected null result");
+ output = PyLong_AsLongLong(pyresult);
+ if (output == (LONG_LONG)-1 && PyErr_Occurred())
+ return raiseTestError("test_longlong_api",
+ "unexpected -1 result");
+ if (output != input)
+ return raiseTestError("test_longlong_api",
+ "output != input");
+ Py_DECREF(pyresult);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+
+ #endif
+
static PyMethodDef TestMethods[] = {
! {"test_config", test_config, METH_VARARGS},
! {"test_list_api", test_list_api, METH_VARARGS},
! {"test_dict_iteration", test_dict_iteration, METH_VARARGS},
! #ifdef HAVE_LONG_LONG
! {"test_longlong_api", test_longlong_api, METH_VARARGS},
! #endif
{NULL, NULL} /* sentinel */
};