summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2006-09-27 19:23:05 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2006-09-27 19:23:05 (GMT)
commit656aee7c442e34530c373b611c01903e7179e94b (patch)
tree79e64550cf25a8b6c6ed6ea1cbd81bf6b7027ba5
parent43889c0b9fdea2b62a5cdc88bb6aee5474838711 (diff)
downloadcpython-656aee7c442e34530c373b611c01903e7179e94b.zip
cpython-656aee7c442e34530c373b611c01903e7179e94b.tar.gz
cpython-656aee7c442e34530c373b611c01903e7179e94b.tar.bz2
Make examples do error checking on Py_InitModule
-rw-r--r--Doc/ext/extending.tex14
1 files changed, 10 insertions, 4 deletions
diff --git a/Doc/ext/extending.tex b/Doc/ext/extending.tex
index 7016f94..53d90db 100644
--- a/Doc/ext/extending.tex
+++ b/Doc/ext/extending.tex
@@ -221,6 +221,8 @@ initspam(void)
PyObject *m;
m = Py_InitModule("spam", SpamMethods);
+ if (m == NULL)
+ return;
SpamError = PyErr_NewException("spam.error", NULL, NULL);
Py_INCREF(SpamError);
@@ -365,9 +367,9 @@ is inserted in the dictionary \code{sys.modules} under the key
created module based upon the table (an array of \ctype{PyMethodDef}
structures) that was passed as its second argument.
\cfunction{Py_InitModule()} returns a pointer to the module object
-that it creates (which is unused here). It aborts with a fatal error
-if the module could not be initialized satisfactorily, so the caller
-doesn't need to check for errors.
+that it creates (which is unused here). It may abort with a fatal error
+for certain errors, or return \NULL{} if the module could not be
+initialized satisfactorily.
When embedding Python, the \cfunction{initspam()} function is not
called automatically unless there's an entry in the
@@ -1276,6 +1278,8 @@ initspam(void)
PyObject *c_api_object;
m = Py_InitModule("spam", SpamMethods);
+ if (m == NULL)
+ return;
/* Initialize the C API pointer array */
PySpam_API[PySpam_System_NUM] = (void *)PySpam_System;
@@ -1362,7 +1366,9 @@ initclient(void)
{
PyObject *m;
- Py_InitModule("client", ClientMethods);
+ m = Py_InitModule("client", ClientMethods);
+ if (m == NULL)
+ return;
if (import_spam() < 0)
return;
/* additional initialization can happen here */