summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMarc-André Lemburg <mal@egenix.com>2002-01-09 16:21:27 (GMT)
committerMarc-André Lemburg <mal@egenix.com>2002-01-09 16:21:27 (GMT)
commit3e3eacb5fc886008fe15fdf331bb606070411d1c (patch)
tree52b3c21d1d3a56aec15b984c12fb37a3e7f4cf01 /Modules
parente0b1e6af5800368c83e780ce5e29d906fe7b9ae6 (diff)
downloadcpython-3e3eacb5fc886008fe15fdf331bb606070411d1c.zip
cpython-3e3eacb5fc886008fe15fdf331bb606070411d1c.tar.gz
cpython-3e3eacb5fc886008fe15fdf331bb606070411d1c.tar.bz2
Fixed "u#" parser marker to pass through Unicode objects as-is without
going through the buffer interface API. Added tests for this to the _testcapi module and updated docs.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapimodule.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 0f5fa7c..824ae87 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -307,6 +307,53 @@ test_L_code(PyObject *self, PyObject *args)
#endif /* ifdef HAVE_LONG_LONG */
+#ifdef Py_USING_UNICODE
+
+/* Test the u and u# codes for PyArg_ParseTuple. May leak memory in case
+ of an error.
+*/
+static PyObject *
+test_u_code(PyObject *self, PyObject *args)
+{
+ PyObject *tuple, *obj;
+ Py_UNICODE *value;
+ int len;
+
+ if (!PyArg_ParseTuple(args, ":test_u_code"))
+ return NULL;
+
+ tuple = PyTuple_New(1);
+ if (tuple == NULL)
+ return NULL;
+
+ obj = PyUnicode_Decode("test", strlen("test"),
+ "ascii", NULL);
+ if (obj == NULL)
+ return NULL;
+
+ PyTuple_SET_ITEM(tuple, 0, obj);
+
+ value = 0;
+ if (PyArg_ParseTuple(tuple, "u:test_u_code", &value) < 0)
+ return NULL;
+ if (value != PyUnicode_AS_UNICODE(obj))
+ return raiseTestError("test_u_code",
+ "u code returned wrong value for u'test'");
+ value = 0;
+ if (PyArg_ParseTuple(tuple, "u#:test_u_code", &value, &len) < 0)
+ return NULL;
+ if (value != PyUnicode_AS_UNICODE(obj) ||
+ len != PyUnicode_GET_SIZE(obj))
+ return raiseTestError("test_u_code",
+ "u# code returned wrong values for u'test'");
+
+ Py_DECREF(tuple);
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+#endif
+
static PyObject *
raise_exception(PyObject *self, PyObject *args)
{
@@ -343,6 +390,9 @@ static PyMethodDef TestMethods[] = {
{"test_longlong_api", test_longlong_api, METH_VARARGS},
{"test_L_code", test_L_code, METH_VARARGS},
#endif
+#ifdef Py_USING_UNICODE
+ {"test_u_code", test_u_code, METH_VARARGS},
+#endif
{NULL, NULL} /* sentinel */
};