aboutsummaryrefslogtreecommitdiff
path: root/python/google/protobuf/pyext/message.cc
diff options
context:
space:
mode:
authorDan O'Reilly <oreilldf@gmail.com>2015-08-26 20:30:41 -0400
committerDan O'Reilly <oreilldf@gmail.com>2015-08-31 16:42:31 -0400
commitd9598ca55db13bcbc8c748ed7a517f12a069962a (patch)
treef836b2757cb6e5cd223827ffceeff2c24eb87f06 /python/google/protobuf/pyext/message.cc
parent0087da9d4775f79c67362cc89c653f3a33a9bae2 (diff)
downloadprotobuf-d9598ca55db13bcbc8c748ed7a517f12a069962a.tar.gz
protobuf-d9598ca55db13bcbc8c748ed7a517f12a069962a.tar.bz2
protobuf-d9598ca55db13bcbc8c748ed7a517f12a069962a.zip
Fix Python 3.4 cpp implementation
Fixes the ScalarMapContainer/MessageMapContainer implementations on Python 3.4, by dynamically allocating their PyTypeObjects using PyType_FromSpecWithBases, instead of statically allocating them. This is necessary because Python 3.4+ disallows statically allocating a class with a dynamically allocated parent. Signed-off-by: Dan O'Reilly <oreilldf@gmail.com>
Diffstat (limited to 'python/google/protobuf/pyext/message.cc')
-rw-r--r--python/google/protobuf/pyext/message.cc16
1 files changed, 16 insertions, 0 deletions
diff --git a/python/google/protobuf/pyext/message.cc b/python/google/protobuf/pyext/message.cc
index 62c7c478..04544cad 100644
--- a/python/google/protobuf/pyext/message.cc
+++ b/python/google/protobuf/pyext/message.cc
@@ -2863,6 +2863,14 @@ bool InitProto2MessageModule(PyObject *m) {
}
Py_INCREF(mutable_mapping);
+#if PY_MAJOR_VERSION >= 3
+ PyObject* bases = PyTuple_New(1);
+ PyTuple_SET_ITEM(bases, 0, mutable_mapping.get());
+
+ ScalarMapContainer_Type =
+ PyType_FromSpecWithBases(&ScalarMapContainer_Type_spec, bases);
+ PyModule_AddObject(m, "ScalarMapContainer", ScalarMapContainer_Type);
+#else
ScalarMapContainer_Type.tp_base =
reinterpret_cast<PyTypeObject*>(mutable_mapping.get());
@@ -2872,6 +2880,7 @@ bool InitProto2MessageModule(PyObject *m) {
PyModule_AddObject(m, "ScalarMapContainer",
reinterpret_cast<PyObject*>(&ScalarMapContainer_Type));
+#endif
if (PyType_Ready(&ScalarMapIterator_Type) < 0) {
return false;
@@ -2880,6 +2889,12 @@ bool InitProto2MessageModule(PyObject *m) {
PyModule_AddObject(m, "ScalarMapIterator",
reinterpret_cast<PyObject*>(&ScalarMapIterator_Type));
+
+#if PY_MAJOR_VERSION >= 3
+ MessageMapContainer_Type =
+ PyType_FromSpecWithBases(&MessageMapContainer_Type_spec, bases);
+ PyModule_AddObject(m, "MessageMapContainer", MessageMapContainer_Type);
+#else
Py_INCREF(mutable_mapping);
MessageMapContainer_Type.tp_base =
reinterpret_cast<PyTypeObject*>(mutable_mapping.get());
@@ -2890,6 +2905,7 @@ bool InitProto2MessageModule(PyObject *m) {
PyModule_AddObject(m, "MessageMapContainer",
reinterpret_cast<PyObject*>(&MessageMapContainer_Type));
+#endif
if (PyType_Ready(&MessageMapIterator_Type) < 0) {
return false;