summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2002-03-12 21:49:44 (GMT)
committerFred Drake <fdrake@acm.org>2002-03-12 21:49:44 (GMT)
commit1de5a722d67558d975082789f36156bd5ad5bb88 (patch)
tree8484f416f8ec6ecbcd4ddd969c1f4c0de077439f
parent193a3f6d37c1440b049f7b1c62ff30c1d8cae38a (diff)
downloadcpython-1de5a722d67558d975082789f36156bd5ad5bb88.zip
cpython-1de5a722d67558d975082789f36156bd5ad5bb88.tar.gz
cpython-1de5a722d67558d975082789f36156bd5ad5bb88.tar.bz2
Change the example code to prefer PyModule_Add*() instead of using the
module dictionary directly. Also, be more careful about not re-initializing globals in the event of re-initialization of a C extension.
-rw-r--r--Modules/xxmodule.c10
-rw-r--r--Modules/xxsubtype.c14
2 files changed, 12 insertions, 12 deletions
diff --git a/Modules/xxmodule.c b/Modules/xxmodule.c
index 0ee9f7a..3587c91 100644
--- a/Modules/xxmodule.c
+++ b/Modules/xxmodule.c
@@ -231,7 +231,11 @@ initxx(void)
m = Py_InitModule("xx", xx_methods);
/* Add some symbolic constants to the module */
- d = PyModule_GetDict(m);
- ErrorObject = PyErr_NewException("xx.error", NULL, NULL);
- PyDict_SetItemString(d, "error", ErrorObject);
+ if (ErrorObject == NULL) {
+ ErrorObject = PyErr_NewException("xx.error", NULL, NULL);
+ if (ErrorObject == NULL)
+ return;
+ }
+ Py_INCREF(ErrorObject);
+ PyModule_AddObject(d, "error", ErrorObject);
}
diff --git a/Modules/xxsubtype.c b/Modules/xxsubtype.c
index f3d8e89..3b91a0c 100644
--- a/Modules/xxsubtype.c
+++ b/Modules/xxsubtype.c
@@ -238,7 +238,7 @@ static PyMethodDef xxsubtype_functions[] = {
DL_EXPORT(void)
initxxsubtype(void)
{
- PyObject *m, *d;
+ PyObject *m;
/* Fill in deferred data addresses. This must be done before
PyType_Ready() is called. Note that PyType_Ready() automatically
@@ -263,17 +263,13 @@ initxxsubtype(void)
if (PyType_Ready(&spamdict_type) < 0)
return;
- d = PyModule_GetDict(m);
- if (d == NULL)
- return;
-
Py_INCREF(&spamlist_type);
- if (PyDict_SetItemString(d, "spamlist",
- (PyObject *) &spamlist_type) < 0)
+ if (PyModule_AddObject(m, "spamlist",
+ (PyObject *) &spamlist_type) < 0)
return;
Py_INCREF(&spamdict_type);
- if (PyDict_SetItemString(d, "spamdict",
- (PyObject *) &spamdict_type) < 0)
+ if (PyModule_AddObject(m, "spamdict",
+ (PyObject *) &spamdict_type) < 0)
return;
}