]> granicus.if.org Git - python/commitdiff
Use the PyModule_*() API instead of manipulating the module dictionary
authorFred Drake <fdrake@acm.org>
Mon, 1 Apr 2002 03:45:06 +0000 (03:45 +0000)
committerFred Drake <fdrake@acm.org>
Mon, 1 Apr 2002 03:45:06 +0000 (03:45 +0000)
directly.

Modules/arraymodule.c
Modules/cmathmodule.c

index 7372a488340716d8ec9dd7240e53652fb2e658a5..46de178f689edada68179a0ff1c386524983780b 100644 (file)
@@ -1731,12 +1731,14 @@ static PyMethodDef a_methods[] = {
 DL_EXPORT(void)
 initarray(void)
 {
-       PyObject *m, *d;
+       PyObject *m;
 
        Arraytype.ob_type = &PyType_Type;
        m = Py_InitModule3("array", a_methods, module_doc);
-       d = PyModule_GetDict(m);
-       PyDict_SetItemString(d, "ArrayType", (PyObject *)&Arraytype);
-       PyDict_SetItemString(d, "array", (PyObject *)&Arraytype);
+
+        Py_INCREF((PyObject *)&Arraytype);
+       PyModule_AddObject(m, "ArrayType", (PyObject *)&Arraytype);
+        Py_INCREF((PyObject *)&Arraytype);
+       PyModule_AddObject(m, "array", (PyObject *)&Arraytype);
        /* No need to check the error here, the caller will do that */
 }
index 6e79680843673858e16cadab98a499b79c4738d2..8e74e513b2f8c08a97a352bde619828fb388113b 100644 (file)
@@ -394,13 +394,11 @@ static PyMethodDef cmath_methods[] = {
 DL_EXPORT(void)
 initcmath(void)
 {
-       PyObject *m, *d, *v;
+       PyObject *m;
 
        m = Py_InitModule3("cmath", cmath_methods, module_doc);
-       d = PyModule_GetDict(m);
-       PyDict_SetItemString(d, "pi",
-                            v = PyFloat_FromDouble(atan(1.0) * 4.0));
-       Py_DECREF(v);
-       PyDict_SetItemString(d, "e", v = PyFloat_FromDouble(exp(1.0)));
-       Py_DECREF(v);
+
+       PyModule_AddObject(m, "pi",
+                           PyFloat_FromDouble(atan(1.0) * 4.0));
+       PyModule_AddObject(m, "e", PyFloat_FromDouble(exp(1.0)));
 }