diff Modules/arraymodule.c @ 47580:94f64f11fdd0

Implement PEP 3121: new module initialization and finalization API.
author Martin v. Löwis <martin@v.loewis.de>
date Wed, 11 Jun 2008 05:26:20 +0000
parents a0193b08f0eb
children b5e02775fffc
line wrap: on
line diff
--- a/Modules/arraymodule.c	Wed Jun 11 03:41:00 2008 +0000
+++ b/Modules/arraymodule.c	Wed Jun 11 05:26:20 2008 +0000
@@ -2156,9 +2156,21 @@
     {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 @@
 	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 @@
 
 	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;
 }