• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /* Python interpreter main program for frozen scripts */
3 
4 #include "Python.h"
5 
6 #ifdef MS_WINDOWS
7 extern void PyWinFreeze_ExeInit(void);
8 extern void PyWinFreeze_ExeTerm(void);
9 extern int PyInitFrozenExtensions(void);
10 #endif
11 
12 /* Main program */
13 
14 int
Py_FrozenMain(int argc,char ** argv)15 Py_FrozenMain(int argc, char **argv)
16 {
17     char *p;
18     int n, sts;
19     int inspect = 0;
20     int unbuffered = 0;
21 
22     Py_FrozenFlag = 1; /* Suppress errors from getpath.c */
23 
24     if ((p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')
25         inspect = 1;
26     if ((p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0')
27         unbuffered = 1;
28 
29     if (unbuffered) {
30         setbuf(stdin, (char *)NULL);
31         setbuf(stdout, (char *)NULL);
32         setbuf(stderr, (char *)NULL);
33     }
34 
35 #ifdef MS_WINDOWS
36     PyInitFrozenExtensions();
37 #endif /* MS_WINDOWS */
38     if (argc >= 1)
39         Py_SetProgramName(argv[0]);
40     Py_Initialize();
41 #ifdef MS_WINDOWS
42     PyWinFreeze_ExeInit();
43 #endif
44 
45     if (Py_VerboseFlag)
46         fprintf(stderr, "Python %s\n%s\n",
47             Py_GetVersion(), Py_GetCopyright());
48 
49     PySys_SetArgv(argc, argv);
50 
51     n = PyImport_ImportFrozenModule("__main__");
52     if (n == 0)
53         Py_FatalError("__main__ not frozen");
54     if (n < 0) {
55         PyErr_Print();
56         sts = 1;
57     }
58     else
59         sts = 0;
60 
61     if (inspect && isatty((int)fileno(stdin)))
62         sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
63 
64 #ifdef MS_WINDOWS
65     PyWinFreeze_ExeTerm();
66 #endif
67     Py_Finalize();
68     return sts;
69 }
70