Commit 4fad8beb authored by Stefan Behnel's avatar Stefan Behnel

call PyUnicode_READY() during unicode indexing to comply with C-API constraints

parent 0d3af956
......@@ -10011,6 +10011,9 @@ proto = '''
__Pyx_GetItemInt_Unicode_Generic(o, to_py_func(i)))
static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Fast(PyObject* ustring, Py_ssize_t i) {
#if CYTHON_PEP393_ENABLED
if (unlikely(__Pyx_PyUnicode_READY(ustring) < 0)) return (Py_UCS4)-1;
#endif
const Py_ssize_t length = __Pyx_PyUnicode_GET_LENGTH(ustring);
if (likely((0 <= i) & (i < length))) {
return __Pyx_PyUnicode_READ_CHAR(ustring, i);
......@@ -10029,6 +10032,12 @@ static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Generic(PyObject* ustring,
uchar_string = PyObject_GetItem(ustring, j);
Py_DECREF(j);
if (!uchar_string) return (Py_UCS4)-1;
#if CYTHON_PEP393_ENABLED
if (unlikely(__Pyx_PyUnicode_READY(uchar_string) < 0)) {
Py_DECREF(uchar_string);
return (Py_UCS4)-1;
}
#endif
uchar = __Pyx_PyUnicode_READ_CHAR(uchar_string, 0);
Py_DECREF(uchar_string);
return uchar;
......
......@@ -119,11 +119,14 @@
/* new Py3.3 unicode type (PEP 393) */
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
#define CYTHON_PEP393_ENABLED 1
#define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ? \
0 : _PyUnicode_Ready((PyObject *)(op)))
#define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
#define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
#define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i)
#else
#define CYTHON_PEP393_ENABLED 0
#define __Pyx_PyUnicode_READY(op) (0)
#define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
#define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
/* (k=k) => avoid unused variable warning due to macro: */
......
......@@ -428,7 +428,7 @@ static CYTHON_INLINE int __Pyx_init_unicode_iteration(
static CYTHON_INLINE int __Pyx_init_unicode_iteration(
PyObject* ustring, Py_ssize_t *length, void** data, int *kind) {
#if CYTHON_PEP393_ENABLED
if (unlikely(PyUnicode_READY(ustring) < 0)) return -1;
if (unlikely(__Pyx_PyUnicode_READY(ustring) < 0)) return -1;
*kind = PyUnicode_KIND(ustring);
*length = PyUnicode_GET_LENGTH(ustring);
*data = PyUnicode_DATA(ustring);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment