summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2008-06-11 05:26:20 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2008-06-11 05:26:20 (GMT)
commit1a21451b1d73b65af949193208372e86bf308411 (patch)
tree8e98d7be9e249b011ae9380479656e5284ec0234 /Modules
parentcdf94635d7e364f9ce1905bafa5b540f4d16147c (diff)
downloadcpython-1a21451b1d73b65af949193208372e86bf308411.zip
cpython-1a21451b1d73b65af949193208372e86bf308411.tar.gz
cpython-1a21451b1d73b65af949193208372e86bf308411.tar.bz2
Implement PEP 3121: new module initialization and finalization API.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_bisectmodule.c19
-rw-r--r--Modules/_bsddb.c24
-rw-r--r--Modules/_bytesio.c22
-rw-r--r--Modules/_codecsmodule.c16
-rw-r--r--Modules/_collectionsmodule.c29
-rw-r--r--Modules/_csv.c38
-rw-r--r--Modules/_ctypes/_ctypes.c64
-rw-r--r--Modules/_ctypes/_ctypes_test.c17
-rw-r--r--Modules/_curses_panel.c20
-rw-r--r--Modules/_cursesmodule.c22
-rw-r--r--Modules/_dbmmodule.c26
-rw-r--r--Modules/_elementtree.c28
-rw-r--r--Modules/_fileio.c22
-rw-r--r--Modules/_functoolsmodule.c26
-rw-r--r--Modules/_gdbmmodule.c24
-rw-r--r--Modules/_gestalt.c16
-rw-r--r--Modules/_hashopenssl.c22
-rw-r--r--Modules/_heapqmodule.c20
-rw-r--r--Modules/_json.c19
-rw-r--r--Modules/_localemodule.c20
-rw-r--r--Modules/_lsprof.c22
-rw-r--r--Modules/_randommodule.c22
-rw-r--r--Modules/_sqlite/module.c23
-rw-r--r--Modules/_sre.c25
-rw-r--r--Modules/_ssl.c30
-rw-r--r--Modules/_struct.c30
-rw-r--r--Modules/_testcapimodule.c20
-rw-r--r--Modules/_threadmodule.c26
-rw-r--r--Modules/_tkinter.c26
-rw-r--r--Modules/_weakref.c19
-rw-r--r--Modules/arraymodule.c26
-rw-r--r--Modules/atexitmodule.c22
-rw-r--r--Modules/audioop.c22
-rw-r--r--Modules/binascii.c26
-rw-r--r--Modules/bz2module.c20
-rw-r--r--Modules/cjkcodecs/cjkcodecs.h18
-rw-r--r--Modules/cjkcodecs/multibytecodec.c29
-rw-r--r--Modules/cmathmodule.c20
-rw-r--r--Modules/config.c.in16
-rw-r--r--Modules/cryptmodule.c17
-rw-r--r--Modules/datetimemodule.c61
-rw-r--r--Modules/errnomodule.c21
-rw-r--r--Modules/fcntlmodule.c20
-rw-r--r--Modules/fpectlmodule.c22
-rw-r--r--Modules/fpetestmodule.c22
-rw-r--r--Modules/gcmodule.c31
-rw-r--r--Modules/grpmodule.c20
-rw-r--r--Modules/itertoolsmodule.c28
-rwxr-xr-xModules/makesetup8
-rw-r--r--Modules/mathmodule.c19
-rw-r--r--Modules/md5module.c23
-rw-r--r--Modules/mmapmodule.c26
-rw-r--r--Modules/nismodule.c21
-rw-r--r--Modules/operator.c29
-rw-r--r--Modules/ossaudiodev.c25
-rw-r--r--Modules/parsermodule.c39
-rw-r--r--Modules/posixmodule.c38
-rw-r--r--Modules/pwdmodule.c20
-rw-r--r--Modules/pyexpat.c28
-rw-r--r--Modules/readline.c21
-rw-r--r--Modules/resource.c20
-rw-r--r--Modules/selectmodule.c26
-rw-r--r--Modules/sha1module.c21
-rw-r--r--Modules/sha256module.c25
-rw-r--r--Modules/sha512module.c25
-rw-r--r--Modules/signalmodule.c34
-rw-r--r--Modules/socketmodule.c39
-rw-r--r--Modules/spwdmodule.c20
-rw-r--r--Modules/symtablemodule.c23
-rw-r--r--Modules/syslogmodule.c20
-rw-r--r--Modules/termios.c20
-rw-r--r--Modules/timemodule.c30
-rw-r--r--Modules/unicodedata.c45
-rw-r--r--Modules/xxmodule.c41
-rw-r--r--Modules/xxsubtype.c34
-rw-r--r--Modules/zipimport.c32
-rw-r--r--Modules/zlibmodule.c20
77 files changed, 1483 insertions, 467 deletions
diff --git a/Modules/_bisectmodule.c b/Modules/_bisectmodule.c
index b283b0d3..1280b04 100644
--- a/Modules/_bisectmodule.c
+++ b/Modules/_bisectmodule.c
@@ -226,10 +226,21 @@ having to sort the list after each insertion. For long lists of items with\n\
expensive comparison operations, this can be an improvement over the more\n\
common approach.\n");
+
+static struct PyModuleDef _bisectmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_bisect",
+ module_doc,
+ -1,
+ bisect_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_bisect(void)
+PyInit__bisect(void)
{
- PyObject *m;
-
- m = Py_InitModule3("_bisect", bisect_methods, module_doc);
+ return PyModule_Create(&_bisectmodule);
}
diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c
index 9e31029..6b543fd 100644
--- a/Modules/_bsddb.c
+++ b/Modules/_bsddb.c
@@ -5646,7 +5646,20 @@ static BSDDB_api bsddb_api;
#define MODULE_NAME_MAX_LEN 11
static char _bsddbModuleName[MODULE_NAME_MAX_LEN+1] = "_bsddb";
-PyMODINIT_FUNC init_bsddb(void)
+
+static struct PyModuleDef _bsddbmodule = {
+ PyModuleDef_HEAD_INIT,
+ _bsddbModuleName,
+ NULL,
+ -1,
+ bsddb_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+PyMODINIT_FUNC PyInit__bsddb(void)
{
PyObject* m;
PyObject* d;
@@ -5673,9 +5686,9 @@ PyMODINIT_FUNC init_bsddb(void)
#endif
/* Create the module and add the functions */
- m = Py_InitModule(_bsddbModuleName, bsddb_methods);
+ m = PyModule_Create(&_bsddbmodule);
if (m == NULL)
- return;
+ return NULL;
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
@@ -6064,7 +6077,10 @@ PyMODINIT_FUNC init_bsddb(void)
if (PyErr_Occurred()) {
PyErr_Print();
Py_FatalError("can't initialize module _bsddb");
+ Py_DECREF(m);
+ m = NULL;
}
+ return m;
}
/* allow this module to be named _pybsddb so that it can be installed
@@ -6073,5 +6089,5 @@ PyMODINIT_FUNC init_bsddb(void)
PyMODINIT_FUNC init_pybsddb(void)
{
strncpy(_bsddbModuleName, "_pybsddb", MODULE_NAME_MAX_LEN);
- init_bsddb();
+ return PyInit__bsddb();
}
diff --git a/Modules/_bytesio.c b/Modules/_bytesio.c
index 455f9b1..d7d2667 100644
--- a/Modules/_bytesio.c
+++ b/Modules/_bytesio.c
@@ -722,16 +722,30 @@ static PyTypeObject BytesIO_Type = {
bytesio_new, /*tp_new*/
};
+
+static struct PyModuleDef _bytesiomodule = {
+ PyModuleDef_HEAD_INIT,
+ "_bytesio",
+ NULL,
+ -1,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_bytesio(void)
+PyInit__bytesio(void)
{
PyObject *m;
if (PyType_Ready(&BytesIO_Type) < 0)
- return;
- m = Py_InitModule("_bytesio", NULL);
+ return NULL;
+ m = PyModule_Create(&_bytesiomodule);
if (m == NULL)
- return;
+ return NULL;
Py_INCREF(&BytesIO_Type);
PyModule_AddObject(m, "_BytesIO", (PyObject *)&BytesIO_Type);
+ return m;
}
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c
index efa4d80..96dfd56 100644
--- a/Modules/_codecsmodule.c
+++ b/Modules/_codecsmodule.c
@@ -1152,8 +1152,20 @@ static PyMethodDef _codecs_functions[] = {
{NULL, NULL} /* sentinel */
};
+static struct PyModuleDef codecsmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_codecs",
+ NULL,
+ -1,
+ _codecs_functions,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_codecs(void)
+PyInit__codecs(void)
{
- Py_InitModule("_codecs", _codecs_functions);
+ return PyModule_Create(&codecsmodule);
}
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index db07537..02ffb56 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -1348,31 +1348,44 @@ PyDoc_STRVAR(module_doc,
- defaultdict: dict subclass with a default value factory\n\
");
+
+static struct PyModuleDef _collectionsmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_collections",
+ module_doc,
+ -1,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_collections(void)
+PyInit__collections(void)
{
PyObject *m;
- m = Py_InitModule3("_collections", NULL, module_doc);
+ m = PyModule_Create(&_collectionsmodule);
if (m == NULL)
- return;
+ return NULL;
if (PyType_Ready(&deque_type) < 0)
- return;
+ return NULL;
Py_INCREF(&deque_type);
PyModule_AddObject(m, "deque", (PyObject *)&deque_type);
defdict_type.tp_base = &PyDict_Type;
if (PyType_Ready(&defdict_type) < 0)
- return;
+ return NULL;
Py_INCREF(&defdict_type);
PyModule_AddObject(m, "defaultdict", (PyObject *)&defdict_type);
if (PyType_Ready(&dequeiter_type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&dequereviter_type) < 0)
- return;
+ return NULL;
- return;
+ return m;
}
diff --git a/Modules/_csv.c b/Modules/_csv.c
index 9a72955..c654712 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -1542,53 +1542,67 @@ static struct PyMethodDef csv_methods[] = {
{ NULL, NULL }
};
+
+static struct PyModuleDef _csvmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_csv",
+ csv_module_doc,
+ -1,
+ csv_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_csv(void)
+PyInit__csv(void)
{
PyObject *module;
StyleDesc *style;
if (PyType_Ready(&Dialect_Type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&Reader_Type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&Writer_Type) < 0)
- return;
+ return NULL;
/* Create the module and add the functions */
- module = Py_InitModule3("_csv", csv_methods, csv_module_doc);
+ module = PyModule_Create(&_csvmodule);
if (module == NULL)
- return;
+ return NULL;
/* Add version to the module. */
if (PyModule_AddStringConstant(module, "__version__",
MODULE_VERSION) == -1)
- return;
+ return NULL;
/* Add _dialects dictionary */
dialects = PyDict_New();
if (dialects == NULL)
- return;
+ return NULL;
if (PyModule_AddObject(module, "_dialects", dialects))
- return;
+ return NULL;
/* Add quote styles into dictionary */
for (style = quote_styles; style->name; style++) {
if (PyModule_AddIntConstant(module, style->name,
style->style) == -1)
- return;
+ return NULL;
}
/* Add the Dialect type */
Py_INCREF(&Dialect_Type);
if (PyModule_AddObject(module, "Dialect", (PyObject *)&Dialect_Type))
- return;
+ return NULL;
/* Add the CSV exception object to the module. */
error_obj = PyErr_NewException("_csv.Error", NULL, NULL);
if (error_obj == NULL)
- return;
+ return NULL;
PyModule_AddObject(module, "Error", error_obj);
+ return module;
}
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index c840757..c4ca29a 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -4995,7 +4995,7 @@ PyTypeObject Pointer_Type = {
* Module initialization.
*/
-static char *module_docs =
+static const char module_docs[] =
"Create and manipulate C compatible data types in Python.";
#ifdef MS_WIN32
@@ -5191,8 +5191,21 @@ wstring_at(const wchar_t *ptr, int size)
}
#endif
+
+static struct PyModuleDef _ctypesmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_ctypes",
+ module_docs,
+ -1,
+ module_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_ctypes(void)
+PyInit__ctypes(void)
{
PyObject *m;
@@ -5203,30 +5216,30 @@ init_ctypes(void)
#ifdef WITH_THREAD
PyEval_InitThreads();
#endif
- m = Py_InitModule3("_ctypes", module_methods, module_docs);
+ m = PyModule_Create(&_ctypesmodule);
if (!m)
- return;
+ return NULL;
_pointer_type_cache = PyDict_New();
if (_pointer_type_cache == NULL)
- return;
+ return NULL;
PyModule_AddObject(m, "_pointer_type_cache", (PyObject *)_pointer_type_cache);
_unpickle = PyObject_GetAttrString(m, "_unpickle");
if (_unpickle == NULL)
- return;
+ return NULL;
if (PyType_Ready(&PyCArg_Type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&CThunk_Type) < 0)
- return;
+ return NULL;
/* StgDict is derived from PyDict_Type */
StgDict_Type.tp_base = &PyDict_Type;
if (PyType_Ready(&StgDict_Type) < 0)
- return;
+ return NULL;
/*************************************************
*
@@ -5235,27 +5248,27 @@ init_ctypes(void)
StructType_Type.tp_base = &PyType_Type;
if (PyType_Ready(&StructType_Type) < 0)
- return;
+ return NULL;
UnionType_Type.tp_base = &PyType_Type;
if (PyType_Ready(&UnionType_Type) < 0)
- return;
+ return NULL;
PointerType_Type.tp_base = &PyType_Type;
if (PyType_Ready(&PointerType_Type) < 0)
- return;
+ return NULL;
ArrayType_Type.tp_base = &PyType_Type;
if (PyType_Ready(&ArrayType_Type) < 0)
- return;
+ return NULL;
SimpleType_Type.tp_base = &PyType_Type;
if (PyType_Ready(&SimpleType_Type) < 0)
- return;
+ return NULL;
CFuncPtrType_Type.tp_base = &PyType_Type;
if (PyType_Ready(&CFuncPtrType_Type) < 0)
- return;
+ return NULL;
/*************************************************
*
@@ -5263,42 +5276,42 @@ init_ctypes(void)
*/
if (PyType_Ready(&CData_Type) < 0)
- return;
+ return NULL;
Py_TYPE(&Struct_Type) = &StructType_Type;
Struct_Type.tp_base = &CData_Type;
if (PyType_Ready(&Struct_Type) < 0)
- return;
+ return NULL;
PyModule_AddObject(m, "Structure", (PyObject *)&Struct_Type);
Py_TYPE(&Union_Type) = &UnionType_Type;
Union_Type.tp_base = &CData_Type;
if (PyType_Ready(&Union_Type) < 0)
- return;
+ return NULL;
PyModule_AddObject(m, "Union", (PyObject *)&Union_Type);
Py_TYPE(&Pointer_Type) = &PointerType_Type;
Pointer_Type.tp_base = &CData_Type;
if (PyType_Ready(&Pointer_Type) < 0)
- return;
+ return NULL;
PyModule_AddObject(m, "_Pointer", (PyObject *)&Pointer_Type);
Py_TYPE(&Array_Type) = &ArrayType_Type;
Array_Type.tp_base = &CData_Type;
if (PyType_Ready(&Array_Type) < 0)
- return;
+ return NULL;
PyModule_AddObject(m, "Array", (PyObject *)&Array_Type);
Py_TYPE(&Simple_Type) = &SimpleType_Type;
Simple_Type.tp_base = &CData_Type;
if (PyType_Ready(&Simple_Type) < 0)
- return;
+ return NULL;
PyModule_AddObject(m, "_SimpleCData", (PyObject *)&Simple_Type);
Py_TYPE(&CFuncPtr_Type) = &CFuncPtrType_Type;
CFuncPtr_Type.tp_base = &CData_Type;
if (PyType_Ready(&CFuncPtr_Type) < 0)
- return;
+ return NULL;
PyModule_AddObject(m, "CFuncPtr", (PyObject *)&CFuncPtr_Type);
/*************************************************
@@ -5308,7 +5321,7 @@ init_ctypes(void)
/* CField_Type is derived from PyBaseObject_Type */
if (PyType_Ready(&CField_Type) < 0)
- return;
+ return NULL;
/*************************************************
*
@@ -5317,11 +5330,11 @@ init_ctypes(void)
DictRemover_Type.tp_new = PyType_GenericNew;
if (PyType_Ready(&DictRemover_Type) < 0)
- return;
+ return NULL;
#ifdef MS_WIN32
if (create_comerror() < 0)
- return;
+ return NULL;
PyModule_AddObject(m, "COMError", ComError);
PyModule_AddObject(m, "FUNCFLAG_HRESULT", PyLong_FromLong(FUNCFLAG_HRESULT));
@@ -5366,6 +5379,7 @@ init_ctypes(void)
* Others...
*/
init_callbacks_in_module(m);
+ return m;
}
/*
diff --git a/Modules/_ctypes/_ctypes_test.c b/Modules/_ctypes/_ctypes_test.c
index ce83df7..2d957de 100644
--- a/Modules/_ctypes/_ctypes_test.c
+++ b/Modules/_ctypes/_ctypes_test.c
@@ -582,8 +582,21 @@ EXPORT (HRESULT) KeepObject(IUnknown *punk)
#endif
+
+static struct PyModuleDef _ctypes_testmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_ctypes_test",
+ NULL,
+ -1,
+ module_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_ctypes_test(void)
+PyInit__ctypes_test(void)
{
- Py_InitModule("_ctypes_test", module_methods);
+ return PyModule_Create(&_ctypes_testmodule);
}
diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c
index 9bdd194..867be7d 100644
--- a/Modules/_curses_panel.c
+++ b/Modules/_curses_panel.c
@@ -451,8 +451,21 @@ static PyMethodDef PyCurses_methods[] = {
/* Initialization function for the module */
+
+static struct PyModuleDef _curses_panelmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_curses_panel",
+ NULL,
+ -1,
+ PyCurses_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_curses_panel(void)
+PyInit__curses_panel(void)
{
PyObject *m, *d, *v;
@@ -462,9 +475,9 @@ init_curses_panel(void)
import_curses();
/* Create the module and add the functions */
- m = Py_InitModule("_curses_panel", PyCurses_methods);
+ m = PyModule_Create(&_curses_panelmodule);
if (m == NULL)
- return;
+ return NULL;
d = PyModule_GetDict(m);
/* For exception _curses_panel.error */
@@ -476,4 +489,5 @@ init_curses_panel(void)
PyDict_SetItemString(d, "version", v);
PyDict_SetItemString(d, "__version__", v);
Py_DECREF(v);
+ return m;
}
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index bde086d..45a0821 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -2770,8 +2770,21 @@ static PyMethodDef PyCurses_methods[] = {
/* Initialization function for the module */
+
+static struct PyModuleDef _cursesmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_curses",
+ NULL,
+ -1,
+ PyCurses_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_curses(void)
+PyInit__curses(void)
{
PyObject *m, *d, *v, *c_api_object;
static void *PyCurses_API[PyCurses_API_pointers];
@@ -2786,14 +2799,14 @@ init_curses(void)
PyCurses_API[3] = (void *)func_PyCursesInitialisedColor;
/* Create the module and add the functions */
- m = Py_InitModule("_curses", PyCurses_methods);
+ m = PyModule_Create(&_cursesmodule);
if (m == NULL)
- return;
+ return NULL;
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
if (d == NULL)
- return;
+ return NULL;
ModDict = d; /* For PyCurses_InitScr to use later */
/* Add a CObject for the C API */
@@ -2931,4 +2944,5 @@ init_curses(void)
SetDictInt("KEY_MIN", KEY_MIN);
SetDictInt("KEY_MAX", KEY_MAX);
}
+ return m;
}
diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c
index 7e80381..28f4aa7 100644
--- a/Modules/_dbmmodule.c
+++ b/Modules/_dbmmodule.c
@@ -390,15 +390,28 @@ static PyMethodDef dbmmodule_methods[] = {
{ 0, 0 },
};
+
+static struct PyModuleDef _dbmmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_dbm",
+ NULL,
+ -1,
+ dbmmodule_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_dbm(void) {
+PyInit__dbm(void) {
PyObject *m, *d, *s;
if (PyType_Ready(&Dbmtype) < 0)
- return;
- m = Py_InitModule("_dbm", dbmmodule_methods);
+ return NULL;
+ m = PyModule_Create(&_dbmmodule);
if (m == NULL)
- return;
+ return NULL;
d = PyModule_GetDict(m);
if (DbmError == NULL)
DbmError = PyErr_NewException("_dbm.error",
@@ -410,4 +423,9 @@ init_dbm(void) {
}
if (DbmError != NULL)
PyDict_SetItemString(d, "error", DbmError);
+ if (PyErr_Occurred()) {
+ Py_DECREF(m);
+ m = NULL;
+ }
+ return m;
}
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 0c8bf2a..099df7b 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -2549,8 +2549,21 @@ static PyMethodDef _functions[] = {
{NULL, NULL}
};
+
+static struct PyModuleDef _elementtreemodule = {
+ PyModuleDef_HEAD_INIT,
+ "_elementtree",
+ NULL,
+ -1,
+ _functions,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_elementtree(void)
+PyInit__elementtree(void)
{
PyObject* m;
PyObject* g;
@@ -2565,15 +2578,21 @@ init_elementtree(void)
Py_TYPE(&XMLParser_Type) = &PyType_Type;
#endif
- m = Py_InitModule("_elementtree", _functions);
+ m = PyModule_Create(&_elementtreemodule);
if (!m)
- return;
+ return NULL;
+
+ /* The code below requires that the module gets already added
+ to sys.modules. */
+ PyDict_SetItemString(PyImport_GetModuleDict(),
+ _elementtreemodule.m_name,
+ m);
/* python glue code */
g = PyDict_New();
if (!g)
- return;
+ return NULL;
PyDict_SetItemString(g, "__builtins__", PyEval_GetBuiltins());
@@ -2748,5 +2767,6 @@ init_elementtree(void)
else
expat_capi = NULL;
#endif
+ return m;
}
diff --git a/Modules/_fileio.c b/Modules/_fileio.c
index 1a78f60..71553ba 100644
--- a/Modules/_fileio.c
+++ b/Modules/_fileio.c
@@ -871,17 +871,29 @@ static PyMethodDef module_methods[] = {
{NULL, NULL}
};
+static struct PyModuleDef fileiomodule = {
+ PyModuleDef_HEAD_INIT,
+ "_fileio",
+ "Fast implementation of io.FileIO.",
+ -1,
+ module_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_fileio(void)
+PyInit__fileio(void)
{
PyObject *m; /* a module object */
- m = Py_InitModule3("_fileio", module_methods,
- "Fast implementation of io.FileIO.");
+ m = PyModule_Create(&fileiomodule);
if (m == NULL)
- return;
+ return NULL;
if (PyType_Ready(&PyFileIO_Type) < 0)
- return;
+ return NULL;
Py_INCREF(&PyFileIO_Type);
PyModule_AddObject(m, "_FileIO", (PyObject *) &PyFileIO_Type);
+ return m;
}
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
index 167f906..731d028 100644
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -326,8 +326,21 @@ static PyMethodDef module_methods[] = {
{NULL, NULL} /* sentinel */
};
+
+static struct PyModuleDef _functoolsmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_functools",
+ module_doc,
+ -1,
+ module_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_functools(void)
+PyInit__functools(void)
{
int i;
PyObject *m;
@@ -337,16 +350,19 @@ init_functools(void)
NULL
};
- m = Py_InitModule3("_functools", module_methods, module_doc);
+ m = PyModule_Create(&_functoolsmodule);
if (m == NULL)
- return;
+ return NULL;
for (i=0 ; typelist[i] != NULL ; i++) {
- if (PyType_Ready(typelist[i]) < 0)
- return;
+ if (PyType_Ready(typelist[i]) < 0) {
+ Py_DECREF(m);
+ return NULL;
+ }
name = strchr(typelist[i]->tp_name, '.');
assert (name != NULL);
Py_INCREF(typelist[i]);
PyModule_AddObject(m, name+1, (PyObject *)typelist[i]);
}
+ return m;
}
diff --git a/Modules/_gdbmmodule.c b/Modules/_gdbmmodule.c
index abc8837..b253e20 100644
--- a/Modules/_gdbmmodule.c
+++ b/Modules/_gdbmmodule.c
@@ -511,17 +511,28 @@ static PyMethodDef dbmmodule_methods[] = {
{ 0, 0 },
};
+
+static struct PyModuleDef _gdbmmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_gdbm",
+ gdbmmodule__doc__,
+ -1,
+ dbmmodule_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_gdbm(void) {
+PyInit__gdbm(void) {
PyObject *m, *d, *s;
if (PyType_Ready(&Dbmtype) < 0)
- return;
- m = Py_InitModule4("_gdbm", dbmmodule_methods,
- gdbmmodule__doc__, (PyObject *)NULL,
- PYTHON_API_VERSION);
+ return NULL;
+ m = PyModule_Create(&_gdbmmodule);
if (m == NULL)
- return;
+ return NULL;
d = PyModule_GetDict(m);
DbmError = PyErr_NewException("_gdbm.error", PyExc_IOError, NULL);
if (DbmError != NULL) {
@@ -530,4 +541,5 @@ init_gdbm(void) {
PyDict_SetItemString(d, "open_flags", s);
Py_DECREF(s);
}
+ return m;
}
diff --git a/Modules/_gestalt.c b/Modules/_gestalt.c
index d106068..7fb1bc9 100644
--- a/Modules/_gestalt.c
+++ b/Modules/_gestalt.c
@@ -65,8 +65,20 @@ static struct PyMethodDef gestalt_methods[] = {
{NULL, NULL} /* Sentinel */
};
+static struct PyModuleDef gestaltmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_gestalt",
+ NULL,
+ -1,
+ gestalt_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
void
-init_gestalt(void)
+PyInit__gestalt(void)
{
- Py_InitModule("_gestalt", gestalt_methods);
+ return PyModule_Create(&gestaltmodule);
}
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
index ecbe01c..8965f43 100644
--- a/Modules/_hashopenssl.c
+++ b/Modules/_hashopenssl.c
@@ -498,8 +498,21 @@ static struct PyMethodDef EVP_functions[] = {
/* Initialize this module. */
+
+static struct PyModuleDef _hashlibmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_hashlib",
+ NULL,
+ -1,
+ EVP_functions,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_hashlib(void)
+PyInit__hashlib(void)
{
PyObject *m;
@@ -512,11 +525,11 @@ init_hashlib(void)
Py_TYPE(&EVPtype) = &PyType_Type;
if (PyType_Ready(&EVPtype) < 0)
- return;
+ return NULL;
- m = Py_InitModule("_hashlib", EVP_functions);
+ m = PyModule_Create(&_hashlibmodule);
if (m == NULL)
- return;
+ return NULL;
#if HASH_OBJ_CONSTRUCTOR
Py_INCREF(&EVPtype);
@@ -530,4 +543,5 @@ init_hashlib(void)
INIT_CONSTRUCTOR_CONSTANTS(sha256);
INIT_CONSTRUCTOR_CONSTANTS(sha384);
INIT_CONSTRUCTOR_CONSTANTS(sha512);
+ return m;
}
diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c
index a5a5605..9d2bb1a 100644
--- a/Modules/_heapqmodule.c
+++ b/Modules/_heapqmodule.c
@@ -679,15 +679,29 @@ backwards, and this was also used to avoid the rewinding time.\n\
Believe me, real good tape sorts were quite spectacular to watch!\n\
From all times, sorting has always been a Great Art! :-)\n");
+
+static struct PyModuleDef _heapqmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_heapq",
+ module_doc,
+ -1,
+ heapq_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_heapq(void)
+PyInit__heapq(void)
{
PyObject *m, *about;
- m = Py_InitModule3("_heapq", heapq_methods, module_doc);
+ m = PyModule_Create(&_heapqmodule);
if (m == NULL)
- return;
+ return NULL;
about = PyUnicode_DecodeUTF8(__about__, strlen(__about__), NULL);
PyModule_AddObject(m, "__about__", about);
+ return m;
}
diff --git a/Modules/_json.c b/Modules/_json.c
index cc52ff6..a4308fd 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -613,9 +613,20 @@ static PyMethodDef json_methods[] = {
PyDoc_STRVAR(module_doc,
"json speedups\n");
-void
-init_json(void)
+static struct PyModuleDef jsonmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_json",
+ module_doc,
+ -1,
+ json_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+PyObject*
+PyInit__json(void)
{
- PyObject *m;
- m = Py_InitModule3("_json", json_methods, module_doc);
+ return PyModule_Create(&jsonmodule);
}
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c
index af36a59..50c72c9 100644
--- a/Modules/_localemodule.c
+++ b/Modules/_localemodule.c
@@ -657,17 +657,30 @@ static struct PyMethodDef PyLocale_Methods[] = {
{NULL, NULL}
};
+
+static struct PyModuleDef _localemodule = {
+ PyModuleDef_HEAD_INIT,
+ "_locale",
+ locale__doc__,
+ -1,
+ PyLocale_Methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_locale(void)
+PyInit__locale(void)
{
PyObject *m, *d, *x;
#ifdef HAVE_LANGINFO_H
int i;
#endif
- m = Py_InitModule3("_locale", PyLocale_Methods, locale__doc__);
+ m = PyModule_Create(&_localemodule);
if (m == NULL)
- return;
+ return NULL;
d = PyModule_GetDict(m);
@@ -714,6 +727,7 @@ init_locale(void)
langinfo_constants[i].value);
}
#endif
+ return m;
}
/*
diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c
index e0446ec..69ecaf1 100644
--- a/Modules/_lsprof.c
+++ b/Modules/_lsprof.c
@@ -857,16 +857,29 @@ static PyMethodDef moduleMethods[] = {
{NULL, NULL}
};
+
+static struct PyModuleDef _lsprofmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_lsprof",
+ "Fast profiler",
+ -1,
+ moduleMethods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_lsprof(void)
+PyInit__lsprof(void)
{
PyObject *module, *d;
- module = Py_InitModule3("_lsprof", moduleMethods, "Fast profiler");
+ module = PyModule_Create(&_lsprofmodule);
if (module == NULL)
- return;
+ return NULL;
d = PyModule_GetDict(module);
if (PyType_Ready(&PyProfiler_Type) < 0)
- return;
+ return NULL;
PyDict_SetItemString(d, "Profiler", (PyObject *)&PyProfiler_Type);
if (!initialized) {
@@ -883,4 +896,5 @@ init_lsprof(void)
(PyObject*) &StatsSubEntryType);
empty_tuple = PyTuple_New(0);
initialized = 1;
+ return module;
}
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c
index 77b238d..4cdd98d 100644
--- a/Modules/_randommodule.c
+++ b/Modules/_randommodule.c
@@ -496,16 +496,30 @@ static PyTypeObject Random_Type = {
PyDoc_STRVAR(module_doc,
"Module implements the Mersenne Twister random number generator.");
+
+static struct PyModuleDef _randommodule = {
+ PyModuleDef_HEAD_INIT,
+ "_random",
+ module_doc,
+ -1,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_random(void)
+PyInit__random(void)
{
PyObject *m;
if (PyType_Ready(&Random_Type) < 0)
- return;
- m = Py_InitModule3("_random", NULL, module_doc);
+ return NULL;
+ m = PyModule_Create(&_randommodule);
if (m == NULL)
- return;
+ return NULL;
Py_INCREF(&Random_Type);
PyModule_AddObject(m, "Random", (PyObject *)&Random_Type);
+ return m;
}
diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c
index 1f8c63f..59d0d17 100644
--- a/Modules/_sqlite/module.c
+++ b/Modules/_sqlite/module.c
@@ -257,13 +257,26 @@ static IntConstantPair _int_constants[] = {
{(char*)NULL, 0}
};
-PyMODINIT_FUNC init_sqlite3(void)
+
+static struct PyModuleDef _sqlite3module = {
+ PyModuleDef_HEAD_INIT,
+ "_sqlite3",
+ NULL,
+ -1,
+ module_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+PyMODINIT_FUNC PyInit__sqlite3(void)
{
PyObject *module, *dict;
PyObject *tmp_obj;
int i;
- module = Py_InitModule("_sqlite3", module_methods);
+ module = PyModule_Create(&_sqlite3module);
if (!module ||
(pysqlite_row_setup_types() < 0) ||
@@ -273,7 +286,8 @@ PyMODINIT_FUNC init_sqlite3(void)
(pysqlite_statement_setup_types() < 0) ||
(pysqlite_prepare_protocol_setup_types() < 0)
) {
- return;
+ Py_DECREF(module);
+ return NULL;
}
Py_INCREF(&pysqlite_ConnectionType);
@@ -408,5 +422,8 @@ error:
if (PyErr_Occurred())
{
PyErr_SetString(PyExc_ImportError, MODULE_NAME ": init failed");
+ Py_DECREF(module);
+ module = NULL;
}
+ return module;
}
diff --git a/Modules/_sre.c b/Modules/_sre.c
index 22aff76..ab8adda 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -3387,7 +3387,19 @@ static PyMethodDef _functions[] = {
{NULL, NULL}
};
-PyMODINIT_FUNC init_sre(void)
+static struct PyModuleDef sremodule = {
+ PyModuleDef_HEAD_INIT,
+ "_" SRE_MODULE,
+ NULL,
+ -1,
+ _functions,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+PyMODINIT_FUNC PyInit__sre(void)
{
PyObject* m;
PyObject* d;
@@ -3395,15 +3407,15 @@ PyMODINIT_FUNC init_sre(void)
/* Initialize object types */
if (PyType_Ready(&Pattern_Type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&Match_Type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&Scanner_Type) < 0)
- return;
+ return NULL;
- m = Py_InitModule("_" SRE_MODULE, _functions);
+ m = PyModule_Create(&sremodule);
if (m == NULL)
- return;
+ return NULL;
d = PyModule_GetDict(m);
x = PyLong_FromLong(SRE_MAGIC);
@@ -3423,6 +3435,7 @@ PyMODINIT_FUNC init_sre(void)
PyDict_SetItemString(d, "copyright", x);
Py_DECREF(x);
}
+ return m;
}
#endif /* !defined(SRE_RECURSIVE) */
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index af8df9c..f2e95b9 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -1563,28 +1563,41 @@ PyDoc_STRVAR(module_doc,
"Implementation module for SSL socket operations. See the socket module\n\
for documentation.");
+
+static struct PyModuleDef _sslmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_ssl",
+ module_doc,
+ -1,
+ PySSL_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_ssl(void)
+PyInit__ssl(void)
{
PyObject *m, *d;
Py_TYPE(&PySSL_Type) = &PyType_Type;
- m = Py_InitModule3("_ssl", PySSL_methods, module_doc);
+ m = PyModule_Create(&_sslmodule);
if (m == NULL)
- return;
+ return NULL;
d = PyModule_GetDict(m);
/* Load _socket module and its C API */
if (PySocketModule_ImportModuleAndAPI())
- return;
+ return NULL;
/* Init OpenSSL */
SSL_load_error_strings();
#ifdef WITH_THREAD
/* note that this will start threading if not already started */
if (!_setup_ssl_threads()) {
- return;
+ return NULL;
}
#endif
SSLeay_add_ssl_algorithms();
@@ -1594,12 +1607,12 @@ init_ssl(void)
PySocketModule.error,
NULL);
if (PySSLErrorObject == NULL)
- return;
+ return NULL;
if (PyDict_SetItemString(d, "SSLError", PySSLErrorObject) != 0)
- return;
+ return NULL;
if (PyDict_SetItemString(d, "SSLType",
(PyObject *)&PySSL_Type) != 0)
- return;
+ return NULL;
PyModule_AddIntConstant(m, "SSL_ERROR_ZERO_RETURN",
PY_SSL_ERROR_ZERO_RETURN);
PyModule_AddIntConstant(m, "SSL_ERROR_WANT_READ",
@@ -1636,4 +1649,5 @@ init_ssl(void)
PY_SSL_VERSION_SSL23);
PyModule_AddIntConstant(m, "PROTOCOL_TLSv1",
PY_SSL_VERSION_TLS1);
+ return m;
}
diff --git a/Modules/_struct.c b/Modules/_struct.c
index ae8a160..e7cbd4b 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -2087,28 +2087,41 @@ Whitespace between formats is ignored.\n\
\n\
The variable struct.error is an exception raised on errors.\n");
+
+static struct PyModuleDef _structmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_struct",
+ module_doc,
+ -1,
+ module_functions,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_struct(void)
+PyInit__struct(void)
{
PyObject *ver, *m;
ver = PyBytes_FromString("0.2");
if (ver == NULL)
- return;
+ return NULL;
- m = Py_InitModule3("_struct", module_functions, module_doc);
+ m = PyModule_Create(&_structmodule);
if (m == NULL)
- return;
+ return NULL;
Py_TYPE(&PyStructType) = &PyType_Type;
if (PyType_Ready(&PyStructType) < 0)
- return;
+ return NULL;
#ifdef PY_STRUCT_OVERFLOW_MASKING
if (pyint_zero == NULL) {
pyint_zero = PyLong_FromLong(0);
if (pyint_zero == NULL)
- return;
+ return NULL;
}
if (pylong_ulong_mask == NULL) {
#if (SIZEOF_LONG == 4)
@@ -2117,7 +2130,7 @@ init_struct(void)
pylong_ulong_mask = PyLong_FromString("FFFFFFFFFFFFFFFF", NULL, 16);
#endif
if (pylong_ulong_mask == NULL)
- return;
+ return NULL;
}
#else
@@ -2168,7 +2181,7 @@ init_struct(void)
if (StructError == NULL) {
StructError = PyErr_NewException("struct.error", NULL, NULL);
if (StructError == NULL)
- return;
+ return NULL;
}
Py_INCREF(StructError);
@@ -2186,5 +2199,6 @@ init_struct(void)
#ifdef PY_STRUCT_FLOAT_COERCE
PyModule_AddIntConstant(m, "_PY_STRUCT_FLOAT_COERCE", 1);
#endif
+ return m;
}
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 7c28538..3dd2cdb 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -1135,14 +1135,27 @@ static PyTypeObject test_structmembersType = {
};
+
+static struct PyModuleDef _testcapimodule = {
+ PyModuleDef_HEAD_INIT,
+ "_testcapi",
+ NULL,
+ -1,
+ TestMethods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_testcapi(void)
+PyInit__testcapi(void)
{
PyObject *m;
- m = Py_InitModule("_testcapi", TestMethods);
+ m = PyModule_Create(&_testcapimodule);
if (m == NULL)
- return;
+ return NULL;
Py_TYPE(&test_structmembersType)=&PyType_Type;
Py_INCREF(&test_structmembersType);
@@ -1173,4 +1186,5 @@ init_testcapi(void)
TestError = PyErr_NewException("_testcapi.error", NULL, NULL);
Py_INCREF(TestError);
PyModule_AddObject(m, "error", TestError);
+ return m;
}
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 5b8fc98..0fe9a76 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -687,21 +687,34 @@ A lock is not owned by the thread that locked it; another thread may\n\
unlock it. A thread attempting to lock a lock that it has already locked\n\
will block until another thread unlocks it. Deadlocks may ensue.");
+static struct PyModuleDef threadmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_thread",
+ thread_doc,
+ -1,
+ thread_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+
PyMODINIT_FUNC
-init_thread(void)
+PyInit__thread(void)
{
PyObject *m, *d;
/* Initialize types: */
if (PyType_Ready(&localtype) < 0)
- return;
+ return NULL;
if (PyType_Ready(&Locktype) < 0)
- return;
+ return NULL;
/* Create the module and add the functions */
- m = Py_InitModule3("_thread", thread_methods, thread_doc);
+ m = PyModule_Create(&threadmodule);
if (m == NULL)
- return;
+ return NULL;
/* Add a symbolic constant */
d = PyModule_GetDict(m);
@@ -713,8 +726,9 @@ init_thread(void)
Py_INCREF(&localtype);
if (PyModule_AddObject(m, "_local", (PyObject *)&localtype) < 0)
- return;
+ return NULL;
/* Initialize the C thread library */
PyThread_init_thread();
+ return m;
}
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 5002f4a..40db86e 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -3009,8 +3009,20 @@ ins_string(PyObject *d, char *name, char *val)
}
+static struct PyModuleDef _tkintermodule = {
+ PyModuleDef_HEAD_INIT,
+ "_tkinter",
+ NULL,
+ -1,
+ moduleMethods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_tkinter(void)
+PyInit__tkinter(void)
{
PyObject *m, *d, *uexe, *cexe;
@@ -3020,9 +3032,9 @@ init_tkinter(void)
tcl_lock = PyThread_allocate_lock();
#endif
- m = Py_InitModule("_tkinter", moduleMethods);
+ m = PyModule_Create(&_tkintermodule);
if (m == NULL)
- return;
+ return NULL;
d = PyModule_GetDict(m);
Tkinter_TclError = PyErr_NewException("_tkinter.TclError", NULL, NULL);
@@ -3076,8 +3088,10 @@ init_tkinter(void)
Py_DECREF(uexe);
}
- if (PyErr_Occurred())
- return;
+ if (PyErr_Occurred()) {
+ Py_DECREF(m);
+ return NULL;
+ }
#if 0
/* This was not a good idea; through <Destroy> bindings,
@@ -3085,5 +3099,5 @@ init_tkinter(void)
interpreter and thread state have already been destroyed! */
Py_AtExit(Tcl_Finalize);
#endif
-
+ return m;
}
diff --git a/Modules/_weakref.c b/Modules/_weakref.c
index b187a26..88995b8 100644
--- a/Modules/_weakref.c
+++ b/Modules/_weakref.c
@@ -88,13 +88,25 @@ weakref_functions[] = {
};
+static struct PyModuleDef weakrefmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_weakref",
+ "Weak-reference support module.",
+ -1,
+ weakref_functions,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_weakref(void)
+PyInit__weakref(void)
{
PyObject *m;
- m = Py_InitModule3("_weakref", weakref_functions,
- "Weak-reference support module.");
+ m = PyModule_Create(&weakrefmodule);
+
if (m != NULL) {
Py_INCREF(&_PyWeakref_RefType);
PyModule_AddObject(m, "ref",
@@ -109,4 +121,5 @@ init_weakref(void)
PyModule_AddObject(m, "CallableProxyType",
(PyObject *) &_PyWeakref_CallableProxyType);
}
+ return m;
}
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index ea59a42..5fa525f 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -2156,9 +2156,21 @@ static PyMethodDef a_methods[] = {
{NULL, NULL, 0, NULL} /* Sentinel */
};
+static struct PyModuleDef arraymodule = {
+ PyModuleDef_HEAD_INIT,
+ "array",
+ module_doc,
+ -1,
+ a_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initarray(void)
+PyInit_array(void)
{
PyObject *m;
PyObject *typecodes;
@@ -2167,11 +2179,11 @@ initarray(void)
struct arraydescr *descr;
if (PyType_Ready(&Arraytype) < 0)
- return;
+ return NULL;
Py_TYPE(&PyArrayIter_Type) = &PyType_Type;
- m = Py_InitModule3("array", a_methods, module_doc);
+ m = PyModule_Create(&arraymodule);
if (m == NULL)
- return;
+ return NULL;
Py_INCREF((PyObject *)&Arraytype);
PyModule_AddObject(m, "ArrayType", (PyObject *)&Arraytype);
@@ -2190,5 +2202,9 @@ initarray(void)
PyModule_AddObject(m, "typecodes", (PyObject *)typecodes);
- /* No need to check the error here, the caller will do that */
+ if (PyErr_Occurred()) {
+ Py_DECREF(m);
+ m = NULL;
+ }
+ return m;
}
diff --git a/Modules/atexitmodule.c b/Modules/atexitmodule.c
index 60bb932..5b073cb 100644
--- a/Modules/atexitmodule.c
+++ b/Modules/atexitmodule.c
@@ -233,21 +233,35 @@ upon normal program termination.\n\
Two public functions, register and unregister, are defined.\n\
");
+
+static struct PyModuleDef atexitmodule = {
+ PyModuleDef_HEAD_INIT,
+ "atexit",
+ atexit__doc__,
+ -1,
+ atexit_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initatexit(void)
+PyInit_atexit(void)
{
PyObject *m;
atexit_callbacks = PyMem_New(atexit_callback*, callback_len);
if (atexit_callbacks == NULL)
- return;
+ return NULL;
- m = Py_InitModule3("atexit", atexit_methods, atexit__doc__);
+ m = PyModule_Create(&atexitmodule);
if (m == NULL)
- return;
+ return NULL;
_Py_PyAtExit(atexit_callfuncs);
/* Register a callback that will free
atexit_callbacks, otherwise valgrind will report memory leaks. */
Py_AtExit(atexit_cleanup);
+ return m;
}
diff --git a/Modules/audioop.c b/Modules/audioop.c
index 7f1e34b..57f25c6 100644
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -1600,17 +1600,31 @@ static PyMethodDef audioop_methods[] = {
{ 0, 0 }
};
+
+static struct PyModuleDef audioopmodule = {
+ PyModuleDef_HEAD_INIT,
+ "audioop",
+ NULL,
+ -1,
+ audioop_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initaudioop(void)
+PyInit_audioop(void)
{
PyObject *m, *d;
- m = Py_InitModule("audioop", audioop_methods);
+ m = PyModule_Create(&audioopmodule);
if (m == NULL)
- return;
+ return NULL;
d = PyModule_GetDict(m);
if (d == NULL)
- return;
+ return NULL;
AudioopError = PyErr_NewException("audioop.error", NULL, NULL);
if (AudioopError != NULL)
PyDict_SetItemString(d,"error",AudioopError);
+ return m;
}
diff --git a/Modules/binascii.c b/Modules/binascii.c
index 62b86a8..d3e8a51 100644
--- a/Modules/binascii.c
+++ b/Modules/binascii.c
@@ -1357,18 +1357,31 @@ static struct PyMethodDef binascii_module_methods[] = {
};
-/* Initialization function for the module (*must* be called initbinascii) */
+/* Initialization function for the module (*must* be called PyInit_binascii) */
PyDoc_STRVAR(doc_binascii, "Conversion between binary data and ASCII");
+
+static struct PyModuleDef binasciimodule = {
+ PyModuleDef_HEAD_INIT,
+ "binascii",
+ doc_binascii,
+ -1,
+ binascii_module_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initbinascii(void)
+PyInit_binascii(void)
{
PyObject *m, *d;
/* Create the module and add the functions */
- m = Py_InitModule3("binascii", binascii_module_methods, doc_binascii);
+ m = PyModule_Create(&binasciimodule);
if (m == NULL)
- return;
+ return NULL;
d = PyModule_GetDict(m);
@@ -1376,4 +1389,9 @@ initbinascii(void)
PyDict_SetItemString(d, "Error", Error);
Incomplete = PyErr_NewException("binascii.Incomplete", NULL, NULL);
PyDict_SetItemString(d, "Incomplete", Incomplete);
+ if (PyErr_Occurred()) {
+ Py_DECREF(m);
+ m = NULL;
+ }
+ return m;
}
diff --git a/Modules/bz2module.c b/Modules/bz2module.c
index 4adf826..db10f31 100644
--- a/Modules/bz2module.c
+++ b/Modules/bz2module.c
@@ -2026,8 +2026,21 @@ interface, one shot (de)compression functions, and types for\n\
sequential (de)compression.\n\
");
+
+static struct PyModuleDef bz2module = {
+ PyModuleDef_HEAD_INIT,
+ "bz2",
+ bz2__doc__,
+ -1,
+ bz2_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initbz2(void)
+PyInit_bz2(void)
{
PyObject *m;
@@ -2035,9 +2048,9 @@ initbz2(void)
Py_TYPE(&BZ2Comp_Type) = &PyType_Type;
Py_TYPE(&BZ2Decomp_Type) = &PyType_Type;
- m = Py_InitModule3("bz2", bz2_methods, bz2__doc__);
+ m = PyModule_Create(&bz2module);
if (m == NULL)
- return;
+ return NULL;
PyModule_AddObject(m, "__author__", PyUnicode_FromString(__author__));
@@ -2049,4 +2062,5 @@ initbz2(void)
Py_INCREF(&BZ2Decomp_Type);
PyModule_AddObject(m, "BZ2Decompressor", (PyObject *)&BZ2Decomp_Type);
+ return m;
}
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;
}
diff --git a/Modules/cmathmodule.c b/Modules/cmathmodule.c
index 109f2cc..eec618e 100644
--- a/Modules/cmathmodule.c
+++ b/Modules/cmathmodule.c
@@ -1077,14 +1077,27 @@ static PyMethodDef cmath_methods[] = {
{NULL, NULL} /* sentinel */
};
+
+static struct PyModuleDef cmathmodule = {
+ PyModuleDef_HEAD_INIT,
+ "cmath",
+ module_doc,
+ -1,
+ cmath_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initcmath(void)
+PyInit_cmath(void)
{
PyObject *m;
- m = Py_InitModule3("cmath", cmath_methods, module_doc);
+ m = PyModule_Create(&cmathmodule);
if (m == NULL)
- return;
+ return NULL;
PyModule_AddObject(m, "pi",
PyFloat_FromDouble(Py_MATH_PI));
@@ -1204,4 +1217,5 @@ initcmath(void)
C(INF,N) C(U,U) C(INF,-0.) C(INF,0.) C(U,U) C(INF,N) C(INF,N)
C(N,N) C(N,N) C(N,0.) C(N,0.) C(N,N) C(N,N) C(N,N)
})
+ return m;
}
diff --git a/Modules/config.c.in b/Modules/config.c.in
index 653faaf..28029d5 100644
--- a/Modules/config.c.in
+++ b/Modules/config.c.in
@@ -24,11 +24,11 @@ extern "C" {
/* -- ADDMODULE MARKER 1 -- */
-extern void PyMarshal_Init(void);
-extern void initimp(void);
-extern void initgc(void);
-extern void init_ast(void);
-extern void _PyWarnings_Init(void);
+extern PyObject* PyMarshal_Init(void);
+extern PyObject* PyInit_imp(void);
+extern PyObject* PyInit_gc(void);
+extern PyObject* PyInit__ast(void);
+extern PyObject* _PyWarnings_Init(void);
struct _inittab _PyImport_Inittab[] = {
@@ -38,10 +38,10 @@ struct _inittab _PyImport_Inittab[] = {
{"marshal", PyMarshal_Init},
/* This lives in import.c */
- {"imp", initimp},
+ {"imp", PyInit_imp},
/* This lives in Python/Python-ast.c */
- {"_ast", init_ast},
+ {"_ast", PyInit__ast},
/* These entries are here for sys.builtin_module_names */
{"__main__", NULL},
@@ -49,7 +49,7 @@ struct _inittab _PyImport_Inittab[] = {
{"sys", NULL},
/* This lives in gcmodule.c */
- {"gc", initgc},
+ {"gc", PyInit_gc},
/* This lives in _warnings.c */
{"_warnings", _PyWarnings_Init},
diff --git a/Modules/cryptmodule.c b/Modules/cryptmodule.c
index 6377f84..d3d9271 100644
--- a/Modules/cryptmodule.c
+++ b/Modules/cryptmodule.c
@@ -42,8 +42,21 @@ static PyMethodDef crypt_methods[] = {
{NULL, NULL} /* sentinel */
};
+
+static struct PyModuleDef cryptmodule = {
+ PyModuleDef_HEAD_INIT,
+ "crypt",
+ NULL,
+ -1,
+ crypt_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initcrypt(void)
+PyInit_crypt(void)
{
- Py_InitModule("crypt", crypt_methods);
+ return PyModule_Create(&cryptmodule);
}
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index f37290c..7d44b24 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -4661,45 +4661,57 @@ static PyDateTime_CAPI CAPI = {
};
+
+static struct PyModuleDef datetimemodule = {
+ PyModuleDef_HEAD_INIT,
+ "datetime",
+ "Fast implementation of the datetime type.",
+ -1,
+ module_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initdatetime(void)
+PyInit_datetime(void)
{
PyObject *m; /* a module object */
PyObject *d; /* its dict */
PyObject *x;
- m = Py_InitModule3("datetime", module_methods,
- "Fast implementation of the datetime type.");
+ m = PyModule_Create(&datetimemodule);
if (m == NULL)
- return;
+ return NULL;
if (PyType_Ready(&PyDateTime_DateType) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PyDateTime_DateTimeType) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PyDateTime_DeltaType) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PyDateTime_TimeType) < 0)
- return;
+ return NULL;
if (PyType_Ready(&PyDateTime_TZInfoType) < 0)
- return;
+ return NULL;
/* timedelta values */
d = PyDateTime_DeltaType.tp_dict;
x = new_delta(0, 0, 1, 0);
if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
x = new_delta(-MAX_DELTA_DAYS, 0, 0, 0);
if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
x = new_delta(MAX_DELTA_DAYS, 24*3600-1, 1000000-1, 0);
if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
/* date values */
@@ -4707,17 +4719,17 @@ initdatetime(void)
x = new_date(1, 1, 1);
if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
x = new_date(MAXYEAR, 12, 31);
if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
x = new_delta(1, 0, 0, 0);
if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
/* time values */
@@ -4725,17 +4737,17 @@ initdatetime(void)
x = new_time(0, 0, 0, 0, Py_None);
if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
x = new_time(23, 59, 59, 999999, Py_None);
if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
x = new_delta(0, 0, 1, 0);
if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
/* datetime values */
@@ -4743,17 +4755,17 @@ initdatetime(void)
x = new_datetime(1, 1, 1, 0, 0, 0, 0, Py_None);
if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
x = new_datetime(MAXYEAR, 12, 31, 23, 59, 59, 999999, Py_None);
if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
x = new_delta(0, 0, 1, 0);
if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
- return;
+ return NULL;
Py_DECREF(x);
/* module initialization */
@@ -4779,7 +4791,7 @@ initdatetime(void)
x = PyCObject_FromVoidPtrAndDesc(&CAPI, (void*) DATETIME_API_MAGIC,
NULL);
if (x == NULL)
- return;
+ return NULL;
PyModule_AddObject(m, "datetime_CAPI", x);
/* A 4-year cycle has an extra leap day over what we'd get from
@@ -4807,7 +4819,7 @@ initdatetime(void)
seconds_per_day = PyLong_FromLong(24 * 3600);
if (us_per_us == NULL || us_per_ms == NULL || us_per_second == NULL ||
us_per_minute == NULL || seconds_per_day == NULL)
- return;
+ return NULL;
/* The rest are too big for 32-bit ints, but even
* us_per_week fits in 40 bits, so doubles should be exact.
@@ -4816,7 +4828,8 @@ initdatetime(void)
us_per_day = PyLong_FromDouble(86400000000.0);
us_per_week = PyLong_FromDouble(604800000000.0);
if (us_per_hour == NULL || us_per_day == NULL || us_per_week == NULL)
- return;
+ return NULL;
+ return m;
}
/* ---------------------------------------------------------------------------
diff --git a/Modules/errnomodule.c b/Modules/errnomodule.c
index ab4b5f1..227e24b 100644
--- a/Modules/errnomodule.c
+++ b/Modules/errnomodule.c
@@ -53,17 +53,29 @@ Symbols that are not relevant to the underlying system are not defined.\n\
To map error codes to error messages, use the function os.strerror(),\n\
e.g. os.strerror(2) could return 'No such file or directory'.");
+static struct PyModuleDef errnomodule = {
+ PyModuleDef_HEAD_INIT,
+ "errno",
+ errno__doc__,
+ -1,
+ errno_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initerrno(void)
+PyInit_errno(void)
{
PyObject *m, *d, *de;
- m = Py_InitModule3("errno", errno_methods, errno__doc__);
+ m = PyModule_Create(&errnomodule);
if (m == NULL)
- return;
+ return NULL;
d = PyModule_GetDict(m);
de = PyDict_New();
if (!d || !de || PyDict_SetItemString(d, "errorcode", de) < 0)
- return;
+ return NULL;
/* Macro so I don't have to edit each and every line below... */
#define inscode(d, ds, de, name, code, comment) _inscode(d, de, name, code)
@@ -786,4 +798,5 @@ initerrno(void)
#endif
Py_DECREF(de);
+ return m;
}
diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c
index 9acfece..353889c 100644
--- a/Modules/fcntlmodule.c
+++ b/Modules/fcntlmodule.c
@@ -599,17 +599,31 @@ all_ins(PyObject* d)
return 0;
}
+
+static struct PyModuleDef fcntlmodule = {
+ PyModuleDef_HEAD_INIT,
+ "fcntl",
+ module_doc,
+ -1,
+ fcntl_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initfcntl(void)
+PyInit_fcntl(void)
{
PyObject *m, *d;
/* Create the module and add the functions and documentation */
- m = Py_InitModule3("fcntl", fcntl_methods, module_doc);
+ m = PyModule_Create(&fcntlmodule);
if (m == NULL)
- return;
+ return NULL;
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
all_ins(d);
+ return m;
}
diff --git a/Modules/fpectlmodule.c b/Modules/fpectlmodule.c
index 74354ba..d3518f5 100644
--- a/Modules/fpectlmodule.c
+++ b/Modules/fpectlmodule.c
@@ -90,7 +90,8 @@ static Sigfunc sigfpe_handler;
static void fpe_reset(Sigfunc *);
static PyObject *fpe_error;
-PyMODINIT_FUNC initfpectl(void);
+
+PyMODINIT_FUNC PyInit_fpectl(void);
static PyObject *turnon_sigfpe (PyObject *self,PyObject *args);
static PyObject *turnoff_sigfpe (PyObject *self,PyObject *args);
@@ -286,16 +287,29 @@ static void sigfpe_handler(int signo)
}
}
-PyMODINIT_FUNC initfpectl(void)
+static struct PyModuleDef fpectlmodule = {
+ PyModuleDef_HEAD_INIT,
+ "fpectl",
+ NULL,
+ -1,
+ fpectl_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+PyMODINIT_FUNC PyInit_fpectl(void)
{
PyObject *m, *d;
- m = Py_InitModule("fpectl", fpectl_methods);
+ m = PyModule_Create("fpectl", fpectl_methods);
if (m == NULL)
- return;
+ return NULL;
d = PyModule_GetDict(m);
fpe_error = PyErr_NewException("fpectl.error", NULL, NULL);
if (fpe_error != NULL)
PyDict_SetItemString(d, "error", fpe_error);
+ return m;
}
#ifdef __cplusplus
diff --git a/Modules/fpetestmodule.c b/Modules/fpetestmodule.c
index 22e95db..64acd3d 100644
--- a/Modules/fpetestmodule.c
+++ b/Modules/fpetestmodule.c
@@ -44,7 +44,8 @@
#include "Python.h"
static PyObject *fpe_error;
-PyMODINIT_FUNC initfpetest(void);
+
+PyMODINIT_FUNC PyInit_fpetest(void);
static PyObject *test(PyObject *self,PyObject *args);
static double db0(double);
static double overflow(double);
@@ -172,15 +173,28 @@ static double overflow(double b)
return a;
}
-PyMODINIT_FUNC initfpetest(void)
+static struct PyModuleDef fpetestmodule = {
+ PyModuleDef_HEAD_INIT,
+ "fpetest",
+ NULL,
+ -1,
+ fpetest_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+PyMODINIT_FUNC PyInit_fpetest(void)
{
PyObject *m, *d;
- m = Py_InitModule("fpetest", fpetest_methods);
+ m = PyModule_Create(&fpetestmodule);
if (m == NULL)
- return;
+ return NULL;
d = PyModule_GetDict(m);
fpe_error = PyErr_NewException("fpetest.error", NULL, NULL);
if (fpe_error != NULL)
PyDict_SetItemString(d, "error", fpe_error);
+ return m;
}
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index f332231..897590c 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -1192,27 +1192,37 @@ static PyMethodDef GcMethods[] = {
{NULL, NULL} /* Sentinel */
};
+static struct PyModuleDef gcmodule = {
+ PyModuleDef_HEAD_INIT,
+ "gc",
+ gc__doc__,
+ -1,
+ GcMethods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+
PyMODINIT_FUNC
-initgc(void)
+PyInit_gc(void)
{
PyObject *m;
- m = Py_InitModule4("gc",
- GcMethods,
- gc__doc__,
- NULL,
- PYTHON_API_VERSION);
+ m = PyModule_Create(&gcmodule);
+
if (m == NULL)
- return;
+ return NULL;
if (garbage == NULL) {
garbage = PyList_New(0);
if (garbage == NULL)
- return;
+ return NULL;
}
Py_INCREF(garbage);
if (PyModule_AddObject(m, "garbage", garbage) < 0)
- return;
+ return NULL;
/* Importing can't be done in collect() because collect()
* can be called via PyGC_Collect() in Py_Finalize().
@@ -1226,13 +1236,14 @@ initgc(void)
PyErr_Clear();
}
-#define ADD_INT(NAME) if (PyModule_AddIntConstant(m, #NAME, NAME) < 0) return
+#define ADD_INT(NAME) if (PyModule_AddIntConstant(m, #NAME, NAME) < 0) return NULL
ADD_INT(DEBUG_STATS);
ADD_INT(DEBUG_COLLECTABLE);
ADD_INT(DEBUG_UNCOLLECTABLE);
ADD_INT(DEBUG_SAVEALL);
ADD_INT(DEBUG_LEAK);
#undef ADD_INT
+ return m;
}
/* API to invoke gc.collect() from C */
diff --git a/Modules/grpmodule.c b/Modules/grpmodule.c
index a39ca76..039f794 100644
--- a/Modules/grpmodule.c
+++ b/Modules/grpmodule.c
@@ -179,16 +179,30 @@ according to the password database. Check both databases to get\n\
complete membership information.)");
+
+static struct PyModuleDef grpmodule = {
+ PyModuleDef_HEAD_INIT,
+ "grp",
+ grp__doc__,
+ -1,
+ grp_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initgrp(void)
+PyInit_grp(void)
{
PyObject *m, *d;
- m = Py_InitModule3("grp", grp_methods, grp__doc__);
+ m = PyModule_Create(&grpmodule);
if (m == NULL)
- return;
+ return NULL;
d = PyModule_GetDict(m);
if (!initialized)
PyStructSequence_InitType(&StructGrpType, &struct_group_type_desc);
PyDict_SetItemString(d, "struct_group", (PyObject *) &StructGrpType);
initialized = 1;
+ return m;
}
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index fb61302..3a095b6 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -3030,8 +3030,21 @@ static PyMethodDef module_methods[] = {
{NULL, NULL} /* sentinel */
};
+
+static struct PyModuleDef itertoolsmodule = {
+ PyModuleDef_HEAD_INIT,
+ "itertools",
+ module_doc,
+ -1,
+ module_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-inititertools(void)
+PyInit_itertools(void)
{
int i;
PyObject *m;
@@ -3055,13 +3068,13 @@ inititertools(void)
};
Py_TYPE(&teedataobject_type) = &PyType_Type;
- m = Py_InitModule3("itertools", module_methods, module_doc);
+ m = PyModule_Create(&itertoolsmodule);
if (m == NULL)
- return;
+ return NULL;
for (i=0 ; typelist[i] != NULL ; i++) {
if (PyType_Ready(typelist[i]) < 0)
- return;
+ return NULL;
name = strchr(typelist[i]->tp_name, '.');
assert (name != NULL);
Py_INCREF(typelist[i]);
@@ -3069,9 +3082,10 @@ inititertools(void)
}
if (PyType_Ready(&teedataobject_type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&tee_type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&_grouper_type) < 0)
- return;
+ return NULL;
+ return m;
}
diff --git a/Modules/makesetup b/Modules/makesetup
index 8862c36..23f778d 100755
--- a/Modules/makesetup
+++ b/Modules/makesetup
@@ -24,8 +24,8 @@
# Copying config.c.in to config.c:
# - insert an identifying comment at the start
# - for each <module> mentioned in Setup before *noconfig*:
-# + insert 'extern void init<module>(void);' before MARKER 1
-# + insert '{"<module>", initmodule},' before MARKER 2
+# + insert 'extern PyObject* PyInit_<module>(void);' before MARKER 1
+# + insert '{"<module>", PyInit_<module>},' before MARKER 2
#
# Copying Makefile.pre to Makefile:
# - insert an identifying comment at the start
@@ -260,8 +260,8 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
INITBITS=
for mod in $MODS
do
- EXTDECLS="${EXTDECLS}extern void init$mod(void);$NL"
- INITBITS="${INITBITS} {\"$mod\", init$mod},$NL"
+ EXTDECLS="${EXTDECLS}extern PyObject* PyInit_$mod(void);$NL"
+ INITBITS="${INITBITS} {\"$mod\", PyInit_$mod},$NL"
done
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index f759ada..fa607e3 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -1099,12 +1099,25 @@ PyDoc_STRVAR(module_doc,
"This module is always available. It provides access to the\n"
"mathematical functions defined by the C standard.");
+
+static struct PyModuleDef mathmodule = {
+ PyModuleDef_HEAD_INIT,
+ "math",
+ module_doc,
+ -1,
+ math_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initmath(void)
+PyInit_math(void)
{
PyObject *m;
- m = Py_InitModule3("math", math_methods, module_doc);
+ m = PyModule_Create(&mathmodule);
if (m == NULL)
goto finally;
@@ -1112,5 +1125,5 @@ initmath(void)
PyModule_AddObject(m, "e", PyFloat_FromDouble(Py_MATH_E));
finally:
- return;
+ return m;
}
diff --git a/Modules/md5module.c b/Modules/md5module.c
index 6a18a13..c6610a6 100644
--- a/Modules/md5module.c
+++ b/Modules/md5module.c
@@ -547,15 +547,24 @@ static struct PyMethodDef MD5_functions[] = {
#define insint(n,v) { PyModule_AddIntConstant(m,n,v); }
+
+static struct PyModuleDef _md5module = {
+ PyModuleDef_HEAD_INIT,
+ "_md5",
+ NULL,
+ -1,
+ MD5_functions,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_md5(void)
+PyInit__md5(void)
{
- PyObject *m;
-
Py_TYPE(&MD5type) = &PyType_Type;
if (PyType_Ready(&MD5type) < 0)
- return;
- m = Py_InitModule("_md5", MD5_functions);
- if (m == NULL)
- return;
+ return NULL;
+ return PyModule_Create("_md5", MD5_functions);
}
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index 3600c98..51ad69c 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -1312,24 +1312,37 @@ setint(PyObject *d, const char *name, long value)
}
}
+
+static struct PyModuleDef mmapmodule = {
+ PyModuleDef_HEAD_INIT,
+ "mmap",
+ NULL,
+ -1,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initmmap(void)
+PyInit_mmap(void)
{
PyObject *dict, *module;
if (PyType_Ready(&mmap_object_type) < 0)
- return;
+ return NULL;
- module = Py_InitModule("mmap", NULL);
+ module = PyModule_Create(&mmapmodule);
if (module == NULL)
- return;
+ return NULL;
dict = PyModule_GetDict(module);
if (!dict)
- return;
+ return NULL;
mmap_module_error = PyErr_NewException("mmap.error",
PyExc_EnvironmentError , NULL);
if (mmap_module_error == NULL)
- return;
+ return NULL;
PyDict_SetItemString(dict, "error", mmap_module_error);
PyDict_SetItemString(dict, "mmap", (PyObject*) &mmap_object_type);
#ifdef PROT_EXEC
@@ -1366,4 +1379,5 @@ initmmap(void)
setint(dict, "ACCESS_READ", ACCESS_READ);
setint(dict, "ACCESS_WRITE", ACCESS_WRITE);
setint(dict, "ACCESS_COPY", ACCESS_COPY);
+ return module;
}
diff --git a/Modules/nismodule.c b/Modules/nismodule.c
index bf2d185..3af394d 100644
--- a/Modules/nismodule.c
+++ b/Modules/nismodule.c
@@ -430,15 +430,28 @@ static PyMethodDef nis_methods[] = {
PyDoc_STRVAR(nis__doc__,
"This module contains functions for accessing NIS maps.\n");
-void
-initnis (void)
+static struct PyModuleDef nismodule = {
+ PyModuleDef_HEAD_INIT,
+ "nis",
+ nis__doc__,
+ -1,
+ nis_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+PyObject*
+PyInit_nis (void)
{
PyObject *m, *d;
- m = Py_InitModule3("nis", nis_methods, nis__doc__);
+ m = PyModule_Create(&nismodule);
if (m == NULL)
- return;
+ return NULL;
d = PyModule_GetDict(m);
NisError = PyErr_NewException("nis.error", NULL, NULL);
if (NisError != NULL)
PyDict_SetItemString(d, "error", NisError);
+ return m;
}
diff --git a/Modules/operator.c b/Modules/operator.c
index e86bccf..d31b178 100644
--- a/Modules/operator.c
+++ b/Modules/operator.c
@@ -688,31 +688,44 @@ static PyTypeObject methodcaller_type = {
};
-/* Initialization function for the module (*must* be called initoperator) */
+/* Initialization function for the module (*must* be called PyInit_operator) */
+
+
+static struct PyModuleDef operatormodule = {
+ PyModuleDef_HEAD_INIT,
+ "operator",
+ operator_doc,
+ -1,
+ operator_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
PyMODINIT_FUNC
-initoperator(void)
+PyInit_operator(void)
{
PyObject *m;
/* Create the module and add the functions */
- m = Py_InitModule4("operator", operator_methods, operator_doc,
- (PyObject*)NULL, PYTHON_API_VERSION);
+ m = PyModule_Create(&operatormodule);
if (m == NULL)
- return;
+ return NULL;
if (PyType_Ready(&itemgetter_type) < 0)
- return;
+ return NULL;
Py_INCREF(&itemgetter_type);
PyModule_AddObject(m, "itemgetter", (PyObject *)&itemgetter_type);
if (PyType_Ready(&attrgetter_type) < 0)
- return;
+ return NULL;
Py_INCREF(&attrgetter_type);
PyModule_AddObject(m, "attrgetter", (PyObject *)&attrgetter_type);
if (PyType_Ready(&methodcaller_type) < 0)
- return;
+ return NULL;
Py_INCREF(&methodcaller_type);
PyModule_AddObject(m, "methodcaller", (PyObject *)&methodcaller_type);
+ return m;
}
diff --git a/Modules/ossaudiodev.c b/Modules/ossaudiodev.c
index b976873..43215b0 100644
--- a/Modules/ossaudiodev.c
+++ b/Modules/ossaudiodev.c
@@ -889,7 +889,7 @@ static PyMethodDef ossaudiodev_methods[] = {
#define _EXPORT_INT(mod, name) \
- if (PyModule_AddIntConstant(mod, #name, (long) (name)) == -1) return;
+ if (PyModule_AddIntConstant(mod, #name, (long) (name)) == -1) return NULL;
static char *control_labels[] = SOUND_DEVICE_LABELS;
@@ -939,14 +939,26 @@ error1:
}
-void
-initossaudiodev(void)
+static struct PyModuleDef ossaudiodevmodule = {
+ PyModuleDef_HEAD_INIT,
+ "ossaudiodev",
+ NULL,
+ -1,
+ ossaudiodev_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+PyObject*
+PyInit_ossaudiodev(void)
{
PyObject *m;
- m = Py_InitModule("ossaudiodev", ossaudiodev_methods);
+ m = PyModule_Create(&ossaudiodevmodule);
if (m == NULL)
- return;
+ return NULL;
OSSAudioError = PyErr_NewException("ossaudiodev.OSSAudioError",
NULL, NULL);
@@ -961,7 +973,7 @@ initossaudiodev(void)
/* Build 'control_labels' and 'control_names' lists and add them
to the module. */
if (build_namelists(m) == -1) /* XXX what to do here? */
- return;
+ return NULL;
/* Expose the audio format numbers -- essential! */
_EXPORT_INT(m, AFMT_QUERY);
@@ -1133,4 +1145,5 @@ initossaudiodev(void)
_EXPORT_INT(m, SNDCTL_TMR_STOP);
_EXPORT_INT(m, SNDCTL_TMR_TEMPO);
_EXPORT_INT(m, SNDCTL_TMR_TIMEBASE);
+ return m;
}
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index ecd4b83..cd7a3b2 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -297,7 +297,7 @@ parser_st2tuple(PyST_Object *self, PyObject *args, PyObject *kw)
static char *keywords[] = {"ast", "line_info", "col_info", NULL};
- if (self == NULL) {
+ if (self == NULL || PyModule_Check(self)) {
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|OO:st2tuple", keywords,
&PyST_Type, &self, &line_option,
&col_option);
@@ -341,7 +341,7 @@ parser_st2list(PyST_Object *self, PyObject *args, PyObject *kw)
static char *keywords[] = {"ast", "line_info", "col_info", NULL};
- if (self == NULL)
+ if (self == NULL || PyModule_Check(self))
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|OO:st2list", keywords,
&PyST_Type, &self, &line_option,
&col_option);
@@ -383,7 +383,7 @@ parser_compilest(PyST_Object *self, PyObject *args, PyObject *kw)
static char *keywords[] = {"ast", "filename", NULL};
- if (self == NULL)
+ if (self == NULL || PyModule_Check(self))
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|s:compilest", keywords,
&PyST_Type, &self, &str);
else
@@ -412,7 +412,7 @@ parser_isexpr(PyST_Object *self, PyObject *args, PyObject *kw)
static char *keywords[] = {"ast", NULL};
- if (self == NULL)
+ if (self == NULL || PyModule_Check(self))
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!:isexpr", keywords,
&PyST_Type, &self);
else
@@ -435,7 +435,7 @@ parser_issuite(PyST_Object *self, PyObject *args, PyObject *kw)
static char *keywords[] = {"ast", NULL};
- if (self == NULL)
+ if (self == NULL || PyModule_Check(self))
ok = PyArg_ParseTupleAndKeywords(args, kw, "O!:issuite", keywords,
&PyST_Type, &self);
else
@@ -3047,33 +3047,45 @@ static PyMethodDef parser_functions[] = {
};
-PyMODINIT_FUNC initparser(void); /* supply a prototype */
+
+static struct PyModuleDef parsermodule = {
+ PyModuleDef_HEAD_INIT,
+ "parser",
+ NULL,
+ -1,
+ parser_functions,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+PyMODINIT_FUNC PyInit_parser(void); /* supply a prototype */
PyMODINIT_FUNC
-initparser(void)
+PyInit_parser(void)
{
PyObject *module, *copyreg;
Py_TYPE(&PyST_Type) = &PyType_Type;
- module = Py_InitModule("parser", parser_functions);
+ module = PyModule_Create(&parsermodule);
if (module == NULL)
- return;
+ return NULL;
if (parser_error == 0)
parser_error = PyErr_NewException("parser.ParserError", NULL, NULL);
if (parser_error == 0)
- /* caller will check PyErr_Occurred() */
- return;
+ return NULL;
/* CAUTION: The code next used to skip bumping the refcount on
- * parser_error. That's a disaster if initparser() gets called more
+ * parser_error. That's a disaster if PyInit_parser() gets called more
* than once. By incref'ing, we ensure that each module dict that
* gets created owns its reference to the shared parser_error object,
* and the file static parser_error vrbl owns a reference too.
*/
Py_INCREF(parser_error);
if (PyModule_AddObject(module, "ParserError", parser_error) != 0)
- return;
+ return NULL;
Py_INCREF(&PyST_Type);
PyModule_AddObject(module, "ASTType", (PyObject*)&PyST_Type);
@@ -3112,4 +3124,5 @@ initparser(void)
Py_XDECREF(pickler);
Py_DECREF(copyreg);
}
+ return module;
}
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index f6bb023..16aed52 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -7326,41 +7326,52 @@ all_ins(PyObject *d)
#if (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__)) && !defined(__QNX__)
-#define INITFUNC initnt
+#define INITFUNC PyInit_nt
#define MODNAME "nt"
#elif defined(PYOS_OS2)
-#define INITFUNC initos2
+#define INITFUNC PyInit_os2
#define MODNAME "os2"
#else
-#define INITFUNC initposix
+#define INITFUNC PyInit_posix
#define MODNAME "posix"
#endif
+static struct PyModuleDef posixmodule = {
+ PyModuleDef_HEAD_INIT,
+ MODNAME,
+ posix__doc__,
+ -1,
+ posix_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+
PyMODINIT_FUNC
INITFUNC(void)
{
PyObject *m, *v;
- m = Py_InitModule3(MODNAME,
- posix_methods,
- posix__doc__);
+ m = PyModule_Create(&posixmodule);
if (m == NULL)
- return;
+ return NULL;
/* Initialize environ dictionary */
v = convertenviron();
Py_XINCREF(v);
if (v == NULL || PyModule_AddObject(m, "environ", v) != 0)
- return;
+ return NULL;
Py_DECREF(v);
if (all_ins(m))
- return;
+ return NULL;
if (setup_confname_tables(m))
- return;
+ return NULL;
Py_INCREF(PyExc_OSError);
PyModule_AddObject(m, "error", PyExc_OSError);
@@ -7403,7 +7414,7 @@ INITFUNC(void)
#ifdef HAVE_FSTATVFS
if (fstatvfs == NULL) {
if (PyObject_DelAttrString(m, "fstatvfs") == -1) {
- return;
+ return NULL;
}
}
#endif /* HAVE_FSTATVFS */
@@ -7411,7 +7422,7 @@ INITFUNC(void)
#ifdef HAVE_STATVFS
if (statvfs == NULL) {
if (PyObject_DelAttrString(m, "statvfs") == -1) {
- return;
+ return NULL;
}
}
#endif /* HAVE_STATVFS */
@@ -7419,13 +7430,14 @@ INITFUNC(void)
# ifdef HAVE_LCHOWN
if (lchown == NULL) {
if (PyObject_DelAttrString(m, "lchown") == -1) {
- return;
+ return NULL;
}
}
#endif /* HAVE_LCHOWN */
#endif /* __APPLE__ */
+ return m;
}
diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c
index 9511736..cb99183 100644
--- a/Modules/pwdmodule.c
+++ b/Modules/pwdmodule.c
@@ -182,13 +182,26 @@ static PyMethodDef pwd_methods[] = {
{NULL, NULL} /* sentinel */
};
+static struct PyModuleDef pwdmodule = {
+ PyModuleDef_HEAD_INIT,
+ "pwd",
+ pwd__doc__,
+ -1,
+ pwd_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+
PyMODINIT_FUNC
-initpwd(void)
+PyInit_pwd(void)
{
PyObject *m;
- m = Py_InitModule3("pwd", pwd_methods, pwd__doc__);
+ m = PyModule_Create(&pwdmodule);
if (m == NULL)
- return;
+ return NULL;
if (!initialized)
PyStructSequence_InitType(&StructPwdType,
@@ -198,4 +211,5 @@ initpwd(void)
/* And for b/w compatibility (this was defined by mistake): */
PyModule_AddObject(m, "struct_pwent", (PyObject *) &StructPwdType);
initialized = 1;
+ return m;
}
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index fcd44c3..92fc753 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -1751,7 +1751,7 @@ get_version_string(void)
#endif
#ifndef MODULE_INITFUNC
-#define MODULE_INITFUNC initpyexpat
+#define MODULE_INITFUNC PyInit_pyexpat
#endif
#ifndef PyMODINIT_FUNC
@@ -1764,6 +1764,18 @@ get_version_string(void)
PyMODINIT_FUNC MODULE_INITFUNC(void); /* avoid compiler warnings */
+static struct PyModuleDef pyexpatmodule = {
+ PyModuleDef_HEAD_INIT,
+ MODULE_NAME,
+ pyexpat_module_documentation,
+ -1,
+ pyexpat_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
MODULE_INITFUNC(void)
{
@@ -1777,25 +1789,24 @@ MODULE_INITFUNC(void)
PyObject* capi_object;
if (errmod_name == NULL)
- return;
+ return NULL;
modelmod_name = PyUnicode_FromString(MODULE_NAME ".model");
if (modelmod_name == NULL)
- return;
+ return NULL;
Py_TYPE(&Xmlparsetype) = &PyType_Type;
/* Create the module and add the functions */
- m = Py_InitModule3(MODULE_NAME, pyexpat_methods,
- pyexpat_module_documentation);
+ m = PyModule_Create(&pyexpatmodule);
if (m == NULL)
- return;
+ return NULL;
/* Add some symbolic constants to the module */
if (ErrorObject == NULL) {
ErrorObject = PyErr_NewException("xml.parsers.expat.ExpatError",
NULL, NULL);
if (ErrorObject == NULL)
- return;
+ return NULL;
}
Py_INCREF(ErrorObject);
PyModule_AddObject(m, "error", ErrorObject);
@@ -1844,7 +1855,7 @@ MODULE_INITFUNC(void)
Py_DECREF(modelmod_name);
if (errors_module == NULL || model_module == NULL)
/* Don't core dump later! */
- return;
+ return NULL;
#if XML_COMBINED_VERSION > 19505
{
@@ -1975,6 +1986,7 @@ MODULE_INITFUNC(void)
capi_object = PyCObject_FromVoidPtr(&capi, NULL);
if (capi_object)
PyModule_AddObject(m, "expat_CAPI", capi_object);
+ return m;
}
static void
diff --git a/Modules/readline.c b/Modules/readline.c
index d42998e..98da33b 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -1002,16 +1002,29 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt)
PyDoc_STRVAR(doc_module,
"Importing this module enables command line editing using GNU readline.");
+
+static struct PyModuleDef readlinemodule = {
+ PyModuleDef_HEAD_INIT,
+ "readline",
+ doc_module,
+ -1,
+ readline_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initreadline(void)
+PyInit_readline(void)
{
PyObject *m;
- m = Py_InitModule4("readline", readline_methods, doc_module,
- (PyObject *)NULL, PYTHON_API_VERSION);
+ m = PyModule_Create(&readlinemodule);
if (m == NULL)
- return;
+ return NULL;
PyOS_ReadlineFunctionPointer = call_readline;
setup_readline();
+ return m;
}
diff --git a/Modules/resource.c b/Modules/resource.c
index d67fe99..294ea92 100644
--- a/Modules/resource.c
+++ b/Modules/resource.c
@@ -225,15 +225,28 @@ resource_methods[] = {
/* Module initialization */
+
+static struct PyModuleDef resourcemodule = {
+ PyModuleDef_HEAD_INIT,
+ "resource",
+ NULL,
+ -1,
+ resource_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initresource(void)
+PyInit_resource(void)
{
PyObject *m, *v;
/* Create the module and add the functions */
- m = Py_InitModule("resource", resource_methods);
+ m = PyModule_Create(&resourcemodule);
if (m == NULL)
- return;
+ return NULL;
/* Add some symbolic constants to the module */
if (ResourceError == NULL) {
@@ -326,4 +339,5 @@ initresource(void)
PyModule_AddObject(m, "RLIM_INFINITY", v);
}
initialized = 1;
+ return m;
}
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 56acf60..f1c71e4 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -1729,13 +1729,26 @@ PyDoc_STRVAR(module_doc,
*** IMPORTANT NOTICE ***\n\
On Windows and OpenVMS, only sockets are supported; on Unix, all file descriptors.");
+
+static struct PyModuleDef selectmodule = {
+ PyModuleDef_HEAD_INIT,
+ "select",
+ module_doc,
+ -1,
+ select_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initselect(void)
+PyInit_select(void)
{
PyObject *m;
- m = Py_InitModule3("select", select_methods, module_doc);
+ m = PyModule_Create(&selectmodule);
if (m == NULL)
- return;
+ return NULL;
SelectError = PyErr_NewException("select.error", NULL, NULL);
Py_INCREF(SelectError);
@@ -1780,7 +1793,7 @@ initselect(void)
#ifdef HAVE_EPOLL
Py_TYPE(&pyEpoll_Type) = &PyType_Type;
if (PyType_Ready(&pyEpoll_Type) < 0)
- return;
+ return NULL;
Py_INCREF(&pyEpoll_Type);
PyModule_AddObject(m, "epoll", (PyObject *) &pyEpoll_Type);
@@ -1807,14 +1820,14 @@ initselect(void)
kqueue_event_Type.tp_new = PyType_GenericNew;
Py_TYPE(&kqueue_event_Type) = &PyType_Type;
if(PyType_Ready(&kqueue_event_Type) < 0)
- return;
+ return NULL;
Py_INCREF(&kqueue_event_Type);
PyModule_AddObject(m, "kevent", (PyObject *)&kqueue_event_Type);
Py_TYPE(&kqueue_queue_Type) = &PyType_Type;
if(PyType_Ready(&kqueue_queue_Type) < 0)
- return;
+ return NULL;
Py_INCREF(&kqueue_queue_Type);
PyModule_AddObject(m, "kqueue", (PyObject *)&kqueue_queue_Type);
@@ -1875,4 +1888,5 @@ initselect(void)
#endif
#endif /* HAVE_KQUEUE */
+ return m;
}
diff --git a/Modules/sha1module.c b/Modules/sha1module.c
index 1d5f070..8502264 100644
--- a/Modules/sha1module.c
+++ b/Modules/sha1module.c
@@ -523,15 +523,26 @@ static struct PyMethodDef SHA1_functions[] = {
#define insint(n,v) { PyModule_AddIntConstant(m,n,v); }
+
+static struct PyModuleDef _sha1module = {
+ PyModuleDef_HEAD_INIT,
+ "_sha1",
+ NULL,
+ -1,
+ SHA1_functions,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_sha1(void)
+PyInit__sha1(void)
{
PyObject *m;
Py_TYPE(&SHA1type) = &PyType_Type;
if (PyType_Ready(&SHA1type) < 0)
- return;
- m = Py_InitModule("_sha1", SHA1_functions);
- if (m == NULL)
- return;
+ return NULL;
+ return PyModule_Create(&_sha1module);
}
diff --git a/Modules/sha256module.c b/Modules/sha256module.c
index 162a905..9cecd3a 100644
--- a/Modules/sha256module.c
+++ b/Modules/sha256module.c
@@ -682,18 +682,27 @@ static struct PyMethodDef SHA_functions[] = {
#define insint(n,v) { PyModule_AddIntConstant(m,n,v); }
+
+static struct PyModuleDef _sha256module = {
+ PyModuleDef_HEAD_INIT,
+ "_sha256",
+ NULL,
+ -1,
+ SHA_functions,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_sha256(void)
+PyInit__sha256(void)
{
- PyObject *m;
-
Py_TYPE(&SHA224type) = &PyType_Type;
if (PyType_Ready(&SHA224type) < 0)
- return;
+ return NULL;
Py_TYPE(&SHA256type) = &PyType_Type;
if (PyType_Ready(&SHA256type) < 0)
- return;
- m = Py_InitModule("_sha256", SHA_functions);
- if (m == NULL)
- return;
+ return NULL;
+ return PyModule_Create(&_sha256module);
}
diff --git a/Modules/sha512module.c b/Modules/sha512module.c
index 3fe5a1b..472b158 100644
--- a/Modules/sha512module.c
+++ b/Modules/sha512module.c
@@ -748,20 +748,29 @@ static struct PyMethodDef SHA_functions[] = {
#define insint(n,v) { PyModule_AddIntConstant(m,n,v); }
+
+static struct PyModuleDef _sha512module = {
+ PyModuleDef_HEAD_INIT,
+ "_sha512",
+ NULL,
+ -1,
+ SHA_functions,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_sha512(void)
+PyInit__sha512(void)
{
- PyObject *m;
-
Py_TYPE(&SHA384type) = &PyType_Type;
if (PyType_Ready(&SHA384type) < 0)
- return;
+ return NULL;
Py_TYPE(&SHA512type) = &PyType_Type;
if (PyType_Ready(&SHA512type) < 0)
- return;
- m = Py_InitModule("_sha512", SHA_functions);
- if (m == NULL)
- return;
+ return NULL;
+ return PyModule_Create(&_sha512module);
}
#endif
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index eb4c25a..15cd964 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -516,8 +516,20 @@ ITIMER_PROF -- decrements both when the process is executing and\n\
A signal handler function is called with two arguments:\n\
the first is the signal number, the second is the interrupted stack frame.");
+static struct PyModuleDef signalmodule = {
+ PyModuleDef_HEAD_INIT,
+ "signal",
+ module_doc,
+ -1,
+ signal_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initsignal(void)
+PyInit_signal(void)
{
PyObject *m, *d, *x;
int i;
@@ -528,9 +540,9 @@ initsignal(void)
#endif
/* Create the module and add the functions */
- m = Py_InitModule3("signal", signal_methods, module_doc);
+ m = PyModule_Create(&signalmodule);
if (m == NULL)
- return;
+ return NULL;
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
@@ -787,12 +799,13 @@ initsignal(void)
PyDict_SetItemString(d, "ItimerError", ItimerError);
#endif
- if (!PyErr_Occurred())
- return;
+ if (PyErr_Occurred()) {
+ Py_DECREF(m);
+ m = NULL;
+ }
- /* Check for errors */
finally:
- return;
+ return m;
}
static void
@@ -893,8 +906,11 @@ PyErr_SetInterrupt(void)
void
PyOS_InitInterrupts(void)
{
- initsignal();
- _PyImport_FixupExtension("signal", "signal");
+ PyObject *m = PyInit_signal();
+ if (m) {
+ _PyImport_FixupExtension(m, "signal", "signal");
+ Py_DECREF(m);
+ }
}
void
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index b2cd9a2..f571c66 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -695,7 +695,7 @@ internal_select(PySocketSockObject *s, int writing)
static double defaulttimeout = -1.0; /* Default timeout for new sockets */
-PyMODINIT_FUNC
+static void
init_sockobject(PySocketSockObject *s,
SOCKET_T fd, int family, int type, int proto)
{
@@ -4096,54 +4096,64 @@ PyDoc_STRVAR(socket_doc,
\n\
See the socket module for documentation.");
+static struct PyModuleDef socketmodule = {
+ PyModuleDef_HEAD_INIT,
+ PySocket_MODULE_NAME,
+ socket_doc,
+ -1,
+ socket_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_socket(void)
+PyInit__socket(void)
{
PyObject *m, *has_ipv6;
if (!os_init())
- return;
+ return NULL;
Py_TYPE(&sock_type) = &PyType_Type;
- m = Py_InitModule3(PySocket_MODULE_NAME,
- socket_methods,
- socket_doc);
+ m = PyModule_Create(&socketmodule);
if (m == NULL)
- return;
+ return NULL;
socket_error = PyErr_NewException("socket.error",
PyExc_IOError, NULL);
if (socket_error == NULL)
- return;
+ return NULL;
PySocketModuleAPI.error = socket_error;
Py_INCREF(socket_error);
PyModule_AddObject(m, "error", socket_error);
socket_herror = PyErr_NewException("socket.herror",
socket_error, NULL);
if (socket_herror == NULL)
- return;
+ return NULL;
Py_INCREF(socket_herror);
PyModule_AddObject(m, "herror", socket_herror);
socket_gaierror = PyErr_NewException("socket.gaierror", socket_error,
NULL);
if (socket_gaierror == NULL)
- return;
+ return NULL;
Py_INCREF(socket_gaierror);
PyModule_AddObject(m, "gaierror", socket_gaierror);
socket_timeout = PyErr_NewException("socket.timeout",
socket_error, NULL);
if (socket_timeout == NULL)
- return;
+ return NULL;
Py_INCREF(socket_timeout);
PyModule_AddObject(m, "timeout", socket_timeout);
Py_INCREF((PyObject *)&sock_type);
if (PyModule_AddObject(m, "SocketType",
(PyObject *)&sock_type) != 0)
- return;
+ return NULL;
Py_INCREF((PyObject *)&sock_type);
if (PyModule_AddObject(m, "socket",
(PyObject *)&sock_type) != 0)
- return;
+ return NULL;
#ifdef ENABLE_IPV6
has_ipv6 = Py_True;
@@ -4157,7 +4167,7 @@ init_socket(void)
if (PyModule_AddObject(m, PySocket_CAPI_NAME,
PyCObject_FromVoidPtr((void *)&PySocketModuleAPI, NULL)
) != 0)
- return;
+ return NULL;
/* Address families (we only support AF_INET and AF_UNIX) */
#ifdef AF_UNSPEC
@@ -4999,6 +5009,7 @@ init_socket(void)
#if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_LOCK)
netdb_lock = PyThread_allocate_lock();
#endif
+ return m;
}
diff --git a/Modules/spwdmodule.c b/Modules/spwdmodule.c
index 08a3d1b..a6b9d93 100644
--- a/Modules/spwdmodule.c
+++ b/Modules/spwdmodule.c
@@ -167,17 +167,31 @@ static PyMethodDef spwd_methods[] = {
};
+
+static struct PyModuleDef spwdmodule = {
+ PyModuleDef_HEAD_INIT,
+ "spwd",
+ spwd__doc__,
+ -1,
+ spwd_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initspwd(void)
+PyInit_spwd(void)
{
PyObject *m;
- m=Py_InitModule3("spwd", spwd_methods, spwd__doc__);
+ m=PyModule_Create(&spwdmodule);
if (m == NULL)
- return;
+ return NULL;
if (!initialized)
PyStructSequence_InitType(&StructSpwdType,
&struct_spwd_type_desc);
Py_INCREF((PyObject *) &StructSpwdType);
PyModule_AddObject(m, "struct_spwd", (PyObject *) &StructSpwdType);
initialized = 1;
+ return m;
}
diff --git a/Modules/symtablemodule.c b/Modules/symtablemodule.c
index 21bf583..e3c9e51 100644
--- a/Modules/symtablemodule.c
+++ b/Modules/symtablemodule.c
@@ -47,14 +47,26 @@ static PyMethodDef symtable_methods[] = {
{NULL, NULL} /* sentinel */
};
+static struct PyModuleDef symtablemodule = {
+ PyModuleDef_HEAD_INIT,
+ "_symtable",
+ NULL,
+ -1,
+ symtable_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_symtable(void)
+PyInit__symtable(void)
{
PyObject *m;
- m = Py_InitModule("_symtable", symtable_methods);
+ m = PyModule_Create(&symtablemodule);
if (m == NULL)
- return;
+ return NULL;
PyModule_AddIntConstant(m, "USE", USE);
PyModule_AddIntConstant(m, "DEF_GLOBAL", DEF_GLOBAL);
PyModule_AddIntConstant(m, "DEF_LOCAL", DEF_LOCAL);
@@ -80,4 +92,9 @@ init_symtable(void)
PyModule_AddIntConstant(m, "GLOBAL_IMPLICIT", GLOBAL_IMPLICIT);
PyModule_AddIntConstant(m, "FREE", FREE);
PyModule_AddIntConstant(m, "CELL", CELL);
+ if (PyErr_Occurred()) {
+ Py_DECREF(m);
+ m = 0;
+ }
+ return m;
}
diff --git a/Modules/syslogmodule.c b/Modules/syslogmodule.c
index 6f2a868..6c78679 100644
--- a/Modules/syslogmodule.c
+++ b/Modules/syslogmodule.c
@@ -163,15 +163,28 @@ static PyMethodDef syslog_methods[] = {
/* Initialization function for the module */
+
+static struct PyModuleDef syslogmodule = {
+ PyModuleDef_HEAD_INIT,
+ "syslog",
+ NULL,
+ -1,
+ syslog_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initsyslog(void)
+PyInit_syslog(void)
{
PyObject *m;
/* Create the module and add the functions */
- m = Py_InitModule("syslog", syslog_methods);
+ m = PyModule_Create(&syslogmodule);
if (m == NULL)
- return;
+ return NULL;
/* Add some symbolic constants to the module */
@@ -229,4 +242,5 @@ initsyslog(void)
PyModule_AddIntConstant(m, "LOG_CRON", LOG_CRON);
PyModule_AddIntConstant(m, "LOG_UUCP", LOG_UUCP);
PyModule_AddIntConstant(m, "LOG_NEWS", LOG_NEWS);
+ return m;
}
diff --git a/Modules/termios.c b/Modules/termios.c
index ff69c92..9fccb2e 100644
--- a/Modules/termios.c
+++ b/Modules/termios.c
@@ -2,8 +2,6 @@
#include "Python.h"
-#define PyInit_termios inittermios
-
/* Apparently, on SGI, termios.h won't define CTRL if _XOPEN_SOURCE
is defined, so we define it here. */
#if defined(__sgi)
@@ -902,16 +900,27 @@ static struct constant {
};
+static struct PyModuleDef termiosmodule = {
+ PyModuleDef_HEAD_INIT,
+ "termios",
+ termios__doc__,
+ -1,
+ termios_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
PyInit_termios(void)
{
PyObject *m;
struct constant *constant = termios_constants;
- m = Py_InitModule4("termios", termios_methods, termios__doc__,
- (PyObject *)NULL, PYTHON_API_VERSION);
+ m = PyModule_Create(&termiosmodule);
if (m == NULL)
- return;
+ return NULL;
if (TermiosError == NULL) {
TermiosError = PyErr_NewException("termios.error", NULL, NULL);
@@ -923,4 +932,5 @@ PyInit_termios(void)
PyModule_AddIntConstant(m, constant->name, constant->value);
++constant;
}
+ return m;
}
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index f0edb09..1954d0c 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -661,7 +661,7 @@ Convert a time tuple in local time to seconds since the Epoch.");
#endif /* HAVE_MKTIME */
#ifdef HAVE_WORKING_TZSET
-static void inittimezone(PyObject *module);
+static void PyInit_timezone(PyObject *module);
static PyObject *
time_tzset(PyObject *self, PyObject *unused)
@@ -676,7 +676,7 @@ time_tzset(PyObject *self, PyObject *unused)
tzset();
/* Reset timezone, altzone, daylight and tzname */
- inittimezone(m);
+ PyInit_timezone(m);
Py_DECREF(m);
Py_INCREF(Py_None);
@@ -698,8 +698,8 @@ should not be relied on.");
#endif /* HAVE_WORKING_TZSET */
static void
-inittimezone(PyObject *m) {
- /* This code moved from inittime wholesale to allow calling it from
+PyInit_timezone(PyObject *m) {
+ /* This code moved from PyInit_time wholesale to allow calling it from
time_tzset. In the future, some parts of it can be moved back
(for platforms that don't HAVE_WORKING_TZSET, when we know what they
are), and the extraneous calls to tzset(3) should be removed.
@@ -858,14 +858,27 @@ strptime() -- parse string to time tuple according to format specification\n\
tzset() -- change the local timezone");
+
+static struct PyModuleDef timemodule = {
+ PyModuleDef_HEAD_INIT,
+ "time",
+ module_doc,
+ -1,
+ time_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-inittime(void)
+PyInit_time(void)
{
PyObject *m;
char *p;
- m = Py_InitModule3("time", time_methods, module_doc);
+ m = PyModule_Create(&timemodule);
if (m == NULL)
- return;
+ return NULL;
/* Accept 2-digit dates unless PYTHONY2K is set and non-empty */
p = Py_GETENV("PYTHONY2K");
@@ -875,7 +888,7 @@ inittime(void)
Py_INCREF(moddict);
/* Set, or reset, module variables like time.timezone */
- inittimezone(m);
+ PyInit_timezone(m);
#ifdef MS_WINDOWS
/* Helper to allow interrupts for Windows.
@@ -893,6 +906,7 @@ inittime(void)
Py_INCREF(&StructTimeType);
PyModule_AddObject(m, "struct_time", (PyObject*) &StructTimeType);
initialized = 1;
+ return m;
}
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c
index 760b7cf..575d836 100644
--- a/Modules/unicodedata.c
+++ b/Modules/unicodedata.c
@@ -71,6 +71,7 @@ static PyMemberDef DB_members[] = {
/* forward declaration */
static PyTypeObject UCD_Type;
+#define UCD_Check(o) (Py_TYPE(o)==&UCD_Type)
static PyObject*
new_previous_version(const char*name, const change_record* (*getrecord)(Py_UCS4),
@@ -128,7 +129,7 @@ unicodedata_decimal(PyObject *self, PyObject *args)
if (c == (Py_UCS4)-1)
return NULL;
- if (self) {
+ if (self && UCD_Check(self)) {
const change_record *old = get_old_record(self, c);
if (old->category_changed == 0) {
/* unassigned */
@@ -213,7 +214,7 @@ unicodedata_numeric(PyObject *self, PyObject *args)
if (c == (Py_UCS4)-1)
return NULL;
- if (self) {
+ if (self && UCD_Check(self)) {
const change_record *old = get_old_record(self, c);
if (old->category_changed == 0) {
/* unassigned */
@@ -261,7 +262,7 @@ unicodedata_category(PyObject *self, PyObject *args)
if (c == (Py_UCS4)-1)
return NULL;
index = (int) _getrecord_ex(c)->category;
- if (self) {
+ if (self && UCD_Check(self)) {
const change_record *old = get_old_record(self, c);
if (old->category_changed != 0xFF)
index = old->category_changed;
@@ -290,7 +291,7 @@ unicodedata_bidirectional(PyObject *self, PyObject *args)
if (c == (Py_UCS4)-1)
return NULL;
index = (int) _getrecord_ex(c)->bidirectional;
- if (self) {
+ if (self && UCD_Check(self)) {
const change_record *old = get_old_record(self, c);
if (old->category_changed == 0)
index = 0; /* unassigned */
@@ -321,7 +322,7 @@ unicodedata_combining(PyObject *self, PyObject *args)
if (c == (Py_UCS4)-1)
return NULL;
index = (int) _getrecord_ex(c)->combining;
- if (self) {
+ if (self && UCD_Check(self)) {
const change_record *old = get_old_record(self, c);
if (old->category_changed == 0)
index = 0; /* unassigned */
@@ -350,7 +351,7 @@ unicodedata_mirrored(PyObject *self, PyObject *args)
if (c == (Py_UCS4)-1)
return NULL;
index = (int) _getrecord_ex(c)->mirrored;
- if (self) {
+ if (self && UCD_Check(self)) {
const change_record *old = get_old_record(self, c);
if (old->category_changed == 0)
index = 0; /* unassigned */
@@ -378,7 +379,7 @@ unicodedata_east_asian_width(PyObject *self, PyObject *args)
if (c == (Py_UCS4)-1)
return NULL;
index = (int) _getrecord_ex(c)->east_asian_width;
- if (self) {
+ if (self && UCD_Check(self)) {
const change_record *old = get_old_record(self, c);
if (old->category_changed == 0)
index = 0; /* unassigned */
@@ -411,7 +412,7 @@ unicodedata_decomposition(PyObject *self, PyObject *args)
code = (int)c;
- if (self) {
+ if (self && UCD_Check(self)) {
const change_record *old = get_old_record(self, c);
if (old->category_changed == 0)
return PyUnicode_FromString(""); /* unassigned */
@@ -461,7 +462,8 @@ get_decomp_record(PyObject *self, Py_UCS4 code, int *index, int *prefix, int *co
{
if (code >= 0x110000) {
*index = 0;
- } else if (self && get_old_record(self, code)->category_changed==0) {
+ } else if (self && UCD_Check(self) &&
+ get_old_record(self, code)->category_changed==0) {
/* unassigned in old version */
*index = 0;
}
@@ -540,7 +542,7 @@ nfd_nfkd(PyObject *self, PyObject *input, int k)
continue;
}
/* normalization changes */
- if (self) {
+ if (self && UCD_Check(self)) {
Py_UCS4 value = ((PreviousDBVersion*)self)->normalization(code);
if (value != 0) {
stack[stackptr++] = value;
@@ -828,7 +830,7 @@ _getucname(PyObject *self, Py_UCS4 code, char* buffer, int buflen)
if (code >= 0x110000)
return 0;
- if (self) {
+ if (self && UCD_Check(self)) {
const change_record *old = get_old_record(self, code);
if (old->category_changed == 0) {
/* unassigned */
@@ -1183,17 +1185,29 @@ The module uses the same names and symbols as defined by the\n\
UnicodeData File Format 4.1.0 (see\n\
http://www.unicode.org/Public/4.1.0/ucd/UCD.html).");
+
+static struct PyModuleDef unicodedatamodule = {
+ PyModuleDef_HEAD_INIT,
+ "unicodedata",
+ unicodedata_docstring,
+ -1,
+ unicodedata_functions,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initunicodedata(void)
+PyInit_unicodedata(void)
{
PyObject *m, *v;
Py_TYPE(&UCD_Type) = &PyType_Type;
- m = Py_InitModule3(
- "unicodedata", unicodedata_functions, unicodedata_docstring);
+ m = PyModule_Create(&unicodedatamodule);
if (!m)
- return;
+ return NULL;
PyModule_AddStringConstant(m, "unidata_version", UNIDATA_VERSION);
Py_INCREF(&UCD_Type);
@@ -1208,6 +1222,7 @@ initunicodedata(void)
v = PyCObject_FromVoidPtr((void *) &hashAPI, NULL);
if (v != NULL)
PyModule_AddObject(m, "ucnhash_CAPI", v);
+ return m;
}
/*
diff --git a/Modules/xxmodule.c b/Modules/xxmodule.c
index 18dcf5c..34d2354 100644
--- a/Modules/xxmodule.c
+++ b/Modules/xxmodule.c
@@ -246,7 +246,7 @@ static PyTypeObject Str_Type = {
0, /*tp_methods*/
0, /*tp_members*/
0, /*tp_getset*/
- 0, /* see initxx */ /*tp_base*/
+ 0, /* see PyInit_xx */ /*tp_base*/
0, /*tp_dict*/
0, /*tp_descr_get*/
0, /*tp_descr_set*/
@@ -301,14 +301,14 @@ static PyTypeObject Null_Type = {
0, /*tp_methods*/
0, /*tp_members*/
0, /*tp_getset*/
- 0, /* see initxx */ /*tp_base*/
+ 0, /* see PyInit_xx */ /*tp_base*/
0, /*tp_dict*/
0, /*tp_descr_get*/
0, /*tp_descr_set*/
0, /*tp_dictoffset*/
0, /*tp_init*/
0, /*tp_alloc*/
- 0, /* see initxx */ /*tp_new*/
+ 0, /* see PyInit_xx */ /*tp_new*/
0, /*tp_free*/
0, /*tp_is_gc*/
};
@@ -334,12 +334,25 @@ static PyMethodDef xx_methods[] = {
PyDoc_STRVAR(module_doc,
"This is a template module just for instruction.");
-/* Initialization function for the module (*must* be called initxx) */
+/* Initialization function for the module (*must* be called PyInit_xx) */
+
+
+static struct PyModuleDef xxmodule = {
+ PyModuleDef_HEAD_INIT,
+ "xx",
+ module_doc,
+ -1,
+ xx_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
PyMODINIT_FUNC
-initxx(void)
+PyInit_xx(void)
{
- PyObject *m;
+ PyObject *m = NULL;
/* Due to cross platform compiler issues the slots must be filled
* here. It's required for portability to Windows without requiring
@@ -351,29 +364,33 @@ initxx(void)
/* Finalize the type object including setting type of the new type
* object; doing it here is required for portability, too. */
if (PyType_Ready(&Xxo_Type) < 0)
- return;
+ goto fail;
/* Create the module and add the functions */
- m = Py_InitModule3("xx", xx_methods, module_doc);
+ m = PyModule_Create(&xxmodule);
if (m == NULL)
- return;
+ goto fail;
/* Add some symbolic constants to the module */
if (ErrorObject == NULL) {
ErrorObject = PyErr_NewException("xx.error", NULL, NULL);
if (ErrorObject == NULL)
- return;
+ goto fail;
}
Py_INCREF(ErrorObject);
PyModule_AddObject(m, "error", ErrorObject);
/* Add Str */
if (PyType_Ready(&Str_Type) < 0)
- return;
+ goto fail;
PyModule_AddObject(m, "Str", (PyObject *)&Str_Type);
/* Add Null */
if (PyType_Ready(&Null_Type) < 0)
- return;
+ goto fail;
PyModule_AddObject(m, "Null", (PyObject *)&Null_Type);
+ return m;
+ fail:
+ Py_XDECREF(m);
+ return NULL;
}
diff --git a/Modules/xxsubtype.c b/Modules/xxsubtype.c
index 6eb77d2..7f33c83 100644
--- a/Modules/xxsubtype.c
+++ b/Modules/xxsubtype.c
@@ -257,8 +257,21 @@ static PyMethodDef xxsubtype_functions[] = {
{NULL, NULL} /* sentinel */
};
+static struct PyModuleDef xxsubtypemodule = {
+ PyModuleDef_HEAD_INIT,
+ "xxsubtype",
+ xxsubtype__doc__,
+ -1,
+ xxsubtype_functions,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+
PyMODINIT_FUNC
-initxxsubtype(void)
+PyInit_xxsubtype(void)
{
PyObject *m;
@@ -268,30 +281,29 @@ initxxsubtype(void)
so it's not necessary to fill in ob_type first. */
spamdict_type.tp_base = &PyDict_Type;
if (PyType_Ready(&spamdict_type) < 0)
- return;
+ return NULL;
spamlist_type.tp_base = &PyList_Type;
if (PyType_Ready(&spamlist_type) < 0)
- return;
+ return NULL;
- m = Py_InitModule3("xxsubtype",
- xxsubtype_functions,
- xxsubtype__doc__);
+ m = PyModule_Create(&xxsubtypemodule);
if (m == NULL)
- return;
+ return NULL;
if (PyType_Ready(&spamlist_type) < 0)
- return;
+ return NULL;
if (PyType_Ready(&spamdict_type) < 0)
- return;
+ return NULL;
Py_INCREF(&spamlist_type);
if (PyModule_AddObject(m, "spamlist",
(PyObject *) &spamlist_type) < 0)
- return;
+ return NULL;
Py_INCREF(&spamdict_type);
if (PyModule_AddObject(m, "spamdict",
(PyObject *) &spamdict_type) < 0)
- return;
+ return NULL;
+ return m;
}
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index 4ad93d5..023d1d4 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -1145,13 +1145,25 @@ It is usually not needed to use the zipimport module explicitly; it is\n\
used by the builtin import mechanism for sys.path items that are paths\n\
to Zip archives.");
+static struct PyModuleDef zipimportmodule = {
+ PyModuleDef_HEAD_INIT,
+ "zipimport",
+ zipimport_doc,
+ -1,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initzipimport(void)
+PyInit_zipimport(void)
{
PyObject *mod;
if (PyType_Ready(&ZipImporter_Type) < 0)
- return;
+ return NULL;
/* Correct directory separator */
zip_searchorder[0].suffix[0] = SEP;
@@ -1168,31 +1180,31 @@ initzipimport(void)
zip_searchorder[4] = tmp;
}
- mod = Py_InitModule4("zipimport", NULL, zipimport_doc,
- NULL, PYTHON_API_VERSION);
+ mod = PyModule_Create(&zipimportmodule);
if (mod == NULL)
- return;
+ return NULL;
ZipImportError = PyErr_NewException("zipimport.ZipImportError",
PyExc_ImportError, NULL);
if (ZipImportError == NULL)
- return;
+ return NULL;
Py_INCREF(ZipImportError);
if (PyModule_AddObject(mod, "ZipImportError",
ZipImportError) < 0)
- return;
+ return NULL;
Py_INCREF(&ZipImporter_Type);
if (PyModule_AddObject(mod, "zipimporter",
(PyObject *)&ZipImporter_Type) < 0)
- return;
+ return NULL;
zip_directory_cache = PyDict_New();
if (zip_directory_cache == NULL)
- return;
+ return NULL;
Py_INCREF(zip_directory_cache);
if (PyModule_AddObject(mod, "_zip_directory_cache",
zip_directory_cache) < 0)
- return;
+ return NULL;
+ return mod;
}
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index 0be9d6f..e63063f 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -53,7 +53,6 @@ static PyThread_type_lock zlib_lock = NULL; /* initialized on module load */
/* The output buffer will be increased in chunks of DEFAULTALLOC bytes. */
#define DEFAULTALLOC (16*1024)
-#define PyInit_zlib initzlib
static PyTypeObject Comptype;
static PyTypeObject Decomptype;
@@ -1013,17 +1012,27 @@ PyDoc_STRVAR(zlib_module_documentation,
"Compressor objects support compress() and flush() methods; decompressor\n"
"objects support decompress() and flush().");
+static struct PyModuleDef zlibmodule = {
+ PyModuleDef_HEAD_INIT,
+ "zlib",
+ zlib_module_documentation,
+ -1,
+ zlib_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
PyInit_zlib(void)
{
PyObject *m, *ver;
Py_TYPE(&Comptype) = &PyType_Type;
Py_TYPE(&Decomptype) = &PyType_Type;
- m = Py_InitModule4("zlib", zlib_methods,
- zlib_module_documentation,
- (PyObject*)NULL,PYTHON_API_VERSION);
+ m = PyModule_Create(&zlibmodule);
if (m == NULL)
- return;
+ return NULL;
ZlibError = PyErr_NewException("zlib.error", NULL, NULL);
if (ZlibError != NULL) {
@@ -1054,4 +1063,5 @@ PyInit_zlib(void)
#ifdef WITH_THREAD
zlib_lock = PyThread_allocate_lock();
#endif /* WITH_THREAD */
+ return m;
}