.. versionchanged:: 3.7
The return type is now ``const char *`` rather of ``char *``.
+ .. versionchanged:: 3.10
+ This function is a part of the :ref:`limited API <stable>`.
+
.. c:function:: const char* PyUnicode_AsUTF8(PyObject *unicode)
sending value into iterator without raising ``StopIteration`` exception.
(Contributed by Vladimir Matveev in :issue:`41756`.)
+* Added :c:func:`PyUnicode_AsUTF8AndSize` to the limited C API.
+ (Contributed by Alex Gaynor in :issue:`41784`.)
+
+
Porting to Python 3.10
----------------------
/* --- Manage the default encoding ---------------------------------------- */
-/* Returns a pointer to the default encoding (UTF-8) of the
- Unicode object unicode and the size of the encoded representation
- in bytes stored in *size.
-
- In case of an error, no *size is set.
-
- This function caches the UTF-8 encoded string in the unicodeobject
- and subsequent calls will return the same string. The memory is released
- when the unicodeobject is deallocated.
-
- _PyUnicode_AsStringAndSize is a #define for PyUnicode_AsUTF8AndSize to
- support the previous internal function with the same behaviour.
-*/
-
-PyAPI_FUNC(const char *) PyUnicode_AsUTF8AndSize(
- PyObject *unicode,
- Py_ssize_t *size);
-
-#define _PyUnicode_AsStringAndSize PyUnicode_AsUTF8AndSize
-
/* Returns a pointer to the default encoding (UTF-8) of the
Unicode object unicode.
PyObject *unicode /* Unicode object */
);
+/* Returns a pointer to the default encoding (UTF-8) of the
+ Unicode object unicode and the size of the encoded representation
+ in bytes stored in *size.
+
+ In case of an error, no *size is set.
+
+ This function caches the UTF-8 encoded string in the unicodeobject
+ and subsequent calls will return the same string. The memory is released
+ when the unicodeobject is deallocated.
+*/
+
+#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000
+PyAPI_FUNC(const char *) PyUnicode_AsUTF8AndSize(
+ PyObject *unicode,
+ Py_ssize_t *size);
+#endif
+
/* --- UTF-32 Codecs ------------------------------------------------------ */
/* Decodes length bytes from a UTF-32 encoded buffer string and returns
--- /dev/null
+Added ``PyUnicode_AsUTF8AndSize`` to the limited C API.
EXPORT_FUNC(PyUnicode_AsUnicodeEscapeString)
EXPORT_FUNC(PyUnicode_AsUTF16String)
EXPORT_FUNC(PyUnicode_AsUTF32String)
+EXPORT_FUNC(PyUnicode_AsUTF8AndSize)
EXPORT_FUNC(PyUnicode_AsUTF8String)
EXPORT_FUNC(PyUnicode_AsWideChar)
EXPORT_FUNC(PyUnicode_AsWideCharString)