]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41784: make PyUnicode_AsUTF8AndSize part of the limited API (GH-22252)
authorAlex Gaynor <alex.gaynor@gmail.com>
Mon, 19 Oct 2020 22:17:50 +0000 (18:17 -0400)
committerGitHub <noreply@github.com>
Mon, 19 Oct 2020 22:17:50 +0000 (23:17 +0100)
Doc/c-api/unicode.rst
Doc/whatsnew/3.10.rst
Include/cpython/unicodeobject.h
Include/unicodeobject.h
Misc/NEWS.d/next/C API/2020-09-14-10-17-00.bpo-41784.Yl4gI2.rst [new file with mode: 0644]
PC/python3dll.c

index 5518214a793e0c5e099f694b7d32e8e56893cc19..54bd0a3cbb65567260873571a1c66af45e820fdc 100644 (file)
@@ -1098,6 +1098,9 @@ These are the UTF-8 codec APIs:
    .. 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)
 
index 738ef974e7867b3e12874f998765c85129977aa2..f57e1b412378e6666e3bd682c4ec450fdc8fb732 100644 (file)
@@ -323,6 +323,10 @@ New Features
   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
 ----------------------
 
index 300408cb262991d2c2e9214f403b04288603c6d0..f1b44554e3078d3d67defd1337952ed6ce8a25e4 100644 (file)
@@ -726,26 +726,6 @@ PyAPI_FUNC(int) _PyUnicode_FormatAdvancedWriter(
 
 /* --- 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.
 
index 90b3299fd26ceb419a8aaeb0c51b5ab760b1a715..b0ac086a6be23de8c61299a0081049f1ed863212 100644 (file)
@@ -468,6 +468,23 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsUTF8String(
     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
diff --git a/Misc/NEWS.d/next/C API/2020-09-14-10-17-00.bpo-41784.Yl4gI2.rst b/Misc/NEWS.d/next/C API/2020-09-14-10-17-00.bpo-41784.Yl4gI2.rst
new file mode 100644 (file)
index 0000000..f09e087
--- /dev/null
@@ -0,0 +1 @@
+Added ``PyUnicode_AsUTF8AndSize`` to the limited C API. 
index 153ba612b7804f5cb0315a508c8a4f7cc3201301..b9b229ea67d7b39eab3e45b536fdeb1aca813b4d 100644 (file)
@@ -568,6 +568,7 @@ EXPORT_FUNC(PyUnicode_AsUCS4Copy)
 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)