summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2021-04-13 11:47:47 +0200
committerStefan Behnel <stefan_ml@behnel.de>2021-04-13 11:47:47 +0200
commit7ce24bc7381c83972e5b6d24bbb8e6ab610541fa (patch)
treebe30b1b9e0480de5b70751c2ce8fb47e8f4777ea
parent26c909bb06830afb553e569d3d9506b19b3e4494 (diff)
downloadcython-7ce24bc7381c83972e5b6d24bbb8e6ab610541fa.tar.gz
Replace usage of the seemingly CPython-internal Py_ISSPACE() macro by a dedicated inline function to make it work in C++ (where Py_ISSPACE() fails to link).
Closes https://github.com/cython/cython/issues/4111 Closes https://github.com/cython/cython/pull/4112
-rw-r--r--Cython/Utility/ModuleSetupCode.c4
-rw-r--r--Cython/Utility/Optimize.c10
2 files changed, 8 insertions, 6 deletions
diff --git a/Cython/Utility/ModuleSetupCode.c b/Cython/Utility/ModuleSetupCode.c
index 9d6c0e48a..2354c00a8 100644
--- a/Cython/Utility/ModuleSetupCode.c
+++ b/Cython/Utility/ModuleSetupCode.c
@@ -784,10 +784,6 @@ static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict,
#define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt)
#endif
-#if CYTHON_COMPILING_IN_PYPY && !defined(Py_ISSPACE)
- #define Py_ISSPACE(c) Py_UNICODE_ISSPACE(c)
-#endif
-
// ("..." % x) must call PyNumber_Remainder() if x is a string subclass that implements "__rmod__()".
#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
diff --git a/Cython/Utility/Optimize.c b/Cython/Utility/Optimize.c
index 83c848a74..f9637b670 100644
--- a/Cython/Utility/Optimize.c
+++ b/Cython/Utility/Optimize.c
@@ -897,6 +897,12 @@ parse_failure:
return -1.0;
}
+static CYTHON_INLINE int __Pyx__PyBytes_AsDouble_IsSpace(char ch) {
+ // see Py_ISSPACE() in CPython
+ // https://github.com/python/cpython/blob/master/Python/pyctype.c
+ return (ch == 0x20) | !((ch < 0x9) | (ch > 0xd));
+}
+
static CYTHON_UNUSED double __Pyx__PyBytes_AsDouble(PyObject *obj, const char* start, Py_ssize_t length) {
double value;
Py_ssize_t i, digits;
@@ -904,9 +910,9 @@ static CYTHON_UNUSED double __Pyx__PyBytes_AsDouble(PyObject *obj, const char* s
char *end;
// strip spaces at start and end
- while (Py_ISSPACE(*start))
+ while (__Pyx__PyBytes_AsDouble_IsSpace(*start))
start++;
- while (start < last - 1 && Py_ISSPACE(last[-1]))
+ while (start < last - 1 && __Pyx__PyBytes_AsDouble_IsSpace(last[-1]))
last--;
length = last - start;
if (unlikely(length <= 0)) goto fallback;