LCOV - code coverage report
Current view: top level - Python - frozenmain.c (source / functions) Hit Total Coverage
Test: CPython lcov report Lines: 22 33 66.7 %
Date: 2022-07-07 18:19:46 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* Python interpreter main program for frozen scripts */
       2             : 
       3             : #include "Python.h"
       4             : #include "pycore_runtime.h"  // _PyRuntime_Initialize()
       5             : #include <locale.h>
       6             : 
       7             : #ifdef MS_WINDOWS
       8             : extern void PyWinFreeze_ExeInit(void);
       9             : extern void PyWinFreeze_ExeTerm(void);
      10             : extern int PyInitFrozenExtensions(void);
      11             : #endif
      12             : 
      13             : /* Main program */
      14             : 
      15             : int
      16           1 : Py_FrozenMain(int argc, char **argv)
      17             : {
      18           1 :     PyStatus status = _PyRuntime_Initialize();
      19           1 :     if (PyStatus_Exception(status)) {
      20           0 :         Py_ExitStatusException(status);
      21             :     }
      22             : 
      23             :     PyConfig config;
      24           1 :     PyConfig_InitPythonConfig(&config);
      25             :     // Suppress errors from getpath.c
      26           1 :     config.pathconfig_warnings = 0;
      27             :     // Don't parse command line options like -E
      28           1 :     config.parse_argv = 0;
      29             : 
      30           1 :     status = PyConfig_SetBytesArgv(&config, argc, argv);
      31           1 :     if (PyStatus_Exception(status)) {
      32           0 :         PyConfig_Clear(&config);
      33           0 :         Py_ExitStatusException(status);
      34             :     }
      35             : 
      36             :     const char *p;
      37           1 :     int inspect = 0;
      38           1 :     if ((p = Py_GETENV("PYTHONINSPECT")) && *p != '\0') {
      39           0 :         inspect = 1;
      40             :     }
      41             : 
      42             : #ifdef MS_WINDOWS
      43             :     PyInitFrozenExtensions();
      44             : #endif /* MS_WINDOWS */
      45             : 
      46           1 :     status = Py_InitializeFromConfig(&config);
      47           1 :     PyConfig_Clear(&config);
      48           1 :     if (PyStatus_Exception(status)) {
      49           0 :         Py_ExitStatusException(status);
      50             :     }
      51             : 
      52             : #ifdef MS_WINDOWS
      53             :     PyWinFreeze_ExeInit();
      54             : #endif
      55             : 
      56           1 :     if (_Py_GetConfig()->verbose) {
      57           0 :         fprintf(stderr, "Python %s\n%s\n",
      58             :                 Py_GetVersion(), Py_GetCopyright());
      59             :     }
      60             : 
      61           1 :     int sts = 1;
      62           1 :     int n = PyImport_ImportFrozenModule("__main__");
      63           1 :     if (n == 0) {
      64           0 :         Py_FatalError("the __main__ module is not frozen");
      65             :     }
      66           1 :     if (n < 0) {
      67           0 :         PyErr_Print();
      68           0 :         sts = 1;
      69             :     }
      70             :     else {
      71           1 :         sts = 0;
      72             :     }
      73             : 
      74           1 :     if (inspect && isatty((int)fileno(stdin))) {
      75           0 :         sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
      76             :     }
      77             : 
      78             : #ifdef MS_WINDOWS
      79             :     PyWinFreeze_ExeTerm();
      80             : #endif
      81           1 :     if (Py_FinalizeEx() < 0) {
      82           0 :         sts = 120;
      83             :     }
      84           1 :     return sts;
      85             : }

Generated by: LCOV version 1.14