File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -395,18 +395,26 @@ optionally followed by an import of the module::
395395 }
396396
397397 /* Add a built-in module, before Py_Initialize */
398- PyImport_AppendInittab("spam", PyInit_spam);
398+ if (PyImport_AppendInittab("spam", PyInit_spam) == -1) {
399+ fprintf(stderr, "Error: could not extend in-built modules table\n");
400+ exit(1);
401+ }
399402
400403 /* Pass argv[0] to the Python interpreter */
401404 Py_SetProgramName(program);
402405
403- /* Initialize the Python interpreter. Required. */
406+ /* Initialize the Python interpreter. Required.
407+ If this step fails, it will be a fatal error. */
404408 Py_Initialize();
405409
406410 /* Optionally import the module; alternatively,
407411 import can be deferred until the embedded script
408412 imports it. */
409- PyImport_ImportModule("spam");
413+ pmodule = PyImport_ImportModule("spam");
414+ if (!pmodule) {
415+ PyErr_Print();
416+ fprintf(stderr, "Error: could not import module 'spam'\n");
417+ }
410418
411419 ...
412420
You can’t perform that action at this time.
0 commit comments