summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-09-08 06:58:51 (GMT)
committerGitHub <noreply@github.com>2017-09-08 06:58:51 (GMT)
commite3b2b4b8d9e751b49e3550cb83ba39b54fdc377c (patch)
treee3cf5fd257df7ac82e2bd47811720daf22ce0666 /Objects
parent70c2dd306f575e8bc9edb10ced5c7a6a555d1c87 (diff)
downloadcpython-e3b2b4b8d9e751b49e3550cb83ba39b54fdc377c.zip
cpython-e3b2b4b8d9e751b49e3550cb83ba39b54fdc377c.tar.gz
cpython-e3b2b4b8d9e751b49e3550cb83ba39b54fdc377c.tar.bz2
bpo-31393: Fix the use of PyUnicode_READY(). (#3451)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/codeobject.c6
-rw-r--r--Objects/typeobject.c6
-rw-r--r--Objects/unicodeobject.c10
3 files changed, 16 insertions, 6 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index eee9bfe..adef625 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -27,7 +27,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);
@@ -63,6 +63,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);
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index b2154bb..a06cab7 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -30,9 +30,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 {
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index db1516d..c4d93fc 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -4185,10 +4185,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;
@@ -11668,10 +11671,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;