[Python-checkins] r52019 - python/branches/release24-maint/Doc/ext/extending.tex

andrew.kuchling python-checkins at python.org
Wed Sep 27 21:23:38 CEST 2006


Author: andrew.kuchling
Date: Wed Sep 27 21:23:38 2006
New Revision: 52019

Modified:
   python/branches/release24-maint/Doc/ext/extending.tex
Log:
Make examples do error checking on Py_InitModule

Modified: python/branches/release24-maint/Doc/ext/extending.tex
==============================================================================
--- python/branches/release24-maint/Doc/ext/extending.tex	(original)
+++ python/branches/release24-maint/Doc/ext/extending.tex	Wed Sep 27 21:23:38 2006
@@ -221,6 +221,8 @@
     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 @@
 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 @@
     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 @@
 {
     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 */


More information about the Python-checkins mailing list