summaryrefslogtreecommitdiffstats
path: root/Tools/clinic
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-11-01 15:34:42 (GMT)
committerGitHub <noreply@github.com>2023-11-01 15:34:42 (GMT)
commitd9b606b3d04fc56fb0bcc479d7d6c14562edb5e2 (patch)
tree14d10605507380e411d5f62e5bab28f74091129d /Tools/clinic
parent97b3cd38d105fd891ba46dd27d08f03d1c6dd348 (diff)
downloadcpython-d9b606b3d04fc56fb0bcc479d7d6c14562edb5e2.zip
cpython-d9b606b3d04fc56fb0bcc479d7d6c14562edb5e2.tar.gz
cpython-d9b606b3d04fc56fb0bcc479d7d6c14562edb5e2.tar.bz2
gh-111089: Use PyUnicode_AsUTF8() in Argument Clinic (#111585)
Replace PyUnicode_AsUTF8AndSize() with PyUnicode_AsUTF8() to remove the explicit check for embedded null characters. The change avoids to have to include explicitly <string.h> to get the strlen() function when using a recent version of the limited C API.
Diffstat (limited to 'Tools/clinic')
-rwxr-xr-xTools/clinic/clinic.py20
1 files changed, 4 insertions, 16 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index 5f94b90a..4f238a3 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -4350,34 +4350,23 @@ class str_converter(CConverter):
{bad_argument}
goto exit;
}}}}
- Py_ssize_t {length_name};
- {paramname} = PyUnicode_AsUTF8AndSize({argname}, &{length_name});
+ {paramname} = PyUnicode_AsUTF8({argname});
if ({paramname} == NULL) {{{{
goto exit;
}}}}
- if (strlen({paramname}) != (size_t){length_name}) {{{{
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }}}}
""",
argname=argname,
- bad_argument=self.bad_argument(displayname, 'str', limited_capi=limited_capi),
- length_name=self.length_name)
+ bad_argument=self.bad_argument(displayname, 'str', limited_capi=limited_capi))
if self.format_unit == 'z':
return self.format_code("""
if ({argname} == Py_None) {{{{
{paramname} = NULL;
}}}}
else if (PyUnicode_Check({argname})) {{{{
- Py_ssize_t {length_name};
- {paramname} = PyUnicode_AsUTF8AndSize({argname}, &{length_name});
+ {paramname} = PyUnicode_AsUTF8({argname});
if ({paramname} == NULL) {{{{
goto exit;
}}}}
- if (strlen({paramname}) != (size_t){length_name}) {{{{
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }}}}
}}}}
else {{{{
{bad_argument}
@@ -4385,8 +4374,7 @@ class str_converter(CConverter):
}}}}
""",
argname=argname,
- bad_argument=self.bad_argument(displayname, 'str or None', limited_capi=limited_capi),
- length_name=self.length_name)
+ bad_argument=self.bad_argument(displayname, 'str or None', limited_capi=limited_capi))
return super().parse_arg(argname, displayname, limited_capi=limited_capi)
#