summaryrefslogtreecommitdiffstats
path: root/PC
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 /PC
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 'PC')
-rw-r--r--PC/_msi.c22
-rw-r--r--PC/_subprocess.c23
-rwxr-xr-xPC/msvcrtmodule.c20
-rw-r--r--PC/winreg.c24
-rw-r--r--PC/winsound.c22
5 files changed, 87 insertions, 24 deletions
diff --git a/PC/_msi.c b/PC/_msi.c
index 6c6f2f8..ec6c203 100644
--- a/PC/_msi.c
+++ b/PC/_msi.c
@@ -997,14 +997,27 @@ static PyMethodDef msi_methods[] = {
static char msi_doc[] = "Documentation";
+
+static struct PyModuleDef _msimodule = {
+ PyModuleDef_HEAD_INIT,
+ "_msi",
+ msi_doc,
+ -1,
+ msi_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_msi(void)
+PyInit__msi(void)
{
PyObject *m;
- m = Py_InitModule3("_msi", msi_methods, msi_doc);
+ m = PyModule_Create(&_msimodule);
if (m == NULL)
- return;
+ return NULL;
PyModule_AddIntConstant(m, "MSIDBOPEN_CREATEDIRECT", (int)MSIDBOPEN_CREATEDIRECT);
PyModule_AddIntConstant(m, "MSIDBOPEN_CREATE", (int)MSIDBOPEN_CREATE);
@@ -1050,6 +1063,7 @@ init_msi(void)
MSIError = PyErr_NewException ("_msi.MSIError", NULL, NULL);
if (!MSIError)
- return;
+ return NULL;
PyModule_AddObject(m, "MSIError", MSIError);
+ return NULL;
}
diff --git a/PC/_subprocess.c b/PC/_subprocess.c
index a752950..c256ca3 100644
--- a/PC/_subprocess.c
+++ b/PC/_subprocess.c
@@ -541,12 +541,20 @@ defint(PyObject* d, const char* name, int value)
}
}
-#if PY_VERSION_HEX >= 0x02030000
+static struct PyModuleDef _subprocessmodule = {
+ PyModuleDef_HEAD_INIT,
+ "_subprocess",
+ NULL,
+ -1,
+ sp_functions,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-#else
-DL_EXPORT(void)
-#endif
-init_subprocess()
+PyInit__subprocess()
{
PyObject *d;
PyObject *m;
@@ -555,9 +563,9 @@ init_subprocess()
Py_TYPE(&sp_handle_type) = &PyType_Type;
sp_handle_as_number.nb_int = (unaryfunc) sp_handle_as_int;
- m = Py_InitModule("_subprocess", sp_functions);
+ m = PyModule_Create(&_subprocessmodule);
if (m == NULL)
- return;
+ return NULL;
d = PyModule_GetDict(m);
/* constants */
@@ -571,4 +579,5 @@ init_subprocess()
defint(d, "INFINITE", INFINITE);
defint(d, "WAIT_OBJECT_0", WAIT_OBJECT_0);
defint(d, "CREATE_NEW_CONSOLE", CREATE_NEW_CONSOLE);
+ return m;
}
diff --git a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c
index aeab3b6..225121f 100755
--- a/PC/msvcrtmodule.c
+++ b/PC/msvcrtmodule.c
@@ -358,13 +358,26 @@ static struct PyMethodDef msvcrt_functions[] = {
{NULL, NULL}
};
+
+static struct PyModuleDef msvcrtmodule = {
+ PyModuleDef_HEAD_INIT,
+ "msvcrt",
+ NULL,
+ -1,
+ msvcrt_functions,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initmsvcrt(void)
+PyInit_msvcrt(void)
{
PyObject *d;
- PyObject *m = Py_InitModule("msvcrt", msvcrt_functions);
+ PyObject *m = PyModule_Create(&msvcrtmodule);
if (m == NULL)
- return;
+ return NULL;
d = PyModule_GetDict(m);
/* constants for the locking() function's mode argument */
@@ -389,4 +402,5 @@ initmsvcrt(void)
insertint(d, "CRTDBG_FILE_STDOUT", (int)_CRTDBG_FILE_STDOUT);
insertint(d, "CRTDBG_REPORT_FILE", (int)_CRTDBG_REPORT_FILE);
#endif
+ return m;
}
diff --git a/PC/winreg.c b/PC/winreg.c
index 8316f6c..d0397e9 100644
--- a/PC/winreg.c
+++ b/PC/winreg.c
@@ -1565,23 +1565,36 @@ inskey(PyObject * d, char * name, HKEY key)
#define ADD_KEY(val) inskey(d, #val, val)
-PyMODINIT_FUNC initwinreg(void)
+
+static struct PyModuleDef winregmodule = {
+ PyModuleDef_HEAD_INIT,
+ "winreg",
+ module_doc,
+ -1,
+ winreg_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+PyMODINIT_FUNC PyInit_winreg(void)
{
PyObject *m, *d;
- m = Py_InitModule3("winreg", winreg_methods, module_doc);
+ m = PyModule_Create(&winregmodule);
if (m == NULL)
- return;
+ return NULL;
d = PyModule_GetDict(m);
Py_TYPE(&PyHKEY_Type) = &PyType_Type;
PyHKEY_Type.tp_doc = PyHKEY_doc;
Py_INCREF(&PyHKEY_Type);
if (PyDict_SetItemString(d, "HKEYType",
(PyObject *)&PyHKEY_Type) != 0)
- return;
+ return NULL;
Py_INCREF(PyExc_WindowsError);
if (PyDict_SetItemString(d, "error",
PyExc_WindowsError) != 0)
- return;
+ return NULL;
/* Add the relevant constants */
ADD_KEY(HKEY_CLASSES_ROOT);
@@ -1640,6 +1653,7 @@ PyMODINIT_FUNC initwinreg(void)
ADD_INT(REG_RESOURCE_LIST);
ADD_INT(REG_FULL_RESOURCE_DESCRIPTOR);
ADD_INT(REG_RESOURCE_REQUIREMENTS_LIST);
+ return m;
}
diff --git a/PC/winsound.c b/PC/winsound.c
index 62e87ae..da5dea9 100644
--- a/PC/winsound.c
+++ b/PC/winsound.c
@@ -163,15 +163,26 @@ add_define(PyObject *dict, const char *key, long value)
#define ADD_DEFINE(tok) add_define(dict,#tok,tok)
+
+static struct PyModuleDef winsoundmodule = {
+ PyModuleDef_HEAD_INIT,
+ "winsound",
+ sound_module_doc,
+ -1,
+ sound_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-initwinsound(void)
+PyInit_winsound(void)
{
PyObject *dict;
- PyObject *module = Py_InitModule3("winsound",
- sound_methods,
- sound_module_doc);
+ PyObject *module = PyModule_Create(&winsoundmodule);
if (module == NULL)
- return;
+ return NULL;
dict = PyModule_GetDict(module);
ADD_DEFINE(SND_ASYNC);
@@ -190,4 +201,5 @@ initwinsound(void)
ADD_DEFINE(MB_ICONEXCLAMATION);
ADD_DEFINE(MB_ICONHAND);
ADD_DEFINE(MB_ICONQUESTION);
+ return module;
}