Commit f0981895 authored by Andrew M. Kuchling's avatar Andrew M. Kuchling

Make examples do error checking on Py_InitModule

parent 9a755a3d
...@@ -221,6 +221,8 @@ initspam(void) ...@@ -221,6 +221,8 @@ initspam(void)
PyObject *m; PyObject *m;
m = Py_InitModule("spam", SpamMethods); m = Py_InitModule("spam", SpamMethods);
if (m == NULL)
return;
SpamError = PyErr_NewException("spam.error", NULL, NULL); SpamError = PyErr_NewException("spam.error", NULL, NULL);
Py_INCREF(SpamError); Py_INCREF(SpamError);
...@@ -365,9 +367,9 @@ is inserted in the dictionary \code{sys.modules} under the key ...@@ -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} created module based upon the table (an array of \ctype{PyMethodDef}
structures) that was passed as its second argument. structures) that was passed as its second argument.
\cfunction{Py_InitModule()} returns a pointer to the module object \cfunction{Py_InitModule()} returns a pointer to the module object
that it creates (which is unused here). It aborts with a fatal error that it creates (which is unused here). It may abort with a fatal error
if the module could not be initialized satisfactorily, so the caller for certain errors, or return \NULL{} if the module could not be
doesn't need to check for errors. initialized satisfactorily.
When embedding Python, the \cfunction{initspam()} function is not When embedding Python, the \cfunction{initspam()} function is not
called automatically unless there's an entry in the called automatically unless there's an entry in the
...@@ -1276,6 +1278,8 @@ initspam(void) ...@@ -1276,6 +1278,8 @@ initspam(void)
PyObject *c_api_object; PyObject *c_api_object;
m = Py_InitModule("spam", SpamMethods); m = Py_InitModule("spam", SpamMethods);
if (m == NULL)
return;
/* Initialize the C API pointer array */ /* Initialize the C API pointer array */
PySpam_API[PySpam_System_NUM] = (void *)PySpam_System; PySpam_API[PySpam_System_NUM] = (void *)PySpam_System;
...@@ -1362,7 +1366,9 @@ initclient(void) ...@@ -1362,7 +1366,9 @@ initclient(void)
{ {
PyObject *m; PyObject *m;
Py_InitModule("client", ClientMethods); m = Py_InitModule("client", ClientMethods);
if (m == NULL)
return;
if (import_spam() < 0) if (import_spam() < 0)
return; return;
/* additional initialization can happen here */ /* additional initialization can happen here */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment