Add Python 3.7 compatibility
authorBen Webb <ben@salilab.org>
Tue, 3 Jul 2018 16:51:09 +0000 (09:51 -0700)
committerLaszlo Boszormenyi (GCS) <gcs@debian.org>
Mon, 26 Nov 2018 23:23:31 +0000 (23:23 +0000)
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.

Gbp-Pq: Name Add_Python_3.7_compatibility.patch

python/google/protobuf/pyext/descriptor.cc
python/google/protobuf/pyext/descriptor_containers.cc
python/google/protobuf/pyext/descriptor_pool.cc
python/google/protobuf/pyext/message.cc

index 8af0cb1289f86c02d7f19862915b27a0702499fe..19a1c38a62e12213e09042578f1a5c52a102bf94 100644 (file)
@@ -56,7 +56,7 @@
   #endif
   #define PyString_AsStringAndSize(ob, charpp, sizep) \
     (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)))
 #endif
 
index bc007f7efa551b1b5430bce6ba05a24f5bea50a1..0153664f504f2985f61ca87396833e5607dbc68f 100644 (file)
@@ -66,7 +66,7 @@
   #endif
   #define PyString_AsStringAndSize(ob, charpp, sizep) \
     (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)))
 #endif
 
index 95882aeb35a9a5cc20d26c2407f9d3278036680b..962accc6e9b4d4c922de4dace414da9812862c57 100644 (file)
@@ -48,7 +48,7 @@
   #endif
   #define PyString_AsStringAndSize(ob, charpp, sizep) \
     (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)))
 #endif
 
index 5893533adf5d928ef294b57101d88b1ae0611a6d..31094b7e1003d4630abe433c010bdec91d4ffdc8 100644 (file)
@@ -79,7 +79,7 @@
     (PyUnicode_Check(ob)? PyUnicode_AsUTF8(ob): PyBytes_AsString(ob))
   #define PyString_AsStringAndSize(ob, charpp, sizep) \
     (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)))
   #endif
 #endif
@@ -1529,7 +1529,7 @@ PyObject* HasField(CMessage* self, PyObject* arg) {
     return NULL;
   }
 #else
-  field_name = PyUnicode_AsUTF8AndSize(arg, &size);
+  field_name = const_cast<char*>(PyUnicode_AsUTF8AndSize(arg, &size));
   if (!field_name) {
     return NULL;
   }