From 3586d7c6250a12a9c34e6bab8a3ea134b9fabb87 Mon Sep 17 00:00:00 2001 From: Cody Maloney Date: Fri, 25 Sep 2026 18:44:20 -0700 Subject: [PATCH 1/3] gh-157407: Use _PyUnicode_AsUTF8NoNUL for AC 's' and 'z' converters The code was doing the same as the helper added in GH-111957 but inline. That resulted in significantly more `.text` for most functions. Refactor the Arguemnt Clinic converters code to deduplicate a bit while keeping generated code close to original. On my Linux x64 box this reduces `.text` by ~6200 bytes in a clang release build (no PGO or LTO). Performance is flat. The helper was already exported for `_sqlite3`, update the comment that it is used in AC generated code as well. Co-Authored-By: Claude Opus 5 (1M context) --- Include/internal/pycore_unicodeobject.h | 3 +- ...-09-25-17-30-00.gh-issue-157407.iOVPov.rst | 3 + Modules/_ctypes/clinic/_ctypes.c.h | 10 +- Modules/_ctypes/clinic/callproc.c.h | 10 +- Modules/_io/clinic/_iomodule.c.h | 31 +- Modules/_io/clinic/fileio.c.h | 10 +- Modules/_io/clinic/textio.c.h | 24 +- Modules/_io/clinic/winconsoleio.c.h | 10 +- .../clinic/multiprocessing.c.h | 10 +- Modules/_multiprocessing/clinic/semaphore.c.h | 10 +- Modules/_sqlite/clinic/_sqlite3.connect.c.h | 3 +- Modules/_sqlite/clinic/connection.c.h | 87 +---- Modules/_sqlite/clinic/cursor.c.h | 10 +- Modules/_sqlite/clinic/module.c.h | 10 +- Modules/_testcapi/clinic/exceptions.c.h | 17 +- Modules/cjkcodecs/clinic/multibytecodec.c.h | 17 +- Modules/clinic/_codecsmodule.c.h | 346 +++--------------- Modules/clinic/_cursesmodule.c.h | 52 +-- Modules/clinic/_datetimemodule.c.h | 17 +- Modules/clinic/_dbmmodule.c.h | 10 +- Modules/clinic/_elementtree.c.h | 10 +- Modules/clinic/_gdbmmodule.c.h | 10 +- Modules/clinic/_hashopenssl.c.h | 17 +- Modules/clinic/_localemodule.c.h | 73 +--- Modules/clinic/_pickle.c.h | 45 +-- Modules/clinic/_ssl.c.h | 73 +--- Modules/clinic/_testclinic.c.h | 17 +- Modules/clinic/_testclinic_depr.c.h | 3 +- Modules/clinic/_testclinic_kwds.c.h | 3 +- Modules/clinic/_tkinter.c.h | 101 +---- Modules/clinic/arraymodule.c.h | 10 +- Modules/clinic/mmapmodule.c.h | 10 +- Modules/clinic/posixmodule.c.h | 24 +- Modules/clinic/pyexpat.c.h | 38 +- Modules/clinic/socketmodule.c.h | 45 +-- Modules/clinic/symtablemodule.c.h | 10 +- Modules/clinic/syslogmodule.c.h | 10 +- Modules/clinic/timemodule.c.h | 10 +- Objects/clinic/bytearrayobject.c.h | 31 +- Objects/clinic/bytesobject.c.h | 31 +- Objects/clinic/floatobject.c.h | 10 +- Objects/clinic/memoryobject.c.h | 10 +- Objects/clinic/unicodeobject.c.h | 31 +- Python/clinic/Python-tokenize.c.h | 10 +- Python/clinic/bltinmodule.c.h | 10 +- Python/clinic/sysmodule.c.h | 17 +- Tools/clinic/libclinic/converters.py | 69 ++-- 47 files changed, 310 insertions(+), 1108 deletions(-) create mode 100644 Misc/NEWS.d/next/Tools-Demos/2026-09-25-17-30-00.gh-issue-157407.iOVPov.rst diff --git a/Include/internal/pycore_unicodeobject.h b/Include/internal/pycore_unicodeobject.h index c091aa94371a756..f64fa39e65741dc 100644 --- a/Include/internal/pycore_unicodeobject.h +++ b/Include/internal/pycore_unicodeobject.h @@ -450,7 +450,8 @@ extern void _PyUnicode_InternStatic(PyInterpreterState *interp, PyObject **); extern void _PyUnicode_ClearInterned(PyInterpreterState *interp); // Like PyUnicode_AsUTF8(), but check for embedded null characters. -// Export for '_sqlite3' shared extension. +// Export for '_sqlite3' shared extension, and for the Argument Clinic code +// generated for the 's' and 'z' converters, which many shared extensions use. PyAPI_FUNC(const char *) _PyUnicode_AsUTF8NoNUL(PyObject *); diff --git a/Misc/NEWS.d/next/Tools-Demos/2026-09-25-17-30-00.gh-issue-157407.iOVPov.rst b/Misc/NEWS.d/next/Tools-Demos/2026-09-25-17-30-00.gh-issue-157407.iOVPov.rst new file mode 100644 index 000000000000000..202269d63bc1a0c --- /dev/null +++ b/Misc/NEWS.d/next/Tools-Demos/2026-09-25-17-30-00.gh-issue-157407.iOVPov.rst @@ -0,0 +1,3 @@ +Argument Clinic now calls the internal function ``_PyUnicode_AsUTF8NoNUL()`` for +``s`` and ``z`` converters instead of writing equivalent code inline to reduce +the generated ``.text`` segment. diff --git a/Modules/_ctypes/clinic/_ctypes.c.h b/Modules/_ctypes/clinic/_ctypes.c.h index b5a64b8730a7722..bd6212af8001ac3 100644 --- a/Modules/_ctypes/clinic/_ctypes.c.h +++ b/Modules/_ctypes/clinic/_ctypes.c.h @@ -8,6 +8,7 @@ preserve #include "pycore_abstract.h" // _PyNumber_Index() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(_ctypes_CType_Type___sizeof____doc__, "__sizeof__($self, /)\n" @@ -295,15 +296,10 @@ CDataType_in_dll(PyObject *type, PyTypeObject *cls, PyObject *const *args, Py_ss _PyArg_BadArgument("in_dll", "argument 2", "str", args[1]); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(args[1], &name_length); + name = _PyUnicode_AsUTF8NoNUL(args[1]); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = CDataType_in_dll_impl(type, cls, dll, name); exit: @@ -968,4 +964,4 @@ Simple_from_outparm(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py #define _CTYPES_SIMPLE_VALUE_GETSETDEF {"value", (getter)_ctypes_Simple_value_get, (setter)_ctypes_Simple_value_set, NULL}, -/*[clinic end generated code: output=1d322c90c81649fd input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3aaca12468398371 input=a9049054013a1b77]*/ diff --git a/Modules/_ctypes/clinic/callproc.c.h b/Modules/_ctypes/clinic/callproc.c.h index ef68372110416a1..82cb08ff00dfb03 100644 --- a/Modules/_ctypes/clinic/callproc.c.h +++ b/Modules/_ctypes/clinic/callproc.c.h @@ -5,6 +5,7 @@ preserve #include "pycore_abstract.h" // _PyNumber_Index() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(_ctypes_get_errno__doc__, "get_errno($module, /)\n" @@ -406,15 +407,10 @@ _ctypes_dlsym(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("dlsym", "argument 2", "str", args[1]); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(args[1], &name_length); + name = _PyUnicode_AsUTF8NoNUL(args[1]); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _ctypes_dlsym_impl(module, handle, name); exit: @@ -797,4 +793,4 @@ PyDoc_STRVAR(_ctypes_buffer_info__doc__, #ifndef _CTYPES_DLLIST_METHODDEF #define _CTYPES_DLLIST_METHODDEF #endif /* !defined(_CTYPES_DLLIST_METHODDEF) */ -/*[clinic end generated code: output=71a41a6d90e69821 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=615c411ddc01d0a4 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/_iomodule.c.h b/Modules/_io/clinic/_iomodule.c.h index f03638064385e28..0547982cad48ccc 100644 --- a/Modules/_io/clinic/_iomodule.c.h +++ b/Modules/_io/clinic/_iomodule.c.h @@ -7,6 +7,7 @@ preserve # include "pycore_runtime.h" // _Py_ID() #endif #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(_io_open__doc__, "open($module, /, file, mode=\'r\', buffering=-1, encoding=None,\n" @@ -192,15 +193,10 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw _PyArg_BadArgument("open", "argument 'mode'", "str", args[1]); goto exit; } - Py_ssize_t mode_length; - mode = PyUnicode_AsUTF8AndSize(args[1], &mode_length); + mode = _PyUnicode_AsUTF8NoNUL(args[1]); if (mode == NULL) { goto exit; } - if (strlen(mode) != (size_t)mode_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!--noptargs) { goto skip_optional_pos; } @@ -219,15 +215,10 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw encoding = NULL; } else if (PyUnicode_Check(args[3])) { - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(args[3], &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(args[3]); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("open", "argument 'encoding'", "str or None", args[3]); @@ -242,15 +233,10 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw errors = NULL; } else if (PyUnicode_Check(args[4])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[4], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[4]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("open", "argument 'errors'", "str or None", args[4]); @@ -265,15 +251,10 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw newline = NULL; } else if (PyUnicode_Check(args[5])) { - Py_ssize_t newline_length; - newline = PyUnicode_AsUTF8AndSize(args[5], &newline_length); + newline = _PyUnicode_AsUTF8NoNUL(args[5]); if (newline == NULL) { goto exit; } - if (strlen(newline) != (size_t)newline_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("open", "argument 'newline'", "str or None", args[5]); @@ -411,4 +392,4 @@ _io_open_code(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec exit: return return_value; } -/*[clinic end generated code: output=5190d11f0803bfe8 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=4570f4466d711d60 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/fileio.c.h b/Modules/_io/clinic/fileio.c.h index 207ad64fe62f958..4716781834a56f6 100644 --- a/Modules/_io/clinic/fileio.c.h +++ b/Modules/_io/clinic/fileio.c.h @@ -8,6 +8,7 @@ preserve #endif #include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(_io_FileIO__dealloc_warn__doc__, "_dealloc_warn($self, source, /)\n" @@ -134,15 +135,10 @@ _io_FileIO___init__(PyObject *self, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("FileIO", "argument 'mode'", "str", fastargs[1]); goto exit; } - Py_ssize_t mode_length; - mode = PyUnicode_AsUTF8AndSize(fastargs[1], &mode_length); + mode = _PyUnicode_AsUTF8NoNUL(fastargs[1]); if (mode == NULL) { goto exit; } - if (strlen(mode) != (size_t)mode_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!--noptargs) { goto skip_optional_pos; } @@ -677,4 +673,4 @@ _io_FileIO__blksize_get(PyObject *self, void *Py_UNUSED(context)) #define _IO_FILEIO__BLKSIZE_GETSETDEF {"_blksize", (getter)_io_FileIO__blksize_get, (setter)NULL, _io_FileIO__blksize__doc__}, -/*[clinic end generated code: output=d0a63950bc345c85 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c3674934f40bfbb6 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h index a0cefdf3bc9a9e7..d9dca69ff0605cb 100644 --- a/Modules/_io/clinic/textio.c.h +++ b/Modules/_io/clinic/textio.c.h @@ -9,6 +9,7 @@ preserve #include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(_io__TextIOBase_detach__doc__, "detach($self, /)\n" @@ -190,15 +191,10 @@ _io__TextIOBase_write(PyObject *self, PyTypeObject *cls, PyObject *const *args, _PyArg_BadArgument("write", "argument 1", "str", args[0]); goto exit; } - Py_ssize_t s_length; - s = PyUnicode_AsUTF8AndSize(args[0], &s_length); + s = _PyUnicode_AsUTF8NoNUL(args[0]); if (s == NULL) { goto exit; } - if (strlen(s) != (size_t)s_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _io__TextIOBase_write_impl(self, cls, s); exit: @@ -572,15 +568,10 @@ _io_TextIOWrapper___init__(PyObject *self, PyObject *args, PyObject *kwargs) encoding = NULL; } else if (PyUnicode_Check(fastargs[1])) { - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(fastargs[1]); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("TextIOWrapper", "argument 'encoding'", "str or None", fastargs[1]); @@ -601,15 +592,10 @@ _io_TextIOWrapper___init__(PyObject *self, PyObject *args, PyObject *kwargs) newline = NULL; } else if (PyUnicode_Check(fastargs[3])) { - Py_ssize_t newline_length; - newline = PyUnicode_AsUTF8AndSize(fastargs[3], &newline_length); + newline = _PyUnicode_AsUTF8NoNUL(fastargs[3]); if (newline == NULL) { goto exit; } - if (strlen(newline) != (size_t)newline_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("TextIOWrapper", "argument 'newline'", "str or None", fastargs[3]); @@ -1299,4 +1285,4 @@ _io_TextIOWrapper_buffer_get(PyObject *self, void *Py_UNUSED(context)) #define _IO_TEXTIOWRAPPER_BUFFER_GETSETDEF {"buffer", (getter)_io_TextIOWrapper_buffer_get, (setter)NULL, NULL}, -/*[clinic end generated code: output=102ae91df6216de2 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=1a8a4718813e63f0 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/winconsoleio.c.h b/Modules/_io/clinic/winconsoleio.c.h index a0ebce1772ae903..300a54dd6fb3622 100644 --- a/Modules/_io/clinic/winconsoleio.c.h +++ b/Modules/_io/clinic/winconsoleio.c.h @@ -8,6 +8,7 @@ preserve #endif #include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() #if defined(HAVE_WINDOWS_CONSOLE_IO) @@ -109,15 +110,10 @@ _io__WindowsConsoleIO___init__(PyObject *self, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("_WindowsConsoleIO", "argument 'mode'", "str", fastargs[1]); goto exit; } - Py_ssize_t mode_length; - mode = PyUnicode_AsUTF8AndSize(fastargs[1], &mode_length); + mode = _PyUnicode_AsUTF8NoNUL(fastargs[1]); if (mode == NULL) { goto exit; } - if (strlen(mode) != (size_t)mode_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!--noptargs) { goto skip_optional_pos; } @@ -594,4 +590,4 @@ _io__WindowsConsoleIO_mode_get(PyObject *self, void *Py_UNUSED(context)) # define _IO__WINDOWSCONSOLEIO_MODE_GETSETDEF #endif -/*[clinic end generated code: output=24fe425795203cee input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ceeb9f5083c7885e input=a9049054013a1b77]*/ diff --git a/Modules/_multiprocessing/clinic/multiprocessing.c.h b/Modules/_multiprocessing/clinic/multiprocessing.c.h index 6d4f5c2afcfd398..ea6fffc428919b4 100644 --- a/Modules/_multiprocessing/clinic/multiprocessing.c.h +++ b/Modules/_multiprocessing/clinic/multiprocessing.c.h @@ -3,6 +3,7 @@ preserve [clinic start generated code]*/ #include "pycore_modsupport.h" // _PyArg_CheckPositional() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() #if defined(MS_WINDOWS) @@ -138,15 +139,10 @@ _multiprocessing_sem_unlink(PyObject *module, PyObject *arg) _PyArg_BadArgument("sem_unlink", "argument", "str", arg); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(arg, &name_length); + name = _PyUnicode_AsUTF8NoNUL(arg); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _multiprocessing_sem_unlink_impl(module, name); exit: @@ -164,4 +160,4 @@ _multiprocessing_sem_unlink(PyObject *module, PyObject *arg) #ifndef _MULTIPROCESSING_SEND_METHODDEF #define _MULTIPROCESSING_SEND_METHODDEF #endif /* !defined(_MULTIPROCESSING_SEND_METHODDEF) */ -/*[clinic end generated code: output=73b4cb8428d816da input=a9049054013a1b77]*/ +/*[clinic end generated code: output=f5147f6a6e2cbd17 input=a9049054013a1b77]*/ diff --git a/Modules/_multiprocessing/clinic/semaphore.c.h b/Modules/_multiprocessing/clinic/semaphore.c.h index 6b1c0092ce48160..34dba39dab54143 100644 --- a/Modules/_multiprocessing/clinic/semaphore.c.h +++ b/Modules/_multiprocessing/clinic/semaphore.c.h @@ -8,6 +8,7 @@ preserve #endif #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() #if defined(HAVE_MP_SEMAPHORE) && defined(MS_WINDOWS) @@ -292,15 +293,10 @@ _multiprocessing_SemLock(PyTypeObject *type, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("SemLock", "argument 'name'", "str", fastargs[3]); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(fastargs[3], &name_length); + name = _PyUnicode_AsUTF8NoNUL(fastargs[3]); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } unlink = PyObject_IsTrue(fastargs[4]); if (unlink < 0) { goto exit; @@ -582,4 +578,4 @@ _multiprocessing_SemLock___exit__(PyObject *self, PyObject *const *args, Py_ssiz #ifndef _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF #define _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF #endif /* !defined(_MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF) */ -/*[clinic end generated code: output=d1e349d4ee3d4bbf input=a9049054013a1b77]*/ +/*[clinic end generated code: output=5c3a00b85537e647 input=a9049054013a1b77]*/ diff --git a/Modules/_sqlite/clinic/_sqlite3.connect.c.h b/Modules/_sqlite/clinic/_sqlite3.connect.c.h index e9d560666c14913..ce8c795ed2d5a02 100644 --- a/Modules/_sqlite/clinic/_sqlite3.connect.c.h +++ b/Modules/_sqlite/clinic/_sqlite3.connect.c.h @@ -7,6 +7,7 @@ preserve # include "pycore_runtime.h" // _Py_ID() #endif #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(pysqlite_connect__doc__, "connect($module, /, database, *, timeout=5.0, detect_types=0,\n" @@ -22,4 +23,4 @@ PyDoc_STRVAR(pysqlite_connect__doc__, #define PYSQLITE_CONNECT_METHODDEF \ {"connect", _PyCFunction_CAST(pysqlite_connect), METH_FASTCALL|METH_KEYWORDS, pysqlite_connect__doc__}, -/*[clinic end generated code: output=3d83139ba65e0bb5 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=07d5692e22b0fdf2 input=a9049054013a1b77]*/ diff --git a/Modules/_sqlite/clinic/connection.c.h b/Modules/_sqlite/clinic/connection.c.h index 2feea0ec97bbcae..75b14fd96becd2d 100644 --- a/Modules/_sqlite/clinic/connection.c.h +++ b/Modules/_sqlite/clinic/connection.c.h @@ -7,6 +7,7 @@ preserve # include "pycore_runtime.h" // _Py_ID() #endif #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() static int pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database, @@ -280,28 +281,18 @@ blobopen(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwna _PyArg_BadArgument("blobopen", "argument 1", "str", args[0]); goto exit; } - Py_ssize_t table_length; - table = PyUnicode_AsUTF8AndSize(args[0], &table_length); + table = _PyUnicode_AsUTF8NoNUL(args[0]); if (table == NULL) { goto exit; } - if (strlen(table) != (size_t)table_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!PyUnicode_Check(args[1])) { _PyArg_BadArgument("blobopen", "argument 2", "str", args[1]); goto exit; } - Py_ssize_t col_length; - col = PyUnicode_AsUTF8AndSize(args[1], &col_length); + col = _PyUnicode_AsUTF8NoNUL(args[1]); if (col == NULL) { goto exit; } - if (strlen(col) != (size_t)col_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!sqlite3_int64_converter(args[2], &row)) { goto exit; } @@ -321,15 +312,10 @@ blobopen(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwna _PyArg_BadArgument("blobopen", "argument 'name'", "str", args[4]); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(args[4], &name_length); + name = _PyUnicode_AsUTF8NoNUL(args[4]); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } skip_optional_kwonly: return_value = blobopen_impl((pysqlite_Connection *)self, table, col, row, readonly, name); @@ -459,15 +445,10 @@ pysqlite_connection_create_function(PyObject *self, PyTypeObject *cls, PyObject _PyArg_BadArgument("create_function", "argument 1", "str", args[0]); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(args[0], &name_length); + name = _PyUnicode_AsUTF8NoNUL(args[0]); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } narg = PyLong_AsInt(args[1]); if (narg == -1 && PyErr_Occurred()) { goto exit; @@ -543,15 +524,10 @@ create_window_function(PyObject *self, PyTypeObject *cls, PyObject *const *args, _PyArg_BadArgument("create_window_function", "argument 1", "str", args[0]); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(args[0], &name_length); + name = _PyUnicode_AsUTF8NoNUL(args[0]); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } num_params = PyLong_AsInt(args[1]); if (num_params == -1 && PyErr_Occurred()) { goto exit; @@ -611,15 +587,10 @@ pysqlite_connection_create_aggregate(PyObject *self, PyTypeObject *cls, PyObject _PyArg_BadArgument("create_aggregate", "argument 1", "str", args[0]); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(args[0], &name_length); + name = _PyUnicode_AsUTF8NoNUL(args[0]); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } n_arg = PyLong_AsInt(args[1]); if (n_arg == -1 && PyErr_Occurred()) { goto exit; @@ -893,15 +864,10 @@ pysqlite_connection_load_extension(PyObject *self, PyObject *const *args, Py_ssi _PyArg_BadArgument("load_extension", "argument 1", "str", args[0]); goto exit; } - Py_ssize_t extension_name_length; - extension_name = PyUnicode_AsUTF8AndSize(args[0], &extension_name_length); + extension_name = _PyUnicode_AsUTF8NoNUL(args[0]); if (extension_name == NULL) { goto exit; } - if (strlen(extension_name) != (size_t)extension_name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!noptargs) { goto skip_optional_kwonly; } @@ -909,15 +875,10 @@ pysqlite_connection_load_extension(PyObject *self, PyObject *const *args, Py_ssi entrypoint = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t entrypoint_length; - entrypoint = PyUnicode_AsUTF8AndSize(args[1], &entrypoint_length); + entrypoint = _PyUnicode_AsUTF8NoNUL(args[1]); if (entrypoint == NULL) { goto exit; } - if (strlen(entrypoint) != (size_t)entrypoint_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("load_extension", "argument 'entrypoint'", "str or None", args[1]); @@ -1202,15 +1163,10 @@ pysqlite_connection_backup(PyObject *self, PyObject *const *args, Py_ssize_t nar _PyArg_BadArgument("backup", "argument 'name'", "str", args[3]); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(args[3], &name_length); + name = _PyUnicode_AsUTF8NoNUL(args[3]); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!--noptargs) { goto skip_optional_kwonly; } @@ -1277,15 +1233,10 @@ pysqlite_connection_create_collation(PyObject *self, PyTypeObject *cls, PyObject _PyArg_BadArgument("create_collation", "argument 1", "str", args[0]); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(args[0], &name_length); + name = _PyUnicode_AsUTF8NoNUL(args[0]); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } callable = args[1]; return_value = pysqlite_connection_create_collation_impl((pysqlite_Connection *)self, cls, name, callable); @@ -1362,15 +1313,10 @@ serialize(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwn _PyArg_BadArgument("serialize", "argument 'name'", "str", args[0]); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(args[0], &name_length); + name = _PyUnicode_AsUTF8NoNUL(args[0]); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } skip_optional_kwonly: return_value = serialize_impl((pysqlite_Connection *)self, name); @@ -1471,15 +1417,10 @@ deserialize(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *k _PyArg_BadArgument("deserialize", "argument 'name'", "str", args[1]); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(args[1], &name_length); + name = _PyUnicode_AsUTF8NoNUL(args[1]); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } skip_optional_kwonly: return_value = deserialize_impl((pysqlite_Connection *)self, &data, name); @@ -1725,4 +1666,4 @@ getconfig(PyObject *self, PyObject *arg) #ifndef DESERIALIZE_METHODDEF #define DESERIALIZE_METHODDEF #endif /* !defined(DESERIALIZE_METHODDEF) */ -/*[clinic end generated code: output=11ccc746e9223121 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=1fcb0c3bf96db31b input=a9049054013a1b77]*/ diff --git a/Modules/_sqlite/clinic/cursor.c.h b/Modules/_sqlite/clinic/cursor.c.h index fcefc6535393b25..45780bd63530073 100644 --- a/Modules/_sqlite/clinic/cursor.c.h +++ b/Modules/_sqlite/clinic/cursor.c.h @@ -8,6 +8,7 @@ preserve #endif #include "pycore_long.h" // _PyLong_UInt32_Converter() #include "pycore_modsupport.h" // _PyArg_CheckPositional() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() static int pysqlite_cursor_init_impl(pysqlite_Cursor *self, @@ -136,15 +137,10 @@ pysqlite_cursor_executescript(PyObject *self, PyObject *arg) _PyArg_BadArgument("executescript", "argument", "str", arg); goto exit; } - Py_ssize_t sql_script_length; - sql_script = PyUnicode_AsUTF8AndSize(arg, &sql_script_length); + sql_script = _PyUnicode_AsUTF8NoNUL(arg); if (sql_script == NULL) { goto exit; } - if (strlen(sql_script) != (size_t)sql_script_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = pysqlite_cursor_executescript_impl((pysqlite_Cursor *)self, sql_script); exit: @@ -364,4 +360,4 @@ _sqlite3_Cursor_arraysize_set(PyObject *self, PyObject *arg, void *Py_UNUSED(con } #define _SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF {"arraysize", (getter)_sqlite3_Cursor_arraysize_get, (setter)_sqlite3_Cursor_arraysize_set, NULL}, -/*[clinic end generated code: output=e920343d84bd4976 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c24b4d93900ed908 input=a9049054013a1b77]*/ diff --git a/Modules/_sqlite/clinic/module.c.h b/Modules/_sqlite/clinic/module.c.h index 82ecd3eea1b39b4..79d1043cd729df7 100644 --- a/Modules/_sqlite/clinic/module.c.h +++ b/Modules/_sqlite/clinic/module.c.h @@ -7,6 +7,7 @@ preserve # include "pycore_runtime.h" // _Py_ID() #endif #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(pysqlite_complete_statement__doc__, "complete_statement($module, /, statement)\n" @@ -63,15 +64,10 @@ pysqlite_complete_statement(PyObject *module, PyObject *const *args, Py_ssize_t _PyArg_BadArgument("complete_statement", "argument 'statement'", "str", args[0]); goto exit; } - Py_ssize_t statement_length; - statement = PyUnicode_AsUTF8AndSize(args[0], &statement_length); + statement = _PyUnicode_AsUTF8NoNUL(args[0]); if (statement == NULL) { goto exit; } - if (strlen(statement) != (size_t)statement_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = pysqlite_complete_statement_impl(module, statement); exit: @@ -211,4 +207,4 @@ pysqlite_adapt(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=17c4e031680a5168 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=02aee45b7f9f14f0 input=a9049054013a1b77]*/ diff --git a/Modules/_testcapi/clinic/exceptions.c.h b/Modules/_testcapi/clinic/exceptions.c.h index cac5d288f437b72..2a91697b06fcda6 100644 --- a/Modules/_testcapi/clinic/exceptions.c.h +++ b/Modules/_testcapi/clinic/exceptions.c.h @@ -7,6 +7,7 @@ preserve # include "pycore_runtime.h" // _Py_ID() #endif #include "pycore_modsupport.h" // _PyArg_CheckPositional() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(_testcapi_err_set_raised__doc__, "err_set_raised($module, exception, /)\n" @@ -115,15 +116,10 @@ _testcapi_make_exception_with_doc(PyObject *module, PyObject *const *args, Py_ss _PyArg_BadArgument("make_exception_with_doc", "argument 'name'", "str", args[0]); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(args[0], &name_length); + name = _PyUnicode_AsUTF8NoNUL(args[0]); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!noptargs) { goto skip_optional_pos; } @@ -132,15 +128,10 @@ _testcapi_make_exception_with_doc(PyObject *module, PyObject *const *args, Py_ss _PyArg_BadArgument("make_exception_with_doc", "argument 'doc'", "str", args[1]); goto exit; } - Py_ssize_t doc_length; - doc = PyUnicode_AsUTF8AndSize(args[1], &doc_length); + doc = _PyUnicode_AsUTF8NoNUL(args[1]); if (doc == NULL) { goto exit; } - if (strlen(doc) != (size_t)doc_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!--noptargs) { goto skip_optional_pos; } @@ -459,4 +450,4 @@ _testcapi_unstable_exc_prep_reraise_star(PyObject *module, PyObject *const *args exit: return return_value; } -/*[clinic end generated code: output=357caea020348789 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=04b9feac7d574475 input=a9049054013a1b77]*/ diff --git a/Modules/cjkcodecs/clinic/multibytecodec.c.h b/Modules/cjkcodecs/clinic/multibytecodec.c.h index 32588b0561e1acc..013c746ccb7030d 100644 --- a/Modules/cjkcodecs/clinic/multibytecodec.c.h +++ b/Modules/cjkcodecs/clinic/multibytecodec.c.h @@ -7,6 +7,7 @@ preserve # include "pycore_runtime.h" // _Py_ID() #endif #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(_multibytecodec_MultibyteCodec_encode__doc__, "encode($self, /, input, errors=None)\n" @@ -77,15 +78,10 @@ _multibytecodec_MultibyteCodec_encode(PyObject *self, PyObject *const *args, Py_ errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("encode", "argument 'errors'", "str or None", args[1]); @@ -169,15 +165,10 @@ _multibytecodec_MultibyteCodec_decode(PyObject *self, PyObject *const *args, Py_ errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("decode", "argument 'errors'", "str or None", args[1]); @@ -698,4 +689,4 @@ PyDoc_STRVAR(_multibytecodec___create_codec__doc__, #define _MULTIBYTECODEC___CREATE_CODEC_METHODDEF \ {"__create_codec", (PyCFunction)_multibytecodec___create_codec, METH_O, _multibytecodec___create_codec__doc__}, -/*[clinic end generated code: output=a84b1544d7d01abb input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7ff5d19e433aecd2 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_codecsmodule.c.h b/Modules/clinic/_codecsmodule.c.h index 5ca9614f7f3216a..0b4ec169a2da149 100644 --- a/Modules/clinic/_codecsmodule.c.h +++ b/Modules/clinic/_codecsmodule.c.h @@ -7,6 +7,7 @@ preserve # include "pycore_runtime.h" // _Py_ID() #endif #include "pycore_modsupport.h" // _PyArg_BadArgument() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(_codecs_register__doc__, "register($module, search_function, /)\n" @@ -55,15 +56,10 @@ _codecs_lookup(PyObject *module, PyObject *arg) _PyArg_BadArgument("lookup", "argument", "str", arg); goto exit; } - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(arg, &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(arg); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _codecs_lookup_impl(module, encoding); exit: @@ -140,15 +136,10 @@ _codecs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje _PyArg_BadArgument("encode", "argument 'encoding'", "str", args[1]); goto exit; } - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(args[1]); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!--noptargs) { goto skip_optional_pos; } @@ -157,15 +148,10 @@ _codecs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje _PyArg_BadArgument("encode", "argument 'errors'", "str", args[2]); goto exit; } - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[2]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } skip_optional_pos: return_value = _codecs_encode_impl(module, obj, encoding, errors); @@ -243,15 +229,10 @@ _codecs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[1]); goto exit; } - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(args[1]); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!--noptargs) { goto skip_optional_pos; } @@ -260,15 +241,10 @@ _codecs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje _PyArg_BadArgument("decode", "argument 'errors'", "str", args[2]); goto exit; } - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[2]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } skip_optional_pos: return_value = _codecs_decode_impl(module, obj, encoding, errors); @@ -320,15 +296,10 @@ _codecs_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("escape_decode", "argument 2", "str or None", args[1]); @@ -380,15 +351,10 @@ _codecs_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("escape_encode", "argument 2", "str or None", args[1]); @@ -434,15 +400,10 @@ _codecs_utf_7_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("utf_7_decode", "argument 2", "str or None", args[1]); @@ -500,15 +461,10 @@ _codecs_utf_8_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("utf_8_decode", "argument 2", "str or None", args[1]); @@ -566,15 +522,10 @@ _codecs_utf_16_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("utf_16_decode", "argument 2", "str or None", args[1]); @@ -632,15 +583,10 @@ _codecs_utf_16_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("utf_16_le_decode", "argument 2", "str or None", args[1]); @@ -698,15 +644,10 @@ _codecs_utf_16_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("utf_16_be_decode", "argument 2", "str or None", args[1]); @@ -766,15 +707,10 @@ _codecs_utf_16_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("utf_16_ex_decode", "argument 2", "str or None", args[1]); @@ -839,15 +775,10 @@ _codecs_utf_32_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("utf_32_decode", "argument 2", "str or None", args[1]); @@ -905,15 +836,10 @@ _codecs_utf_32_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("utf_32_le_decode", "argument 2", "str or None", args[1]); @@ -971,15 +897,10 @@ _codecs_utf_32_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("utf_32_be_decode", "argument 2", "str or None", args[1]); @@ -1039,15 +960,10 @@ _codecs_utf_32_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("utf_32_ex_decode", "argument 2", "str or None", args[1]); @@ -1124,15 +1040,10 @@ _codecs_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_ errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("unicode_escape_decode", "argument 2", "str or None", args[1]); @@ -1202,15 +1113,10 @@ _codecs_raw_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ss errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("raw_unicode_escape_decode", "argument 2", "str or None", args[1]); @@ -1267,15 +1173,10 @@ _codecs_latin_1_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("latin_1_decode", "argument 2", "str or None", args[1]); @@ -1325,15 +1226,10 @@ _codecs_ascii_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("ascii_decode", "argument 2", "str or None", args[1]); @@ -1384,15 +1280,10 @@ _codecs_charmap_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("charmap_decode", "argument 2", "str or None", args[1]); @@ -1449,15 +1340,10 @@ _codecs_mbcs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("mbcs_decode", "argument 2", "str or None", args[1]); @@ -1519,15 +1405,10 @@ _codecs_oem_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("oem_decode", "argument 2", "str or None", args[1]); @@ -1594,15 +1475,10 @@ _codecs_code_page_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[2])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[2]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("code_page_decode", "argument 3", "str or None", args[2]); @@ -1659,15 +1535,10 @@ _codecs_iconv_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("iconv_decode", "argument 1", "str", args[0]); goto exit; } - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(args[0]); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) { goto exit; } @@ -1678,15 +1549,10 @@ _codecs_iconv_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[2])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[2]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("iconv_decode", "argument 3", "str or None", args[2]); @@ -1757,15 +1623,10 @@ _codecs_readbuffer_encode(PyObject *module, PyObject *const *args, Py_ssize_t na errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("readbuffer_encode", "argument 2", "str or None", args[1]); @@ -1817,15 +1678,10 @@ _codecs_utf_7_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("utf_7_encode", "argument 2", "str or None", args[1]); @@ -1872,15 +1728,10 @@ _codecs_utf_8_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("utf_8_encode", "argument 2", "str or None", args[1]); @@ -1928,15 +1779,10 @@ _codecs_utf_16_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("utf_16_encode", "argument 2", "str or None", args[1]); @@ -1990,15 +1836,10 @@ _codecs_utf_16_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("utf_16_le_encode", "argument 2", "str or None", args[1]); @@ -2045,15 +1886,10 @@ _codecs_utf_16_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("utf_16_be_encode", "argument 2", "str or None", args[1]); @@ -2101,15 +1937,10 @@ _codecs_utf_32_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("utf_32_encode", "argument 2", "str or None", args[1]); @@ -2163,15 +1994,10 @@ _codecs_utf_32_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("utf_32_le_encode", "argument 2", "str or None", args[1]); @@ -2218,15 +2044,10 @@ _codecs_utf_32_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("utf_32_be_encode", "argument 2", "str or None", args[1]); @@ -2273,15 +2094,10 @@ _codecs_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_ errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("unicode_escape_encode", "argument 2", "str or None", args[1]); @@ -2328,15 +2144,10 @@ _codecs_raw_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ss errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("raw_unicode_escape_encode", "argument 2", "str or None", args[1]); @@ -2383,15 +2194,10 @@ _codecs_latin_1_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("latin_1_encode", "argument 2", "str or None", args[1]); @@ -2438,15 +2244,10 @@ _codecs_ascii_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("ascii_encode", "argument 2", "str or None", args[1]); @@ -2494,15 +2295,10 @@ _codecs_charmap_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("charmap_encode", "argument 2", "str or None", args[1]); @@ -2582,15 +2378,10 @@ _codecs_mbcs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("mbcs_encode", "argument 2", "str or None", args[1]); @@ -2640,15 +2431,10 @@ _codecs_oem_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("oem_encode", "argument 2", "str or None", args[1]); @@ -2704,15 +2490,10 @@ _codecs_code_page_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[2])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[2]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("code_page_encode", "argument 3", "str or None", args[2]); @@ -2756,15 +2537,10 @@ _codecs_iconv_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("iconv_encode", "argument 1", "str", args[0]); goto exit; } - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(args[0]); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!PyUnicode_Check(args[1])) { _PyArg_BadArgument("iconv_encode", "argument 2", "str", args[1]); goto exit; @@ -2777,15 +2553,10 @@ _codecs_iconv_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[2])) { - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[2]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("iconv_encode", "argument 3", "str or None", args[2]); @@ -2832,15 +2603,10 @@ _codecs_register_error(PyObject *module, PyObject *const *args, Py_ssize_t nargs _PyArg_BadArgument("register_error", "argument 1", "str", args[0]); goto exit; } - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[0], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[0]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } handler = args[1]; return_value = _codecs_register_error_impl(module, errors, handler); @@ -2879,15 +2645,10 @@ _codecs__unregister_error(PyObject *module, PyObject *arg) _PyArg_BadArgument("_unregister_error", "argument", "str", arg); goto exit; } - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(arg, &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(arg); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } _return_value = _codecs__unregister_error_impl(module, errors); if ((_return_value == -1) && PyErr_Occurred()) { goto exit; @@ -2923,15 +2684,10 @@ _codecs_lookup_error(PyObject *module, PyObject *arg) _PyArg_BadArgument("lookup_error", "argument", "str", arg); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(arg, &name_length); + name = _PyUnicode_AsUTF8NoNUL(arg); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _codecs_lookup_error_impl(module, name); exit: @@ -3033,4 +2789,4 @@ _codecs__normalize_encoding(PyObject *module, PyObject *const *args, Py_ssize_t #ifndef _CODECS_ICONV_ENCODE_METHODDEF #define _CODECS_ICONV_ENCODE_METHODDEF #endif /* !defined(_CODECS_ICONV_ENCODE_METHODDEF) */ -/*[clinic end generated code: output=d6e155d435335482 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=2bf386d7e284e6f3 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_cursesmodule.c.h b/Modules/clinic/_cursesmodule.c.h index 7b83727a20b68aa..1eb42e884a61ec1 100644 --- a/Modules/clinic/_cursesmodule.c.h +++ b/Modules/clinic/_cursesmodule.c.h @@ -8,6 +8,7 @@ preserve #endif #include "pycore_long.h" // _PyLong_UnsignedInt_Converter() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(complexchar_new__doc__, "complexchar(text, /, attr=0, pair=0)\n" @@ -3814,15 +3815,10 @@ _curses_define_key(PyObject *module, PyObject *const *args, Py_ssize_t nargs) definition = NULL; } else if (PyUnicode_Check(args[0])) { - Py_ssize_t definition_length; - definition = PyUnicode_AsUTF8AndSize(args[0], &definition_length); + definition = _PyUnicode_AsUTF8NoNUL(args[0]); if (definition == NULL) { goto exit; } - if (strlen(definition) != (size_t)definition_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("define_key", "argument 1", "str or None", args[0]); @@ -3870,15 +3866,10 @@ _curses_key_defined(PyObject *module, PyObject *arg) _PyArg_BadArgument("key_defined", "argument", "str", arg); goto exit; } - Py_ssize_t definition_length; - definition = PyUnicode_AsUTF8AndSize(arg, &definition_length); + definition = _PyUnicode_AsUTF8NoNUL(arg); if (definition == NULL) { goto exit; } - if (strlen(definition) != (size_t)definition_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _curses_key_defined_impl(module, definition); exit: @@ -4273,15 +4264,10 @@ _curses_setupterm(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyO term = NULL; } else if (PyUnicode_Check(args[0])) { - Py_ssize_t term_length; - term = PyUnicode_AsUTF8AndSize(args[0], &term_length); + term = _PyUnicode_AsUTF8NoNUL(args[0]); if (term == NULL) { goto exit; } - if (strlen(term) != (size_t)term_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("setupterm", "argument 'term'", "str or None", args[0]); @@ -4343,15 +4329,10 @@ _curses_newterm(PyObject *module, PyObject *const *args, Py_ssize_t nargs) type = NULL; } else if (PyUnicode_Check(args[0])) { - Py_ssize_t type_length; - type = PyUnicode_AsUTF8AndSize(args[0], &type_length); + type = _PyUnicode_AsUTF8NoNUL(args[0]); if (type == NULL) { goto exit; } - if (strlen(type) != (size_t)type_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("newterm", "argument 1", "str or None", args[0]); @@ -5735,15 +5716,10 @@ _curses_tigetflag(PyObject *module, PyObject *arg) _PyArg_BadArgument("tigetflag", "argument", "str", arg); goto exit; } - Py_ssize_t capname_length; - capname = PyUnicode_AsUTF8AndSize(arg, &capname_length); + capname = _PyUnicode_AsUTF8NoNUL(arg); if (capname == NULL) { goto exit; } - if (strlen(capname) != (size_t)capname_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _curses_tigetflag_impl(module, capname); exit: @@ -5778,15 +5754,10 @@ _curses_tigetnum(PyObject *module, PyObject *arg) _PyArg_BadArgument("tigetnum", "argument", "str", arg); goto exit; } - Py_ssize_t capname_length; - capname = PyUnicode_AsUTF8AndSize(arg, &capname_length); + capname = _PyUnicode_AsUTF8NoNUL(arg); if (capname == NULL) { goto exit; } - if (strlen(capname) != (size_t)capname_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _curses_tigetnum_impl(module, capname); exit: @@ -5821,15 +5792,10 @@ _curses_tigetstr(PyObject *module, PyObject *arg) _PyArg_BadArgument("tigetstr", "argument", "str", arg); goto exit; } - Py_ssize_t capname_length; - capname = PyUnicode_AsUTF8AndSize(arg, &capname_length); + capname = _PyUnicode_AsUTF8NoNUL(arg); if (capname == NULL) { goto exit; } - if (strlen(capname) != (size_t)capname_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _curses_tigetstr_impl(module, capname); exit: @@ -6749,4 +6715,4 @@ _curses_has_extended_color_support(PyObject *module, PyObject *Py_UNUSED(ignored #ifndef _CURSES_ASSUME_DEFAULT_COLORS_METHODDEF #define _CURSES_ASSUME_DEFAULT_COLORS_METHODDEF #endif /* !defined(_CURSES_ASSUME_DEFAULT_COLORS_METHODDEF) */ -/*[clinic end generated code: output=cc7b5de1c82ae56b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=957470523e2b0eb1 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_datetimemodule.c.h b/Modules/clinic/_datetimemodule.c.h index fac41e7aefc7f4f..392a9da93ddbb41 100644 --- a/Modules/clinic/_datetimemodule.c.h +++ b/Modules/clinic/_datetimemodule.c.h @@ -7,6 +7,7 @@ preserve # include "pycore_runtime.h" // _Py_ID() #endif #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(delta_new__doc__, "timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0,\n" @@ -957,15 +958,10 @@ datetime_time_isoformat(PyObject *self, PyObject *const *args, Py_ssize_t nargs, _PyArg_BadArgument("isoformat", "argument 'timespec'", "str", args[0]); goto exit; } - Py_ssize_t timespec_length; - timespec = PyUnicode_AsUTF8AndSize(args[0], ×pec_length); + timespec = _PyUnicode_AsUTF8NoNUL(args[0]); if (timespec == NULL) { goto exit; } - if (strlen(timespec) != (size_t)timespec_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } skip_optional_pos: return_value = datetime_time_isoformat_impl((PyDateTime_Time *)self, timespec); @@ -1816,15 +1812,10 @@ datetime_datetime_isoformat(PyObject *self, PyObject *const *args, Py_ssize_t na _PyArg_BadArgument("isoformat", "argument 'timespec'", "str", args[1]); goto exit; } - Py_ssize_t timespec_length; - timespec = PyUnicode_AsUTF8AndSize(args[1], ×pec_length); + timespec = _PyUnicode_AsUTF8NoNUL(args[1]); if (timespec == NULL) { goto exit; } - if (strlen(timespec) != (size_t)timespec_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } skip_optional_pos: return_value = datetime_datetime_isoformat_impl((PyDateTime_DateTime *)self, sep, timespec); @@ -2091,4 +2082,4 @@ datetime_datetime___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored)) { return datetime_datetime___reduce___impl((PyDateTime_DateTime *)self); } -/*[clinic end generated code: output=8f63509398651723 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7bdfdfbd568c63ed input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_dbmmodule.c.h b/Modules/clinic/_dbmmodule.c.h index 6c979a4b0081df3..1bf05e6d8c2050d 100644 --- a/Modules/clinic/_dbmmodule.c.h +++ b/Modules/clinic/_dbmmodule.c.h @@ -7,6 +7,7 @@ preserve #endif #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(_dbm_dbm_close__doc__, "close($self, /)\n" @@ -225,15 +226,10 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("open", "argument 2", "str", args[1]); goto exit; } - Py_ssize_t flags_length; - flags = PyUnicode_AsUTF8AndSize(args[1], &flags_length); + flags = _PyUnicode_AsUTF8NoNUL(args[1]); if (flags == NULL) { goto exit; } - if (strlen(flags) != (size_t)flags_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (nargs < 3) { goto skip_optional; } @@ -247,4 +243,4 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=677deecf525167a5 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=a841c5e1dae0e22d input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_elementtree.c.h b/Modules/clinic/_elementtree.c.h index a39e738ec538b63..d57e0f70dc4d2c8 100644 --- a/Modules/clinic/_elementtree.c.h +++ b/Modules/clinic/_elementtree.c.h @@ -8,6 +8,7 @@ preserve #endif #include "pycore_abstract.h" // _PyNumber_Index() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(_elementtree_Element_append__doc__, "append($self, subelement, /)\n" @@ -1345,15 +1346,10 @@ _elementtree_XMLParser___init__(PyObject *self, PyObject *args, PyObject *kwargs encoding = NULL; } else if (PyUnicode_Check(fastargs[1])) { - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(fastargs[1]); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("XMLParser", "argument 'encoding'", "str or None", fastargs[1]); @@ -1479,4 +1475,4 @@ _elementtree_XMLParser__setevents(PyObject *self, PyObject *const *args, Py_ssiz exit: return return_value; } -/*[clinic end generated code: output=e2e9cf288c4400f6 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=9898ed184e12143d input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_gdbmmodule.c.h b/Modules/clinic/_gdbmmodule.c.h index fe993cc328fbd2f..9b786f71e4ac235 100644 --- a/Modules/clinic/_gdbmmodule.c.h +++ b/Modules/clinic/_gdbmmodule.c.h @@ -7,6 +7,7 @@ preserve #endif #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(_gdbm_gdbm_get__doc__, "get($self, key, default=None, /)\n" @@ -367,15 +368,10 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("open", "argument 2", "str", args[1]); goto exit; } - Py_ssize_t flags_length; - flags = PyUnicode_AsUTF8AndSize(args[1], &flags_length); + flags = _PyUnicode_AsUTF8NoNUL(args[1]); if (flags == NULL) { goto exit; } - if (strlen(flags) != (size_t)flags_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (nargs < 3) { goto skip_optional; } @@ -389,4 +385,4 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=429b5db24568292e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=f13a471f51ae35e0 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_hashopenssl.c.h b/Modules/clinic/_hashopenssl.c.h index 17ed37bbd3b6191..b99545b0eb33471 100644 --- a/Modules/clinic/_hashopenssl.c.h +++ b/Modules/clinic/_hashopenssl.c.h @@ -9,6 +9,7 @@ preserve #include "pycore_abstract.h" // _PyNumber_Index() #include "pycore_long.h" // _PyLong_UnsignedLong_Converter() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(_hashlib_HASH_copy__doc__, "copy($self, /)\n" @@ -307,15 +308,10 @@ _hashlib_HASH_new(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyO _PyArg_BadArgument("new", "argument 'name'", "str", args[0]); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(args[0], &name_length); + name = _PyUnicode_AsUTF8NoNUL(args[0]); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!noptargs) { goto skip_optional_pos; } @@ -1463,15 +1459,10 @@ pbkdf2_hmac(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject _PyArg_BadArgument("pbkdf2_hmac", "argument 'hash_name'", "str", args[0]); goto exit; } - Py_ssize_t hash_name_length; - hash_name = PyUnicode_AsUTF8AndSize(args[0], &hash_name_length); + hash_name = _PyUnicode_AsUTF8NoNUL(args[0]); if (hash_name == NULL) { goto exit; } - if (strlen(hash_name) != (size_t)hash_name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (PyObject_GetBuffer(args[1], &password, PyBUF_SIMPLE) != 0) { goto exit; } @@ -1986,4 +1977,4 @@ _hashlib_compare_digest(PyObject *module, PyObject *const *args, Py_ssize_t narg #ifndef _HASHLIB_OPENSSL_SHAKE_256_METHODDEF #define _HASHLIB_OPENSSL_SHAKE_256_METHODDEF #endif /* !defined(_HASHLIB_OPENSSL_SHAKE_256_METHODDEF) */ -/*[clinic end generated code: output=cf405e652a340bb2 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=608e8ac9483c9173 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_localemodule.c.h b/Modules/clinic/_localemodule.c.h index 118946b81474ea1..902673894774562 100644 --- a/Modules/clinic/_localemodule.c.h +++ b/Modules/clinic/_localemodule.c.h @@ -3,6 +3,7 @@ preserve [clinic start generated code]*/ #include "pycore_modsupport.h" // _PyArg_CheckPositional() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(_locale_setlocale__doc__, "setlocale($module, category, locale=None, /)\n" @@ -37,15 +38,10 @@ _locale_setlocale(PyObject *module, PyObject *const *args, Py_ssize_t nargs) locale = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t locale_length; - locale = PyUnicode_AsUTF8AndSize(args[1], &locale_length); + locale = _PyUnicode_AsUTF8NoNUL(args[1]); if (locale == NULL) { goto exit; } - if (strlen(locale) != (size_t)locale_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("setlocale", "argument 2", "str or None", args[1]); @@ -230,15 +226,10 @@ _locale_gettext(PyObject *module, PyObject *arg) _PyArg_BadArgument("gettext", "argument", "str", arg); goto exit; } - Py_ssize_t in_length; - in = PyUnicode_AsUTF8AndSize(arg, &in_length); + in = _PyUnicode_AsUTF8NoNUL(arg); if (in == NULL) { goto exit; } - if (strlen(in) != (size_t)in_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _locale_gettext_impl(module, in); exit: @@ -277,15 +268,10 @@ _locale_dgettext(PyObject *module, PyObject *const *args, Py_ssize_t nargs) domain = NULL; } else if (PyUnicode_Check(args[0])) { - Py_ssize_t domain_length; - domain = PyUnicode_AsUTF8AndSize(args[0], &domain_length); + domain = _PyUnicode_AsUTF8NoNUL(args[0]); if (domain == NULL) { goto exit; } - if (strlen(domain) != (size_t)domain_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("dgettext", "argument 1", "str or None", args[0]); @@ -295,15 +281,10 @@ _locale_dgettext(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("dgettext", "argument 2", "str", args[1]); goto exit; } - Py_ssize_t in_length; - in = PyUnicode_AsUTF8AndSize(args[1], &in_length); + in = _PyUnicode_AsUTF8NoNUL(args[1]); if (in == NULL) { goto exit; } - if (strlen(in) != (size_t)in_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _locale_dgettext_impl(module, domain, in); exit: @@ -342,15 +323,10 @@ _locale_dcgettext(PyObject *module, PyObject *const *args, Py_ssize_t nargs) domain = NULL; } else if (PyUnicode_Check(args[0])) { - Py_ssize_t domain_length; - domain = PyUnicode_AsUTF8AndSize(args[0], &domain_length); + domain = _PyUnicode_AsUTF8NoNUL(args[0]); if (domain == NULL) { goto exit; } - if (strlen(domain) != (size_t)domain_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("dcgettext", "argument 1", "str or None", args[0]); @@ -360,15 +336,10 @@ _locale_dcgettext(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("dcgettext", "argument 2", "str", args[1]); goto exit; } - Py_ssize_t msgid_length; - msgid = PyUnicode_AsUTF8AndSize(args[1], &msgid_length); + msgid = _PyUnicode_AsUTF8NoNUL(args[1]); if (msgid == NULL) { goto exit; } - if (strlen(msgid) != (size_t)msgid_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } category = PyLong_AsInt(args[2]); if (category == -1 && PyErr_Occurred()) { goto exit; @@ -405,15 +376,10 @@ _locale_textdomain(PyObject *module, PyObject *arg) domain = NULL; } else if (PyUnicode_Check(arg)) { - Py_ssize_t domain_length; - domain = PyUnicode_AsUTF8AndSize(arg, &domain_length); + domain = _PyUnicode_AsUTF8NoNUL(arg); if (domain == NULL) { goto exit; } - if (strlen(domain) != (size_t)domain_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("textdomain", "argument", "str or None", arg); @@ -456,15 +422,10 @@ _locale_bindtextdomain(PyObject *module, PyObject *const *args, Py_ssize_t nargs _PyArg_BadArgument("bindtextdomain", "argument 1", "str", args[0]); goto exit; } - Py_ssize_t domain_length; - domain = PyUnicode_AsUTF8AndSize(args[0], &domain_length); + domain = _PyUnicode_AsUTF8NoNUL(args[0]); if (domain == NULL) { goto exit; } - if (strlen(domain) != (size_t)domain_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } dirname_obj = args[1]; return_value = _locale_bindtextdomain_impl(module, domain, dirname_obj); @@ -503,28 +464,18 @@ _locale_bind_textdomain_codeset(PyObject *module, PyObject *const *args, Py_ssiz _PyArg_BadArgument("bind_textdomain_codeset", "argument 1", "str", args[0]); goto exit; } - Py_ssize_t domain_length; - domain = PyUnicode_AsUTF8AndSize(args[0], &domain_length); + domain = _PyUnicode_AsUTF8NoNUL(args[0]); if (domain == NULL) { goto exit; } - if (strlen(domain) != (size_t)domain_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (args[1] == Py_None) { codeset = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t codeset_length; - codeset = PyUnicode_AsUTF8AndSize(args[1], &codeset_length); + codeset = _PyUnicode_AsUTF8NoNUL(args[1]); if (codeset == NULL) { goto exit; } - if (strlen(codeset) != (size_t)codeset_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("bind_textdomain_codeset", "argument 2", "str or None", args[1]); @@ -595,4 +546,4 @@ _locale_getencoding(PyObject *module, PyObject *Py_UNUSED(ignored)) #ifndef _LOCALE_BIND_TEXTDOMAIN_CODESET_METHODDEF #define _LOCALE_BIND_TEXTDOMAIN_CODESET_METHODDEF #endif /* !defined(_LOCALE_BIND_TEXTDOMAIN_CODESET_METHODDEF) */ -/*[clinic end generated code: output=bb987603f9de8824 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b995b35bd3085d5b input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_pickle.c.h b/Modules/clinic/_pickle.c.h index 213e817a50a287f..4d54b3107ee4fb8 100644 --- a/Modules/clinic/_pickle.c.h +++ b/Modules/clinic/_pickle.c.h @@ -7,6 +7,7 @@ preserve # include "pycore_runtime.h" // _Py_SINGLETON() #endif #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(_pickle_Pickler_clear_memo__doc__, "clear_memo($self, /)\n" @@ -518,15 +519,10 @@ _pickle_Unpickler___init__(PyObject *self, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("Unpickler", "argument 'encoding'", "str", fastargs[2]); goto exit; } - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(fastargs[2], &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(fastargs[2]); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!--noptargs) { goto skip_optional_kwonly; } @@ -536,15 +532,10 @@ _pickle_Unpickler___init__(PyObject *self, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("Unpickler", "argument 'errors'", "str", fastargs[3]); goto exit; } - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(fastargs[3], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(fastargs[3]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!--noptargs) { goto skip_optional_kwonly; } @@ -931,15 +922,10 @@ _pickle_load(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject _PyArg_BadArgument("load", "argument 'encoding'", "str", args[2]); goto exit; } - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(args[2], &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(args[2]); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!--noptargs) { goto skip_optional_kwonly; } @@ -949,15 +935,10 @@ _pickle_load(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject _PyArg_BadArgument("load", "argument 'errors'", "str", args[3]); goto exit; } - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[3], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[3]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!--noptargs) { goto skip_optional_kwonly; } @@ -1060,15 +1041,10 @@ _pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec _PyArg_BadArgument("loads", "argument 'encoding'", "str", args[2]); goto exit; } - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(args[2], &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(args[2]); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!--noptargs) { goto skip_optional_kwonly; } @@ -1078,15 +1054,10 @@ _pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec _PyArg_BadArgument("loads", "argument 'errors'", "str", args[3]); goto exit; } - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[3], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[3]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!--noptargs) { goto skip_optional_kwonly; } @@ -1098,4 +1069,4 @@ _pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec exit: return return_value; } -/*[clinic end generated code: output=6331c72b3c427f63 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=08a3181c6f78ca87 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_ssl.c.h b/Modules/clinic/_ssl.c.h index b0dc01adfc999ee..d0bce13f2fd945e 100644 --- a/Modules/clinic/_ssl.c.h +++ b/Modules/clinic/_ssl.c.h @@ -11,6 +11,7 @@ preserve #include "pycore_fileutils.h" // _Py_Off_t_Converter() #include "pycore_long.h" // _PyLong_Size_t_Converter() #include "pycore_modsupport.h" // _PyArg_CheckPositional() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(_ssl__SSLSocket_do_handshake__doc__, "do_handshake($self, /)\n" @@ -771,15 +772,10 @@ _ssl__SSLSocket_get_channel_binding(PyObject *self, PyObject *const *args, Py_ss _PyArg_BadArgument("get_channel_binding", "argument 'cb_type'", "str", args[0]); goto exit; } - Py_ssize_t cb_type_length; - cb_type = PyUnicode_AsUTF8AndSize(args[0], &cb_type_length); + cb_type = _PyUnicode_AsUTF8NoNUL(args[0]); if (cb_type == NULL) { goto exit; } - if (strlen(cb_type) != (size_t)cb_type_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } skip_optional_pos: Py_BEGIN_CRITICAL_SECTION(self); return_value = _ssl__SSLSocket_get_channel_binding_impl((PySSLSocket *)self, cb_type); @@ -922,15 +918,10 @@ _ssl__SSLContext_set_ciphers(PyObject *self, PyObject *arg) _PyArg_BadArgument("set_ciphers", "argument", "str", arg); goto exit; } - Py_ssize_t cipherlist_length; - cipherlist = PyUnicode_AsUTF8AndSize(arg, &cipherlist_length); + cipherlist = _PyUnicode_AsUTF8NoNUL(arg); if (cipherlist == NULL) { goto exit; } - if (strlen(cipherlist) != (size_t)cipherlist_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } Py_BEGIN_CRITICAL_SECTION(self); return_value = _ssl__SSLContext_set_ciphers_impl((PySSLContext *)self, cipherlist); Py_END_CRITICAL_SECTION(); @@ -961,15 +952,10 @@ _ssl__SSLContext_set_ciphersuites(PyObject *self, PyObject *arg) _PyArg_BadArgument("set_ciphersuites", "argument", "str", arg); goto exit; } - Py_ssize_t ciphersuites_length; - ciphersuites = PyUnicode_AsUTF8AndSize(arg, &ciphersuites_length); + ciphersuites = _PyUnicode_AsUTF8NoNUL(arg); if (ciphersuites == NULL) { goto exit; } - if (strlen(ciphersuites) != (size_t)ciphersuites_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } Py_BEGIN_CRITICAL_SECTION(self); return_value = _ssl__SSLContext_set_ciphersuites_impl((PySSLContext *)self, ciphersuites); Py_END_CRITICAL_SECTION(); @@ -1022,15 +1008,10 @@ _ssl__SSLContext_set_groups(PyObject *self, PyObject *arg) _PyArg_BadArgument("set_groups", "argument", "str", arg); goto exit; } - Py_ssize_t grouplist_length; - grouplist = PyUnicode_AsUTF8AndSize(arg, &grouplist_length); + grouplist = _PyUnicode_AsUTF8NoNUL(arg); if (grouplist == NULL) { goto exit; } - if (strlen(grouplist) != (size_t)grouplist_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } Py_BEGIN_CRITICAL_SECTION(self); return_value = _ssl__SSLContext_set_groups_impl((PySSLContext *)self, grouplist); Py_END_CRITICAL_SECTION(); @@ -1128,15 +1109,10 @@ _ssl__SSLContext_set_client_sigalgs(PyObject *self, PyObject *arg) _PyArg_BadArgument("set_client_sigalgs", "argument", "str", arg); goto exit; } - Py_ssize_t sigalgslist_length; - sigalgslist = PyUnicode_AsUTF8AndSize(arg, &sigalgslist_length); + sigalgslist = _PyUnicode_AsUTF8NoNUL(arg); if (sigalgslist == NULL) { goto exit; } - if (strlen(sigalgslist) != (size_t)sigalgslist_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } Py_BEGIN_CRITICAL_SECTION(self); return_value = _ssl__SSLContext_set_client_sigalgs_impl((PySSLContext *)self, sigalgslist); Py_END_CRITICAL_SECTION(); @@ -1167,15 +1143,10 @@ _ssl__SSLContext_set_server_sigalgs(PyObject *self, PyObject *arg) _PyArg_BadArgument("set_server_sigalgs", "argument", "str", arg); goto exit; } - Py_ssize_t sigalgslist_length; - sigalgslist = PyUnicode_AsUTF8AndSize(arg, &sigalgslist_length); + sigalgslist = _PyUnicode_AsUTF8NoNUL(arg); if (sigalgslist == NULL) { goto exit; } - if (strlen(sigalgslist) != (size_t)sigalgslist_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } Py_BEGIN_CRITICAL_SECTION(self); return_value = _ssl__SSLContext_set_server_sigalgs_impl((PySSLContext *)self, sigalgslist); Py_END_CRITICAL_SECTION(); @@ -2354,15 +2325,10 @@ _ssl__SSLContext_set_psk_server_callback(PyObject *self, PyObject *const *args, identity_hint = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t identity_hint_length; - identity_hint = PyUnicode_AsUTF8AndSize(args[1], &identity_hint_length); + identity_hint = _PyUnicode_AsUTF8NoNUL(args[1]); if (identity_hint == NULL) { goto exit; } - if (strlen(identity_hint) != (size_t)identity_hint_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("set_psk_server_callback", "argument 'identity_hint'", "str or None", args[1]); @@ -2855,15 +2821,10 @@ _ssl_txt2obj(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject _PyArg_BadArgument("txt2obj", "argument 'txt'", "str", args[0]); goto exit; } - Py_ssize_t txt_length; - txt = PyUnicode_AsUTF8AndSize(args[0], &txt_length); + txt = _PyUnicode_AsUTF8NoNUL(args[0]); if (txt == NULL) { goto exit; } - if (strlen(txt) != (size_t)txt_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!noptargs) { goto skip_optional_pos; } @@ -2973,15 +2934,10 @@ _ssl_enum_certificates(PyObject *module, PyObject *const *args, Py_ssize_t nargs _PyArg_BadArgument("enum_certificates", "argument 'store_name'", "str", args[0]); goto exit; } - Py_ssize_t store_name_length; - store_name = PyUnicode_AsUTF8AndSize(args[0], &store_name_length); + store_name = _PyUnicode_AsUTF8NoNUL(args[0]); if (store_name == NULL) { goto exit; } - if (strlen(store_name) != (size_t)store_name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } Py_BEGIN_CRITICAL_SECTION(module); return_value = _ssl_enum_certificates_impl(module, store_name); Py_END_CRITICAL_SECTION(); @@ -3054,15 +3010,10 @@ _ssl_enum_crls(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje _PyArg_BadArgument("enum_crls", "argument 'store_name'", "str", args[0]); goto exit; } - Py_ssize_t store_name_length; - store_name = PyUnicode_AsUTF8AndSize(args[0], &store_name_length); + store_name = _PyUnicode_AsUTF8NoNUL(args[0]); if (store_name == NULL) { goto exit; } - if (strlen(store_name) != (size_t)store_name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } Py_BEGIN_CRITICAL_SECTION(module); return_value = _ssl_enum_crls_impl(module, store_name); Py_END_CRITICAL_SECTION(); @@ -3132,4 +3083,4 @@ _ssl_enum_crls(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje #define _SSL_SSLSESSION_HAS_TICKET_GETSETDEF {"has_ticket", (getter)_ssl_SSLSession_has_ticket_get, (setter)NULL, _ssl_SSLSession_has_ticket__doc__}, -/*[clinic end generated code: output=42b28429643df3e3 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=14ced41bd24b60c3 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_testclinic.c.h b/Modules/clinic/_testclinic.c.h index c3bf217a9e7b7b7..1995768835b7cb7 100644 --- a/Modules/clinic/_testclinic.c.h +++ b/Modules/clinic/_testclinic.c.h @@ -11,6 +11,7 @@ preserve #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_runtime.h" // _Py_ID() #include "pycore_tuple.h" // _PyTuple_ITEMS() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(test_empty_function__doc__, "test_empty_function($module, /)\n" @@ -4043,15 +4044,10 @@ clone_f1(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw _PyArg_BadArgument("clone_f1", "argument 'path'", "str", args[0]); goto exit; } - Py_ssize_t path_length; - path = PyUnicode_AsUTF8AndSize(args[0], &path_length); + path = _PyUnicode_AsUTF8NoNUL(args[0]); if (path == NULL) { goto exit; } - if (strlen(path) != (size_t)path_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = clone_f1_impl(module, path); exit: @@ -4112,15 +4108,10 @@ clone_f2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw _PyArg_BadArgument("clone_f2", "argument 'path'", "str", args[0]); goto exit; } - Py_ssize_t path_length; - path = PyUnicode_AsUTF8AndSize(args[0], &path_length); + path = _PyUnicode_AsUTF8NoNUL(args[0]); if (path == NULL) { goto exit; } - if (strlen(path) != (size_t)path_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = clone_f2_impl(module, path); exit: @@ -5349,4 +5340,4 @@ vc_kwonly_vectorcall(PyObject *type, PyObject *const *args, kwnames ? PyTuple_GET_SIZE(kwnames) : 0, NULL, kwnames); } -/*[clinic end generated code: output=8a219f606f1296ac input=a9049054013a1b77]*/ +/*[clinic end generated code: output=440e5a80f2f311f1 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_testclinic_depr.c.h b/Modules/clinic/_testclinic_depr.c.h index 1b0195185329a2a..1652e9223e54f94 100644 --- a/Modules/clinic/_testclinic_depr.c.h +++ b/Modules/clinic/_testclinic_depr.c.h @@ -11,6 +11,7 @@ preserve #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_runtime.h" // _Py_ID() #include "pycore_tuple.h" // _PyTuple_ITEMS() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(depr_star_new__doc__, "DeprStarNew(a=None)\n" @@ -2681,4 +2682,4 @@ depr_multi(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject * exit: return return_value; } -/*[clinic end generated code: output=858abe8a5a885725 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=abe0af8d8c637c36 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_testclinic_kwds.c.h b/Modules/clinic/_testclinic_kwds.c.h index ce4ee7a850f45b9..faae3f3d0c26584 100644 --- a/Modules/clinic/_testclinic_kwds.c.h +++ b/Modules/clinic/_testclinic_kwds.c.h @@ -11,6 +11,7 @@ preserve #include "pycore_modsupport.h" // _PyArg_CheckPositional() #include "pycore_runtime.h" // _Py_ID() #include "pycore_tuple.h" // _PyTuple_ITEMS() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(lone_kwds__doc__, "lone_kwds($module, /, **kwds)\n" @@ -229,4 +230,4 @@ kwds_with_pos_only_and_stararg(PyObject *module, PyObject *args, PyObject *kwarg return return_value; } -/*[clinic end generated code: output=62804c41a11bbd73 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=27a7ba9440b9a884 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_tkinter.c.h b/Modules/clinic/_tkinter.c.h index 3147cf7f9d2cff3..3b3fac1f75bc93e 100644 --- a/Modules/clinic/_tkinter.c.h +++ b/Modules/clinic/_tkinter.c.h @@ -3,6 +3,7 @@ preserve [clinic start generated code]*/ #include "pycore_modsupport.h" // _PyArg_BadArgument() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(_tkinter_tkapp_eval__doc__, "eval($self, script, /)\n" @@ -25,15 +26,10 @@ _tkinter_tkapp_eval(PyObject *self, PyObject *arg) _PyArg_BadArgument("eval", "argument", "str", arg); goto exit; } - Py_ssize_t script_length; - script = PyUnicode_AsUTF8AndSize(arg, &script_length); + script = _PyUnicode_AsUTF8NoNUL(arg); if (script == NULL) { goto exit; } - if (strlen(script) != (size_t)script_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _tkinter_tkapp_eval_impl((TkappObject *)self, script); exit: @@ -61,15 +57,10 @@ _tkinter_tkapp_evalfile(PyObject *self, PyObject *arg) _PyArg_BadArgument("evalfile", "argument", "str", arg); goto exit; } - Py_ssize_t fileName_length; - fileName = PyUnicode_AsUTF8AndSize(arg, &fileName_length); + fileName = _PyUnicode_AsUTF8NoNUL(arg); if (fileName == NULL) { goto exit; } - if (strlen(fileName) != (size_t)fileName_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _tkinter_tkapp_evalfile_impl((TkappObject *)self, fileName); exit: @@ -97,15 +88,10 @@ _tkinter_tkapp_record(PyObject *self, PyObject *arg) _PyArg_BadArgument("record", "argument", "str", arg); goto exit; } - Py_ssize_t script_length; - script = PyUnicode_AsUTF8AndSize(arg, &script_length); + script = _PyUnicode_AsUTF8NoNUL(arg); if (script == NULL) { goto exit; } - if (strlen(script) != (size_t)script_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _tkinter_tkapp_record_impl((TkappObject *)self, script); exit: @@ -133,15 +119,10 @@ _tkinter_tkapp_adderrorinfo(PyObject *self, PyObject *arg) _PyArg_BadArgument("adderrorinfo", "argument", "str", arg); goto exit; } - Py_ssize_t msg_length; - msg = PyUnicode_AsUTF8AndSize(arg, &msg_length); + msg = _PyUnicode_AsUTF8NoNUL(arg); if (msg == NULL) { goto exit; } - if (strlen(msg) != (size_t)msg_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _tkinter_tkapp_adderrorinfo_impl((TkappObject *)self, msg); exit: @@ -232,15 +213,10 @@ _tkinter_tkapp_exprstring(PyObject *self, PyObject *arg) _PyArg_BadArgument("exprstring", "argument", "str", arg); goto exit; } - Py_ssize_t s_length; - s = PyUnicode_AsUTF8AndSize(arg, &s_length); + s = _PyUnicode_AsUTF8NoNUL(arg); if (s == NULL) { goto exit; } - if (strlen(s) != (size_t)s_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _tkinter_tkapp_exprstring_impl((TkappObject *)self, s); exit: @@ -268,15 +244,10 @@ _tkinter_tkapp_exprlong(PyObject *self, PyObject *arg) _PyArg_BadArgument("exprlong", "argument", "str", arg); goto exit; } - Py_ssize_t s_length; - s = PyUnicode_AsUTF8AndSize(arg, &s_length); + s = _PyUnicode_AsUTF8NoNUL(arg); if (s == NULL) { goto exit; } - if (strlen(s) != (size_t)s_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _tkinter_tkapp_exprlong_impl((TkappObject *)self, s); exit: @@ -304,15 +275,10 @@ _tkinter_tkapp_exprdouble(PyObject *self, PyObject *arg) _PyArg_BadArgument("exprdouble", "argument", "str", arg); goto exit; } - Py_ssize_t s_length; - s = PyUnicode_AsUTF8AndSize(arg, &s_length); + s = _PyUnicode_AsUTF8NoNUL(arg); if (s == NULL) { goto exit; } - if (strlen(s) != (size_t)s_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _tkinter_tkapp_exprdouble_impl((TkappObject *)self, s); exit: @@ -340,15 +306,10 @@ _tkinter_tkapp_exprboolean(PyObject *self, PyObject *arg) _PyArg_BadArgument("exprboolean", "argument", "str", arg); goto exit; } - Py_ssize_t s_length; - s = PyUnicode_AsUTF8AndSize(arg, &s_length); + s = _PyUnicode_AsUTF8NoNUL(arg); if (s == NULL) { goto exit; } - if (strlen(s) != (size_t)s_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _tkinter_tkapp_exprboolean_impl((TkappObject *)self, s); exit: @@ -402,15 +363,10 @@ _tkinter_tkapp_createcommand(PyObject *self, PyObject *const *args, Py_ssize_t n _PyArg_BadArgument("createcommand", "argument 1", "str", args[0]); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(args[0], &name_length); + name = _PyUnicode_AsUTF8NoNUL(args[0]); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } func = args[1]; return_value = _tkinter_tkapp_createcommand_impl((TkappObject *)self, name, func); @@ -439,15 +395,10 @@ _tkinter_tkapp_deletecommand(PyObject *self, PyObject *arg) _PyArg_BadArgument("deletecommand", "argument", "str", arg); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(arg, &name_length); + name = _PyUnicode_AsUTF8NoNUL(arg); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _tkinter_tkapp_deletecommand_impl((TkappObject *)self, name); exit: @@ -799,15 +750,10 @@ _tkinter_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs) screenName = NULL; } else if (PyUnicode_Check(args[0])) { - Py_ssize_t screenName_length; - screenName = PyUnicode_AsUTF8AndSize(args[0], &screenName_length); + screenName = _PyUnicode_AsUTF8NoNUL(args[0]); if (screenName == NULL) { goto exit; } - if (strlen(screenName) != (size_t)screenName_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("create", "argument 1", "str or None", args[0]); @@ -820,15 +766,10 @@ _tkinter_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("create", "argument 2", "str", args[1]); goto exit; } - Py_ssize_t baseName_length; - baseName = PyUnicode_AsUTF8AndSize(args[1], &baseName_length); + baseName = _PyUnicode_AsUTF8NoNUL(args[1]); if (baseName == NULL) { goto exit; } - if (strlen(baseName) != (size_t)baseName_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (nargs < 3) { goto skip_optional; } @@ -836,15 +777,10 @@ _tkinter_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("create", "argument 3", "str", args[2]); goto exit; } - Py_ssize_t className_length; - className = PyUnicode_AsUTF8AndSize(args[2], &className_length); + className = _PyUnicode_AsUTF8NoNUL(args[2]); if (className == NULL) { goto exit; } - if (strlen(className) != (size_t)className_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (nargs < 4) { goto skip_optional; } @@ -880,15 +816,10 @@ _tkinter_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs) use = NULL; } else if (PyUnicode_Check(args[7])) { - Py_ssize_t use_length; - use = PyUnicode_AsUTF8AndSize(args[7], &use_length); + use = _PyUnicode_AsUTF8NoNUL(args[7]); if (use == NULL) { goto exit; } - if (strlen(use) != (size_t)use_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("create", "argument 8", "str or None", args[7]); @@ -967,4 +898,4 @@ _tkinter_getbusywaitinterval(PyObject *module, PyObject *Py_UNUSED(ignored)) #ifndef _TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF #define _TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF #endif /* !defined(_TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF) */ -/*[clinic end generated code: output=c807adb73e305725 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=205b2d1309a44339 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/arraymodule.c.h b/Modules/clinic/arraymodule.c.h index 1e9f317853d6c2e..9544e475cf68a8c 100644 --- a/Modules/clinic/arraymodule.c.h +++ b/Modules/clinic/arraymodule.c.h @@ -7,6 +7,7 @@ preserve #endif #include "pycore_abstract.h" // _PyNumber_Index() #include "pycore_modsupport.h" // _PyArg_CheckPositional() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(array_array_clear__doc__, "clear($self, /)\n" @@ -673,15 +674,10 @@ array__array_reconstructor(PyObject *module, PyObject *const *args, Py_ssize_t n _PyArg_BadArgument("_array_reconstructor", "argument 2", "str", args[1]); goto exit; } - Py_ssize_t typecode_length; - typecode = PyUnicode_AsUTF8AndSize(args[1], &typecode_length); + typecode = _PyUnicode_AsUTF8NoNUL(args[1]); if (typecode == NULL) { goto exit; } - if (strlen(typecode) != (size_t)typecode_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } mformat_code = PyLong_AsInt(args[2]); if (mformat_code == -1 && PyErr_Occurred()) { goto exit; @@ -781,4 +777,4 @@ array_arrayiterator___setstate__(PyObject *self, PyObject *state) return return_value; } -/*[clinic end generated code: output=32784678e77ac658 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=5f0bd4dcfec24e97 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/mmapmodule.c.h b/Modules/clinic/mmapmodule.c.h index 98c5bf6a2fb1462..1343eda42e84ec2 100644 --- a/Modules/clinic/mmapmodule.c.h +++ b/Modules/clinic/mmapmodule.c.h @@ -9,6 +9,7 @@ preserve #include "pycore_abstract.h" // _PyNumber_Index() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(mmap_mmap_close__doc__, "close($self, /)\n" @@ -547,15 +548,10 @@ mmap_mmap_set_name(PyObject *self, PyObject *arg) _PyArg_BadArgument("set_name", "argument", "str", arg); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(arg, &name_length); + name = _PyUnicode_AsUTF8NoNUL(arg); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } Py_BEGIN_CRITICAL_SECTION(self); return_value = mmap_mmap_set_name_impl((mmap_object *)self, name); Py_END_CRITICAL_SECTION(); @@ -881,4 +877,4 @@ mmap_mmap_madvise(PyObject *self, PyObject *const *args, Py_ssize_t nargs) #ifndef MMAP_MMAP_MADVISE_METHODDEF #define MMAP_MMAP_MADVISE_METHODDEF #endif /* !defined(MMAP_MMAP_MADVISE_METHODDEF) */ -/*[clinic end generated code: output=1122b93314aebc5c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d2ae0d1d754f51cc input=a9049054013a1b77]*/ diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 7c8171c04c0727b..403cb2df7191c7d 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -10,6 +10,7 @@ preserve #include "pycore_fileutils.h" // _Py_Off_t_Converter() #include "pycore_long.h" // _PyLong_UnsignedInt_Converter() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(os_stat__doc__, "stat($module, /, path, *, dir_fd=None, follow_symlinks=True)\n" @@ -5321,15 +5322,10 @@ os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]); goto exit; } - Py_ssize_t user_length; - user = PyUnicode_AsUTF8AndSize(args[0], &user_length); + user = _PyUnicode_AsUTF8NoNUL(args[0]); if (user == NULL) { goto exit; } - if (strlen(user) != (size_t)user_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } basegid = PyLong_AsInt(args[1]); if (basegid == -1 && PyErr_Occurred()) { goto exit; @@ -5375,15 +5371,10 @@ os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]); goto exit; } - Py_ssize_t user_length; - user = PyUnicode_AsUTF8AndSize(args[0], &user_length); + user = _PyUnicode_AsUTF8NoNUL(args[0]); if (user == NULL) { goto exit; } - if (strlen(user) != (size_t)user_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!_Py_Gid_Converter(args[1], &basegid)) { goto exit; } @@ -13043,15 +13034,10 @@ os__emscripten_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py _PyArg_BadArgument("_emscripten_log", "argument 'arg'", "str", args[0]); goto exit; } - Py_ssize_t arg_length; - arg = PyUnicode_AsUTF8AndSize(args[0], &arg_length); + arg = _PyUnicode_AsUTF8NoNUL(args[0]); if (arg == NULL) { goto exit; } - if (strlen(arg) != (size_t)arg_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = os__emscripten_log_impl(module, arg); exit: @@ -13747,4 +13733,4 @@ os__emscripten_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py #ifndef OS__EMSCRIPTEN_LOG_METHODDEF #define OS__EMSCRIPTEN_LOG_METHODDEF #endif /* !defined(OS__EMSCRIPTEN_LOG_METHODDEF) */ -/*[clinic end generated code: output=d4e858cbdf280235 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=8e456e180637dfb3 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/pyexpat.c.h b/Modules/clinic/pyexpat.c.h index 959e06da7791145..5943c2f840020b0 100644 --- a/Modules/clinic/pyexpat.c.h +++ b/Modules/clinic/pyexpat.c.h @@ -8,6 +8,7 @@ preserve #endif #include "pycore_long.h" // _PyLong_UnsignedLongLong_Converter() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(pyexpat_xmlparser_SetReparseDeferralEnabled__doc__, "SetReparseDeferralEnabled($self, enabled, /)\n" @@ -183,15 +184,10 @@ pyexpat_xmlparser_SetBase(PyObject *self, PyObject *arg) _PyArg_BadArgument("SetBase", "argument", "str", arg); goto exit; } - Py_ssize_t base_length; - base = PyUnicode_AsUTF8AndSize(arg, &base_length); + base = _PyUnicode_AsUTF8NoNUL(arg); if (base == NULL) { goto exit; } - if (strlen(base) != (size_t)base_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = pyexpat_xmlparser_SetBase_impl((xmlparseobject *)self, base); exit: @@ -311,15 +307,10 @@ pyexpat_xmlparser_ExternalEntityParserCreate(PyObject *self, PyTypeObject *cls, context = NULL; } else if (PyUnicode_Check(args[0])) { - Py_ssize_t context_length; - context = PyUnicode_AsUTF8AndSize(args[0], &context_length); + context = _PyUnicode_AsUTF8NoNUL(args[0]); if (context == NULL) { goto exit; } - if (strlen(context) != (size_t)context_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("ExternalEntityParserCreate", "argument 1", "str or None", args[0]); @@ -332,15 +323,10 @@ pyexpat_xmlparser_ExternalEntityParserCreate(PyObject *self, PyTypeObject *cls, _PyArg_BadArgument("ExternalEntityParserCreate", "argument 2", "str", args[1]); goto exit; } - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(args[1]); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } skip_optional_posonly: return_value = pyexpat_xmlparser_ExternalEntityParserCreate_impl((xmlparseobject *)self, cls, context, encoding); @@ -774,15 +760,10 @@ pyexpat_ParserCreate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, encoding = NULL; } else if (PyUnicode_Check(args[0])) { - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(args[0]); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("ParserCreate", "argument 'encoding'", "str or None", args[0]); @@ -797,15 +778,10 @@ pyexpat_ParserCreate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, namespace_separator = NULL; } else if (PyUnicode_Check(args[1])) { - Py_ssize_t namespace_separator_length; - namespace_separator = PyUnicode_AsUTF8AndSize(args[1], &namespace_separator_length); + namespace_separator = _PyUnicode_AsUTF8NoNUL(args[1]); if (namespace_separator == NULL) { goto exit; } - if (strlen(namespace_separator) != (size_t)namespace_separator_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("ParserCreate", "argument 'namespace_separator'", "str or None", args[1]); @@ -870,4 +846,4 @@ pyexpat_ErrorString(PyObject *module, PyObject *arg) #ifndef PYEXPAT_XMLPARSER_SETALLOCTRACKERMAXIMUMAMPLIFICATION_METHODDEF #define PYEXPAT_XMLPARSER_SETALLOCTRACKERMAXIMUMAMPLIFICATION_METHODDEF #endif /* !defined(PYEXPAT_XMLPARSER_SETALLOCTRACKERMAXIMUMAMPLIFICATION_METHODDEF) */ -/*[clinic end generated code: output=c68606a1fbc3a501 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=f3d03801815b5b13 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/socketmodule.c.h b/Modules/clinic/socketmodule.c.h index fcccf347a0ae9bd..09041d92a305793 100644 --- a/Modules/clinic/socketmodule.c.h +++ b/Modules/clinic/socketmodule.c.h @@ -9,6 +9,7 @@ preserve #include "pycore_abstract.h" // _PyNumber_Index() #include "pycore_long.h" // _PyLong_UInt16_Converter() #include "pycore_modsupport.h" // _PyArg_CheckPositional() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() #if (defined(HAVE_ACCEPT) || defined(HAVE_ACCEPT4)) @@ -1485,15 +1486,10 @@ _socket_getservbyname(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("getservbyname", "argument 1", "str", args[0]); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(args[0], &name_length); + name = _PyUnicode_AsUTF8NoNUL(args[0]); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (nargs < 2) { goto skip_optional; } @@ -1501,15 +1497,10 @@ _socket_getservbyname(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("getservbyname", "argument 2", "str", args[1]); goto exit; } - Py_ssize_t proto_length; - proto = PyUnicode_AsUTF8AndSize(args[1], &proto_length); + proto = _PyUnicode_AsUTF8NoNUL(args[1]); if (proto == NULL) { goto exit; } - if (strlen(proto) != (size_t)proto_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } skip_optional: return_value = _socket_getservbyname_impl(module, name, proto); @@ -1557,15 +1548,10 @@ _socket_getservbyport(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("getservbyport", "argument 2", "str", args[1]); goto exit; } - Py_ssize_t proto_length; - proto = PyUnicode_AsUTF8AndSize(args[1], &proto_length); + proto = _PyUnicode_AsUTF8NoNUL(args[1]); if (proto == NULL) { goto exit; } - if (strlen(proto) != (size_t)proto_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } skip_optional: return_value = _socket_getservbyport_impl(module, port, proto); @@ -1599,15 +1585,10 @@ _socket_getprotobyname(PyObject *module, PyObject *arg) _PyArg_BadArgument("getprotobyname", "argument", "str", arg); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(arg, &name_length); + name = _PyUnicode_AsUTF8NoNUL(arg); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _socket_getprotobyname_impl(module, name); exit: @@ -1835,15 +1816,10 @@ _socket_inet_aton(PyObject *module, PyObject *arg) _PyArg_BadArgument("inet_aton", "argument", "str", arg); goto exit; } - Py_ssize_t ip_addr_length; - ip_addr = PyUnicode_AsUTF8AndSize(arg, &ip_addr_length); + ip_addr = _PyUnicode_AsUTF8NoNUL(arg); if (ip_addr == NULL) { goto exit; } - if (strlen(ip_addr) != (size_t)ip_addr_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _socket_inet_aton_impl(module, ip_addr); exit: @@ -1920,15 +1896,10 @@ _socket_inet_pton(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("inet_pton", "argument 2", "str", args[1]); goto exit; } - Py_ssize_t ip_length; - ip = PyUnicode_AsUTF8AndSize(args[1], &ip_length); + ip = _PyUnicode_AsUTF8NoNUL(args[1]); if (ip == NULL) { goto exit; } - if (strlen(ip) != (size_t)ip_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = _socket_inet_pton_impl(module, af, ip); exit: @@ -2478,4 +2449,4 @@ _socket_CMSG_SPACE(PyObject *module, PyObject *arg) #ifndef _SOCKET_CMSG_SPACE_METHODDEF #define _SOCKET_CMSG_SPACE_METHODDEF #endif /* !defined(_SOCKET_CMSG_SPACE_METHODDEF) */ -/*[clinic end generated code: output=dfe0ca7c716c1183 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=bca43f33969d67ad input=a9049054013a1b77]*/ diff --git a/Modules/clinic/symtablemodule.c.h b/Modules/clinic/symtablemodule.c.h index 00ee4315846b603..2df590875955f36 100644 --- a/Modules/clinic/symtablemodule.c.h +++ b/Modules/clinic/symtablemodule.c.h @@ -7,6 +7,7 @@ preserve # include "pycore_runtime.h" // _Py_ID() #endif #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(_symtable_symtable__doc__, "symtable($module, source, filename, startstr, /, *, module=None)\n" @@ -75,15 +76,10 @@ _symtable_symtable(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py _PyArg_BadArgument("symtable", "argument 3", "str", args[2]); goto exit; } - Py_ssize_t startstr_length; - startstr = PyUnicode_AsUTF8AndSize(args[2], &startstr_length); + startstr = _PyUnicode_AsUTF8NoNUL(args[2]); if (startstr == NULL) { goto exit; } - if (strlen(startstr) != (size_t)startstr_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!noptargs) { goto skip_optional_kwonly; } @@ -97,4 +93,4 @@ _symtable_symtable(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py return return_value; } -/*[clinic end generated code: output=23523cada784726e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=910e4f6ce98ae0a1 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/syslogmodule.c.h b/Modules/clinic/syslogmodule.c.h index 1603d8ba9ff1c29..6f878d675045e45 100644 --- a/Modules/clinic/syslogmodule.c.h +++ b/Modules/clinic/syslogmodule.c.h @@ -8,6 +8,7 @@ preserve #endif #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(syslog_openlog__doc__, "openlog($module, /, ident=, logoption=0,\n" @@ -134,15 +135,10 @@ syslog_syslog(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("syslog", "argument", "str", args[nargs - 1]); goto exit; } - Py_ssize_t message_length; - message = PyUnicode_AsUTF8AndSize(args[nargs - 1], &message_length); + message = _PyUnicode_AsUTF8NoNUL(args[nargs - 1]); if (message == NULL) { goto exit; } - if (strlen(message) != (size_t)message_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } Py_BEGIN_CRITICAL_SECTION(module); return_value = syslog_syslog_impl(module, group_left_1, priority, message); Py_END_CRITICAL_SECTION(); @@ -273,4 +269,4 @@ syslog_LOG_UPTO(PyObject *module, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=ab818466dcdbbe59 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=0c9607f279107505 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/timemodule.c.h b/Modules/clinic/timemodule.c.h index 3b0a8d44129d381..a42c1d7905e811d 100644 --- a/Modules/clinic/timemodule.c.h +++ b/Modules/clinic/timemodule.c.h @@ -3,6 +3,7 @@ preserve [clinic start generated code]*/ #include "pycore_modsupport.h" // _PyArg_CheckPositional() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(time_time__doc__, "time($module, /)\n" @@ -697,15 +698,10 @@ time_get_clock_info(PyObject *module, PyObject *arg) _PyArg_BadArgument("get_clock_info", "argument", "str", arg); goto exit; } - Py_ssize_t name_length; - name = PyUnicode_AsUTF8AndSize(arg, &name_length); + name = _PyUnicode_AsUTF8NoNUL(arg); if (name == NULL) { goto exit; } - if (strlen(name) != (size_t)name_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = time_get_clock_info_impl(module, name); exit: @@ -751,4 +747,4 @@ time_get_clock_info(PyObject *module, PyObject *arg) #ifndef TIME_THREAD_TIME_NS_METHODDEF #define TIME_THREAD_TIME_NS_METHODDEF #endif /* !defined(TIME_THREAD_TIME_NS_METHODDEF) */ -/*[clinic end generated code: output=540a094cac69e0d4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d89be8cc2b2a7b05 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/bytearrayobject.c.h b/Objects/clinic/bytearrayobject.c.h index 41ce82c05c57d97..b074851f1fbf78f 100644 --- a/Objects/clinic/bytearrayobject.c.h +++ b/Objects/clinic/bytearrayobject.c.h @@ -9,6 +9,7 @@ preserve #include "pycore_abstract.h" // _PyNumber_Index() #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() static int bytearray___init___impl(PyByteArrayObject *self, PyObject *arg, @@ -72,15 +73,10 @@ bytearray___init__(PyObject *self, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("bytearray", "argument 'encoding'", "str", fastargs[1]); goto exit; } - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(fastargs[1]); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!--noptargs) { goto skip_optional_pos; } @@ -89,15 +85,10 @@ bytearray___init__(PyObject *self, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("bytearray", "argument 'errors'", "str", fastargs[2]); goto exit; } - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(fastargs[2], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(fastargs[2]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } skip_optional_pos: return_value = bytearray___init___impl((PyByteArrayObject *)self, arg, encoding, errors); @@ -1542,15 +1533,10 @@ bytearray_decode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObje _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[0]); goto exit; } - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(args[0]); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!--noptargs) { goto skip_optional_pos; } @@ -1559,15 +1545,10 @@ bytearray_decode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObje _PyArg_BadArgument("decode", "argument 'errors'", "str", args[1]); goto exit; } - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } skip_optional_pos: Py_BEGIN_CRITICAL_SECTION(self); return_value = bytearray_decode_impl((PyByteArrayObject *)self, encoding, errors); @@ -1882,4 +1863,4 @@ bytearray_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored)) { return bytearray_sizeof_impl((PyByteArrayObject *)self); } -/*[clinic end generated code: output=6dc315d35de3e670 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=16fb40de6aefa5f8 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/bytesobject.c.h b/Objects/clinic/bytesobject.c.h index ee2b737f9e63f97..56e8d089334a7a7 100644 --- a/Objects/clinic/bytesobject.c.h +++ b/Objects/clinic/bytesobject.c.h @@ -8,6 +8,7 @@ preserve #endif #include "pycore_abstract.h" // _PyNumber_Index() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(bytes___bytes____doc__, "__bytes__($self, /)\n" @@ -1136,15 +1137,10 @@ bytes_decode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject * _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[0]); goto exit; } - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(args[0]); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!--noptargs) { goto skip_optional_pos; } @@ -1153,15 +1149,10 @@ bytes_decode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject * _PyArg_BadArgument("decode", "argument 'errors'", "str", args[1]); goto exit; } - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } skip_optional_pos: return_value = bytes_decode_impl((PyBytesObject *)self, encoding, errors); @@ -1423,15 +1414,10 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("bytes", "argument 'encoding'", "str", fastargs[1]); goto exit; } - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(fastargs[1]); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!--noptargs) { goto skip_optional_pos; } @@ -1440,19 +1426,14 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("bytes", "argument 'errors'", "str", fastargs[2]); goto exit; } - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(fastargs[2], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(fastargs[2]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } skip_optional_pos: return_value = bytes_new_impl(type, x, encoding, errors); exit: return return_value; } -/*[clinic end generated code: output=c20458db7a2123db input=a9049054013a1b77]*/ +/*[clinic end generated code: output=2de57d656cc2f041 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/floatobject.c.h b/Objects/clinic/floatobject.c.h index 8768555c909257a..cc37ea55612a8fb 100644 --- a/Objects/clinic/floatobject.c.h +++ b/Objects/clinic/floatobject.c.h @@ -3,6 +3,7 @@ preserve [clinic start generated code]*/ #include "pycore_modsupport.h" // _PyArg_CheckPositional() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(float_is_integer__doc__, "is_integer($self, /)\n" @@ -310,15 +311,10 @@ float___getformat__(PyObject *type, PyObject *arg) _PyArg_BadArgument("__getformat__", "argument", "str", arg); goto exit; } - Py_ssize_t typestr_length; - typestr = PyUnicode_AsUTF8AndSize(arg, &typestr_length); + typestr = _PyUnicode_AsUTF8NoNUL(arg); if (typestr == NULL) { goto exit; } - if (strlen(typestr) != (size_t)typestr_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = float___getformat___impl((PyTypeObject *)type, typestr); exit: @@ -353,4 +349,4 @@ float___format__(PyObject *self, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=5d7b0bf9e47ff997 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e0ffc05aa7fc4b10 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/memoryobject.c.h b/Objects/clinic/memoryobject.c.h index d55e7c4ac475766..163392ca618cad7 100644 --- a/Objects/clinic/memoryobject.c.h +++ b/Objects/clinic/memoryobject.c.h @@ -8,6 +8,7 @@ preserve #endif #include "pycore_abstract.h" // _PyNumber_Index() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(memoryview__doc__, "memoryview(object)\n" @@ -345,15 +346,10 @@ memoryview_tobytes(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb order = NULL; } else if (PyUnicode_Check(args[0])) { - Py_ssize_t order_length; - order = PyUnicode_AsUTF8AndSize(args[0], &order_length); + order = _PyUnicode_AsUTF8NoNUL(args[0]); if (order == NULL) { goto exit; } - if (strlen(order) != (size_t)order_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } } else { _PyArg_BadArgument("tobytes", "argument 'order'", "str or None", args[0]); @@ -532,4 +528,4 @@ memoryview_index(PyObject *self, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=17a403895f4f778c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e207155e2006ff40 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index d0753b38843fccf..f214fa42fa1a594 100644 --- a/Objects/clinic/unicodeobject.c.h +++ b/Objects/clinic/unicodeobject.c.h @@ -8,6 +8,7 @@ preserve #endif #include "pycore_abstract.h" // _PyNumber_Index() #include "pycore_modsupport.h" // _PyArg_CheckPositional() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(EncodingMap_size__doc__, "size($self, /)\n" @@ -263,15 +264,10 @@ unicode_encode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject _PyArg_BadArgument("encode", "argument 'encoding'", "str", args[0]); goto exit; } - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(args[0]); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!--noptargs) { goto skip_optional_pos; } @@ -280,15 +276,10 @@ unicode_encode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject _PyArg_BadArgument("encode", "argument 'errors'", "str", args[1]); goto exit; } - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } skip_optional_pos: return_value = unicode_encode_impl(self, encoding, errors); @@ -1884,15 +1875,10 @@ unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("str", "argument 'encoding'", "str", fastargs[1]); goto exit; } - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(fastargs[1]); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!--noptargs) { goto skip_optional_pos; } @@ -1901,19 +1887,14 @@ unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("str", "argument 'errors'", "str", fastargs[2]); goto exit; } - Py_ssize_t errors_length; - errors = PyUnicode_AsUTF8AndSize(fastargs[2], &errors_length); + errors = _PyUnicode_AsUTF8NoNUL(fastargs[2]); if (errors == NULL) { goto exit; } - if (strlen(errors) != (size_t)errors_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } skip_optional_pos: return_value = unicode_new_impl(type, x, encoding, errors); exit: return return_value; } -/*[clinic end generated code: output=9d243c63e951e31d input=a9049054013a1b77]*/ +/*[clinic end generated code: output=80d039a395f835c3 input=a9049054013a1b77]*/ diff --git a/Python/clinic/Python-tokenize.c.h b/Python/clinic/Python-tokenize.c.h index 9e64c2055a8db6d..ebdb6dbc73a980d 100644 --- a/Python/clinic/Python-tokenize.c.h +++ b/Python/clinic/Python-tokenize.c.h @@ -7,6 +7,7 @@ preserve # include "pycore_runtime.h" // _Py_ID() #endif #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() static PyObject * tokenizeriter_new_impl(PyTypeObject *type, PyObject *readline, @@ -68,19 +69,14 @@ tokenizeriter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("tokenizeriter", "argument 'encoding'", "str", fastargs[2]); goto exit; } - Py_ssize_t encoding_length; - encoding = PyUnicode_AsUTF8AndSize(fastargs[2], &encoding_length); + encoding = _PyUnicode_AsUTF8NoNUL(fastargs[2]); if (encoding == NULL) { goto exit; } - if (strlen(encoding) != (size_t)encoding_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } skip_optional_kwonly: return_value = tokenizeriter_new_impl(type, readline, extra_tokens, encoding); exit: return return_value; } -/*[clinic end generated code: output=4c448f34d9c835c0 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=f9091945b96e09b7 input=a9049054013a1b77]*/ diff --git a/Python/clinic/bltinmodule.c.h b/Python/clinic/bltinmodule.c.h index 5858ca9ff88ec22..db9379ef3d8dc4c 100644 --- a/Python/clinic/bltinmodule.c.h +++ b/Python/clinic/bltinmodule.c.h @@ -7,6 +7,7 @@ preserve # include "pycore_runtime.h" // _Py_ID() #endif #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(builtin___import____doc__, "__import__($module, /, name, globals=None, locals=None, fromlist=(),\n" @@ -415,15 +416,10 @@ builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj _PyArg_BadArgument("compile", "argument 'mode'", "str", args[2]); goto exit; } - Py_ssize_t mode_length; - mode = PyUnicode_AsUTF8AndSize(args[2], &mode_length); + mode = _PyUnicode_AsUTF8NoNUL(args[2]); if (mode == NULL) { goto exit; } - if (strlen(mode) != (size_t)mode_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } if (!noptargs) { goto skip_optional_pos; } @@ -1501,4 +1497,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=b56739f2e13f616a input=a9049054013a1b77]*/ +/*[clinic end generated code: output=9c67c0bd41101a57 input=a9049054013a1b77]*/ diff --git a/Python/clinic/sysmodule.c.h b/Python/clinic/sysmodule.c.h index 0c72760f69a4c41..44a7494ca66fe67 100644 --- a/Python/clinic/sysmodule.c.h +++ b/Python/clinic/sysmodule.c.h @@ -7,6 +7,7 @@ preserve # include "pycore_runtime.h" // _Py_ID() #endif #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() PyDoc_STRVAR(sys_addaudithook__doc__, "addaudithook($module, /, hook)\n" @@ -92,15 +93,10 @@ sys_audit(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("audit", "argument 1", "str", args[0]); goto exit; } - Py_ssize_t event_length; - event = PyUnicode_AsUTF8AndSize(args[0], &event_length); + event = _PyUnicode_AsUTF8NoNUL(args[0]); if (event == NULL) { goto exit; } - if (strlen(event) != (size_t)event_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } __clinic_args = PyTuple_FromArray(args + 1, nargs - 1); if (__clinic_args == NULL) { goto exit; @@ -1438,15 +1434,10 @@ sys_activate_stack_trampoline(PyObject *module, PyObject *arg) _PyArg_BadArgument("activate_stack_trampoline", "argument", "str", arg); goto exit; } - Py_ssize_t backend_length; - backend = PyUnicode_AsUTF8AndSize(arg, &backend_length); + backend = _PyUnicode_AsUTF8NoNUL(arg); if (backend == NULL) { goto exit; } - if (strlen(backend) != (size_t)backend_length) { - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - } return_value = sys_activate_stack_trampoline_impl(module, backend); exit: @@ -2089,4 +2080,4 @@ _jit_is_active(PyObject *module, PyObject *Py_UNUSED(ignored)) #ifndef SYS_GETANDROIDAPILEVEL_METHODDEF #define SYS_GETANDROIDAPILEVEL_METHODDEF #endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */ -/*[clinic end generated code: output=8a4482f9c5c493e5 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b3e91878491883a0 input=a9049054013a1b77]*/ diff --git a/Tools/clinic/libclinic/converters.py b/Tools/clinic/libclinic/converters.py index c2ac6fd22d5bdc9..836448c9df58412 100644 --- a/Tools/clinic/libclinic/converters.py +++ b/Tools/clinic/libclinic/converters.py @@ -4,6 +4,7 @@ from types import NoneType from typing import Any +import libclinic from libclinic import fail, NullType, unspecified, NULL, c_bytes_repr, c_unichar_repr from libclinic.function import ( Function, Parameter, @@ -825,12 +826,13 @@ def post_parsing(self) -> str: return "" def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> str | None: - if self.format_unit == 's': - return self.format_code(""" - if (!PyUnicode_Check({argname})) {{{{ - {bad_argument} - goto exit; - }}}} + if self.format_unit not in ('s', 'z'): + return super().parse_arg(argname, displayname, limited_capi=limited_capi) + + # Decode a value already known to be a str. Shared by 's' and 'z', + # which differ only in whether None is also accepted. + if limited_capi: + decode = """ Py_ssize_t {length_name}; {paramname} = PyUnicode_AsUTF8AndSize({argname}, &{length_name}); if ({paramname} == NULL) {{{{ @@ -840,35 +842,52 @@ def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> st 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) + """ + else: + # _PyUnicode_AsUTF8NoNUL() is the same code, but its Py_ssize_t + # stays in the callee's frame. An address-taken local here would + # give every generated parser a stack protector canary. + self.add_include('pycore_unicodeobject.h', + '_PyUnicode_AsUTF8NoNUL()') + decode = """ + {paramname} = _PyUnicode_AsUTF8NoNUL({argname}); + if ({paramname} == NULL) {{{{ + goto exit; + }}}} + """ + if self.format_unit == 'z': - return self.format_code(""" + expected = 'str or None' + code = """ if ({argname} == Py_None) {{{{ {paramname} = NULL; }}}} else if (PyUnicode_Check({argname})) {{{{ - Py_ssize_t {length_name}; - {paramname} = PyUnicode_AsUTF8AndSize({argname}, &{length_name}); - if ({paramname} == NULL) {{{{ - goto exit; - }}}} - if (strlen({paramname}) != (size_t){length_name}) {{{{ - PyErr_SetString(PyExc_ValueError, "embedded null character"); - goto exit; - }}}} + {decode} }}}} else {{{{ {bad_argument} goto exit; }}}} - """, - argname=argname, - bad_argument=self.bad_argument(displayname, 'str or None', limited_capi=limited_capi), - length_name=self.length_name) - return super().parse_arg(argname, displayname, limited_capi=limited_capi) + """ + else: + expected = 'str' + code = """ + if (!PyUnicode_Check({argname})) {{{{ + {bad_argument} + goto exit; + }}}} + {decode} + """ + + return self.format_code( + libclinic.linear_format( + libclinic.normalize_snippet(code), + decode=libclinic.normalize_snippet(decode)), + argname=argname, + bad_argument=self.bad_argument(displayname, expected, + limited_capi=limited_capi), + length_name=self.length_name) # # This is the fourth or fifth rewrite of registering all the From 6469ac21ab5bbdaf27d2e70dbe10f61addfe3fca Mon Sep 17 00:00:00 2001 From: Cody Maloney Date: Sat, 26 Sep 2026 13:32:26 -0700 Subject: [PATCH 2/3] Update Include/internal/pycore_unicodeobject.h Co-authored-by: Pieter Eendebak --- Include/internal/pycore_unicodeobject.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Include/internal/pycore_unicodeobject.h b/Include/internal/pycore_unicodeobject.h index f64fa39e65741dc..3a4e176a4cfd464 100644 --- a/Include/internal/pycore_unicodeobject.h +++ b/Include/internal/pycore_unicodeobject.h @@ -450,8 +450,7 @@ extern void _PyUnicode_InternStatic(PyInterpreterState *interp, PyObject **); extern void _PyUnicode_ClearInterned(PyInterpreterState *interp); // Like PyUnicode_AsUTF8(), but check for embedded null characters. -// Export for '_sqlite3' shared extension, and for the Argument Clinic code -// generated for the 's' and 'z' converters, which many shared extensions use. +// Export for '_sqlite3' shared extension, and for Argument Clinic code PyAPI_FUNC(const char *) _PyUnicode_AsUTF8NoNUL(PyObject *); From 7cf010ac6c8b7924e11ca6849c0263d32fb67501 Mon Sep 17 00:00:00 2001 From: Cody Maloney Date: Sat, 26 Sep 2026 13:56:17 -0700 Subject: [PATCH 3/3] Remove NEWS, add period --- Include/internal/pycore_unicodeobject.h | 2 +- .../Tools-Demos/2026-09-25-17-30-00.gh-issue-157407.iOVPov.rst | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 Misc/NEWS.d/next/Tools-Demos/2026-09-25-17-30-00.gh-issue-157407.iOVPov.rst diff --git a/Include/internal/pycore_unicodeobject.h b/Include/internal/pycore_unicodeobject.h index 3a4e176a4cfd464..0dd35fb288fb882 100644 --- a/Include/internal/pycore_unicodeobject.h +++ b/Include/internal/pycore_unicodeobject.h @@ -450,7 +450,7 @@ extern void _PyUnicode_InternStatic(PyInterpreterState *interp, PyObject **); extern void _PyUnicode_ClearInterned(PyInterpreterState *interp); // Like PyUnicode_AsUTF8(), but check for embedded null characters. -// Export for '_sqlite3' shared extension, and for Argument Clinic code +// Export for '_sqlite3' shared extension, and for Argument Clinic code. PyAPI_FUNC(const char *) _PyUnicode_AsUTF8NoNUL(PyObject *); diff --git a/Misc/NEWS.d/next/Tools-Demos/2026-09-25-17-30-00.gh-issue-157407.iOVPov.rst b/Misc/NEWS.d/next/Tools-Demos/2026-09-25-17-30-00.gh-issue-157407.iOVPov.rst deleted file mode 100644 index 202269d63bc1a0c..000000000000000 --- a/Misc/NEWS.d/next/Tools-Demos/2026-09-25-17-30-00.gh-issue-157407.iOVPov.rst +++ /dev/null @@ -1,3 +0,0 @@ -Argument Clinic now calls the internal function ``_PyUnicode_AsUTF8NoNUL()`` for -``s`` and ``z`` converters instead of writing equivalent code inline to reduce -the generated ``.text`` segment.