Skip to content

Remove references to Unicode objects being ready #130790

Description

@picnixz

We have some code referrencing readiness of Unicode objects but this property is deprecated (see #129894 (comment)). Following @encukou's advice, we should address each module with a separate PR so that experts can review them separately.

unicodedata.c

/* result is guaranteed to be ready, as it is compact. */
kind=PyUnicode_KIND(result);
data=PyUnicode_DATA(result);

result=nfd_nfkd(self, input, k);
if (!result)
returnNULL;
/* result will be "ready". */
kind=PyUnicode_KIND(result);
data=PyUnicode_DATA(result);
len=PyUnicode_GET_LENGTH(result);

_io/textio.c

kind=PyUnicode_KIND(modified);
out=PyUnicode_DATA(modified);
PyUnicode_WRITE(kind, out, 0, '\r');
memcpy(out+kind, PyUnicode_DATA(output), kind*output_len);
Py_SETREF(output, modified); /* output remains ready */
self->pendingcr=0;
output_len++;

/* decoded_chars is guaranteed to be "ready". */
avail= (PyUnicode_GET_LENGTH(self->decoded_chars)
-self->decoded_chars_used);

Parser files

/* Verify that the identifier follows PEP 3131.
All identifier strings are guaranteed to be "ready" unicode objects.
*/
staticint
verify_identifier(structtok_state*tok)

cpython/Parser/pegen.c

Lines 505 to 513 in a85eeb9

PyObject*
_PyPegen_new_identifier(Parser*p, constchar*n)
{
PyObject*id=PyUnicode_DecodeUTF8(n, (Py_ssize_t)strlen(n), NULL);
if (!id) {
goto error;
}
/* PyUnicode_DecodeUTF8 should always return a ready string. */
assert(PyUnicode_IS_READY(id));

tracemalloc.c

if (!PyUnicode_IS_READY(filename)) {
/* Don't make a Unicode string ready to avoid reentrant calls
to tracemalloc_alloc() or tracemalloc_realloc() */
#ifdefTRACE_DEBUG
tracemalloc_error("filename is not a ready unicode string");
#endif
return;
}

This one seems to be dead code (cc @vstinner)

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions