Coverage Report

Created: 2022-07-08 09:39

/home/mdboom/Work/builds/cpython/Python/frozenmain.c
Line
Count
Source (jump to first uncovered line)
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
Py_FrozenMain(int argc, char **argv)
17
{
18
    PyStatus status = _PyRuntime_Initialize();
19
    if (PyStatus_Exception(status)) {
  Branch (19:9): [True: 0, False: 1]
20
        Py_ExitStatusException(status);
21
    }
22
23
    PyConfig config;
24
    PyConfig_InitPythonConfig(&config);
25
    // Suppress errors from getpath.c
26
    config.pathconfig_warnings = 0;
27
    // Don't parse command line options like -E
28
    config.parse_argv = 0;
29
30
    status = PyConfig_SetBytesArgv(&config, argc, argv);
31
    if (PyStatus_Exception(status)) {
  Branch (31:9): [True: 0, False: 1]
32
        PyConfig_Clear(&config);
33
        Py_ExitStatusException(status);
34
    }
35
36
    const char *p;
37
    int inspect = 0;
38
    if ((p = Py_GETENV("PYTHONINSPECT")) && 
*p != '\0'0
) {
  Branch (38:9): [True: 0, False: 1]
  Branch (38:45): [True: 0, False: 0]
39
        inspect = 1;
40
    }
41
42
#ifdef MS_WINDOWS
43
    PyInitFrozenExtensions();
44
#endif /* MS_WINDOWS */
45
46
    status = Py_InitializeFromConfig(&config);
47
    PyConfig_Clear(&config);
48
    if (PyStatus_Exception(status)) {
  Branch (48:9): [True: 0, False: 1]
49
        Py_ExitStatusException(status);
50
    }
51
52
#ifdef MS_WINDOWS
53
    PyWinFreeze_ExeInit();
54
#endif
55
56
    if (_Py_GetConfig()->verbose) {
  Branch (56:9): [True: 0, False: 1]
57
        fprintf(stderr, "Python %s\n%s\n",
58
                Py_GetVersion(), Py_GetCopyright());
59
    }
60
61
    int sts = 1;
62
    int n = PyImport_ImportFrozenModule("__main__");
63
    if (n == 0) {
  Branch (63:9): [True: 0, False: 1]
64
        Py_FatalError("the __main__ module is not frozen");
65
    }
66
    if (n < 0) {
  Branch (66:9): [True: 0, False: 1]
67
        PyErr_Print();
68
        sts = 1;
69
    }
70
    else {
71
        sts = 0;
72
    }
73
74
    if (inspect && 
isatty((int)fileno(stdin))0
) {
  Branch (74:9): [True: 0, False: 1]
  Branch (74:20): [True: 0, False: 0]
75
        sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
76
    }
77
78
#ifdef MS_WINDOWS
79
    PyWinFreeze_ExeTerm();
80
#endif
81
    if (Py_FinalizeEx() < 0) {
  Branch (81:9): [True: 0, False: 1]
82
        sts = 120;
83
    }
84
    return sts;
85
}