diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2008-06-11 05:26:20 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2008-06-11 05:26:20 (GMT) |
commit | 1a21451b1d73b65af949193208372e86bf308411 (patch) | |
tree | 8e98d7be9e249b011ae9380479656e5284ec0234 /Modules/cjkcodecs | |
parent | cdf94635d7e364f9ce1905bafa5b540f4d16147c (diff) | |
download | cpython-1a21451b1d73b65af949193208372e86bf308411.zip cpython-1a21451b1d73b65af949193208372e86bf308411.tar.gz cpython-1a21451b1d73b65af949193208372e86bf308411.tar.bz2 |
Implement PEP 3121: new module initialization and finalization API.
Diffstat (limited to 'Modules/cjkcodecs')
-rw-r--r-- | Modules/cjkcodecs/cjkcodecs.h | 18 | ||||
-rw-r--r-- | Modules/cjkcodecs/multibytecodec.c | 29 |
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; } |