gh-92536: Remove PyUnicode_READY() calls (#105210)

Since Python 3.12, PyUnicode_READY() does nothing and always
returns 0.
This commit is contained in:
Victor Stinner 2023-06-02 01:33:17 +02:00 committed by GitHub
parent cbb9ba844f
commit ef300937c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 5 additions and 186 deletions

View file

@ -533,9 +533,6 @@ show_warning(PyThreadState *tstate, PyObject *filename, int lineno,
Py_UCS4 ch;
PyObject *truncated;
if (PyUnicode_READY(sourceline) < 1)
goto error;
kind = PyUnicode_KIND(sourceline);
data = PyUnicode_DATA(sourceline);
len = PyUnicode_GET_LENGTH(sourceline);

View file

@ -1914,8 +1914,6 @@ builtin_ord(PyObject *module, PyObject *c)
}
}
else if (PyUnicode_Check(c)) {
if (PyUnicode_READY(c) == -1)
return NULL;
size = PyUnicode_GET_LENGTH(c);
if (size == 1) {
ord = (long)PyUnicode_READ_CHAR(c, 0);

View file

@ -982,7 +982,7 @@ format_long_internal(PyObject *value, const InternalFormatSpec *format,
/* Do the hard part, converting to a string in a given base */
tmp = _PyLong_Format(value, base);
if (tmp == NULL || PyUnicode_READY(tmp) == -1)
if (tmp == NULL)
goto done;
inumeric_chars = 0;

View file

@ -824,9 +824,6 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
if (!PyUnicode_Check(arg))
return converterr("a unicode character", arg, msgbuf, bufsize);
if (PyUnicode_READY(arg))
RETURN_ERR_OCCURRED;
if (PyUnicode_GET_LENGTH(arg) != 1)
return converterr("a unicode character", arg, msgbuf, bufsize);
@ -1144,8 +1141,6 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
case 'U': { /* PyUnicode object */
PyObject **p = va_arg(*p_va, PyObject **);
if (PyUnicode_Check(arg)) {
if (PyUnicode_READY(arg) == -1)
RETURN_ERR_OCCURRED;
*p = arg;
}
else

View file

@ -2610,10 +2610,6 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level
if (!haspath) {
Py_ssize_t dot;
if (PyUnicode_READY(package) < 0) {
goto error;
}
dot = PyUnicode_FindChar(package, '.',
0, PyUnicode_GET_LENGTH(package), -1);
if (dot == -2) {
@ -2762,9 +2758,6 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
"module name must be a string");
goto error;
}
if (PyUnicode_READY(name) < 0) {
goto error;
}
if (level < 0) {
_PyErr_SetString(tstate, PyExc_ValueError, "level must be >= 0");
goto error;

View file

@ -96,11 +96,6 @@ import_all_from(PyThreadState *tstate, PyObject *locals, PyObject *v)
break;
}
if (skip_leading_underscores) {
if (PyUnicode_READY(name) == -1) {
Py_DECREF(name);
err = -1;
break;
}
if (PyUnicode_READ_CHAR(name, 0) == '_') {
Py_DECREF(name);
continue;

View file

@ -21,8 +21,6 @@ static PyObject *_Py_strhex_impl(const char* argbuf, const Py_ssize_t arglen,
return NULL;
}
if (PyUnicode_Check(sep)) {
if (PyUnicode_READY(sep))
return NULL;
if (PyUnicode_KIND(sep) != PyUnicode_1BYTE_KIND) {
PyErr_SetString(PyExc_ValueError, "sep must be ASCII.");
return NULL;