summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-08-29 18:38:11 (GMT)
committerGuido van Rossum <guido@python.org>2007-08-29 18:38:11 (GMT)
commitfb67be2f6b12e6ab07c17ece1caaf0057d610252 (patch)
tree1cc5f5a63ff45d5dd716a502432ed0db15c5596b /Modules
parente86254e2560250ce958330433488ba092ca8ffea (diff)
downloadcpython-fb67be2f6b12e6ab07c17ece1caaf0057d610252.zip
cpython-fb67be2f6b12e6ab07c17ece1caaf0057d610252.tar.gz
cpython-fb67be2f6b12e6ab07c17ece1caaf0057d610252.tar.bz2
Three patches from issue #1047, by Amaury Forgeot d'Arc:
1/ getargs.diff adds the 'Z' and 'Z#' format specifiers for PyArg_ParseTuple. They mimic z and z# for unicode strings, by accepting a Unicode or None (in which case the Py_UNICODE* pointer is set to NULL). With doc and tests. 2/ subprocess.diff converts file PC/_subprocess.c to unicode. We use the Unicode version of the win32 api (and Z conversion from previous patch) 3/ stdout.diff: sys.stdout must not convert the line endings, Windows already does it. Without this patch, when redirecting the output of python, the file contains \r\r\n for each line. (test_subprocess did catch this) However, I (GvR) removed the change to _fileio.c (included in the patches) that prevents closing file descripors < 3 from being closed; I think that needs to be solved in a different way.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapimodule.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index ca159e5..b76c713 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -497,6 +497,59 @@ test_u_code(PyObject *self)
return Py_None;
}
+/* Test Z and Z# codes for PyArg_ParseTuple */
+static PyObject *
+test_Z_code(PyObject *self)
+{
+ PyObject *tuple, *obj;
+ Py_UNICODE *value1, *value2;
+ int len1, len2;
+
+ tuple = PyTuple_New(2);
+ if (tuple == NULL)
+ return NULL;
+
+ obj = PyUnicode_FromString("test");
+ PyTuple_SET_ITEM(tuple, 0, obj);
+ Py_INCREF(Py_None);
+ PyTuple_SET_ITEM(tuple, 1, Py_None);
+
+ /* swap values on purpose */
+ value1 = NULL;
+ value2 = PyUnicode_AS_UNICODE(obj);
+
+ /* Test Z for both values */
+ if (PyArg_ParseTuple(tuple, "ZZ:test_Z_code", &value1, &value2) < 0)
+ return NULL;
+ if (value1 != PyUnicode_AS_UNICODE(obj))
+ return raiseTestError("test_Z_code",
+ "Z code returned wrong value for 'test'");
+ if (value2 != NULL)
+ return raiseTestError("test_Z_code",
+ "Z code returned wrong value for None");
+
+ value1 = NULL;
+ value2 = PyUnicode_AS_UNICODE(obj);
+ len1 = -1;
+ len2 = -1;
+
+ /* Test Z# for both values */
+ if (PyArg_ParseTuple(tuple, "Z#Z#:test_Z_code", &value1, &len1,
+ &value2, &len2) < 0)
+ return NULL;
+ if (value1 != PyUnicode_AS_UNICODE(obj) ||
+ len1 != PyUnicode_GET_SIZE(obj))
+ return raiseTestError("test_Z_code",
+ "Z# code returned wrong values for 'test'");
+ if (value2 != NULL ||
+ len2 != 0)
+ return raiseTestError("test_Z_code",
+ "Z# code returned wrong values for None'");
+
+ Py_DECREF(tuple);
+ Py_RETURN_NONE;
+}
+
static PyObject *
codec_incrementalencoder(PyObject *self, PyObject *args)
{
@@ -862,6 +915,7 @@ static PyMethodDef TestMethods[] = {
(PyCFunction)codec_incrementaldecoder, METH_VARARGS},
#endif
{"test_u_code", (PyCFunction)test_u_code, METH_NOARGS},
+ {"test_Z_code", (PyCFunction)test_Z_code, METH_NOARGS},
#ifdef WITH_THREAD
{"_test_thread_state", test_thread_state, METH_VARARGS},
#endif