Mercurial > cpython-lru_cache-weakref
annotate Python/frozenmain.c @ 5758:bfe9ba74c19e legacy-trunk
Fix problem discovered by Greg McFarlane: when an imported module
replaces its own entry in sys.module, reference count errors ensue;
even if there is no reference count problem, it would be preferable
for the import to yield the new thing in sys.modules anyway (if only
because that's what later imports will yield). This opens the road to
an official hack to implement a __getattr__ like feature for modules:
stick an instance in sys.modules[__name__].
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 10 Jul 1997 18:00:45 +0000 |
| parents | 65d2d8e67da3 |
| children | 4a4778e61c14 |
| rev | line source |
|---|---|
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 /*********************************************************** |
|
2062
d0d0a69b5ca3
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
d0d0a69b5ca3
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
3 The Netherlands. |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 All Rights Reserved |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4041
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4041
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4041
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4041
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4041
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4041
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4041
diff
changeset
|
15 permission. |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4041
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4041
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4041
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4041
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4041
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4041
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4041
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4041
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4041
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4041
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4041
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4041
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 ******************************************************************/ |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 /* Python interpreter main program for frozen scripts */ |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 |
| 2624 | 34 #include "Python.h" |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 |
|
2892
33b154b6c61b
moved stuff around to resemble main.c
Guido van Rossum <guido@python.org>
parents:
2624
diff
changeset
|
36 /* Subroutines that live in their own file */ |
|
3621
f158edccc72c
grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents:
2892
diff
changeset
|
37 extern char *Py_GetVersion(); |
|
f158edccc72c
grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents:
2892
diff
changeset
|
38 extern char *Py_GetCopyright(); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1396
diff
changeset
|
39 |
|
4041
8a010dd4736e
getprogramname -> Py_GetProgramName.
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
40 /* For Py_GetProgramName(); set by main() */ |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1396
diff
changeset
|
41 static char *argv0; |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 |
|
2892
33b154b6c61b
moved stuff around to resemble main.c
Guido van Rossum <guido@python.org>
parents:
2624
diff
changeset
|
43 /* Main program */ |
|
33b154b6c61b
moved stuff around to resemble main.c
Guido van Rossum <guido@python.org>
parents:
2624
diff
changeset
|
44 |
|
33b154b6c61b
moved stuff around to resemble main.c
Guido van Rossum <guido@python.org>
parents:
2624
diff
changeset
|
45 int |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 main(argc, argv) |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 int argc; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 char **argv; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 { |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 char *p; |
|
1396
4a286b300b5e
Must initialize 'inspect' flag
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
51 int n, sts; |
|
4a286b300b5e
Must initialize 'inspect' flag
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
52 int inspect = 0; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1396
diff
changeset
|
53 int unbuffered = 0; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1396
diff
changeset
|
54 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1396
diff
changeset
|
55 argv0 = argv[0]; |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
56 |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 if ((p = getenv("PYTHONDEBUG")) && *p != '\0') |
| 2624 | 58 Py_DebugFlag = 1; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1396
diff
changeset
|
59 if ((p = getenv("PYTHONSUPPRESS")) && *p != '\0') |
| 2624 | 60 Py_SuppressPrintingFlag = 1; |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 if ((p = getenv("PYTHONVERBOSE")) && *p != '\0') |
| 2624 | 62 Py_VerboseFlag = 1; |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
63 if ((p = getenv("PYTHONINSPECT")) && *p != '\0') |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
64 inspect = 1; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1396
diff
changeset
|
65 if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0') |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1396
diff
changeset
|
66 unbuffered = 1; |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
67 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1396
diff
changeset
|
68 if (unbuffered) { |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1396
diff
changeset
|
69 setbuf(stdout, (char *)NULL); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1396
diff
changeset
|
70 setbuf(stderr, (char *)NULL); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1396
diff
changeset
|
71 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1396
diff
changeset
|
72 |
| 2624 | 73 if (Py_VerboseFlag) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1396
diff
changeset
|
74 fprintf(stderr, "Python %s\n%s\n", |
|
3621
f158edccc72c
grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents:
2892
diff
changeset
|
75 Py_GetVersion(), Py_GetCopyright()); |
| 2624 | 76 Py_Initialize(); |
| 77 PySys_SetArgv(argc, argv); | |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
78 |
| 2624 | 79 n = PyImport_ImportFrozenModule("__main__"); |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 if (n == 0) |
| 2624 | 81 Py_FatalError("__main__ not frozen"); |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 if (n < 0) { |
| 2624 | 83 PyErr_Print(); |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
84 sts = 1; |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 } |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 else |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
87 sts = 0; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
88 |
|
1319
cd397266dc1c
* Makefile: added all: and default: targets.
Guido van Rossum <guido@python.org>
parents:
1318
diff
changeset
|
89 if (inspect && isatty((int)fileno(stdin))) |
| 2624 | 90 sts = PyRun_AnyFile(stdin, "<stdin>") != 0; |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
91 |
| 2624 | 92 Py_Exit(sts); |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 /*NOTREACHED*/ |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 } |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1396
diff
changeset
|
95 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1396
diff
changeset
|
96 char * |
|
4041
8a010dd4736e
getprogramname -> Py_GetProgramName.
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
97 Py_GetProgramName() |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1396
diff
changeset
|
98 { |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1396
diff
changeset
|
99 return argv0; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1396
diff
changeset
|
100 } |
