summaryrefslogtreecommitdiffstats
path: root/Modules/cjkcodecs
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/cjkcodecs')
-rw-r--r--Modules/cjkcodecs/cjkcodecs.h18
-rw-r--r--Modules/cjkcodecs/multibytecodec.c29
2 files changed, 38 insertions, 9 deletions
diff --git a/Modules/cjkcodecs/cjkcodecs.h b/Modules/cjkcodecs/cjkcodecs.h
index fb6b5ce..89c644c 100644
--- a/Modules/cjkcodecs/cjkcodecs.h
+++ b/Modules/cjkcodecs/cjkcodecs.h
@@ -389,12 +389,24 @@ errorexit:
#endif
#define I_AM_A_MODULE_FOR(loc) \
- void \
- init_codecs_##loc(void) \
+ static struct PyModuleDef __module = { \
+ PyModuleDef_HEAD_INIT, \
+ "_codecs_"#loc, \
+ NULL, \
+ 0, \
+ __methods, \
+ NULL, \
+ NULL, \
+ NULL, \
+ NULL \
+ }; \
+ PyObject* \
+ PyInit__codecs_##loc(void) \
{ \
- PyObject *m = Py_InitModule("_codecs_" #loc, __methods);\
+ PyObject *m = PyModule_Create(&__module); \
if (m != NULL) \
(void)register_maps(m); \
+ return m; \
}
#endif
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index 26dd8dd..546f4e2 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -1778,8 +1778,21 @@ static struct PyMethodDef __methods[] = {
{NULL, NULL},
};
+
+static struct PyModuleDef _multibytecodecmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_multibytecodec",
+ NULL,
+ -1,
+ __methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_multibytecodec(void)
+PyInit__multibytecodec(void)
{
int i;
PyObject *m;
@@ -1792,20 +1805,24 @@ init_multibytecodec(void)
};
if (PyType_Ready(&MultibyteCodec_Type) < 0)
- return;
+ return NULL;
- m = Py_InitModule("_multibytecodec", __methods);
+ m = PyModule_Create(&_multibytecodecmodule);
if (m == NULL)
- return;
+ return NULL;
for (i = 0; typelist[i] != NULL; i++) {
if (PyType_Ready(typelist[i]) < 0)
- return;
+ return NULL;
Py_INCREF(typelist[i]);
PyModule_AddObject(m, typelist[i]->tp_name,
(PyObject *)typelist[i]);
}
- if (PyErr_Occurred())
+ if (PyErr_Occurred()) {
Py_FatalError("can't initialize the _multibytecodec module");
+ Py_DECREF(m);
+ m = NULL;
+ }
+ return m;
}