10000 bpo-41692: Deprecate PyUnicode_InternImmortal() by vstinner · Pull Request #22486 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-41692: Deprecate PyUnicode_InternImmortal() #22486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ Porting to Python 3.10
Unicode object without initial data.
(Contributed by Inada Naoki in :issue:`36346`.)

Deprecated
----------

* The ``PyUnicode_InternImmortal()`` function is now deprecated
and will be removed in Python 3.12: use :c:func:`PyUnicode_InternInPlace`
instead.
(Contributed by Victor Stinner in :issue:`41692`.)

Removed
-------

Expand Down
5 changes: 4 additions & 1 deletion Include/unicodeobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,14 @@ PyAPI_FUNC(PyObject *) PyUnicode_FromFormat(
);

PyAPI_FUNC(void) PyUnicode_InternInPlace(PyObject **);
PyAPI_FUNC(void) PyUnicode_InternImmortal(PyObject **);
PyAPI_FUNC(PyObject *) PyUnicode_InternFromString(
const char *u /* UTF-8 encoded string */
);

// PyUnicode_InternImmortal() is deprecated since Python 3.10
// and will be removed in Python 3.12. Use PyUnicode_InternInPlace() instead.
Py_DEPRECATED(3.10) PyAPI_FUNC(void) PyUnicode_InternImmortal(PyObject **);

/* Use only if you know it's a string */
#define PyUnicode_CHECK_INTERNED(op) \
(((PyASCIIObject *)(op))->state.interned)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The ``PyUnicode_InternImmortal()`` function is now deprecated and will be
removed in Python 3.12: use :c:func:`PyUnicode_InternInPlace` instead.
Patch by Victor Stinner.
9 changes: 9 additions & 0 deletions Objects/unicodeobject.c
4541
Original file line number Diff line number Diff line change
Expand Up @@ -15764,6 +15764,15 @@ PyUnicode_InternInPlace(PyObject **p)
void
PyUnicode_InternImmortal(PyObject **p)
{
if (PyErr_WarnEx(PyExc_DeprecationWarning,
"PyUnicode_InternImmortal() is deprecated; "
"use PyUnicode_InternInPlace() instead", 1) < 0)
{
// The function has no return value, the exception cannot
// be reported to the caller, so just log it.
PyErr_WriteUnraisable(NULL);
}

PyUnicode_InternInPlace(p);
if (PyUnicode_CHECK_INTERNED(*p) != SSTATE_INTERNED_IMMORTAL) {
_PyUnicode_STATE(*p).interned = SSTATE_INTERNED_IMMORTAL;
Expand Down
0