[3.6] bpo-31393: Fix the use of PyUnicode_READY(). (GH-3451). (#3453) · python/cpython@ddb536b (original) (raw)
5 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1464,7 +1464,10 @@ idna_converter(PyObject *obj, struct maybe_idna *data) | ||
1464 | 1464 | len = PyByteArray_Size(obj); |
1465 | 1465 | } |
1466 | 1466 | else if (PyUnicode_Check(obj)) { |
1467 | -if (PyUnicode_READY(obj) == 0 && PyUnicode_IS_COMPACT_ASCII(obj)) { | |
1467 | +if (PyUnicode_READY(obj) == -1) { | |
1468 | +return 0; | |
1469 | + } | |
1470 | +if (PyUnicode_IS_COMPACT_ASCII(obj)) { | |
1468 | 1471 | data->buf = PyUnicode_DATA(obj); |
1469 | 1472 | len = PyUnicode_GET_LENGTH(obj); |
1470 | 1473 | } |
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
@@ -22,8 +22,7 @@ all_name_chars(PyObject *o) | |||
22 | 22 | static const unsigned char *name_chars = (unsigned char *)NAME_CHARS; | |
23 | 23 | const unsigned char *s, *e; | |
24 | 24 | ||
25 | -if (!PyUnicode_Check(o) | | PyUnicode_READY(o) == -1 | |
26 | - !PyUnicode_IS_ASCII(o)) | ||
25 | +if (!PyUnicode_IS_ASCII(o)) | ||
27 | 26 | return 0; | |
28 | 27 | ||
29 | 28 | if (ok_name_char[*name_chars] == 0) { | |
@@ -64,6 +63,10 @@ intern_string_constants(PyObject *tuple) | |||
64 | 63 | for (i = PyTuple_GET_SIZE(tuple); --i >= 0; ) { | |
65 | 64 | PyObject *v = PyTuple_GET_ITEM(tuple, i); | |
66 | 65 | if (PyUnicode_CheckExact(v)) { | |
66 | +if (PyUnicode_READY(v) == -1) { | ||
67 | +PyErr_Clear(); | ||
68 | +continue; | ||
69 | + } | ||
67 | 70 | if (all_name_chars(v)) { | |
68 | 71 | PyObject *w = v; | |
69 | 72 | PyUnicode_InternInPlace(&v); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -22,9 +22,9 @@ | ||
22 | 22 | #define MCACHE_HASH_METHOD(type, name) \ |
23 | 23 | MCACHE_HASH((type)->tp_version_tag, \ |
24 | 24 | ((PyASCIIObject *)(name))->hash) |
25 | -#define MCACHE_CACHEABLE_NAME(name) \ | |
26 | - PyUnicode_CheckExact(name) && \ | |
27 | -PyUnicode_READY(name) != -1 && \ | |
25 | +#define MCACHE_CACHEABLE_NAME(name) \ | |
26 | + PyUnicode_CheckExact(name) && \ | |
27 | +PyUnicode_IS_READY(name) && \ | |
28 | 28 | PyUnicode_GET_LENGTH(name) <= MCACHE_MAX_ATTR_SIZE |
29 | 29 | |
30 | 30 | struct method_cache_entry { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -4210,10 +4210,13 @@ PyUnicode_ReadChar(PyObject *unicode, Py_ssize_t index) | ||
4210 | 4210 | void *data; |
4211 | 4211 | int kind; |
4212 | 4212 | |
4213 | -if (!PyUnicode_Check(unicode) | | |
4213 | +if (!PyUnicode_Check(unicode)) { | |
4214 | 4214 | PyErr_BadArgument(); |
4215 | 4215 | return (Py_UCS4)-1; |
4216 | 4216 | } |
4217 | +if (PyUnicode_READY(unicode) == -1) { | |
4218 | +return (Py_UCS4)-1; | |
4219 | + } | |
4217 | 4220 | if (index < 0 | |
4218 | 4221 | PyErr_SetString(PyExc_IndexError, "string index out of range"); |
4219 | 4222 | return (Py_UCS4)-1; |
@@ -11706,10 +11709,13 @@ unicode_getitem(PyObject *self, Py_ssize_t index) | ||
11706 | 11709 | enum PyUnicode_Kind kind; |
11707 | 11710 | Py_UCS4 ch; |
11708 | 11711 | |
11709 | -if (!PyUnicode_Check(self) | | |
11712 | +if (!PyUnicode_Check(self)) { | |
11710 | 11713 | PyErr_BadArgument(); |
11711 | 11714 | return NULL; |
11712 | 11715 | } |
11716 | +if (PyUnicode_READY(self) == -1) { | |
11717 | +return NULL; | |
11718 | + } | |
11713 | 11719 | if (index < 0 | |
11714 | 11720 | PyErr_SetString(PyExc_IndexError, "string index out of range"); |
11715 | 11721 | return NULL; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -5307,13 +5307,16 @@ import_all_from(PyObject *locals, PyObject *v) | ||
5307 | 5307 | PyErr_Clear(); |
5308 | 5308 | break; |
5309 | 5309 | } |
5310 | -if (skip_leading_underscores && | |
5311 | -PyUnicode_Check(name) && | |
5312 | -PyUnicode_READY(name) != -1 && | |
5313 | -PyUnicode_READ_CHAR(name, 0) == '_') | |
5314 | - { | |
5315 | -Py_DECREF(name); | |
5316 | -continue; | |
5310 | +if (skip_leading_underscores && PyUnicode_Check(name)) { | |
5311 | +if (PyUnicode_READY(name) == -1) { | |
5312 | +Py_DECREF(name); | |
5313 | +err = -1; | |
5314 | +break; | |
5315 | + } | |
5316 | +if (PyUnicode_READ_CHAR(name, 0) == '_') { | |
5317 | +Py_DECREF(name); | |
5318 | +continue; | |
5319 | + } | |
5317 | 5320 | } |
5318 | 5321 | value = PyObject_GetAttr(v, name); |
5319 | 5322 | if (value == NULL) |