THRIFT-3613 Port Python C extension to Python 3
Client: Python
Patch: Nobuaki Sukegawa
This closes #845
diff --git a/lib/py/src/ext/module.cpp b/lib/py/src/ext/module.cpp
index 82e3fe7..5ffc155 100644
--- a/lib/py/src/ext/module.cpp
+++ b/lib/py/src/ext/module.cpp
@@ -142,6 +142,24 @@
{NULL, NULL, 0, NULL} /* Sentinel */
};
+#if PY_MAJOR_VERSION >= 3
+
+static struct PyModuleDef ThriftFastBinaryDef = {PyModuleDef_HEAD_INIT,
+ "thrift.protocol.fastbinary",
+ NULL,
+ 0,
+ ThriftFastBinaryMethods,
+ NULL,
+ NULL,
+ NULL,
+ NULL};
+
+#define INITERROR return NULL;
+
+PyObject* PyInit_fastbinary() {
+
+#else
+
#define INITERROR return;
void initfastbinary() {
@@ -150,6 +168,8 @@
if (PycStringIO == NULL)
INITERROR
+#endif
+
const rlim_t kStackSize = 16 * 1024 * 1024; // min stack size = 16 MB
struct rlimit rl;
int result;
@@ -181,9 +201,16 @@
#undef INIT_INTERN_STRING
PyObject* module =
+#if PY_MAJOR_VERSION >= 3
+ PyModule_Create(&ThriftFastBinaryDef);
+#else
Py_InitModule("thrift.protocol.fastbinary", ThriftFastBinaryMethods);
+#endif
if (module == NULL)
INITERROR;
+#if PY_MAJOR_VERSION >= 3
+ return module;
+#endif
}
}