diff options
author | Matus Valo <matusvalo@gmail.com> | 2017-09-10 12:17:21 -0700 |
---|---|---|
committer | Matus Valo <matusvalo@gmail.com> | 2017-09-10 12:17:21 -0700 |
commit | 54cbb7686d521855e21e52d869a36ffc6853caec (patch) | |
tree | 60bc3691691a17d44057388b1876f45f88963840 | |
parent | 1f87e8797a4163e145a5794ddab2f4c4754d5fa2 (diff) | |
download | librabbitmq-54cbb7686d521855e21e52d869a36ffc6853caec.tar.gz |
Module initialization ported to python3
-rw-r--r-- | Modules/_librabbitmq/connection.c | 32 | ||||
-rw-r--r-- | Modules/_librabbitmq/connection.h | 6 |
2 files changed, 35 insertions, 3 deletions
diff --git a/Modules/_librabbitmq/connection.c b/Modules/_librabbitmq/connection.c index a77a976..b3979eb 100644 --- a/Modules/_librabbitmq/connection.c +++ b/Modules/_librabbitmq/connection.c @@ -15,6 +15,9 @@ #define PYRABBITMQ_CONNECTION_ERROR 0x10 #define PYRABBITMQ_CHANNEL_ERROR 0x20 +#define PYRABBITMQ_MODULE_NAME "_librabbitmq" +#define PYRABBITMQ_MODULE_DESC "Hand-made wrapper for librabbitmq." + /* ------: Private Prototypes :------------------------------------------- */ PyMODINIT_FUNC init_librabbitmq(void); @@ -2242,7 +2245,21 @@ static PyMethodDef PyRabbitMQ_functions[] = { {NULL, NULL, 0, NULL} }; -PyMODINIT_FUNC init_librabbitmq(void) +#if PY_MAJOR_VERSION >= 3 + static struct PyModuleDef PyRabbitMQ_moduledef = { + PyModuleDef_HEAD_INIT, + PYRABBITMQ_MODULE_NAME, /* m_name */ + PYRABBITMQ_MODULE_DESC, /* m_doc */ + -1, /* m_size */ + PyRabbitMQ_functions, /* m_methods */ + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL, /* m_free */ + }; +#endif + +PYRABBITMQ_MOD_INIT(_librabbitmq) { PyObject *module, *socket_module; @@ -2250,8 +2267,13 @@ PyMODINIT_FUNC init_librabbitmq(void) return; } - module = Py_InitModule3("_librabbitmq", PyRabbitMQ_functions, - "Hand-made wrapper for librabbitmq."); +#if PY_MAJOR_VERSION >= 3 + module = PyModule_Create(&PyRabbitMQ_moduledef); +#else + module = Py_InitModule3(PYRABBITMQ_MODULE_NAME, PyRabbitMQ_functions, + PYRABBITMQ_MODULE_DESC); +#endif + if (module == NULL) { return; } @@ -2281,5 +2303,9 @@ PyMODINIT_FUNC init_librabbitmq(void) "_librabbitmq.ChannelError", NULL, NULL); PyModule_AddObject(module, "ChannelError", (PyObject *)PyRabbitMQExc_ChannelError); +#if PY_MAJOR_VERSION >= 3 + return module; +#else return; +#endif } diff --git a/Modules/_librabbitmq/connection.h b/Modules/_librabbitmq/connection.h index c709d37..0e2c3d0 100644 --- a/Modules/_librabbitmq/connection.h +++ b/Modules/_librabbitmq/connection.h @@ -14,6 +14,12 @@ # define TP_FLAGS (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE) #endif +#if PY_MAJOR_VERSION >= 3 + #define PYRABBITMQ_MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void) +#else + #define PYRABBITMQ_MOD_INIT(name) PyMODINIT_FUNC init##name(void) +#endif + #if PY_VERSION_HEX >= 0x03000000 /* 3.0 and up */ # define BUILD_METHOD_NAME PyUnicode_FromString |