Skip to content
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
5 changes: 4 additions & 1 deletion Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,10 @@ idna_converter(PyObject *obj, struct maybe_idna *data)
len = PyByteArray_Size(obj);
}
else if (PyUnicode_Check(obj)) {
if (PyUnicode_READY(obj) == 0 && PyUnicode_IS_COMPACT_ASCII(obj)) {
if (PyUnicode_READY(obj) == -1) {
return 0;
}
if (PyUnicode_IS_COMPACT_ASCII(obj)) {
data->buf = PyUnicode_DATA(obj);
len = PyUnicode_GET_LENGTH(obj);
}
Expand Down
6 changes: 5 additions & 1 deletion Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ all_name_chars(PyObject *o)
};
const unsigned char *s, *e;

if (PyUnicode_READY(o) == -1 || !PyUnicode_IS_ASCII(o))
if (!PyUnicode_IS_ASCII(o))
return 0;

s = PyUnicode_1BYTE_DATA(o);
Expand Down Expand Up @@ -64,6 +64,10 @@ intern_string_constants(PyObject *tuple)
for (i = PyTuple_GET_SIZE(tuple); --i >= 0; ) {
PyObject *v = PyTuple_GET_ITEM(tuple, i);
if (PyUnicode_CheckExact(v)) {
if (PyUnicode_READY(v) == -1) {
PyErr_Clear();
continue;
}
if (all_name_chars(v)) {
PyObject *w = v;
PyUnicode_InternInPlace(&v);
Expand Down
6 changes: 3 additions & 3 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class object "PyObject *" "&PyBaseObject_Type"
#define MCACHE_HASH_METHOD(type, name) \
MCACHE_HASH((type)->tp_version_tag, \
((PyASCIIObject *)(name))->hash)
#define MCACHE_CACHEABLE_NAME(name) \
PyUnicode_CheckExact(name) && \
PyUnicode_READY(name) != -1 && \
#define MCACHE_CACHEABLE_NAME(name) \
PyUnicode_CheckExact(name) && \
PyUnicode_IS_READY(name) && \
PyUnicode_GET_LENGTH(name) <= MCACHE_MAX_ATTR_SIZE

struct method_cache_entry {
Expand Down
10 changes: 8 additions & 2 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4184,10 +4184,13 @@ PyUnicode_ReadChar(PyObject *unicode, Py_ssize_t index)
void *data;
int kind;

if (!PyUnicode_Check(unicode) || PyUnicode_READY(unicode) == -1) {
if (!PyUnicode_Check(unicode)) {
PyErr_BadArgument();
return (Py_UCS4)-1;
}
if (PyUnicode_READY(unicode) == -1) {
return (Py_UCS4)-1;
}
if (index < 0 || index >= PyUnicode_GET_LENGTH(unicode)) {
PyErr_SetString(PyExc_IndexError, "string index out of range");
return (Py_UCS4)-1;
Expand Down Expand Up @@ -11667,10 +11670,13 @@ unicode_getitem(PyObject *self, Py_ssize_t index)
enum PyUnicode_Kind kind;
Py_UCS4 ch;

if (!PyUnicode_Check(self) || PyUnicode_READY(self) == -1) {
if (!PyUnicode_Check(self)) {
PyErr_BadArgument();
return NULL;
}
if (PyUnicode_READY(self) == -1) {
return NULL;
}
if (index < 0 || index >= PyUnicode_GET_LENGTH(self)) {
PyErr_SetString(PyExc_IndexError, "string index out of range");
return NULL;
Expand Down
17 changes: 10 additions & 7 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -5021,13 +5021,16 @@ import_all_from(PyObject *locals, PyObject *v)
PyErr_Clear();
break;
}
if (skip_leading_underscores &&
PyUnicode_Check(name) &&
PyUnicode_READY(name) != -1 &&
PyUnicode_READ_CHAR(name, 0) == '_')
{
Py_DECREF(name);
continue;
if (skip_leading_underscores && PyUnicode_Check(name)) {
if (PyUnicode_READY(name) == -1) {
Py_DECREF(name);
err = -1;
break;
}
if (PyUnicode_READ_CHAR(name, 0) == '_') {
Py_DECREF(name);
continue;
}
}
value = PyObject_GetAttr(v, name);
if (value == NULL)
Expand Down