diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index 5fa37963e07eff..3127ac600c1229 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -979,6 +979,15 @@ These are the UTF-8 codec APIs: responsible for deallocating the buffer. The buffer is deallocated and pointers to it become invalid when the Unicode object is garbage collected. + If *size* is NULL and the *unicode* string contains null characters, the + UTF-8 encoded string contains embedded null bytes and the caller is not + aware since the string size is not stored. C functions processing null + terminated ``char*`` truncate the string at the first embedded null byte, and + so ignore bytes after the null byte. The :c:func:`PyUnicode_AsUTF8` function + can be used to raise an exception rather than truncating the string. Or + :c:func:`PyUnicode_AsUTF8(unicode, &size) ` can be + used to store the size. + .. versionadded:: 3.3 .. versionchanged:: 3.7 @@ -990,12 +999,13 @@ These are the UTF-8 codec APIs: .. c:function:: const char* PyUnicode_AsUTF8(PyObject *unicode) - As :c:func:`PyUnicode_AsUTF8AndSize`, but does not store the size. + Similar to :c:func:`PyUnicode_AsUTF8AndSize`, but does not store the size. - Raise an exception if the *unicode* string contains embedded null - characters. To accept embedded null characters and truncate on purpose - at the first null byte, ``PyUnicode_AsUTF8AndSize(unicode, NULL)`` can be - used instead. + If the *unicode* string contains null characters, the UTF-8 encoded string + contains embedded null bytes. C functions processing null terminated ``char*`` + truncate the string at the first embedded null byte, and so ignore bytes + after the null byte. The :c:func:`PyUnicode_AsUTF8` function can be used to + raise an exception rather than truncating the string. .. versionadded:: 3.3 @@ -1005,6 +1015,20 @@ These are the UTF-8 codec APIs: .. versionchanged:: 3.13 Raise an exception if the string contains embedded null characters. +.. c:function:: const char* PyUnicode_AsUTF8NoNUL(PyObject *unicode) + + Similar to :c:func:`PyUnicode_AsUTF8`, but raise :exc:`ValueError` if the + string contains embedded null characters. + + The Unicode Character Set contains characters which can cause bugs or even + security issues depending on how they are proceed. See for example `Unicode + Technical Report #36: Unicode Security Considerations + `_. This function implements a single + check: only test if the string contains null characters. Additional checks + are needed to prevent further issues cause by Unicode characters. + + .. versionadded:: 3.13 + UTF-32 Codecs """"""""""""" diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat index 52d6d967d66327..b8cc671fd05fd6 100644 --- a/Doc/data/stable_abi.dat +++ b/Doc/data/stable_abi.dat @@ -728,6 +728,7 @@ function,PyUnicode_AsUTF16String,3.2,, function,PyUnicode_AsUTF32String,3.2,, function,PyUnicode_AsUTF8,3.13,, function,PyUnicode_AsUTF8AndSize,3.10,, +function,PyUnicode_AsUTF8NoNUL,3.13,, function,PyUnicode_AsUTF8String,3.2,, function,PyUnicode_AsUnicodeEscapeString,3.2,, function,PyUnicode_AsWideChar,3.2,, diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index ef83f662788fe4..b70afc5a01a26f 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -1137,6 +1137,11 @@ New Features * Add :c:func:`PyUnicode_AsUTF8` function to the limited C API. (Contributed by Victor Stinner in :gh:`111089`.) +* Add :c:func:`PyUnicode_AsUTF8NoNUL` function: similar to + :c:func:`PyUnicode_AsUTF8`, but raise :exc:`ValueError` if the string + contains embedded null characters. + (Contributed by Victor Stinner in :gh:`111089`.) + Porting to Python 3.13 ---------------------- @@ -1207,12 +1212,6 @@ Porting to Python 3.13 Note that ``Py_TRASHCAN_BEGIN`` has a second argument which should be the deallocation function it is in. -* The :c:func:`PyUnicode_AsUTF8` function now raises an exception if the string - contains embedded null characters. To accept embedded null characters and - truncate on purpose at the first null byte, - ``PyUnicode_AsUTF8AndSize(unicode, NULL)`` can be used instead. - (Contributed by Victor Stinner in :gh:`111089`.) - * On Windows, ``Python.h`` no longer includes the ```` standard header file. If needed, it should now be included explicitly. For example, it provides ``offsetof()`` function, and ``size_t`` and ``ptrdiff_t`` types. diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index ee7b769ce5a6fc..6755e628a65fc2 100644 --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -453,6 +453,10 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsUTF8String( // when the Unicode object is deallocated. PyAPI_FUNC(const char *) PyUnicode_AsUTF8(PyObject *unicode); +// Similar to PyUnicode_AsUTF8(), but raise ValueError if the string contains +// embedded null characters. +PyAPI_FUNC(const char *) PyUnicode_AsUTF8NoNUL(PyObject *unicode); + // Returns a pointer to the UTF-8 encoding of the // Unicode object unicode and the size of the encoded representation // in bytes stored in `*size` (if size is not NULL). diff --git a/Lib/test/test_capi/test_unicode.py b/Lib/test/test_capi/test_unicode.py index d8537244b39555..f29b49bf3f1530 100644 --- a/Lib/test/test_capi/test_unicode.py +++ b/Lib/test/test_capi/test_unicode.py @@ -905,25 +905,38 @@ def test_fromordinal(self): self.assertRaises(ValueError, fromordinal, 0x110000) self.assertRaises(ValueError, fromordinal, -1) - @support.cpython_only - @unittest.skipIf(_testcapi is None, 'need _testcapi module') - def test_asutf8(self): - """Test PyUnicode_AsUTF8()""" - from _testcapi import unicode_asutf8 - + def check_asutf8(self, unicode_asutf8): self.assertEqual(unicode_asutf8('abc', 4), b'abc\0') self.assertEqual(unicode_asutf8('абв', 7), b'\xd0\xb0\xd0\xb1\xd0\xb2\0') self.assertEqual(unicode_asutf8('\U0001f600', 5), b'\xf0\x9f\x98\x80\0') - # disallow embedded null characters - self.assertRaises(ValueError, unicode_asutf8, 'abc\0', 0) - self.assertRaises(ValueError, unicode_asutf8, 'abc\0def', 0) - self.assertRaises(UnicodeEncodeError, unicode_asutf8, '\ud8ff', 0) self.assertRaises(TypeError, unicode_asutf8, b'abc', 0) self.assertRaises(TypeError, unicode_asutf8, [], 0) # CRASHES unicode_asutf8(NULL, 0) + @support.cpython_only + @unittest.skipIf(_testcapi is None, 'need _testcapi module') + def test_asutf8(self): + """Test PyUnicode_AsUTF8()""" + from _testcapi import unicode_asutf8 + self.check_asutf8(unicode_asutf8) + + # allow embedded null characters + self.assertEqual(unicode_asutf8('abc\0', 5), b'abc\0\0') + self.assertEqual(unicode_asutf8('abc\0def', 8), b'abc\0def\0') + + @support.cpython_only + @unittest.skipIf(_testcapi is None, 'need _testcapi module') + def test_asutf8nonul(self): + """Test PyUnicode_AsUTF8NoNUL()""" + from _testcapi import unicode_asutf8nonul + self.check_asutf8(unicode_asutf8nonul) + + # disallow embedded null characters + self.assertRaises(ValueError, unicode_asutf8nonul, 'abc\0', 0) + self.assertRaises(ValueError, unicode_asutf8nonul, 'abc\0def', 0) + @support.cpython_only @unittest.skipIf(_testcapi is None, 'need _testcapi module') def test_asutf8andsize(self): diff --git a/Lib/test/test_stable_abi_ctypes.py b/Lib/test/test_stable_abi_ctypes.py index 85a63c44b49431..1e67f85531bed5 100644 --- a/Lib/test/test_stable_abi_ctypes.py +++ b/Lib/test/test_stable_abi_ctypes.py @@ -747,6 +747,7 @@ def test_windows_feature_macros(self): "PyUnicode_AsUTF32String", "PyUnicode_AsUTF8", "PyUnicode_AsUTF8AndSize", + "PyUnicode_AsUTF8NoNUL", "PyUnicode_AsUTF8String", "PyUnicode_AsUnicodeEscapeString", "PyUnicode_AsWideChar", diff --git a/Misc/NEWS.d/next/C API/2023-11-03-12-43-35.gh-issue-111089.LWRfqR.rst b/Misc/NEWS.d/next/C API/2023-11-03-12-43-35.gh-issue-111089.LWRfqR.rst new file mode 100644 index 00000000000000..62a28cf4f51b13 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2023-11-03-12-43-35.gh-issue-111089.LWRfqR.rst @@ -0,0 +1,3 @@ +Add :c:func:`PyUnicode_AsUTF8NoNUL` function: similar to +:c:func:`PyUnicode_AsUTF8`, but raise :exc:`ValueError` if the string +contains embedded null characters. Patch by Victor Stinner. diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml index b55bb599d71dcc..7d720af201ed7f 100644 --- a/Misc/stable_abi.toml +++ b/Misc/stable_abi.toml @@ -2480,6 +2480,8 @@ added = '3.13' [function.PyUnicode_AsUTF8] added = '3.13' +[function.PyUnicode_AsUTF8NoNUL] + added = '3.13' [function._Py_SetRefcnt] added = '3.13' abi_only = true diff --git a/Modules/_io/clinic/_iomodule.c.h b/Modules/_io/clinic/_iomodule.c.h index 68a8a20514027d..892ca028b094d9 100644 --- a/Modules/_io/clinic/_iomodule.c.h +++ b/Modules/_io/clinic/_iomodule.c.h @@ -188,7 +188,7 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw _PyArg_BadArgument("open", "argument 'mode'", "str", args[1]); goto exit; } - mode = PyUnicode_AsUTF8(args[1]); + mode = PyUnicode_AsUTF8NoNUL(args[1]); if (mode == NULL) { goto exit; } @@ -210,7 +210,7 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw encoding = NULL; } else if (PyUnicode_Check(args[3])) { - encoding = PyUnicode_AsUTF8(args[3]); + encoding = PyUnicode_AsUTF8NoNUL(args[3]); if (encoding == NULL) { goto exit; } @@ -228,7 +228,7 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw errors = NULL; } else if (PyUnicode_Check(args[4])) { - errors = PyUnicode_AsUTF8(args[4]); + errors = PyUnicode_AsUTF8NoNUL(args[4]); if (errors == NULL) { goto exit; } @@ -246,7 +246,7 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw newline = NULL; } else if (PyUnicode_Check(args[5])) { - newline = PyUnicode_AsUTF8(args[5]); + newline = PyUnicode_AsUTF8NoNUL(args[5]); if (newline == NULL) { goto exit; } @@ -384,4 +384,4 @@ _io_open_code(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec exit: return return_value; } -/*[clinic end generated code: output=feb173d5f2bfb98a input=a9049054013a1b77]*/ +/*[clinic end generated code: output=0b66ce439402f1ac input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/fileio.c.h b/Modules/_io/clinic/fileio.c.h index 6f5d660affd569..225a10f54d49b7 100644 --- a/Modules/_io/clinic/fileio.c.h +++ b/Modules/_io/clinic/fileio.c.h @@ -107,7 +107,7 @@ _io_FileIO___init__(PyObject *self, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("FileIO", "argument 'mode'", "str", fastargs[1]); goto exit; } - mode = PyUnicode_AsUTF8(fastargs[1]); + mode = PyUnicode_AsUTF8NoNUL(fastargs[1]); if (mode == NULL) { goto exit; } @@ -523,4 +523,4 @@ _io_FileIO_isatty(fileio *self, PyObject *Py_UNUSED(ignored)) #ifndef _IO_FILEIO_TRUNCATE_METHODDEF #define _IO_FILEIO_TRUNCATE_METHODDEF #endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */ -/*[clinic end generated code: output=27cff9d0a618edb6 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=350433a33037b84a input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h index 25c301ecdb6dab..39de1ed4625321 100644 --- a/Modules/_io/clinic/textio.c.h +++ b/Modules/_io/clinic/textio.c.h @@ -185,7 +185,7 @@ _io__TextIOBase_write(PyObject *self, PyTypeObject *cls, PyObject *const *args, _PyArg_BadArgument("write", "argument 1", "str", args[0]); goto exit; } - s = PyUnicode_AsUTF8(args[0]); + s = PyUnicode_AsUTF8NoNUL(args[0]); if (s == NULL) { goto exit; } @@ -470,7 +470,7 @@ _io_TextIOWrapper___init__(PyObject *self, PyObject *args, PyObject *kwargs) encoding = NULL; } else if (PyUnicode_Check(fastargs[1])) { - encoding = PyUnicode_AsUTF8(fastargs[1]); + encoding = PyUnicode_AsUTF8NoNUL(fastargs[1]); if (encoding == NULL) { goto exit; } @@ -494,7 +494,7 @@ _io_TextIOWrapper___init__(PyObject *self, PyObject *args, PyObject *kwargs) newline = NULL; } else if (PyUnicode_Check(fastargs[3])) { - newline = PyUnicode_AsUTF8(fastargs[3]); + newline = PyUnicode_AsUTF8NoNUL(fastargs[3]); if (newline == NULL) { goto exit; } @@ -965,4 +965,4 @@ _io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored)) { return _io_TextIOWrapper_close_impl(self); } -/*[clinic end generated code: output=c9ffb48a5278cbd4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=465f72d6944aa506 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/winconsoleio.c.h b/Modules/_io/clinic/winconsoleio.c.h index 8609fc9ede95fe..336366cd014b1c 100644 --- a/Modules/_io/clinic/winconsoleio.c.h +++ b/Modules/_io/clinic/winconsoleio.c.h @@ -106,7 +106,7 @@ _io__WindowsConsoleIO___init__(PyObject *self, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("_WindowsConsoleIO", "argument 'mode'", "str", fastargs[1]); goto exit; } - mode = PyUnicode_AsUTF8(fastargs[1]); + mode = PyUnicode_AsUTF8NoNUL(fastargs[1]); if (mode == NULL) { goto exit; } @@ -452,4 +452,4 @@ _io__WindowsConsoleIO_isatty(winconsoleio *self, PyObject *Py_UNUSED(ignored)) #ifndef _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF #define _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF #endif /* !defined(_IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF) */ -/*[clinic end generated code: output=76408dd67894bc9c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=6b5a0af31fafa1ab input=a9049054013a1b77]*/ diff --git a/Modules/_multiprocessing/clinic/multiprocessing.c.h b/Modules/_multiprocessing/clinic/multiprocessing.c.h index 9133d5d8bb04fd..c31be74586f9b4 100644 --- a/Modules/_multiprocessing/clinic/multiprocessing.c.h +++ b/Modules/_multiprocessing/clinic/multiprocessing.c.h @@ -138,7 +138,7 @@ _multiprocessing_sem_unlink(PyObject *module, PyObject *arg) _PyArg_BadArgument("sem_unlink", "argument", "str", arg); goto exit; } - name = PyUnicode_AsUTF8(arg); + name = PyUnicode_AsUTF8NoNUL(arg); if (name == NULL) { goto exit; } @@ -159,4 +159,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=c6735cbc59b6f324 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=104ba2e58e5c696f input=a9049054013a1b77]*/ diff --git a/Modules/_multiprocessing/clinic/semaphore.c.h b/Modules/_multiprocessing/clinic/semaphore.c.h index ae340c2f57af20..1636f04c715531 100644 --- a/Modules/_multiprocessing/clinic/semaphore.c.h +++ b/Modules/_multiprocessing/clinic/semaphore.c.h @@ -266,7 +266,7 @@ _multiprocessing_SemLock(PyTypeObject *type, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("SemLock", "argument 'name'", "str", fastargs[3]); goto exit; } - name = PyUnicode_AsUTF8(fastargs[3]); + name = PyUnicode_AsUTF8NoNUL(fastargs[3]); if (name == NULL) { goto exit; } @@ -537,4 +537,4 @@ _multiprocessing_SemLock___exit__(SemLockObject *self, PyObject *const *args, Py #ifndef _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF #define _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF #endif /* !defined(_MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF) */ -/*[clinic end generated code: output=fd94dc907e6ab57f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=1179107ccbaa9e95 input=a9049054013a1b77]*/ diff --git a/Modules/_sqlite/clinic/connection.c.h b/Modules/_sqlite/clinic/connection.c.h index 8e1a57415c2bd9..608829375bd345 100644 --- a/Modules/_sqlite/clinic/connection.c.h +++ b/Modules/_sqlite/clinic/connection.c.h @@ -297,7 +297,7 @@ blobopen(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyO _PyArg_BadArgument("blobopen", "argument 1", "str", args[0]); goto exit; } - table = PyUnicode_AsUTF8(args[0]); + table = PyUnicode_AsUTF8NoNUL(args[0]); if (table == NULL) { goto exit; } @@ -305,7 +305,7 @@ blobopen(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyO _PyArg_BadArgument("blobopen", "argument 2", "str", args[1]); goto exit; } - col = PyUnicode_AsUTF8(args[1]); + col = PyUnicode_AsUTF8NoNUL(args[1]); if (col == NULL) { goto exit; } @@ -328,7 +328,7 @@ blobopen(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyO _PyArg_BadArgument("blobopen", "argument 'name'", "str", args[4]); goto exit; } - name = PyUnicode_AsUTF8(args[4]); + name = PyUnicode_AsUTF8NoNUL(args[4]); if (name == NULL) { goto exit; } @@ -484,7 +484,7 @@ pysqlite_connection_create_function(pysqlite_Connection *self, PyTypeObject *cls _PyArg_BadArgument("create_function", "argument 'name'", "str", args[0]); goto exit; } - name = PyUnicode_AsUTF8(args[0]); + name = PyUnicode_AsUTF8NoNUL(args[0]); if (name == NULL) { goto exit; } @@ -562,7 +562,7 @@ create_window_function(pysqlite_Connection *self, PyTypeObject *cls, PyObject *c _PyArg_BadArgument("create_window_function", "argument 1", "str", args[0]); goto exit; } - name = PyUnicode_AsUTF8(args[0]); + name = PyUnicode_AsUTF8NoNUL(args[0]); if (name == NULL) { goto exit; } @@ -663,7 +663,7 @@ pysqlite_connection_create_aggregate(pysqlite_Connection *self, PyTypeObject *cl _PyArg_BadArgument("create_aggregate", "argument 'name'", "str", args[0]); goto exit; } - name = PyUnicode_AsUTF8(args[0]); + name = PyUnicode_AsUTF8NoNUL(args[0]); if (name == NULL) { goto exit; } @@ -1033,7 +1033,7 @@ pysqlite_connection_load_extension(pysqlite_Connection *self, PyObject *const *a _PyArg_BadArgument("load_extension", "argument 1", "str", args[0]); goto exit; } - extension_name = PyUnicode_AsUTF8(args[0]); + extension_name = PyUnicode_AsUTF8NoNUL(args[0]); if (extension_name == NULL) { goto exit; } @@ -1044,7 +1044,7 @@ pysqlite_connection_load_extension(pysqlite_Connection *self, PyObject *const *a entrypoint = NULL; } else if (PyUnicode_Check(args[1])) { - entrypoint = PyUnicode_AsUTF8(args[1]); + entrypoint = PyUnicode_AsUTF8NoNUL(args[1]); if (entrypoint == NULL) { goto exit; } @@ -1266,7 +1266,7 @@ pysqlite_connection_backup(pysqlite_Connection *self, PyObject *const *args, Py_ _PyArg_BadArgument("backup", "argument 'name'", "str", args[3]); goto exit; } - name = PyUnicode_AsUTF8(args[3]); + name = PyUnicode_AsUTF8NoNUL(args[3]); if (name == NULL) { goto exit; } @@ -1335,7 +1335,7 @@ pysqlite_connection_create_collation(pysqlite_Connection *self, PyTypeObject *cl _PyArg_BadArgument("create_collation", "argument 1", "str", args[0]); goto exit; } - name = PyUnicode_AsUTF8(args[0]); + name = PyUnicode_AsUTF8NoNUL(args[0]); if (name == NULL) { goto exit; } @@ -1412,7 +1412,7 @@ serialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, Py _PyArg_BadArgument("serialize", "argument 'name'", "str", args[0]); goto exit; } - name = PyUnicode_AsUTF8(args[0]); + name = PyUnicode_AsUTF8NoNUL(args[0]); if (name == NULL) { goto exit; } @@ -1510,7 +1510,7 @@ deserialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, _PyArg_BadArgument("deserialize", "argument 'name'", "str", args[1]); goto exit; } - name = PyUnicode_AsUTF8(args[1]); + name = PyUnicode_AsUTF8NoNUL(args[1]); if (name == NULL) { goto exit; } @@ -1758,4 +1758,4 @@ getconfig(pysqlite_Connection *self, PyObject *arg) #ifndef DESERIALIZE_METHODDEF #define DESERIALIZE_METHODDEF #endif /* !defined(DESERIALIZE_METHODDEF) */ -/*[clinic end generated code: output=7d2a4d9272f7cb9e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7b73e7401cd046ea input=a9049054013a1b77]*/ diff --git a/Modules/_sqlite/clinic/cursor.c.h b/Modules/_sqlite/clinic/cursor.c.h index 7a5850312ee789..677d08c34ce9f2 100644 --- a/Modules/_sqlite/clinic/cursor.c.h +++ b/Modules/_sqlite/clinic/cursor.c.h @@ -135,7 +135,7 @@ pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *arg) _PyArg_BadArgument("executescript", "argument", "str", arg); goto exit; } - sql_script = PyUnicode_AsUTF8(arg); + sql_script = PyUnicode_AsUTF8NoNUL(arg); if (sql_script == NULL) { goto exit; } @@ -308,4 +308,4 @@ pysqlite_cursor_close(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored)) { return pysqlite_cursor_close_impl(self); } -/*[clinic end generated code: output=c772882c7df587ea input=a9049054013a1b77]*/ +/*[clinic end generated code: output=cd45cf70827f462f input=a9049054013a1b77]*/ diff --git a/Modules/_sqlite/clinic/module.c.h b/Modules/_sqlite/clinic/module.c.h index d3c7ad8b7ca998..76831f5d0f4708 100644 --- a/Modules/_sqlite/clinic/module.c.h +++ b/Modules/_sqlite/clinic/module.c.h @@ -60,7 +60,7 @@ pysqlite_complete_statement(PyObject *module, PyObject *const *args, Py_ssize_t _PyArg_BadArgument("complete_statement", "argument 'statement'", "str", args[0]); goto exit; } - statement = PyUnicode_AsUTF8(args[0]); + statement = PyUnicode_AsUTF8NoNUL(args[0]); if (statement == NULL) { goto exit; } @@ -203,4 +203,4 @@ pysqlite_adapt(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=19016e67830c19eb input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ab6619583fb1ce4d input=a9049054013a1b77]*/ diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index ce46c1e69f3131..612c451d198b04 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -76,7 +76,7 @@ isolation_level_converter(PyObject *str_or_none, const char **result) *result = NULL; } else if (PyUnicode_Check(str_or_none)) { - const char *str = PyUnicode_AsUTF8(str_or_none); + const char *str = PyUnicode_AsUTF8NoNUL(str_or_none); if (str == NULL) { return 0; } diff --git a/Modules/_testcapi/clinic/exceptions.c.h b/Modules/_testcapi/clinic/exceptions.c.h index 80c52f48ced7b3..b0a339442f2c02 100644 --- a/Modules/_testcapi/clinic/exceptions.c.h +++ b/Modules/_testcapi/clinic/exceptions.c.h @@ -112,7 +112,7 @@ _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; } - name = PyUnicode_AsUTF8(args[0]); + name = PyUnicode_AsUTF8NoNUL(args[0]); if (name == NULL) { goto exit; } @@ -124,7 +124,7 @@ _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; } - doc = PyUnicode_AsUTF8(args[1]); + doc = PyUnicode_AsUTF8NoNUL(args[1]); if (doc == NULL) { goto exit; } @@ -446,4 +446,4 @@ _testcapi_unstable_exc_prep_reraise_star(PyObject *module, PyObject *const *args exit: return return_value; } -/*[clinic end generated code: output=6f2b4f773e0ae755 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e4196978780b52bf input=a9049054013a1b77]*/ diff --git a/Modules/_testcapi/unicode.c b/Modules/_testcapi/unicode.c index a10183dddeca98..74cfc3138adf79 100644 --- a/Modules/_testcapi/unicode.c +++ b/Modules/_testcapi/unicode.c @@ -619,6 +619,25 @@ unicode_asutf8(PyObject *self, PyObject *args) return PyBytes_FromStringAndSize(s, buflen); } +/* Test PyUnicode_AsUTF8NoNUL() */ +static PyObject * +unicode_asutf8nonul(PyObject *self, PyObject *args) +{ + PyObject *unicode; + Py_ssize_t buflen; + const char *s; + + if (!PyArg_ParseTuple(args, "On", &unicode, &buflen)) + return NULL; + + NULLABLE(unicode); + s = PyUnicode_AsUTF8NoNUL(unicode); + if (s == NULL) + return NULL; + + return PyBytes_FromStringAndSize(s, buflen); +} + /* Test PyUnicode_AsUTF8AndSize() */ static PyObject * unicode_asutf8andsize(PyObject *self, PyObject *args) @@ -2031,6 +2050,7 @@ static PyMethodDef TestMethods[] = { {"unicode_asucs4copy", unicode_asucs4copy, METH_VARARGS}, {"unicode_fromordinal", unicode_fromordinal, METH_VARARGS}, {"unicode_asutf8", unicode_asutf8, METH_VARARGS}, + {"unicode_asutf8nonul", unicode_asutf8nonul, METH_VARARGS}, {"unicode_asutf8andsize", unicode_asutf8andsize, METH_VARARGS}, {"unicode_asutf8andsize_null",unicode_asutf8andsize_null, METH_VARARGS}, {"unicode_getdefaultencoding",unicode_getdefaultencoding, METH_NOARGS}, diff --git a/Modules/cjkcodecs/clinic/multibytecodec.c.h b/Modules/cjkcodecs/clinic/multibytecodec.c.h index fec223930cd48c..cc7d45af7efdce 100644 --- a/Modules/cjkcodecs/clinic/multibytecodec.c.h +++ b/Modules/cjkcodecs/clinic/multibytecodec.c.h @@ -73,7 +73,7 @@ _multibytecodec_MultibyteCodec_encode(MultibyteCodecObject *self, PyObject *cons errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -156,7 +156,7 @@ _multibytecodec_MultibyteCodec_decode(MultibyteCodecObject *self, PyObject *cons errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -672,4 +672,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=b35a5c3797e0e54a input=a9049054013a1b77]*/ +/*[clinic end generated code: output=75b59c883d65e654 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_codecsmodule.c.h b/Modules/clinic/_codecsmodule.c.h index bf17596274baf2..b9fdf3c504dfce 100644 --- a/Modules/clinic/_codecsmodule.c.h +++ b/Modules/clinic/_codecsmodule.c.h @@ -54,7 +54,7 @@ _codecs_lookup(PyObject *module, PyObject *arg) _PyArg_BadArgument("lookup", "argument", "str", arg); goto exit; } - encoding = PyUnicode_AsUTF8(arg); + encoding = PyUnicode_AsUTF8NoNUL(arg); if (encoding == NULL) { goto exit; } @@ -131,7 +131,7 @@ _codecs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje _PyArg_BadArgument("encode", "argument 'encoding'", "str", args[1]); goto exit; } - encoding = PyUnicode_AsUTF8(args[1]); + encoding = PyUnicode_AsUTF8NoNUL(args[1]); if (encoding == NULL) { goto exit; } @@ -143,7 +143,7 @@ _codecs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje _PyArg_BadArgument("encode", "argument 'errors'", "str", args[2]); goto exit; } - errors = PyUnicode_AsUTF8(args[2]); + errors = PyUnicode_AsUTF8NoNUL(args[2]); if (errors == NULL) { goto exit; } @@ -221,7 +221,7 @@ _codecs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[1]); goto exit; } - encoding = PyUnicode_AsUTF8(args[1]); + encoding = PyUnicode_AsUTF8NoNUL(args[1]); if (encoding == NULL) { goto exit; } @@ -233,7 +233,7 @@ _codecs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje _PyArg_BadArgument("decode", "argument 'errors'", "str", args[2]); goto exit; } - errors = PyUnicode_AsUTF8(args[2]); + errors = PyUnicode_AsUTF8NoNUL(args[2]); if (errors == NULL) { goto exit; } @@ -286,7 +286,7 @@ _codecs_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -341,7 +341,7 @@ _codecs_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -390,7 +390,7 @@ _codecs_utf_7_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -451,7 +451,7 @@ _codecs_utf_8_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -512,7 +512,7 @@ _codecs_utf_16_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -573,7 +573,7 @@ _codecs_utf_16_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -634,7 +634,7 @@ _codecs_utf_16_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -697,7 +697,7 @@ _codecs_utf_16_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -765,7 +765,7 @@ _codecs_utf_32_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -826,7 +826,7 @@ _codecs_utf_32_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -887,7 +887,7 @@ _codecs_utf_32_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -950,7 +950,7 @@ _codecs_utf_32_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -1028,7 +1028,7 @@ _codecs_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_ errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -1099,7 +1099,7 @@ _codecs_raw_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ss errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -1159,7 +1159,7 @@ _codecs_latin_1_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -1212,7 +1212,7 @@ _codecs_ascii_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -1266,7 +1266,7 @@ _codecs_charmap_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -1326,7 +1326,7 @@ _codecs_mbcs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -1391,7 +1391,7 @@ _codecs_oem_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -1461,7 +1461,7 @@ _codecs_code_page_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[2])) { - errors = PyUnicode_AsUTF8(args[2]); + errors = PyUnicode_AsUTF8NoNUL(args[2]); if (errors == NULL) { goto exit; } @@ -1533,7 +1533,7 @@ _codecs_readbuffer_encode(PyObject *module, PyObject *const *args, Py_ssize_t na errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -1588,7 +1588,7 @@ _codecs_utf_7_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -1638,7 +1638,7 @@ _codecs_utf_8_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -1689,7 +1689,7 @@ _codecs_utf_16_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -1746,7 +1746,7 @@ _codecs_utf_16_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -1796,7 +1796,7 @@ _codecs_utf_16_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -1847,7 +1847,7 @@ _codecs_utf_32_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -1904,7 +1904,7 @@ _codecs_utf_32_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -1954,7 +1954,7 @@ _codecs_utf_32_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -2004,7 +2004,7 @@ _codecs_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_ errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -2054,7 +2054,7 @@ _codecs_raw_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ss errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -2104,7 +2104,7 @@ _codecs_latin_1_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -2154,7 +2154,7 @@ _codecs_ascii_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -2205,7 +2205,7 @@ _codecs_charmap_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -2288,7 +2288,7 @@ _codecs_mbcs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -2341,7 +2341,7 @@ _codecs_oem_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) errors = NULL; } else if (PyUnicode_Check(args[1])) { - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -2400,7 +2400,7 @@ _codecs_code_page_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar errors = NULL; } else if (PyUnicode_Check(args[2])) { - errors = PyUnicode_AsUTF8(args[2]); + errors = PyUnicode_AsUTF8NoNUL(args[2]); if (errors == NULL) { goto exit; } @@ -2449,7 +2449,7 @@ _codecs_register_error(PyObject *module, PyObject *const *args, Py_ssize_t nargs _PyArg_BadArgument("register_error", "argument 1", "str", args[0]); goto exit; } - errors = PyUnicode_AsUTF8(args[0]); + errors = PyUnicode_AsUTF8NoNUL(args[0]); if (errors == NULL) { goto exit; } @@ -2485,7 +2485,7 @@ _codecs_lookup_error(PyObject *module, PyObject *arg) _PyArg_BadArgument("lookup_error", "argument", "str", arg); goto exit; } - name = PyUnicode_AsUTF8(arg); + name = PyUnicode_AsUTF8NoNUL(arg); if (name == NULL) { goto exit; } @@ -2518,4 +2518,4 @@ _codecs_lookup_error(PyObject *module, PyObject *arg) #ifndef _CODECS_CODE_PAGE_ENCODE_METHODDEF #define _CODECS_CODE_PAGE_ENCODE_METHODDEF #endif /* !defined(_CODECS_CODE_PAGE_ENCODE_METHODDEF) */ -/*[clinic end generated code: output=5c95a170d813a46f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=a8b37539bbbd76e3 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_cursesmodule.c.h b/Modules/clinic/_cursesmodule.c.h index 409c61578572f9..5a5a9f7473f5e5 100644 --- a/Modules/clinic/_cursesmodule.c.h +++ b/Modules/clinic/_cursesmodule.c.h @@ -2726,7 +2726,7 @@ _curses_setupterm(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyO term = NULL; } else if (PyUnicode_Check(args[0])) { - term = PyUnicode_AsUTF8(args[0]); + term = PyUnicode_AsUTF8NoNUL(args[0]); if (term == NULL) { goto exit; } @@ -3921,7 +3921,7 @@ _curses_tigetflag(PyObject *module, PyObject *arg) _PyArg_BadArgument("tigetflag", "argument", "str", arg); goto exit; } - capname = PyUnicode_AsUTF8(arg); + capname = PyUnicode_AsUTF8NoNUL(arg); if (capname == NULL) { goto exit; } @@ -3959,7 +3959,7 @@ _curses_tigetnum(PyObject *module, PyObject *arg) _PyArg_BadArgument("tigetnum", "argument", "str", arg); goto exit; } - capname = PyUnicode_AsUTF8(arg); + capname = PyUnicode_AsUTF8NoNUL(arg); if (capname == NULL) { goto exit; } @@ -3997,7 +3997,7 @@ _curses_tigetstr(PyObject *module, PyObject *arg) _PyArg_BadArgument("tigetstr", "argument", "str", arg); goto exit; } - capname = PyUnicode_AsUTF8(arg); + capname = PyUnicode_AsUTF8NoNUL(arg); if (capname == NULL) { goto exit; } @@ -4298,4 +4298,4 @@ _curses_has_extended_color_support(PyObject *module, PyObject *Py_UNUSED(ignored #ifndef _CURSES_USE_DEFAULT_COLORS_METHODDEF #define _CURSES_USE_DEFAULT_COLORS_METHODDEF #endif /* !defined(_CURSES_USE_DEFAULT_COLORS_METHODDEF) */ -/*[clinic end generated code: output=555e266fc4838612 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=fc378d5547d18d78 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_dbmmodule.c.h b/Modules/clinic/_dbmmodule.c.h index 4b4baf8cd49d34..e7f17a1cf72b85 100644 --- a/Modules/clinic/_dbmmodule.c.h +++ b/Modules/clinic/_dbmmodule.c.h @@ -196,7 +196,7 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("open", "argument 2", "str", args[1]); goto exit; } - flags = PyUnicode_AsUTF8(args[1]); + flags = PyUnicode_AsUTF8NoNUL(args[1]); if (flags == NULL) { goto exit; } @@ -213,4 +213,4 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=48183905532205c2 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b8fc5e57a1bc67eb input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_elementtree.c.h b/Modules/clinic/_elementtree.c.h index a14b3815e56423..0c05755ceaa0e5 100644 --- a/Modules/clinic/_elementtree.c.h +++ b/Modules/clinic/_elementtree.c.h @@ -1131,7 +1131,7 @@ _elementtree_XMLParser___init__(PyObject *self, PyObject *args, PyObject *kwargs encoding = NULL; } else if (PyUnicode_Check(fastargs[1])) { - encoding = PyUnicode_AsUTF8(fastargs[1]); + encoding = PyUnicode_AsUTF8NoNUL(fastargs[1]); if (encoding == NULL) { goto exit; } @@ -1214,4 +1214,4 @@ _elementtree_XMLParser__setevents(XMLParserObject *self, PyObject *const *args, exit: return return_value; } -/*[clinic end generated code: output=399d9d5c9435070b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=6bec7201507ff599 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_gdbmmodule.c.h b/Modules/clinic/_gdbmmodule.c.h index ab7288ee22360c..04cc3b3fa913a7 100644 --- a/Modules/clinic/_gdbmmodule.c.h +++ b/Modules/clinic/_gdbmmodule.c.h @@ -318,7 +318,7 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("open", "argument 2", "str", args[1]); goto exit; } - flags = PyUnicode_AsUTF8(args[1]); + flags = PyUnicode_AsUTF8NoNUL(args[1]); if (flags == NULL) { goto exit; } @@ -335,4 +335,4 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=725cafd8b2d8cfdb input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7f8e6cc1cc5ffc61 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_hashopenssl.c.h b/Modules/clinic/_hashopenssl.c.h index e360e98500729b..98a610c517c6c6 100644 --- a/Modules/clinic/_hashopenssl.c.h +++ b/Modules/clinic/_hashopenssl.c.h @@ -1278,7 +1278,7 @@ pbkdf2_hmac(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject _PyArg_BadArgument("pbkdf2_hmac", "argument 'hash_name'", "str", args[0]); goto exit; } - hash_name = PyUnicode_AsUTF8(args[0]); + hash_name = PyUnicode_AsUTF8NoNUL(args[0]); if (hash_name == NULL) { goto exit; } @@ -1819,4 +1819,4 @@ _hashlib_compare_digest(PyObject *module, PyObject *const *args, Py_ssize_t narg #ifndef _HASHLIB_SCRYPT_METHODDEF #define _HASHLIB_SCRYPT_METHODDEF #endif /* !defined(_HASHLIB_SCRYPT_METHODDEF) */ -/*[clinic end generated code: output=bc372898eaa3e000 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b746eb5bf1132d42 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_localemodule.c.h b/Modules/clinic/_localemodule.c.h index 2663b28fa72bd9..dc228cb3c16432 100644 --- a/Modules/clinic/_localemodule.c.h +++ b/Modules/clinic/_localemodule.c.h @@ -37,7 +37,7 @@ _locale_setlocale(PyObject *module, PyObject *const *args, Py_ssize_t nargs) locale = NULL; } else if (PyUnicode_Check(args[1])) { - locale = PyUnicode_AsUTF8(args[1]); + locale = PyUnicode_AsUTF8NoNUL(args[1]); if (locale == NULL) { goto exit; } @@ -225,7 +225,7 @@ _locale_gettext(PyObject *module, PyObject *arg) _PyArg_BadArgument("gettext", "argument", "str", arg); goto exit; } - in = PyUnicode_AsUTF8(arg); + in = PyUnicode_AsUTF8NoNUL(arg); if (in == NULL) { goto exit; } @@ -267,7 +267,7 @@ _locale_dgettext(PyObject *module, PyObject *const *args, Py_ssize_t nargs) domain = NULL; } else if (PyUnicode_Check(args[0])) { - domain = PyUnicode_AsUTF8(args[0]); + domain = PyUnicode_AsUTF8NoNUL(args[0]); if (domain == NULL) { goto exit; } @@ -280,7 +280,7 @@ _locale_dgettext(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("dgettext", "argument 2", "str", args[1]); goto exit; } - in = PyUnicode_AsUTF8(args[1]); + in = PyUnicode_AsUTF8NoNUL(args[1]); if (in == NULL) { goto exit; } @@ -322,7 +322,7 @@ _locale_dcgettext(PyObject *module, PyObject *const *args, Py_ssize_t nargs) domain = NULL; } else if (PyUnicode_Check(args[0])) { - domain = PyUnicode_AsUTF8(args[0]); + domain = PyUnicode_AsUTF8NoNUL(args[0]); if (domain == NULL) { goto exit; } @@ -335,7 +335,7 @@ _locale_dcgettext(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("dcgettext", "argument 2", "str", args[1]); goto exit; } - msgid = PyUnicode_AsUTF8(args[1]); + msgid = PyUnicode_AsUTF8NoNUL(args[1]); if (msgid == NULL) { goto exit; } @@ -375,7 +375,7 @@ _locale_textdomain(PyObject *module, PyObject *arg) domain = NULL; } else if (PyUnicode_Check(arg)) { - domain = PyUnicode_AsUTF8(arg); + domain = PyUnicode_AsUTF8NoNUL(arg); if (domain == NULL) { goto exit; } @@ -421,7 +421,7 @@ _locale_bindtextdomain(PyObject *module, PyObject *const *args, Py_ssize_t nargs _PyArg_BadArgument("bindtextdomain", "argument 1", "str", args[0]); goto exit; } - domain = PyUnicode_AsUTF8(args[0]); + domain = PyUnicode_AsUTF8NoNUL(args[0]); if (domain == NULL) { goto exit; } @@ -463,7 +463,7 @@ _locale_bind_textdomain_codeset(PyObject *module, PyObject *const *args, Py_ssiz _PyArg_BadArgument("bind_textdomain_codeset", "argument 1", "str", args[0]); goto exit; } - domain = PyUnicode_AsUTF8(args[0]); + domain = PyUnicode_AsUTF8NoNUL(args[0]); if (domain == NULL) { goto exit; } @@ -471,7 +471,7 @@ _locale_bind_textdomain_codeset(PyObject *module, PyObject *const *args, Py_ssiz codeset = NULL; } else if (PyUnicode_Check(args[1])) { - codeset = PyUnicode_AsUTF8(args[1]); + codeset = PyUnicode_AsUTF8NoNUL(args[1]); if (codeset == NULL) { goto exit; } @@ -545,4 +545,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=14a4bffed066ebb3 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=8a454a2d0ebd9b4f input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_pickle.c.h b/Modules/clinic/_pickle.c.h index 75edfd03e8ca23..88f194b37fe860 100644 --- a/Modules/clinic/_pickle.c.h +++ b/Modules/clinic/_pickle.c.h @@ -466,7 +466,7 @@ _pickle_Unpickler___init__(PyObject *self, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("Unpickler", "argument 'encoding'", "str", fastargs[2]); goto exit; } - encoding = PyUnicode_AsUTF8(fastargs[2]); + encoding = PyUnicode_AsUTF8NoNUL(fastargs[2]); if (encoding == NULL) { goto exit; } @@ -479,7 +479,7 @@ _pickle_Unpickler___init__(PyObject *self, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("Unpickler", "argument 'errors'", "str", fastargs[3]); goto exit; } - errors = PyUnicode_AsUTF8(fastargs[3]); + errors = PyUnicode_AsUTF8NoNUL(fastargs[3]); if (errors == NULL) { goto exit; } @@ -860,7 +860,7 @@ _pickle_load(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject _PyArg_BadArgument("load", "argument 'encoding'", "str", args[2]); goto exit; } - encoding = PyUnicode_AsUTF8(args[2]); + encoding = PyUnicode_AsUTF8NoNUL(args[2]); if (encoding == NULL) { goto exit; } @@ -873,7 +873,7 @@ _pickle_load(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject _PyArg_BadArgument("load", "argument 'errors'", "str", args[3]); goto exit; } - errors = PyUnicode_AsUTF8(args[3]); + errors = PyUnicode_AsUTF8NoNUL(args[3]); if (errors == NULL) { goto exit; } @@ -976,7 +976,7 @@ _pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec _PyArg_BadArgument("loads", "argument 'encoding'", "str", args[2]); goto exit; } - encoding = PyUnicode_AsUTF8(args[2]); + encoding = PyUnicode_AsUTF8NoNUL(args[2]); if (encoding == NULL) { goto exit; } @@ -989,7 +989,7 @@ _pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec _PyArg_BadArgument("loads", "argument 'errors'", "str", args[3]); goto exit; } - errors = PyUnicode_AsUTF8(args[3]); + errors = PyUnicode_AsUTF8NoNUL(args[3]); if (errors == NULL) { goto exit; } @@ -1004,4 +1004,4 @@ _pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec exit: return return_value; } -/*[clinic end generated code: output=1c675a6680a6b90c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=26ef80b97b8f511a input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_ssl.c.h b/Modules/clinic/_ssl.c.h index 7aa435f0b8f3cd..89411a2354c426 100644 --- a/Modules/clinic/_ssl.c.h +++ b/Modules/clinic/_ssl.c.h @@ -391,7 +391,7 @@ _ssl__SSLSocket_get_channel_binding(PySSLSocket *self, PyObject *const *args, Py _PyArg_BadArgument("get_channel_binding", "argument 'cb_type'", "str", args[0]); goto exit; } - cb_type = PyUnicode_AsUTF8(args[0]); + cb_type = PyUnicode_AsUTF8NoNUL(args[0]); if (cb_type == NULL) { goto exit; } @@ -468,7 +468,7 @@ _ssl__SSLContext_set_ciphers(PySSLContext *self, PyObject *arg) _PyArg_BadArgument("set_ciphers", "argument", "str", arg); goto exit; } - cipherlist = PyUnicode_AsUTF8(arg); + cipherlist = PyUnicode_AsUTF8NoNUL(arg); if (cipherlist == NULL) { goto exit; } @@ -1306,7 +1306,7 @@ _ssl_txt2obj(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject _PyArg_BadArgument("txt2obj", "argument 'txt'", "str", args[0]); goto exit; } - txt = PyUnicode_AsUTF8(args[0]); + txt = PyUnicode_AsUTF8NoNUL(args[0]); if (txt == NULL) { goto exit; } @@ -1412,7 +1412,7 @@ _ssl_enum_certificates(PyObject *module, PyObject *const *args, Py_ssize_t nargs _PyArg_BadArgument("enum_certificates", "argument 'store_name'", "str", args[0]); goto exit; } - store_name = PyUnicode_AsUTF8(args[0]); + store_name = PyUnicode_AsUTF8NoNUL(args[0]); if (store_name == NULL) { goto exit; } @@ -1483,7 +1483,7 @@ _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; } - store_name = PyUnicode_AsUTF8(args[0]); + store_name = PyUnicode_AsUTF8NoNUL(args[0]); if (store_name == NULL) { goto exit; } @@ -1502,4 +1502,4 @@ _ssl_enum_crls(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje #ifndef _SSL_ENUM_CRLS_METHODDEF #define _SSL_ENUM_CRLS_METHODDEF #endif /* !defined(_SSL_ENUM_CRLS_METHODDEF) */ -/*[clinic end generated code: output=8350af68e0a56792 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=6306e45271b952d8 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_testclinic.c.h b/Modules/clinic/_testclinic.c.h index df81710364d910..c5211e268e9c1f 100644 --- a/Modules/clinic/_testclinic.c.h +++ b/Modules/clinic/_testclinic.c.h @@ -2935,7 +2935,7 @@ clone_f1(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw _PyArg_BadArgument("clone_f1", "argument 'path'", "str", args[0]); goto exit; } - path = PyUnicode_AsUTF8(args[0]); + path = PyUnicode_AsUTF8NoNUL(args[0]); if (path == NULL) { goto exit; } @@ -2996,7 +2996,7 @@ clone_f2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw _PyArg_BadArgument("clone_f2", "argument 'path'", "str", args[0]); goto exit; } - path = PyUnicode_AsUTF8(args[0]); + path = PyUnicode_AsUTF8NoNUL(args[0]); if (path == NULL) { goto exit; } @@ -3131,4 +3131,4 @@ clone_with_conv_f2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py exit: return return_value; } -/*[clinic end generated code: output=32dc6ac90757da7a input=a9049054013a1b77]*/ +/*[clinic end generated code: output=de4e5e1ce2e8a314 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_tkinter.c.h b/Modules/clinic/_tkinter.c.h index 1ff3cec568e330..e511d0d4813a75 100644 --- a/Modules/clinic/_tkinter.c.h +++ b/Modules/clinic/_tkinter.c.h @@ -25,7 +25,7 @@ _tkinter_tkapp_eval(TkappObject *self, PyObject *arg) _PyArg_BadArgument("eval", "argument", "str", arg); goto exit; } - script = PyUnicode_AsUTF8(arg); + script = PyUnicode_AsUTF8NoNUL(arg); if (script == NULL) { goto exit; } @@ -56,7 +56,7 @@ _tkinter_tkapp_evalfile(TkappObject *self, PyObject *arg) _PyArg_BadArgument("evalfile", "argument", "str", arg); goto exit; } - fileName = PyUnicode_AsUTF8(arg); + fileName = PyUnicode_AsUTF8NoNUL(arg); if (fileName == NULL) { goto exit; } @@ -87,7 +87,7 @@ _tkinter_tkapp_record(TkappObject *self, PyObject *arg) _PyArg_BadArgument("record", "argument", "str", arg); goto exit; } - script = PyUnicode_AsUTF8(arg); + script = PyUnicode_AsUTF8NoNUL(arg); if (script == NULL) { goto exit; } @@ -118,7 +118,7 @@ _tkinter_tkapp_adderrorinfo(TkappObject *self, PyObject *arg) _PyArg_BadArgument("adderrorinfo", "argument", "str", arg); goto exit; } - msg = PyUnicode_AsUTF8(arg); + msg = PyUnicode_AsUTF8NoNUL(arg); if (msg == NULL) { goto exit; } @@ -173,7 +173,7 @@ _tkinter_tkapp_exprstring(TkappObject *self, PyObject *arg) _PyArg_BadArgument("exprstring", "argument", "str", arg); goto exit; } - s = PyUnicode_AsUTF8(arg); + s = PyUnicode_AsUTF8NoNUL(arg); if (s == NULL) { goto exit; } @@ -204,7 +204,7 @@ _tkinter_tkapp_exprlong(TkappObject *self, PyObject *arg) _PyArg_BadArgument("exprlong", "argument", "str", arg); goto exit; } - s = PyUnicode_AsUTF8(arg); + s = PyUnicode_AsUTF8NoNUL(arg); if (s == NULL) { goto exit; } @@ -235,7 +235,7 @@ _tkinter_tkapp_exprdouble(TkappObject *self, PyObject *arg) _PyArg_BadArgument("exprdouble", "argument", "str", arg); goto exit; } - s = PyUnicode_AsUTF8(arg); + s = PyUnicode_AsUTF8NoNUL(arg); if (s == NULL) { goto exit; } @@ -266,7 +266,7 @@ _tkinter_tkapp_exprboolean(TkappObject *self, PyObject *arg) _PyArg_BadArgument("exprboolean", "argument", "str", arg); goto exit; } - s = PyUnicode_AsUTF8(arg); + s = PyUnicode_AsUTF8NoNUL(arg); if (s == NULL) { goto exit; } @@ -310,7 +310,7 @@ _tkinter_tkapp_createcommand(TkappObject *self, PyObject *const *args, Py_ssize_ _PyArg_BadArgument("createcommand", "argument 1", "str", args[0]); goto exit; } - name = PyUnicode_AsUTF8(args[0]); + name = PyUnicode_AsUTF8NoNUL(args[0]); if (name == NULL) { goto exit; } @@ -342,7 +342,7 @@ _tkinter_tkapp_deletecommand(TkappObject *self, PyObject *arg) _PyArg_BadArgument("deletecommand", "argument", "str", arg); goto exit; } - name = PyUnicode_AsUTF8(arg); + name = PyUnicode_AsUTF8NoNUL(arg); if (name == NULL) { goto exit; } @@ -644,7 +644,7 @@ _tkinter_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs) screenName = NULL; } else if (PyUnicode_Check(args[0])) { - screenName = PyUnicode_AsUTF8(args[0]); + screenName = PyUnicode_AsUTF8NoNUL(args[0]); if (screenName == NULL) { goto exit; } @@ -660,7 +660,7 @@ _tkinter_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("create", "argument 2", "str", args[1]); goto exit; } - baseName = PyUnicode_AsUTF8(args[1]); + baseName = PyUnicode_AsUTF8NoNUL(args[1]); if (baseName == NULL) { goto exit; } @@ -671,7 +671,7 @@ _tkinter_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("create", "argument 3", "str", args[2]); goto exit; } - className = PyUnicode_AsUTF8(args[2]); + className = PyUnicode_AsUTF8NoNUL(args[2]); if (className == NULL) { goto exit; } @@ -710,7 +710,7 @@ _tkinter_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs) use = NULL; } else if (PyUnicode_Check(args[7])) { - use = PyUnicode_AsUTF8(args[7]); + use = PyUnicode_AsUTF8NoNUL(args[7]); if (use == NULL) { goto exit; } @@ -791,4 +791,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=0c8b5f960d7738fd input=a9049054013a1b77]*/ +/*[clinic end generated code: output=1bd2d8236b8e1752 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index d91793c8be8d96..dc33d366b0eedf 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -4672,7 +4672,7 @@ os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]); goto exit; } - user = PyUnicode_AsUTF8(args[0]); + user = PyUnicode_AsUTF8NoNUL(args[0]); if (user == NULL) { goto exit; } @@ -4721,7 +4721,7 @@ os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]); goto exit; } - user = PyUnicode_AsUTF8(args[0]); + user = PyUnicode_AsUTF8NoNUL(args[0]); if (user == NULL) { goto exit; } @@ -12393,4 +12393,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=a377982a6d1e77b9 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=11b4352368b8ffc4 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/pyexpat.c.h b/Modules/clinic/pyexpat.c.h index 4fac03ebaf2a07..e9356e39eb85c2 100644 --- a/Modules/clinic/pyexpat.c.h +++ b/Modules/clinic/pyexpat.c.h @@ -129,7 +129,7 @@ pyexpat_xmlparser_SetBase(xmlparseobject *self, PyObject *arg) _PyArg_BadArgument("SetBase", "argument", "str", arg); goto exit; } - base = PyUnicode_AsUTF8(arg); + base = PyUnicode_AsUTF8NoNUL(arg); if (base == NULL) { goto exit; } @@ -223,7 +223,7 @@ pyexpat_xmlparser_ExternalEntityParserCreate(xmlparseobject *self, PyTypeObject context = NULL; } else if (PyUnicode_Check(args[0])) { - context = PyUnicode_AsUTF8(args[0]); + context = PyUnicode_AsUTF8NoNUL(args[0]); if (context == NULL) { goto exit; } @@ -239,7 +239,7 @@ pyexpat_xmlparser_ExternalEntityParserCreate(xmlparseobject *self, PyTypeObject _PyArg_BadArgument("ExternalEntityParserCreate", "argument 2", "str", args[1]); goto exit; } - encoding = PyUnicode_AsUTF8(args[1]); + encoding = PyUnicode_AsUTF8NoNUL(args[1]); if (encoding == NULL) { goto exit; } @@ -403,7 +403,7 @@ pyexpat_ParserCreate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, encoding = NULL; } else if (PyUnicode_Check(args[0])) { - encoding = PyUnicode_AsUTF8(args[0]); + encoding = PyUnicode_AsUTF8NoNUL(args[0]); if (encoding == NULL) { goto exit; } @@ -421,7 +421,7 @@ pyexpat_ParserCreate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, namespace_separator = NULL; } else if (PyUnicode_Check(args[1])) { - namespace_separator = PyUnicode_AsUTF8(args[1]); + namespace_separator = PyUnicode_AsUTF8NoNUL(args[1]); if (namespace_separator == NULL) { goto exit; } @@ -473,4 +473,4 @@ pyexpat_ErrorString(PyObject *module, PyObject *arg) #ifndef PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF #define PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF #endif /* !defined(PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF) */ -/*[clinic end generated code: output=bfc1f3d3e2cbc8dc input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ec5d735a62823205 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/symtablemodule.c.h b/Modules/clinic/symtablemodule.c.h index d624c22cf282ff..9efc3ad1195840 100644 --- a/Modules/clinic/symtablemodule.c.h +++ b/Modules/clinic/symtablemodule.c.h @@ -36,7 +36,7 @@ _symtable_symtable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) _PyArg_BadArgument("symtable", "argument 3", "str", args[2]); goto exit; } - startstr = PyUnicode_AsUTF8(args[2]); + startstr = PyUnicode_AsUTF8NoNUL(args[2]); if (startstr == NULL) { goto exit; } @@ -45,4 +45,4 @@ _symtable_symtable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=9af1ab5a114a1ec7 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=fa992f64a859a833 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/bytearrayobject.c.h b/Objects/clinic/bytearrayobject.c.h index 355ae49ca74f71..80a2b31ef0f45d 100644 --- a/Objects/clinic/bytearrayobject.c.h +++ b/Objects/clinic/bytearrayobject.c.h @@ -68,7 +68,7 @@ bytearray___init__(PyObject *self, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("bytearray", "argument 'encoding'", "str", fastargs[1]); goto exit; } - encoding = PyUnicode_AsUTF8(fastargs[1]); + encoding = PyUnicode_AsUTF8NoNUL(fastargs[1]); if (encoding == NULL) { goto exit; } @@ -80,7 +80,7 @@ bytearray___init__(PyObject *self, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("bytearray", "argument 'errors'", "str", fastargs[2]); goto exit; } - errors = PyUnicode_AsUTF8(fastargs[2]); + errors = PyUnicode_AsUTF8NoNUL(fastargs[2]); if (errors == NULL) { goto exit; } @@ -950,7 +950,7 @@ bytearray_decode(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[0]); goto exit; } - encoding = PyUnicode_AsUTF8(args[0]); + encoding = PyUnicode_AsUTF8NoNUL(args[0]); if (encoding == NULL) { goto exit; } @@ -962,7 +962,7 @@ bytearray_decode(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg _PyArg_BadArgument("decode", "argument 'errors'", "str", args[1]); goto exit; } - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -1241,4 +1241,4 @@ bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored)) { return bytearray_sizeof_impl(self); } -/*[clinic end generated code: output=5a7de6295a7ce6cc input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c7c208d5ae6cadfc input=a9049054013a1b77]*/ diff --git a/Objects/clinic/bytesobject.c.h b/Objects/clinic/bytesobject.c.h index 042d0bf86e453c..734090e4d1599f 100644 --- a/Objects/clinic/bytesobject.c.h +++ b/Objects/clinic/bytesobject.c.h @@ -720,7 +720,7 @@ bytes_decode(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObj _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[0]); goto exit; } - encoding = PyUnicode_AsUTF8(args[0]); + encoding = PyUnicode_AsUTF8NoNUL(args[0]); if (encoding == NULL) { goto exit; } @@ -732,7 +732,7 @@ bytes_decode(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObj _PyArg_BadArgument("decode", "argument 'errors'", "str", args[1]); goto exit; } - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -987,7 +987,7 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("bytes", "argument 'encoding'", "str", fastargs[1]); goto exit; } - encoding = PyUnicode_AsUTF8(fastargs[1]); + encoding = PyUnicode_AsUTF8NoNUL(fastargs[1]); if (encoding == NULL) { goto exit; } @@ -999,7 +999,7 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("bytes", "argument 'errors'", "str", fastargs[2]); goto exit; } - errors = PyUnicode_AsUTF8(fastargs[2]); + errors = PyUnicode_AsUTF8NoNUL(fastargs[2]); if (errors == NULL) { goto exit; } @@ -1009,4 +1009,4 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=97aab3f6ae398664 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=cdbfbcfb16e0cbe9 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/floatobject.c.h b/Objects/clinic/floatobject.c.h index 8c331197f05b5c..3f9052b33b1091 100644 --- a/Objects/clinic/floatobject.c.h +++ b/Objects/clinic/floatobject.c.h @@ -275,7 +275,7 @@ float___getformat__(PyTypeObject *type, PyObject *arg) _PyArg_BadArgument("__getformat__", "argument", "str", arg); goto exit; } - typestr = PyUnicode_AsUTF8(arg); + typestr = PyUnicode_AsUTF8NoNUL(arg); if (typestr == NULL) { goto exit; } @@ -313,4 +313,4 @@ float___format__(PyObject *self, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=01f6fbd082eefead input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3eae9bc51630eb00 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/memoryobject.c.h b/Objects/clinic/memoryobject.c.h index ebc1e0617bd303..4a73b7c9b87c96 100644 --- a/Objects/clinic/memoryobject.c.h +++ b/Objects/clinic/memoryobject.c.h @@ -305,7 +305,7 @@ memoryview_tobytes(PyMemoryViewObject *self, PyObject *const *args, Py_ssize_t n order = NULL; } else if (PyUnicode_Check(args[0])) { - order = PyUnicode_AsUTF8(args[0]); + order = PyUnicode_AsUTF8NoNUL(args[0]); if (order == NULL) { goto exit; } @@ -408,4 +408,4 @@ memoryview_hex(PyMemoryViewObject *self, PyObject *const *args, Py_ssize_t nargs exit: return return_value; } -/*[clinic end generated code: output=abd8c0ce804d8992 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=9cf520557bc4094a input=a9049054013a1b77]*/ diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index 83e3bf22989848..de18784df5b79b 100644 --- a/Objects/clinic/unicodeobject.c.h +++ b/Objects/clinic/unicodeobject.c.h @@ -203,7 +203,7 @@ unicode_encode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject _PyArg_BadArgument("encode", "argument 'encoding'", "str", args[0]); goto exit; } - encoding = PyUnicode_AsUTF8(args[0]); + encoding = PyUnicode_AsUTF8NoNUL(args[0]); if (encoding == NULL) { goto exit; } @@ -215,7 +215,7 @@ unicode_encode(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject _PyArg_BadArgument("encode", "argument 'errors'", "str", args[1]); goto exit; } - errors = PyUnicode_AsUTF8(args[1]); + errors = PyUnicode_AsUTF8NoNUL(args[1]); if (errors == NULL) { goto exit; } @@ -1463,7 +1463,7 @@ unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("str", "argument 'encoding'", "str", fastargs[1]); goto exit; } - encoding = PyUnicode_AsUTF8(fastargs[1]); + encoding = PyUnicode_AsUTF8NoNUL(fastargs[1]); if (encoding == NULL) { goto exit; } @@ -1475,7 +1475,7 @@ unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("str", "argument 'errors'", "str", fastargs[2]); goto exit; } - errors = PyUnicode_AsUTF8(fastargs[2]); + errors = PyUnicode_AsUTF8NoNUL(fastargs[2]); if (errors == NULL) { goto exit; } @@ -1485,4 +1485,4 @@ unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=20313d6339272ddc input=a9049054013a1b77]*/ +/*[clinic end generated code: output=aab55c9b2f2b29a3 input=a9049054013a1b77]*/ diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 87636efcfca050..649e027626c460 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -3843,6 +3843,12 @@ PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *psize) const char * PyUnicode_AsUTF8(PyObject *unicode) +{ + return PyUnicode_AsUTF8AndSize(unicode, NULL); +} + +const char * +PyUnicode_AsUTF8NoNUL(PyObject *unicode) { Py_ssize_t size; const char *utf8 = PyUnicode_AsUTF8AndSize(unicode, &size); diff --git a/PC/python3dll.c b/PC/python3dll.c index fa6bf1f0282b0a..e6470a943316ce 100755 --- a/PC/python3dll.c +++ b/PC/python3dll.c @@ -664,6 +664,7 @@ EXPORT_FUNC(PyUnicode_AsUTF16String) EXPORT_FUNC(PyUnicode_AsUTF32String) EXPORT_FUNC(PyUnicode_AsUTF8) EXPORT_FUNC(PyUnicode_AsUTF8AndSize) +EXPORT_FUNC(PyUnicode_AsUTF8NoNUL) EXPORT_FUNC(PyUnicode_AsUTF8String) EXPORT_FUNC(PyUnicode_AsWideChar) EXPORT_FUNC(PyUnicode_AsWideCharString) diff --git a/Python/clinic/Python-tokenize.c.h b/Python/clinic/Python-tokenize.c.h index 7417020d94c2f2..a868d0ce40a661 100644 --- a/Python/clinic/Python-tokenize.c.h +++ b/Python/clinic/Python-tokenize.c.h @@ -65,7 +65,7 @@ tokenizeriter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) _PyArg_BadArgument("tokenizeriter", "argument 'encoding'", "str", fastargs[2]); goto exit; } - encoding = PyUnicode_AsUTF8(fastargs[2]); + encoding = PyUnicode_AsUTF8NoNUL(fastargs[2]); if (encoding == NULL) { goto exit; } @@ -75,4 +75,4 @@ tokenizeriter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=92cb8176149f0924 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d537a02f60a4f68d input=a9049054013a1b77]*/ diff --git a/Python/clinic/bltinmodule.c.h b/Python/clinic/bltinmodule.c.h index 4fb06bd0dba5fe..2dca7fe1d6469d 100644 --- a/Python/clinic/bltinmodule.c.h +++ b/Python/clinic/bltinmodule.c.h @@ -329,7 +329,7 @@ builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj _PyArg_BadArgument("compile", "argument 'mode'", "str", args[2]); goto exit; } - mode = PyUnicode_AsUTF8(args[2]); + mode = PyUnicode_AsUTF8NoNUL(args[2]); if (mode == NULL) { goto exit; } @@ -1207,4 +1207,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=95d3813b1798f018 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=f5a9aee81d182504 input=a9049054013a1b77]*/ diff --git a/Python/clinic/sysmodule.c.h b/Python/clinic/sysmodule.c.h index 571a34bd4a64af..e027461abf9a59 100644 --- a/Python/clinic/sysmodule.c.h +++ b/Python/clinic/sysmodule.c.h @@ -1259,7 +1259,7 @@ sys_activate_stack_trampoline(PyObject *module, PyObject *arg) _PyArg_BadArgument("activate_stack_trampoline", "argument", "str", arg); goto exit; } - backend = PyUnicode_AsUTF8(arg); + backend = PyUnicode_AsUTF8NoNUL(arg); if (backend == NULL) { goto exit; } @@ -1447,4 +1447,4 @@ sys__get_cpu_count_config(PyObject *module, PyObject *Py_UNUSED(ignored)) #ifndef SYS_GETANDROIDAPILEVEL_METHODDEF #define SYS_GETANDROIDAPILEVEL_METHODDEF #endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */ -/*[clinic end generated code: output=cdfb714878deeaf1 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=05e050c1fc6a4833 input=a9049054013a1b77]*/ diff --git a/Python/getargs.c b/Python/getargs.c index 4d91818ad21a44..bbff67ab03f5b4 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -937,7 +937,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, if (c == 'z' && arg == Py_None) *p = NULL; else if (PyUnicode_Check(arg)) { - sarg = PyUnicode_AsUTF8(arg); + sarg = PyUnicode_AsUTF8NoNUL(arg); if (sarg == NULL) { return converterr(CONV_UNICODE, arg, msgbuf, bufsize); diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 4f238a3dc0d4af..61f78cb5b33675 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -4350,7 +4350,7 @@ def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> st {bad_argument} goto exit; }}}} - {paramname} = PyUnicode_AsUTF8({argname}); + {paramname} = PyUnicode_AsUTF8NoNUL({argname}); if ({paramname} == NULL) {{{{ goto exit; }}}} @@ -4363,7 +4363,7 @@ def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> st {paramname} = NULL; }}}} else if (PyUnicode_Check({argname})) {{{{ - {paramname} = PyUnicode_AsUTF8({argname}); + {paramname} = PyUnicode_AsUTF8NoNUL({argname}); if ({paramname} == NULL) {{{{ goto exit; }}}}