Commit 74a080f4 authored by Stefan Behnel's avatar Stefan Behnel

adapted __Pyx_PyObject_AsPy_UNICODE() to PEP 393

parent 0b27c6a5
...@@ -1053,20 +1053,31 @@ static CYTHON_INLINE Py_UNICODE __Pyx_PyObject_AsPy_UNICODE(PyObject*); ...@@ -1053,20 +1053,31 @@ static CYTHON_INLINE Py_UNICODE __Pyx_PyObject_AsPy_UNICODE(PyObject*);
''', ''',
impl=''' impl='''
static CYTHON_INLINE Py_UNICODE __Pyx_PyObject_AsPy_UNICODE(PyObject* x) { static CYTHON_INLINE Py_UNICODE __Pyx_PyObject_AsPy_UNICODE(PyObject* x) {
static long maxval = 0;
long ival; long ival;
#ifdef CYTHON_PEP393_ENABLED
const long maxval = 1114111;
#else
static long maxval = 0;
#endif
if (PyUnicode_Check(x)) { if (PyUnicode_Check(x)) {
if (unlikely(PyUnicode_GET_SIZE(x) != 1)) { if (unlikely(__Pyx_PyUnicode_GET_LENGTH(x) != 1)) {
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"only single character unicode strings can be converted to Py_UNICODE, " "only single character unicode strings can be converted to Py_UNICODE, "
"got length %"PY_FORMAT_SIZE_T"d", PyUnicode_GET_SIZE(x)); "got length %"PY_FORMAT_SIZE_T"d", __Pyx_PyUnicode_GET_LENGTH(x));
return (Py_UNICODE)-1; return (Py_UNICODE)-1;
} }
#ifdef CYTHON_PEP393_ENABLED
ival = PyUnicode_READ_CHAR(x, 0);
#else
return PyUnicode_AS_UNICODE(x)[0]; return PyUnicode_AS_UNICODE(x)[0];
} #endif
} else {
#ifndef CYTHON_PEP393_ENABLED
if (unlikely(!maxval)) if (unlikely(!maxval))
maxval = (long)PyUnicode_GetMax(); maxval = (long)PyUnicode_GetMax();
#endif
ival = __Pyx_PyInt_AsLong(x); ival = __Pyx_PyInt_AsLong(x);
}
if (unlikely(ival < 0)) { if (unlikely(ival < 0)) {
if (!PyErr_Occurred()) if (!PyErr_Occurred())
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
......
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