8000 bpo-41123: Remove PyUnicode_AsUnicodeCopy (GH-21209) · python/cpython@b333266 · GitHub
[go: up one dir, main page]

Skip to content

Commit b333266

Browse files
authored
bpo-41123: Remove PyUnicode_AsUnicodeCopy (GH-21209)
1 parent 2515a28 commit b333266

File tree

6 files changed

+5
-58
lines changed

6 files changed

+5
-58
lines changed

Doc/c-api/unicode.rst

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -724,20 +724,6 @@ Extension modules can continue using them, as they will not be removed in Python
724724
.. versionadded:: 3.3
725725
726726
727-
.. c:function:: Py_UNICODE* PyUnicode_AsUnicodeCopy(PyObject *unicode)
728-
729-
Create a copy of a Unicode string ending with a null code point. Return ``NULL``
730-
and raise a :exc:`MemoryError` exception on memory allocation failure,
731-
otherwise return a new allocated buffer (use :c:func:`PyMem_Free` to free
732-
the buffer). Note that the resulting :c:type:`Py_UNICODE*` string may
733-
contain embedded null code points, which would cause the string to be
734-
truncated when used in most C functions.
735-
736-
.. versionadded:: 3.2
737-
738-
Please migrate to using :c:func:`PyUnicode_AsUCS4Copy` or similar new APIs.
739-
740-
741727
.. c:function:: Py_ssize_t PyUnicode_GetSize(PyObject *unicode)
742728
743729
Return the size of the deprecated :c:type:`Py_UNICODE` representation, in

Doc/data/refcounts.dat

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,9 +2419,6 @@ PyUnicode_AsUnicodeAndSize:Py_UNICODE*:::
24192419
PyUnicode_AsUnicodeAndSize:PyObject*:unicode:0:
24202420
PyUnicode_AsUnicodeAndSize:Py_ssize_t*:size::
24212421

2422-
PyUnicode_AsUnicodeCopy:Py_UNICODE*:::
2423-
PyUnicode_AsUnicodeCopy:PyObject*:unicode:0:
2424-
24252422
PyUnicode_GetSize:Py_ssize_t:::
24262423
PyUnicode_GetSize:PyObject*:unicode:0:
24272424

Doc/whatsnew/3.10.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,7 @@ Removed
240240

241241
* Removed ``PyLong_FromUnicode()``. Please migrate to :c:func:`PyLong_FromUnicodeObject`.
242242
(Contributed by Inada Naoki in :issue:`41103`.)
243+
244+
* Removed ``PyUnicode_AsUnicodeCopy()``. Please use :c:func:`PyUnicode_AsUCS4Copy` or
245+
:c:func:`PyUnicode_AsWideCharString`
246+
(Contributed by Inada Naoki in :issue:`41103`.)

Include/cpython/unicodeobject.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,14 +1162,6 @@ PyAPI_FUNC(int) _PyUnicode_IsAlpha(
11621162

11631163
PyAPI_FUNC(PyObject*) _PyUnicode_FormatLong(PyObject *, int, int, int);
11641164

1165-
/* Create a copy of a unicode string ending with a nul character. Return NULL
1166-
and raise a MemoryError exception on memory allocation failure, otherwise
1167-
return a new allocated buffer (use PyMem_Free() to free the buffer). */
1168-
1169-
Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE*) PyUnicode_AsUnicodeCopy(
1170-
PyObject *unicode
1171-
);
1172-
11731165
/* Return an interned Unicode object for an Identifier; may fail if there is no memory.*/
11741166
PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*);
11751167

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove ``PyUnicode_AsUnicodeCopy``.

Objects/unicodeobject.c

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15862,39 +15862,6 @@ unicode_iter(PyObject *seq)
1586215862
return (PyObject *)it;
1586315863
}
1586415864

15865-
Py_UNICODE*
15866-
PyUnicode_AsUnicodeCopy(PyObject *unicode)
15867-
{
15868-
Py_UNICODE *u, *copy;
15869-
Py_ssize_t len, size;
15870-
15871-
if (!PyUnicode_Check(unicode)) {
15872-
PyErr_BadArgument();
15873-
return NULL;
15874-
}
15875-
_Py_COMP_DIAG_PUSH
15876-
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
15877-
u = PyUnicode_AsUnicodeAndSize(unicode, &len);
15878-
_Py_COMP_DIAG_POP
15879-
if (u == NULL)
15880-
return NULL;
15881-
/* Ensure we won't overflow the size. */
15882-
if (len > ((PY_SSIZE_T_MAX / (Py_ssize_t)sizeof(Py_UNICODE)) - 1)) {
15883-
PyErr_NoMemory();
15884-
return NULL;
15885-
}
15886-
size = len + 1; /* copy the null character */
15887-
size *= sizeof(Py_UNICODE);
15888-
copy = PyMem_Malloc(size);
15889-
if (copy == NULL) {
15890-
PyErr_NoMemory();
15891-
return NULL;
15892-
}
15893-
memcpy(copy, u, size);
15894-
return copy;
15895-
}
15896-
15897-
1589815865
static int
1589915866
encode_wstr_utf8(wchar_t *wstr, char **str, const char *name)
1590015867
{

0 commit comments

Comments
 (0)
0