summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-10-02 18:29:26 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-10-02 18:29:26 (GMT)
commitcc164232aa736006d3c45ee76680c14738e2f9e6 (patch)
tree27c809a3a3d19db5b822b1178184d09cca1e5eca /Modules
parent63b5b6fd450260a4239371e96263020587648ad9 (diff)
downloadcpython-cc164232aa736006d3c45ee76680c14738e2f9e6.zip
cpython-cc164232aa736006d3c45ee76680c14738e2f9e6.tar.gz
cpython-cc164232aa736006d3c45ee76680c14738e2f9e6.tar.bz2
Issue #28295: Fixed the documentation and added tests for PyUnicode_AsUCS4().
Original patch by Xiang Zhang.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapimodule.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 81f5b1d..f4a1e97 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -1830,6 +1830,36 @@ unicode_aswidecharstring(PyObject *self, PyObject *args)
}
static PyObject *
+unicode_asucs4(PyObject *self, PyObject *args)
+{
+ PyObject *unicode, *result;
+ Py_UCS4 *buffer;
+ int copy_null;
+ Py_ssize_t str_len, buf_len;
+
+ if (!PyArg_ParseTuple(args, "Unp:unicode_asucs4", &unicode, &str_len, &copy_null)) {
+ return NULL;
+ }
+
+ buf_len = str_len + 1;
+ buffer = PyMem_NEW(Py_UCS4, buf_len);
+ if (buffer == NULL) {
+ return PyErr_NoMemory();
+ }
+ memset(buffer, 0, sizeof(Py_UCS4)*buf_len);
+ buffer[str_len] = 0xffffU;
+
+ if (!PyUnicode_AsUCS4(unicode, buffer, buf_len, copy_null)) {
+ PyMem_FREE(buffer);
+ return NULL;
+ }
+
+ result = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, buffer, buf_len);
+ PyMem_FREE(buffer);
+ return result;
+}
+
+static PyObject *
unicode_encodedecimal(PyObject *self, PyObject *args)
{
Py_UNICODE *unicode;
@@ -3884,6 +3914,7 @@ static PyMethodDef TestMethods[] = {
{"test_widechar", (PyCFunction)test_widechar, METH_NOARGS},
{"unicode_aswidechar", unicode_aswidechar, METH_VARARGS},
{"unicode_aswidecharstring",unicode_aswidecharstring, METH_VARARGS},
+ {"unicode_asucs4", unicode_asucs4, METH_VARARGS},
{"unicode_encodedecimal", unicode_encodedecimal, METH_VARARGS},
{"unicode_transformdecimaltoascii", unicode_transformdecimaltoascii, METH_VARARGS},
{"unicode_legacy_string", unicode_legacy_string, METH_VARARGS},