summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-07-25 11:15:14 (GMT)
committerGitHub <noreply@github.com>2023-07-25 11:15:14 (GMT)
commitb8b3e6afc0a48c3cbb7c36d2f73e332edcd6058c (patch)
treefdced2a6b57abb0be7f710d4c70320deec48ce57 /Modules
parent058741cc39dd2b63907931e2b626f7428ba13253 (diff)
downloadcpython-b8b3e6afc0a48c3cbb7c36d2f73e332edcd6058c.zip
cpython-b8b3e6afc0a48c3cbb7c36d2f73e332edcd6058c.tar.gz
cpython-b8b3e6afc0a48c3cbb7c36d2f73e332edcd6058c.tar.bz2
[3.11] gh-99612: Fix PyUnicode_DecodeUTF8Stateful() for ASCII-only data (GH-99613) (GH-107224)
Previously *consumed was not set in this case. (cherry picked from commit f08e52ccb027f6f703302b8c1a82db9fd3934270)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapimodule.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index b40368e..b29a919 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -2307,6 +2307,40 @@ unicode_asutf8andsize(PyObject *self, PyObject *args)
return Py_BuildValue("(Nn)", result, utf8_len);
}
+/* Test PyUnicode_DecodeUTF8() */
+static PyObject *
+unicode_decodeutf8(PyObject *self, PyObject *args)
+{
+ const char *data;
+ Py_ssize_t size;
+ const char *errors = NULL;
+
+ if (!PyArg_ParseTuple(args, "y#|z", &data, &size, &errors))
+ return NULL;
+
+ return PyUnicode_DecodeUTF8(data, size, errors);
+}
+
+/* Test PyUnicode_DecodeUTF8Stateful() */
+static PyObject *
+unicode_decodeutf8stateful(PyObject *self, PyObject *args)
+{
+ const char *data;
+ Py_ssize_t size;
+ const char *errors = NULL;
+ Py_ssize_t consumed = 123456789;
+ PyObject *result;
+
+ if (!PyArg_ParseTuple(args, "y#|z", &data, &size, &errors))
+ return NULL;
+
+ result = PyUnicode_DecodeUTF8Stateful(data, size, errors, &consumed);
+ if (!result) {
+ return NULL;
+ }
+ return Py_BuildValue("(Nn)", result, consumed);
+}
+
static PyObject *
unicode_findchar(PyObject *self, PyObject *args)
{
@@ -6562,7 +6596,8 @@ static PyMethodDef TestMethods[] = {
{"unicode_asucs4", unicode_asucs4, METH_VARARGS},
{"unicode_asutf8", unicode_asutf8, METH_VARARGS},
{"unicode_asutf8andsize", unicode_asutf8andsize, METH_VARARGS},
- {"unicode_findchar", unicode_findchar, METH_VARARGS},
+ {"unicode_decodeutf8", unicode_decodeutf8, METH_VARARGS},
+ {"unicode_decodeutf8stateful",unicode_decodeutf8stateful, METH_VARARGS}, {"unicode_findchar", unicode_findchar, METH_VARARGS},
{"unicode_copycharacters", unicode_copycharacters, METH_VARARGS},
#if USE_UNICODE_WCHAR_CACHE
{"unicode_legacy_string", unicode_legacy_string, METH_VARARGS},