aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCajetan Rodrigues <caje731@gmail.com>2020-04-25 07:27:53 +0200
committerGitHub <noreply@github.com>2020-04-25 07:27:53 +0200
commitd4f3923d5901ef1ccdbe6ad6c5a753af90832a0f (patch)
tree515a53414966104b21e47dd0f6171c1550a8846f /Doc/extending
parentcloses bpo-40385: Remove Tools/scripts/checkpyc.py (GH-19709) (diff)
downloadcpython-d4f3923d5901ef1ccdbe6ad6c5a753af90832a0f.tar.gz
cpython-d4f3923d5901ef1ccdbe6ad6c5a753af90832a0f.tar.bz2
cpython-d4f3923d5901ef1ccdbe6ad6c5a753af90832a0f.zip
bpo-40279: Add some error-handling to the module initialisation docs example (GH-19705)
Diffstat (limited to 'Doc/extending')
-rw-r--r--Doc/extending/extending.rst14
1 files changed, 11 insertions, 3 deletions
diff --git a/Doc/extending/extending.rst b/Doc/extending/extending.rst
index 5b32a2cdc55..25dc2934d29 100644
--- a/Doc/extending/extending.rst
+++ b/Doc/extending/extending.rst
@@ -395,18 +395,26 @@ optionally followed by an import of the module::
}
/* Add a built-in module, before Py_Initialize */
- PyImport_AppendInittab("spam", PyInit_spam);
+ if (PyImport_AppendInittab("spam", PyInit_spam) == -1) {
+ fprintf(stderr, "Error: could not extend in-built modules table\n");
+ exit(1);
+ }
/* Pass argv[0] to the Python interpreter */
Py_SetProgramName(program);
- /* Initialize the Python interpreter. Required. */
+ /* Initialize the Python interpreter. Required.
+ If this step fails, it will be a fatal error. */
Py_Initialize();
/* Optionally import the module; alternatively,
import can be deferred until the embedded script
imports it. */
- PyImport_ImportModule("spam");
+ pmodule = PyImport_ImportModule("spam");
+ if (!pmodule) {
+ PyErr_Print();
+ fprintf(stderr, "Error: could not import module 'spam'\n");
+ }
...