|
5 | 5 | #include <Python.h> |
6 | 6 | #include "CPy.h" |
7 | 7 |
|
8 | | -// Copied from cpython.git:Objects/unicodeobject.c. |
| 8 | +// Copied from cpython.git:Objects/unicodeobject.c@0ef4ffeefd1737c18dc9326133c7894d58108c2e. |
9 | 9 | #define BLOOM_MASK unsigned long |
10 | 10 | #define BLOOM(mask, ch) ((mask & (1UL << ((ch) & (BLOOM_WIDTH - 1))))) |
11 | 11 | #if LONG_BIT >= 128 |
|
18 | 18 | #error "LONG_BIT is smaller than 32" |
19 | 19 | #endif |
20 | 20 |
|
21 | | -// Copied from cpython.git:Objects/unicodeobject.c. This is needed for str.strip("..."). |
| 21 | +// Copied from cpython.git:Objects/unicodeobject.c@0ef4ffeefd1737c18dc9326133c7894d58108c2e. |
| 22 | +// This is needed for str.strip("..."). |
22 | 23 | static inline BLOOM_MASK |
23 | 24 | make_bloom_mask(int kind, const void* ptr, Py_ssize_t len) |
24 | 25 | { |
@@ -226,14 +227,18 @@ PyObject *CPyStr_RSplit(PyObject *str, PyObject *sep, CPyTagged max_split) { |
226 | 227 | return PyUnicode_RSplit(str, sep, temp_max_split); |
227 | 228 | } |
228 | 229 |
|
229 | | -// This function has been copied from _PyUnicode_XStrip in cpython.git:Objects/unicodeobject.c. |
| 230 | +// This function has been copied from _PyUnicode_XStrip in cpython.git:Objects/unicodeobject.c@0ef4ffeefd1737c18dc9326133c7894d58108c2e. |
230 | 231 | static PyObject *_PyStr_XStrip(PyObject *self, int striptype, PyObject *sepobj) { |
231 | 232 | const void *data; |
232 | 233 | int kind; |
233 | 234 | Py_ssize_t i, j, len; |
234 | 235 | BLOOM_MASK sepmask; |
235 | 236 | Py_ssize_t seplen; |
236 | 237 |
|
| 238 | + // This check is needed from Python 3.9 and earlier. |
| 239 | + if (PyUnicode_READY(self) == -1 || PyUnicode_READY(sepobj) == -1) |
| 240 | + return NULL; |
| 241 | + |
237 | 242 | kind = PyUnicode_KIND(self); |
238 | 243 | data = PyUnicode_DATA(self); |
239 | 244 | len = PyUnicode_GET_LENGTH(self); |
@@ -272,11 +277,15 @@ static PyObject *_PyStr_XStrip(PyObject *self, int striptype, PyObject *sepobj) |
272 | 277 | return PyUnicode_Substring(self, i, j); |
273 | 278 | } |
274 | 279 |
|
275 | | -// Copied from do_strip function in cpython.git/Objects/unicodeobject.c. |
| 280 | +// Copied from do_strip function in cpython.git/Objects/unicodeobject.c@0ef4ffeefd1737c18dc9326133c7894d58108c2e. |
276 | 281 | PyObject *_CPyStr_Strip(PyObject *self, int strip_type, PyObject *sep) { |
277 | 282 | if (sep == NULL || sep == Py_None) { |
278 | 283 | Py_ssize_t len, i, j; |
279 | 284 |
|
| 285 | + // This check is needed from Python 3.9 and earlier. |
| 286 | + if (PyUnicode_READY(self) == -1) |
| 287 | + return NULL; |
| 288 | + |
280 | 289 | len = PyUnicode_GET_LENGTH(self); |
281 | 290 |
|
282 | 291 | if (PyUnicode_IS_ASCII(self)) { |
|
0 commit comments