From 07f1073592ac9e5f538bf699d728fa59db3629cb Mon Sep 17 00:00:00 2001 From: Cajetan Rodrigues Date: Sat, 25 Apr 2020 07:27:53 +0200 Subject: [PATCH] bpo-40279: Add some error-handling to the module initialisation docs example (GH-19705) (cherry picked from commit d4f3923d5901ef1ccdbe6ad6c5a753af90832a0f) Co-authored-by: Cajetan Rodrigues --- Doc/extending/extending.rst | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Doc/extending/extending.rst b/Doc/extending/extending.rst index 5b32a2cdc5506e..25dc2934d29ef6 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"); + } ... pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy