[Python-checkins] CVS: python/dist/src/Modules _testcapimodule.c,1.11,1.12
Tim Peters
tim_one@users.sourceforge.net
Sat, 29 Sep 2001 22:09:39 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv21648/python/Modules
Modified Files:
_testcapimodule.c
Log Message:
SF [#466125] PyLong_AsLongLong works for any integer.
Generalize PyLong_AsLongLong to accept int arguments too. The real point
is so that PyArg_ParseTuple's 'L' code does too. That code was
undocumented (AFAICT), so documented it.
Index: _testcapimodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_testcapimodule.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** _testcapimodule.c 2001/09/26 20:01:13 1.11
--- _testcapimodule.c 2001/09/30 05:09:37 1.12
***************
*** 256,259 ****
--- 256,308 ----
#undef F_PY_TO_U
+ /* Test the L code for PyArg_ParseTuple. This should deliver a LONG_LONG
+ for both long and int arguments. The test may leak a little memory if
+ it fails.
+ */
+ static PyObject *
+ test_L_code(PyObject *self, PyObject *args)
+ {
+ PyObject *tuple, *num;
+ LONG_LONG value;
+
+ if (!PyArg_ParseTuple(args, ":test_L_code"))
+ return NULL;
+
+ tuple = PyTuple_New(1);
+ if (tuple == NULL)
+ return NULL;
+
+ num = PyLong_FromLong(42);
+ if (num == NULL)
+ return NULL;
+
+ PyTuple_SET_ITEM(tuple, 0, num);
+
+ value = -1;
+ if (PyArg_ParseTuple(tuple, "L:test_L_code", &value) < 0)
+ return NULL;
+ if (value != 42)
+ return raiseTestError("test_L_code",
+ "L code returned wrong value for long 42");
+
+ Py_DECREF(num);
+ num = PyInt_FromLong(42);
+ if (num == NULL)
+ return NULL;
+
+ PyTuple_SET_ITEM(tuple, 0, num);
+
+ value = -1;
+ if (PyArg_ParseTuple(tuple, "L:test_L_code", &value) < 0)
+ return NULL;
+ if (value != 42)
+ return raiseTestError("test_L_code",
+ "L code returned wrong value for int 42");
+
+ Py_DECREF(tuple);
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+
#endif /* ifdef HAVE_LONG_LONG */
***************
*** 292,295 ****
--- 341,345 ----
#ifdef HAVE_LONG_LONG
{"test_longlong_api", test_longlong_api, METH_VARARGS},
+ {"test_L_code", test_L_code, METH_VARARGS},
#endif
{NULL, NULL} /* sentinel */