summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2020-10-19 18:17:50 -0400
committerGitHub <noreply@github.com>2020-10-19 23:17:50 +0100
commit3a8fdb28794b2f19f6c8464378fb8b46bce1f5f4 (patch)
tree860c455643cb15787c0b2c4de90dec28d96f9d2e
parent4dfb190a33a1deac60306f15d52d2fe11fb93464 (diff)
downloadcpython-git-3a8fdb28794b2f19f6c8464378fb8b46bce1f5f4.tar.gz
bpo-41784: make PyUnicode_AsUTF8AndSize part of the limited API (GH-22252)
-rw-r--r--Doc/c-api/unicode.rst3
-rw-r--r--Doc/whatsnew/3.10.rst4
-rw-r--r--Include/cpython/unicodeobject.h20
-rw-r--r--Include/unicodeobject.h17
-rw-r--r--Misc/NEWS.d/next/C API/2020-09-14-10-17-00.bpo-41784.Yl4gI2.rst1
-rw-r--r--PC/python3dll.c1
6 files changed, 26 insertions, 20 deletions
diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst
index 5518214a79..54bd0a3cbb 100644
--- a/Doc/c-api/unicode.rst
+++ b/Doc/c-api/unicode.rst
@@ -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)
diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst
index 738ef974e7..f57e1b4123 100644
--- a/Doc/whatsnew/3.10.rst
+++ b/Doc/whatsnew/3.10.rst
@@ -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
----------------------
diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h
index 300408cb26..f1b44554e3 100644
--- a/Include/cpython/unicodeobject.h
+++ b/Include/cpython/unicodeobject.h
@@ -727,26 +727,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.
Like PyUnicode_AsUTF8AndSize(), this also caches the UTF-8 representation
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
index 90b3299fd2..b0ac086a6b 100644
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -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
index 0000000000..f09e0879ad
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2020-09-14-10-17-00.bpo-41784.Yl4gI2.rst
@@ -0,0 +1 @@
+Added ``PyUnicode_AsUTF8AndSize`` to the limited C API.
diff --git a/PC/python3dll.c b/PC/python3dll.c
index 153ba612b7..b9b229ea67 100644
--- a/PC/python3dll.c
+++ b/PC/python3dll.c
@@ -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)