Commit 0a59054c authored by Ben Webb's avatar Ben Webb Committed by Jie Luo

Add Python 3.7 compatibility (#4862)

Compilation of Python wrappers fails with Python 3.7 because
the Python folks changed their C API such that
PyUnicode_AsUTF8AndSize() now returns a const char* rather
than a char*. Add a patch to work around. Relates #4086.
parent 029dbfd7
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
#endif #endif
#define PyString_AsStringAndSize(ob, charpp, sizep) \ #define PyString_AsStringAndSize(ob, charpp, sizep) \
(PyUnicode_Check(ob)? \ (PyUnicode_Check(ob)? \
((*(charpp) = PyUnicode_AsUTF8AndSize(ob, (sizep))) == NULL? -1: 0): \ ((*(charpp) = const_cast<char*>(PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL? -1: 0): \
PyBytes_AsStringAndSize(ob, (charpp), (sizep))) PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
#endif #endif
......
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
#endif #endif
#define PyString_AsStringAndSize(ob, charpp, sizep) \ #define PyString_AsStringAndSize(ob, charpp, sizep) \
(PyUnicode_Check(ob)? \ (PyUnicode_Check(ob)? \
((*(charpp) = PyUnicode_AsUTF8AndSize(ob, (sizep))) == NULL? -1: 0): \ ((*(charpp) = const_cast<char*>(PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL? -1: 0): \
PyBytes_AsStringAndSize(ob, (charpp), (sizep))) PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
#endif #endif
......
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
#endif #endif
#define PyString_AsStringAndSize(ob, charpp, sizep) \ #define PyString_AsStringAndSize(ob, charpp, sizep) \
(PyUnicode_Check(ob)? \ (PyUnicode_Check(ob)? \
((*(charpp) = PyUnicode_AsUTF8AndSize(ob, (sizep))) == NULL? -1: 0): \ ((*(charpp) = const_cast<char*>(PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL? -1: 0): \
PyBytes_AsStringAndSize(ob, (charpp), (sizep))) PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
#endif #endif
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
#endif #endif
#define PyString_AsStringAndSize(ob, charpp, sizep) \ #define PyString_AsStringAndSize(ob, charpp, sizep) \
(PyUnicode_Check(ob)? \ (PyUnicode_Check(ob)? \
((*(charpp) = PyUnicode_AsUTF8AndSize(ob, (sizep))) == NULL? -1: 0): \ ((*(charpp) = const_cast<char*>(PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL? -1: 0): \
PyBytes_AsStringAndSize(ob, (charpp), (sizep))) PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
#endif #endif
......
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
(PyUnicode_Check(ob)? PyUnicode_AsUTF8(ob): PyBytes_AsString(ob)) (PyUnicode_Check(ob)? PyUnicode_AsUTF8(ob): PyBytes_AsString(ob))
#define PyString_AsStringAndSize(ob, charpp, sizep) \ #define PyString_AsStringAndSize(ob, charpp, sizep) \
(PyUnicode_Check(ob)? \ (PyUnicode_Check(ob)? \
((*(charpp) = PyUnicode_AsUTF8AndSize(ob, (sizep))) == NULL? -1: 0): \ ((*(charpp) = const_cast<char*>(PyUnicode_AsUTF8AndSize(ob, (sizep)))) == NULL? -1: 0): \
PyBytes_AsStringAndSize(ob, (charpp), (sizep))) PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
#endif #endif
#endif #endif
...@@ -1529,7 +1529,7 @@ PyObject* HasField(CMessage* self, PyObject* arg) { ...@@ -1529,7 +1529,7 @@ PyObject* HasField(CMessage* self, PyObject* arg) {
return NULL; return NULL;
} }
#else #else
field_name = PyUnicode_AsUTF8AndSize(arg, &size); field_name = const_cast<char*>(PyUnicode_AsUTF8AndSize(arg, &size));
if (!field_name) { if (!field_name) {
return NULL; return NULL;
} }
......
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