summaryrefslogtreecommitdiffstats
path: root/Modules/arraymodule.c
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2015-05-23 12:24:10 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2015-05-23 12:24:10 (GMT)
commitd5cacbb1d9c3edc02bf0ba01702e7c06da5bc318 (patch)
treee92dda9e119e043482b0aa0ad1fdefff785d54c0 /Modules/arraymodule.c
parentec219ba1c04c4514b8b004239b1a0eac914dde4a (diff)
downloadcpython-d5cacbb1d9c3edc02bf0ba01702e7c06da5bc318.zip
cpython-d5cacbb1d9c3edc02bf0ba01702e7c06da5bc318.tar.gz
cpython-d5cacbb1d9c3edc02bf0ba01702e7c06da5bc318.tar.bz2
PEP 489: Multi-phase extension module initialization
Known limitations of the current implementation: - documentation changes are incomplete - there's a reference leak I haven't tracked down yet The leak is most visible by running: ./python -m test -R3:3 test_importlib However, you can also see it by running: ./python -X showrefcount Importing the array or _testmultiphase modules, and then deleting them from both sys.modules and the local namespace shows significant increases in the total number of active references each cycle. By contrast, with _testcapi (which continues to use single-phase initialisation) the global refcounts stabilise after a couple of cycles.
Diffstat (limited to 'Modules/arraymodule.c')
-rw-r--r--Modules/arraymodule.c50
1 files changed, 29 insertions, 21 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 8d0462d..a3ccf93 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -2981,34 +2981,17 @@ 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
-PyInit_array(void)
+static int
+array_modexec(PyObject *m)
{
- PyObject *m;
char buffer[Py_ARRAY_LENGTH(descriptors)], *p;
PyObject *typecodes;
Py_ssize_t size = 0;
struct arraydescr *descr;
if (PyType_Ready(&Arraytype) < 0)
- return NULL;
+ return -1;
Py_TYPE(&PyArrayIter_Type) = &PyType_Type;
- m = PyModule_Create(&arraymodule);
- if (m == NULL)
- return NULL;
Py_INCREF((PyObject *)&Arraytype);
PyModule_AddObject(m, "ArrayType", (PyObject *)&Arraytype);
@@ -3031,5 +3014,30 @@ PyInit_array(void)
Py_DECREF(m);
m = NULL;
}
- return m;
+ return 0;
+}
+
+static PyModuleDef_Slot arrayslots[] = {
+ {Py_mod_exec, array_modexec},
+ {0, NULL}
+};
+
+
+static struct PyModuleDef arraymodule = {
+ PyModuleDef_HEAD_INIT,
+ "array",
+ module_doc,
+ 0,
+ a_methods,
+ arrayslots,
+ NULL,
+ NULL,
+ NULL
+};
+
+
+PyMODINIT_FUNC
+PyInit_array(void)
+{
+ return PyModuleDef_Init(&arraymodule);
}