|
15 | 15 | #define PYRABBITMQ_CONNECTION_ERROR 0x10 |
16 | 16 | #define PYRABBITMQ_CHANNEL_ERROR 0x20 |
17 | 17 |
|
| 18 | +#define PYRABBITMQ_MODULE_NAME "_librabbitmq" |
| 19 | +#define PYRABBITMQ_MODULE_DESC "Hand-made wrapper for librabbitmq." |
| 20 | + |
18 | 21 | /* ------: Private Prototypes :------------------------------------------- */ |
19 | 22 | PyMODINIT_FUNC init_librabbitmq(void); |
20 | 23 |
|
@@ -2242,16 +2245,35 @@ static PyMethodDef PyRabbitMQ_functions[] = { |
2242 | 2245 | {NULL, NULL, 0, NULL} |
2243 | 2246 | }; |
2244 | 2247 |
|
2245 | | -PyMODINIT_FUNC init_librabbitmq(void) |
| 2248 | +#if PY_MAJOR_VERSION >= 3 |
| 2249 | + static struct PyModuleDef PyRabbitMQ_moduledef = { |
| 2250 | + PyModuleDef_HEAD_INIT, |
| 2251 | + PYRABBITMQ_MODULE_NAME, /* m_name */ |
| 2252 | + PYRABBITMQ_MODULE_DESC, /* m_doc */ |
| 2253 | + -1, /* m_size */ |
| 2254 | + PyRabbitMQ_functions, /* m_methods */ |
| 2255 | + NULL, /* m_reload */ |
| 2256 | + NULL, /* m_traverse */ |
| 2257 | + NULL, /* m_clear */ |
| 2258 | + NULL, /* m_free */ |
| 2259 | + }; |
| 2260 | +#endif |
| 2261 | + |
| 2262 | +PYRABBITMQ_MOD_INIT(_librabbitmq) |
2246 | 2263 | { |
2247 | 2264 | PyObject *module, *socket_module; |
2248 | 2265 |
|
2249 | 2266 | if (PyType_Ready(&PyRabbitMQ_ConnectionType) < 0) { |
2250 | 2267 | return; |
2251 | 2268 | } |
2252 | 2269 |
|
2253 | | - module = Py_InitModule3("_librabbitmq", PyRabbitMQ_functions, |
2254 | | - "Hand-made wrapper for librabbitmq."); |
| 2270 | +#if PY_MAJOR_VERSION >= 3 |
| 2271 | + module = PyModule_Create(&PyRabbitMQ_moduledef); |
| 2272 | +#else |
| 2273 | + module = Py_InitModule3(PYRABBITMQ_MODULE_NAME, PyRabbitMQ_functions, |
| 2274 | + PYRABBITMQ_MODULE_DESC); |
| 2275 | +#endif |
| 2276 | + |
2255 | 2277 | if (module == NULL) { |
2256 | 2278 | return; |
2257 | 2279 | } |
@@ -2281,5 +2303,9 @@ PyMODINIT_FUNC init_librabbitmq(void) |
2281 | 2303 | "_librabbitmq.ChannelError", NULL, NULL); |
2282 | 2304 | PyModule_AddObject(module, "ChannelError", |
2283 | 2305 | (PyObject *)PyRabbitMQExc_ChannelError); |
| 2306 | +#if PY_MAJOR_VERSION >= 3 |
| 2307 | + return module; |
| 2308 | +#else |
2284 | 2309 | return; |
| 2310 | +#endif |
2285 | 2311 | } |
0 commit comments