Add PyUnicode_AsUTF8() function to the limited C API.
multiprocessing posixshmem now uses PyUnicode_AsUTF8() instead of
PyUnicode_AsUTF8AndSize(): the extension is built with the limited C
API. The function now raises an exception if the filename contains an
embedded null character instead of truncating silently the filename.
function,PyUnicode_AsUCS4Copy,3.7,,
function,PyUnicode_AsUTF16String,3.2,,
function,PyUnicode_AsUTF32String,3.2,,
+function,PyUnicode_AsUTF8,3.13,,
function,PyUnicode_AsUTF8AndSize,3.10,,
function,PyUnicode_AsUTF8String,3.2,,
function,PyUnicode_AsUnicodeEscapeString,3.2,,
limited C API.
(Contributed by Victor Stinner in :gh:`85283`.)
+* Add :c:func:`PyUnicode_AsUTF8` function to the limited C API.
+ (Contributed by Victor Stinner in :gh:`111089`.)
+
Porting to Python 3.13
----------------------
const void *buffer,
Py_ssize_t size);
-/* --- Manage the default encoding ---------------------------------------- */
-
-// Returns a pointer to the default encoding (UTF-8) of the
-// Unicode object unicode.
-//
-// Raise an exception if the string contains embedded null characters.
-// Use PyUnicode_AsUTF8AndSize() to accept embedded null characters.
-//
-// This function caches the UTF-8 encoded string in the Unicode object
-// and subsequent calls will return the same string. The memory is released
-// when the Unicode object is deallocated.
-PyAPI_FUNC(const char *) PyUnicode_AsUTF8(PyObject *unicode);
-
/* === Characters Type APIs =============================================== */
PyObject *unicode /* Unicode object */
);
-// Returns a pointer to the default encoding (UTF-8) of the
+// Returns a pointer to the UTF-8 encoding of the Unicode object unicode.
+//
+// Raise an exception if the string contains embedded null characters.
+// Use PyUnicode_AsUTF8AndSize() to accept embedded null characters.
+//
+// This function caches the UTF-8 encoded string in the Unicode object
+// and subsequent calls will return the same string. The memory is released
+// when the Unicode object is deallocated.
+PyAPI_FUNC(const char *) PyUnicode_AsUTF8(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).
//
"PyUnicode_AsUCS4Copy",
"PyUnicode_AsUTF16String",
"PyUnicode_AsUTF32String",
+ "PyUnicode_AsUTF8",
"PyUnicode_AsUTF8AndSize",
"PyUnicode_AsUTF8String",
"PyUnicode_AsUnicodeEscapeString",
--- /dev/null
+Add :c:func:`PyUnicode_AsUTF8` function to the limited C API. Patch by
+Victor Stinner.
added = '3.13'
[function.PySys_AuditTuple]
added = '3.13'
+[function.PyUnicode_AsUTF8]
+ added = '3.13'
{
int fd;
int async_err = 0;
- const char *name = PyUnicode_AsUTF8AndSize(path, NULL);
+ const char *name = PyUnicode_AsUTF8(path);
if (name == NULL) {
return -1;
}
{
int rv;
int async_err = 0;
- const char *name = PyUnicode_AsUTF8AndSize(path, NULL);
+ const char *name = PyUnicode_AsUTF8(path);
if (name == NULL) {
return NULL;
}
EXPORT_FUNC(PyUnicode_AsUnicodeEscapeString)
EXPORT_FUNC(PyUnicode_AsUTF16String)
EXPORT_FUNC(PyUnicode_AsUTF32String)
+EXPORT_FUNC(PyUnicode_AsUTF8)
EXPORT_FUNC(PyUnicode_AsUTF8AndSize)
EXPORT_FUNC(PyUnicode_AsUTF8String)
EXPORT_FUNC(PyUnicode_AsWideChar)