annotate Python/pythonrun.c @ 5108:a9a6d416b945 legacy-trunk

Added new global flag variable Py_InteractiveFlag and new function Py_FdIsInteractive(). The flag is supposed to be set by the -i command line option. The function is supposed to be called instead of isatty(). This is used for Lee Busby's wish #1, to have an option that pretends stdin is interactive even when it really isn't.
author Guido van Rossum <guido@python.org>
date Fri, 14 Feb 1997 19:45:36 +0000
parents 4fa19659591e
children f5d707ce4223
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /***********************************************************
2062
d0d0a69b5ca3 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2052
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
d0d0a69b5ca3 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2052
diff changeset
3 The Netherlands.
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 All Rights Reserved
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4291
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: 4291
diff changeset
8 documentation for any purpose and without fee is hereby granted,
923
72aceed365d4 * Makefile adapted to changes below.
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: 4291
diff changeset
10 both that copyright notice and this permission notice appear in
923
72aceed365d4 * Makefile adapted to changes below.
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: 4291
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: 4291
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: 4291
diff changeset
14 distribution of the software without specific, written prior
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4291
diff changeset
15 permission.
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4291
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: 4291
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: 4291
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: 4291
diff changeset
20
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4291
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: 4291
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: 4291
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: 4291
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: 4291
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: 4291
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: 4291
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: 4291
diff changeset
28 PERFORMANCE OF THIS SOFTWARE.
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 ******************************************************************/
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 /* Python interpreter top-level routines, including init/exit */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 #include "allobjects.h"
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 #include "grammar.h"
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 #include "node.h"
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 #include "parsetok.h"
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 #include "graminit.h"
3102
692715abbd0b #undef argument, for the Mac
Guido van Rossum <guido@python.org>
parents: 2877
diff changeset
40 #undef argument /* Avoid conflict on Mac */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 #include "errcode.h"
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 #include "sysmodule.h"
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
43 #include "bltinmodule.h"
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 #include "compile.h"
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
45 #include "eval.h"
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 #include "ceval.h"
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 #include "import.h"
1886
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
48 #include "marshal.h"
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
49
4596
4fa19659591e Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
50 #ifdef HAVE_UNISTD_H
4fa19659591e Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
51 #include <unistd.h>
4fa19659591e Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
52 #endif
4fa19659591e Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
53
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
54 #ifdef HAVE_SIGNAL_H
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
55 #include <signal.h>
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
56 #endif
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
57
4291
1427d61f1307 Rationalized MS ifdefs
Guido van Rossum <guido@python.org>
parents: 3609
diff changeset
58 #ifdef MS_WIN32
2529
16ea57c38c4f In NT, write fatal() msg to debugging device
Guido van Rossum <guido@python.org>
parents: 2318
diff changeset
59 #undef BYTE
3489
3b6ebf8d2a59 Add'l change for NT (Mark H.).
Guido van Rossum <guido@python.org>
parents: 3235
diff changeset
60 #undef arglist
2529
16ea57c38c4f In NT, write fatal() msg to debugging device
Guido van Rossum <guido@python.org>
parents: 2318
diff changeset
61 #include "windows.h"
16ea57c38c4f In NT, write fatal() msg to debugging device
Guido van Rossum <guido@python.org>
parents: 2318
diff changeset
62 #endif
16ea57c38c4f In NT, write fatal() msg to debugging device
Guido van Rossum <guido@python.org>
parents: 2318
diff changeset
63
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 extern char *getpythonpath();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
65
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 extern grammar gram; /* From graminit.c */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
67
1391
7c3245c18677 * ceval.c, longobject.c, methodobject.c, listnode.c, arraymodule.c,
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
68 /* Forward */
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
69 static void initmain PROTO((void));
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
70 static object *run_err_node PROTO((node *n, char *filename,
1391
7c3245c18677 * ceval.c, longobject.c, methodobject.c, listnode.c, arraymodule.c,
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
71 object *globals, object *locals));
7c3245c18677 * ceval.c, longobject.c, methodobject.c, listnode.c, arraymodule.c,
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
72 static object *run_node PROTO((node *n, char *filename,
7c3245c18677 * ceval.c, longobject.c, methodobject.c, listnode.c, arraymodule.c,
Guido van Rossum <guido@python.org>
parents: 1347
diff changeset
73 object *globals, object *locals));
2293
a24146241991 print class name for exceptions that are classes
Guido van Rossum <guido@python.org>
parents: 2279
diff changeset
74 static object *run_pyc_file PROTO((FILE *fp, char *filename,
a24146241991 print class name for exceptions that are classes
Guido van Rossum <guido@python.org>
parents: 2279
diff changeset
75 object *globals, object *locals));
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
76 static void err_input PROTO((perrdetail *));
1413
c914b10bf2ed * timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents: 1391
diff changeset
77 static void initsigs PROTO((void));
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
78
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 int debugging; /* Needed by parser.c */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 int verbose; /* Needed by import.c */
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
81 int suppress_print; /* Needed by ceval.c */
5108
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
82 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
83
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 /* Initialize all */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
85
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 void
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 initall()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 static int inited;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
90
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 if (inited)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 return;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 inited = 1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
94
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 initimport();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
96
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
97 /* Modules '__builtin__' and 'sys' are initialized here,
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 they are needed by random bits of the interpreter.
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 All other modules are optional and are initialized
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 when they are first imported. */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
101
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 initbuiltin(); /* Also initializes builtin exceptions */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 initsys();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
104
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 setpythonpath(getpythonpath());
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
106
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
107 initsigs(); /* Signal handling stuff, including initintr() */
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
108
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
109 initmain();
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
110 }
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
111
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
112 /* Create __main__ module */
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
113
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
114 static void
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
115 initmain()
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
116 {
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
117 object *m, *d;
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
118 m = add_module("__main__");
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
119 if (m == NULL)
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
120 fatal("can't create __main__ module");
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
121 d = getmoduledict(m);
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
122 if (dictlookup(d, "__builtins__") == NULL) {
2128
92da8901517e use getbuiltins() everywhere, it defaults to getbuiltidict()
Guido van Rossum <guido@python.org>
parents: 2098
diff changeset
123 if (dictinsert(d, "__builtins__", getbuiltins()))
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
124 fatal("can't add __builtins__ to __main__");
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
125 }
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
127
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 /* Parse input from a file and execute it */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
129
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 int
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 run(fp, filename)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 FILE *fp;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 char *filename;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 if (filename == NULL)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 filename = "???";
5108
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
137 if (Py_FdIsInteractive(fp, filename))
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 return run_tty_loop(fp, filename);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 else
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 return run_script(fp, filename);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
142
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 int
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 run_tty_loop(fp, filename)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 FILE *fp;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 char *filename;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 object *v;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 int ret;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 v = sysget("ps1");
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 if (v == NULL) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 sysset("ps1", v = newstringobject(">>> "));
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 XDECREF(v);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 v = sysget("ps2");
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 if (v == NULL) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 sysset("ps2", v = newstringobject("... "));
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 XDECREF(v);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 for (;;) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 ret = run_tty_1(fp, filename);
3575
e2b3a696d69c Use new names for debug macros. Don't include pythonrun.h.
Guido van Rossum <guido@python.org>
parents: 3489
diff changeset
162 #ifdef Py_REF_DEBUG
2612
ca6b60d4ea90 fix dusty debugging macros
Guido van Rossum <guido@python.org>
parents: 2529
diff changeset
163 fprintf(stderr, "[%ld refs]\n", _Py_RefTotal);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 if (ret == E_EOF)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 return 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 /*
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 if (ret == E_NOMEM)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 return -1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
173
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 int
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 run_tty_1(fp, filename)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 FILE *fp;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 char *filename;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 object *m, *d, *v, *w;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 node *n;
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
181 perrdetail err;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 char *ps1, *ps2;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 v = sysget("ps1");
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
184 w = sysget("ps2");
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 if (v != NULL && is_stringobject(v)) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 INCREF(v);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 ps1 = getstringvalue(v);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 else {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 v = NULL;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 ps1 = "";
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 if (w != NULL && is_stringobject(w)) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 INCREF(w);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 ps2 = getstringvalue(w);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 else {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 w = NULL;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 ps2 = "";
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 }
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
201 BGN_SAVE
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
202 n = parsefile(fp, filename, &gram, single_input, ps1, ps2, &err);
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
203 END_SAVE
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 XDECREF(v);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 XDECREF(w);
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
206 if (n == NULL) {
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
207 if (err.error == E_EOF) {
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
208 if (err.text)
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
209 free(err.text);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
210 return E_EOF;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
211 }
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
212 err_input(&err);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
213 print_error();
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
214 return err.error;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 m = add_module("__main__");
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 if (m == NULL)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 return -1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 d = getmoduledict(m);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 v = run_node(n, filename, d, d);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 if (v == NULL) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
222 print_error();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
223 return -1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 DECREF(v);
2062
d0d0a69b5ca3 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2052
diff changeset
226 flushline();
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 return 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
229
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 int
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 run_script(fp, filename)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 FILE *fp;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 char *filename;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 object *m, *d, *v;
1886
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
236 char *ext;
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
237
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 m = add_module("__main__");
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 if (m == NULL)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 return -1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 d = getmoduledict(m);
1886
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
242 ext = filename + strlen(filename) - 4;
2318
99e7ac22bd2e mac changes:
Jack Jansen <jack.jansen@cwi.nl>
parents: 2293
diff changeset
243 #ifdef macintosh
99e7ac22bd2e mac changes:
Jack Jansen <jack.jansen@cwi.nl>
parents: 2293
diff changeset
244 /* On a mac, we also assume a pyc file for types 'PYC ' and 'APPL' */
99e7ac22bd2e mac changes:
Jack Jansen <jack.jansen@cwi.nl>
parents: 2293
diff changeset
245 if ( strcmp(ext, ".pyc") == 0 || getfiletype(filename) == 'PYC ' ||
99e7ac22bd2e mac changes:
Jack Jansen <jack.jansen@cwi.nl>
parents: 2293
diff changeset
246 getfiletype(filename) == 'APPL' ) {
99e7ac22bd2e mac changes:
Jack Jansen <jack.jansen@cwi.nl>
parents: 2293
diff changeset
247 #else
1886
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
248 if ( strcmp(ext, ".pyc") == 0 ) {
2318
99e7ac22bd2e mac changes:
Jack Jansen <jack.jansen@cwi.nl>
parents: 2293
diff changeset
249 #endif /* macintosh */
1886
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
250 /* Try to run a pyc file. First, re-open in binary */
2022
eee3d715f0cf Removed extraneous fclose() in case of .pyc file argument
Jack Jansen <jack.jansen@cwi.nl>
parents: 1911
diff changeset
251 /* Don't close, done in main: fclose(fp); */
1886
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
252 if( (fp = fopen(filename, "rb")) == NULL ) {
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
253 fprintf(stderr, "python: Can't reopen .pyc file\n");
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
254 return -1;
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
255 }
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
256 v = run_pyc_file(fp, filename, d, d);
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
257 } else {
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
258 v = run_file(fp, filename, file_input, d, d);
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
259 }
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 if (v == NULL) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
261 print_error();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
262 return -1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
264 DECREF(v);
2062
d0d0a69b5ca3 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2052
diff changeset
265 flushline();
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
266 return 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
267 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
268
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 int
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 run_command(command)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
271 char *command;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
272 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
273 object *m, *d, *v;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
274 m = add_module("__main__");
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
275 if (m == NULL)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
276 return -1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
277 d = getmoduledict(m);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
278 v = run_string(command, file_input, d, d);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
279 if (v == NULL) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
280 print_error();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
281 return -1;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
282 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
283 DECREF(v);
2062
d0d0a69b5ca3 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2052
diff changeset
284 flushline();
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
285 return 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
286 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
287
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
288 void
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
289 print_error()
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
290 {
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2022
diff changeset
291 object *exception, *v, *tb, *f;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2022
diff changeset
292 err_fetch(&exception, &v, &tb);
2062
d0d0a69b5ca3 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2052
diff changeset
293 flushline();
2617
ed30bca184bb flush stdout before writing to stderr in print_error()
Guido van Rossum <guido@python.org>
parents: 2612
diff changeset
294 fflush(stdout);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2022
diff changeset
295 if (exception == NULL)
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2022
diff changeset
296 fatal("print_error called but no exception");
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 if (exception == SystemExit) {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
298 if (v == NULL || v == None)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
299 goaway(0);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
300 if (is_intobject(v))
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
301 goaway((int)getintvalue(v));
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
302 else {
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1015
diff changeset
303 /* OK to use real stderr here */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
304 printobject(v, stderr, PRINT_RAW);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
305 fprintf(stderr, "\n");
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
306 goaway(1);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
307 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
308 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
309 sysset("last_type", exception);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
310 sysset("last_value", v);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2022
diff changeset
311 sysset("last_traceback", tb);
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1015
diff changeset
312 f = sysget("stderr");
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1015
diff changeset
313 if (f == NULL)
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1015
diff changeset
314 fprintf(stderr, "lost sys.stderr\n");
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1015
diff changeset
315 else {
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2022
diff changeset
316 tb_print(tb, f);
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
317 if (exception == SyntaxError) {
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
318 object *message;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
319 char *filename, *text;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
320 int lineno, offset;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
321 if (!getargs(v, "(O(ziiz))", &message,
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
322 &filename, &lineno, &offset, &text))
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
323 err_clear();
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
324 else {
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
325 char buf[10];
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
326 writestring(" File \"", f);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
327 if (filename == NULL)
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
328 writestring("<string>", f);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
329 else
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
330 writestring(filename, f);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
331 writestring("\", line ", f);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
332 sprintf(buf, "%d", lineno);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
333 writestring(buf, f);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
334 writestring("\n", f);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
335 if (text != NULL) {
1898
20f17b5accbf * Python/pythonrun.c (print_error): print only last line of
Guido van Rossum <guido@python.org>
parents: 1886
diff changeset
336 char *nl;
20f17b5accbf * Python/pythonrun.c (print_error): print only last line of
Guido van Rossum <guido@python.org>
parents: 1886
diff changeset
337 if (offset > 0 &&
20f17b5accbf * Python/pythonrun.c (print_error): print only last line of
Guido van Rossum <guido@python.org>
parents: 1886
diff changeset
338 offset == strlen(text))
20f17b5accbf * Python/pythonrun.c (print_error): print only last line of
Guido van Rossum <guido@python.org>
parents: 1886
diff changeset
339 offset--;
20f17b5accbf * Python/pythonrun.c (print_error): print only last line of
Guido van Rossum <guido@python.org>
parents: 1886
diff changeset
340 for (;;) {
20f17b5accbf * Python/pythonrun.c (print_error): print only last line of
Guido van Rossum <guido@python.org>
parents: 1886
diff changeset
341 nl = strchr(text, '\n');
20f17b5accbf * Python/pythonrun.c (print_error): print only last line of
Guido van Rossum <guido@python.org>
parents: 1886
diff changeset
342 if (nl == NULL ||
20f17b5accbf * Python/pythonrun.c (print_error): print only last line of
Guido van Rossum <guido@python.org>
parents: 1886
diff changeset
343 nl-text >= offset)
20f17b5accbf * Python/pythonrun.c (print_error): print only last line of
Guido van Rossum <guido@python.org>
parents: 1886
diff changeset
344 break;
20f17b5accbf * Python/pythonrun.c (print_error): print only last line of
Guido van Rossum <guido@python.org>
parents: 1886
diff changeset
345 offset -= (nl+1-text);
20f17b5accbf * Python/pythonrun.c (print_error): print only last line of
Guido van Rossum <guido@python.org>
parents: 1886
diff changeset
346 text = nl+1;
20f17b5accbf * Python/pythonrun.c (print_error): print only last line of
Guido van Rossum <guido@python.org>
parents: 1886
diff changeset
347 }
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
348 while (*text == ' ' || *text == '\t') {
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
349 text++;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
350 offset--;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
351 }
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
352 writestring(" ", f);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
353 writestring(text, f);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
354 if (*text == '\0' ||
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
355 text[strlen(text)-1] != '\n')
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
356 writestring("\n", f);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
357 writestring(" ", f);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
358 offset--;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
359 while (offset > 0) {
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
360 writestring(" ", f);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
361 offset--;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
362 }
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
363 writestring("^\n", f);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
364 }
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
365 INCREF(message);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
366 DECREF(v);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
367 v = message;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
368 }
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
369 }
2293
a24146241991 print class name for exceptions that are classes
Guido van Rossum <guido@python.org>
parents: 2279
diff changeset
370 if (is_classobject(exception)) {
a24146241991 print class name for exceptions that are classes
Guido van Rossum <guido@python.org>
parents: 2279
diff changeset
371 object* className = ((classobject*)exception)->cl_name;
a24146241991 print class name for exceptions that are classes
Guido van Rossum <guido@python.org>
parents: 2279
diff changeset
372 if (className == NULL)
a24146241991 print class name for exceptions that are classes
Guido van Rossum <guido@python.org>
parents: 2279
diff changeset
373 writestring("<unknown>", f);
a24146241991 print class name for exceptions that are classes
Guido van Rossum <guido@python.org>
parents: 2279
diff changeset
374 else {
a24146241991 print class name for exceptions that are classes
Guido van Rossum <guido@python.org>
parents: 2279
diff changeset
375 if (writeobject(className, f, PRINT_RAW) != 0)
a24146241991 print class name for exceptions that are classes
Guido van Rossum <guido@python.org>
parents: 2279
diff changeset
376 err_clear();
a24146241991 print class name for exceptions that are classes
Guido van Rossum <guido@python.org>
parents: 2279
diff changeset
377 }
a24146241991 print class name for exceptions that are classes
Guido van Rossum <guido@python.org>
parents: 2279
diff changeset
378 } else {
a24146241991 print class name for exceptions that are classes
Guido van Rossum <guido@python.org>
parents: 2279
diff changeset
379 if (writeobject(exception, f, PRINT_RAW) != 0)
a24146241991 print class name for exceptions that are classes
Guido van Rossum <guido@python.org>
parents: 2279
diff changeset
380 err_clear();
a24146241991 print class name for exceptions that are classes
Guido van Rossum <guido@python.org>
parents: 2279
diff changeset
381 }
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1015
diff changeset
382 if (v != NULL && v != None) {
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1015
diff changeset
383 writestring(": ", f);
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1015
diff changeset
384 if (writeobject(v, f, PRINT_RAW) != 0)
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1015
diff changeset
385 err_clear();
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1015
diff changeset
386 }
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1015
diff changeset
387 writestring("\n", f);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
388 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
389 XDECREF(exception);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
390 XDECREF(v);
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2022
diff changeset
391 XDECREF(tb);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
392 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
393
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
394 object *
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
395 run_string(str, start, globals, locals)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
396 char *str;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
397 int start;
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
398 object *globals, *locals;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
399 {
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
400 return run_err_node(parse_string(str, start),
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
401 "<string>", globals, locals);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
402 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
403
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
404 object *
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
405 run_file(fp, filename, start, globals, locals)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
406 FILE *fp;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
407 char *filename;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
408 int start;
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
409 object *globals, *locals;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
410 {
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
411 return run_err_node(parse_file(fp, filename, start),
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
412 filename, globals, locals);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
413 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
414
1319
cd397266dc1c * Makefile: added all: and default: targets.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
415 static object *
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
416 run_err_node(n, filename, globals, locals)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
417 node *n;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
418 char *filename;
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
419 object *globals, *locals;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
420 {
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
421 if (n == NULL)
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
422 return NULL;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
423 return run_node(n, filename, globals, locals);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
424 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
425
1319
cd397266dc1c * Makefile: added all: and default: targets.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
426 static object *
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
427 run_node(n, filename, globals, locals)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
428 node *n;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
429 char *filename;
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
430 object *globals, *locals;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
431 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
432 codeobject *co;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
433 object *v;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
434 co = compile(n, filename);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
435 freetree(n);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
436 if (co == NULL)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
437 return NULL;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2617
diff changeset
438 v = eval_code(co, globals, locals);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
439 DECREF(co);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
440 return v;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
441 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
442
2242
d3b5be0c872f make call_pyc_file static
Guido van Rossum <guido@python.org>
parents: 2128
diff changeset
443 static object *
1886
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
444 run_pyc_file(fp, filename, globals, locals)
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
445 FILE *fp;
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
446 char *filename;
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
447 object *globals, *locals;
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
448 {
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
449 codeobject *co;
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
450 object *v;
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
451 long magic;
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
452 long get_pyc_magic();
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
453
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
454 magic = rd_long(fp);
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
455 if (magic != get_pyc_magic()) {
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
456 err_setstr(RuntimeError,
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
457 "Bad magic number in .pyc file");
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
458 return NULL;
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
459 }
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
460 (void) rd_long(fp);
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
461 v = rd_object(fp);
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
462 fclose(fp);
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
463 if (v == NULL || !is_codeobject(v)) {
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
464 XDECREF(v);
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
465 err_setstr(RuntimeError,
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
466 "Bad code object in .pyc file");
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
467 return NULL;
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
468 }
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
469 co = (codeobject *)v;
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2617
diff changeset
470 v = eval_code(co, globals, locals);
1886
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
471 DECREF(co);
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
472 return v;
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
473 }
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
474
ac6a9f90f6fd * Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents: 1870
diff changeset
475 object *
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
476 compile_string(str, filename, start)
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
477 char *str;
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
478 char *filename;
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
479 int start;
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
480 {
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
481 node *n;
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
482 codeobject *co;
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
483 n = parse_string(str, start);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
484 if (n == NULL)
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
485 return NULL;
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
486 co = compile(n, filename);
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
487 freetree(n);
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
488 return (object *)co;
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
489 }
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1262
diff changeset
490
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
491 /* Simplified interface to parsefile -- return node or set exception */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
492
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
493 node *
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
494 parse_file(fp, filename, start)
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
495 FILE *fp;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
496 char *filename;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
497 int start;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
498 {
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
499 node *n;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
500 perrdetail err;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
501 BGN_SAVE
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
502 n = parsefile(fp, filename, &gram, start,
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
503 (char *)0, (char *)0, &err);
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
504 END_SAVE
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
505 if (n == NULL)
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
506 err_input(&err);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
507 return n;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
508 }
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
509
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
510 /* Simplified interface to parsestring -- return node or set exception */
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
511
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
512 node *
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
513 parse_string(str, start)
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
514 char *str;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
515 int start;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
516 {
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
517 node *n;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
518 perrdetail err;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
519 n = parsestring(str, &gram, start, &err);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
520 if (n == NULL)
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
521 err_input(&err);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
522 return n;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
523 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
524
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
525 /* Set the error appropriate to the given input error code (see errcode.h) */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
526
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
527 static void
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
528 err_input(err)
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
529 perrdetail *err;
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
530 {
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
531 object *v, *w;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
532 char *msg = NULL;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
533 v = mkvalue("(ziiz)", err->filename,
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
534 err->lineno, err->offset, err->text);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
535 if (err->text != NULL) {
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
536 free(err->text);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
537 err->text = NULL;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
538 }
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
539 switch (err->error) {
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
540 case E_SYNTAX:
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
541 msg = "invalid syntax";
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
542 break;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
543 case E_TOKEN:
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
544 msg = "invalid token";
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
545
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
546 break;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
547 case E_INTR:
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
548 err_set(KeyboardInterrupt);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
549 return;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
550 case E_NOMEM:
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
551 err_nomem();
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
552 return;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
553 case E_EOF:
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
554 msg = "unexpected EOF while parsing";
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
555 break;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
556 default:
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
557 fprintf(stderr, "error=%d\n", err->error);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
558 msg = "unknown parsing error";
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
559 break;
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
560 }
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
561 w = mkvalue("(sO)", msg, v);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
562 XDECREF(v);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
563 err_setval(SyntaxError, w);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
564 XDECREF(w);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
565 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
566
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
567 /* Print fatal error message and abort */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
568
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
569 void
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
570 fatal(msg)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
571 char *msg;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
572 {
1911
a7f269610ec2 * Python/pythonrun.c: add string "Python" to fatal error message
Guido van Rossum <guido@python.org>
parents: 1898
diff changeset
573 fprintf(stderr, "Fatal Python error: %s\n", msg);
2242
d3b5be0c872f make call_pyc_file static
Guido van Rossum <guido@python.org>
parents: 2128
diff changeset
574 #ifdef macintosh
d3b5be0c872f make call_pyc_file static
Guido van Rossum <guido@python.org>
parents: 2128
diff changeset
575 for (;;);
d3b5be0c872f make call_pyc_file static
Guido van Rossum <guido@python.org>
parents: 2128
diff changeset
576 #endif
4291
1427d61f1307 Rationalized MS ifdefs
Guido van Rossum <guido@python.org>
parents: 3609
diff changeset
577 #ifdef MS_WIN32
2529
16ea57c38c4f In NT, write fatal() msg to debugging device
Guido van Rossum <guido@python.org>
parents: 2318
diff changeset
578 OutputDebugString("Fatal Python error:");
16ea57c38c4f In NT, write fatal() msg to debugging device
Guido van Rossum <guido@python.org>
parents: 2318
diff changeset
579 OutputDebugString(msg);
16ea57c38c4f In NT, write fatal() msg to debugging device
Guido van Rossum <guido@python.org>
parents: 2318
diff changeset
580 OutputDebugString("\n");
16ea57c38c4f In NT, write fatal() msg to debugging device
Guido van Rossum <guido@python.org>
parents: 2318
diff changeset
581 #endif
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
582 abort();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
583 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
584
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
585 /* Clean up and exit */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
586
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
587 #ifdef WITH_THREAD
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
588 #include "thread.h"
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
589 int threads_started = 0; /* Set by threadmodule.c and maybe others */
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 941
diff changeset
590 #endif
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 941
diff changeset
591
1870
61738ed6cc10 added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents: 1839
diff changeset
592 #define NEXITFUNCS 32
61738ed6cc10 added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents: 1839
diff changeset
593 static void (*exitfuncs[NEXITFUNCS])();
61738ed6cc10 added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents: 1839
diff changeset
594 static int nexitfuncs = 0;
61738ed6cc10 added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents: 1839
diff changeset
595
61738ed6cc10 added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents: 1839
diff changeset
596 int Py_AtExit(func)
61738ed6cc10 added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents: 1839
diff changeset
597 void (*func) PROTO((void));
61738ed6cc10 added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents: 1839
diff changeset
598 {
61738ed6cc10 added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents: 1839
diff changeset
599 if (nexitfuncs >= NEXITFUNCS)
61738ed6cc10 added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents: 1839
diff changeset
600 return -1;
61738ed6cc10 added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents: 1839
diff changeset
601 exitfuncs[nexitfuncs++] = func;
61738ed6cc10 added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents: 1839
diff changeset
602 return 0;
61738ed6cc10 added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents: 1839
diff changeset
603 }
61738ed6cc10 added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents: 1839
diff changeset
604
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
605 void
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
606 cleanup()
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
607 {
1015
f3d5e2c3b9a3 Add sys.exitfunc feature. Make askync non-static.
Guido van Rossum <guido@python.org>
parents: 961
diff changeset
608 object *exitfunc = sysget("exitfunc");
f3d5e2c3b9a3 Add sys.exitfunc feature. Make askync non-static.
Guido van Rossum <guido@python.org>
parents: 961
diff changeset
609
f3d5e2c3b9a3 Add sys.exitfunc feature. Make askync non-static.
Guido van Rossum <guido@python.org>
parents: 961
diff changeset
610 if (exitfunc) {
f3d5e2c3b9a3 Add sys.exitfunc feature. Make askync non-static.
Guido van Rossum <guido@python.org>
parents: 961
diff changeset
611 object *res;
3152
a36e30240d06 keep exitfunc alive while calling it
Guido van Rossum <guido@python.org>
parents: 3102
diff changeset
612 INCREF(exitfunc);
1015
f3d5e2c3b9a3 Add sys.exitfunc feature. Make askync non-static.
Guido van Rossum <guido@python.org>
parents: 961
diff changeset
613 sysset("exitfunc", (object *)NULL);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2617
diff changeset
614 res = call_object(exitfunc, (object *)NULL);
1015
f3d5e2c3b9a3 Add sys.exitfunc feature. Make askync non-static.
Guido van Rossum <guido@python.org>
parents: 961
diff changeset
615 if (res == NULL) {
f3d5e2c3b9a3 Add sys.exitfunc feature. Make askync non-static.
Guido van Rossum <guido@python.org>
parents: 961
diff changeset
616 fprintf(stderr, "Error in sys.exitfunc:\n");
f3d5e2c3b9a3 Add sys.exitfunc feature. Make askync non-static.
Guido van Rossum <guido@python.org>
parents: 961
diff changeset
617 print_error();
f3d5e2c3b9a3 Add sys.exitfunc feature. Make askync non-static.
Guido van Rossum <guido@python.org>
parents: 961
diff changeset
618 }
3152
a36e30240d06 keep exitfunc alive while calling it
Guido van Rossum <guido@python.org>
parents: 3102
diff changeset
619 DECREF(exitfunc);
1015
f3d5e2c3b9a3 Add sys.exitfunc feature. Make askync non-static.
Guido van Rossum <guido@python.org>
parents: 961
diff changeset
620 }
f3d5e2c3b9a3 Add sys.exitfunc feature. Make askync non-static.
Guido van Rossum <guido@python.org>
parents: 961
diff changeset
621
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
622 flushline();
1870
61738ed6cc10 added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents: 1839
diff changeset
623
61738ed6cc10 added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents: 1839
diff changeset
624 while (nexitfuncs > 0)
61738ed6cc10 added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents: 1839
diff changeset
625 (*exitfuncs[--nexitfuncs])();
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
626 }
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
627
1347
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1319
diff changeset
628 #ifdef COUNT_ALLOCS
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1319
diff changeset
629 extern void dump_counts PROTO((void));
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1319
diff changeset
630 #endif
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1319
diff changeset
631
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
632 void
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
633 goaway(sts)
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
634 int sts;
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
635 {
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
636 cleanup();
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
637
1347
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1319
diff changeset
638 #ifdef COUNT_ALLOCS
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1319
diff changeset
639 dump_counts();
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1319
diff changeset
640 #endif
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1319
diff changeset
641
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
642 #ifdef WITH_THREAD
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
643
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
644 /* Other threads may still be active, so skip most of the
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
645 cleanup actions usually done (these are mostly for
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
646 debugging anyway). */
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
647
941
cd40e3eebb49 To ignore a call, cast it to (void), not to (void *)...
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
648 (void) save_thread();
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
649 #ifndef NO_EXIT_PROG
961
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 941
diff changeset
650 if (threads_started)
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 941
diff changeset
651 _exit_prog(sts);
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 941
diff changeset
652 else
a31e07847063 New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents: 941
diff changeset
653 exit_prog(sts);
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
654 #else /* !NO_EXIT_PROG */
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
655 if (threads_started)
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
656 _exit(sts);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
657 else
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
658 exit(sts);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
659 #endif /* !NO_EXIT_PROG */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
660
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
661 #else /* WITH_THREAD */
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
662
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
663 doneimport();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
664
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
665 err_clear();
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
666
3575
e2b3a696d69c Use new names for debug macros. Don't include pythonrun.h.
Guido van Rossum <guido@python.org>
parents: 3489
diff changeset
667 #ifdef Py_REF_DEBUG
2612
ca6b60d4ea90 fix dusty debugging macros
Guido van Rossum <guido@python.org>
parents: 2529
diff changeset
668 fprintf(stderr, "[%ld refs]\n", _Py_RefTotal);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
669 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
670
3575
e2b3a696d69c Use new names for debug macros. Don't include pythonrun.h.
Guido van Rossum <guido@python.org>
parents: 3489
diff changeset
671 #ifdef Py_TRACE_REFS
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
672 if (askyesno("Print left references?")) {
3609
0b0c4ed1936a rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents: 3575
diff changeset
673 _Py_PrintReferences(stderr);
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
674 }
3575
e2b3a696d69c Use new names for debug macros. Don't include pythonrun.h.
Guido van Rossum <guido@python.org>
parents: 3489
diff changeset
675 #endif /* Py_TRACE_REFS */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
676
3235
3df9ab03badf Moved mac-specific exit handling to macmain.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 3152
diff changeset
677 #ifdef macintosh
3df9ab03badf Moved mac-specific exit handling to macmain.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 3152
diff changeset
678 PyMac_Exit(sts);
3df9ab03badf Moved mac-specific exit handling to macmain.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 3152
diff changeset
679 #else
3df9ab03badf Moved mac-specific exit handling to macmain.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 3152
diff changeset
680 exit(sts);
2269
a8c6da3bd305 Think C mod to suppress pausing at normal exit
Guido van Rossum <guido@python.org>
parents: 2242
diff changeset
681 #endif
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
682 #endif /* WITH_THREAD */
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
683 /*NOTREACHED*/
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
684 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
685
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
686 #ifdef HAVE_SIGNAL_H
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
687 static RETSIGTYPE
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
688 sighandler(sig)
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
689 int sig;
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
690 {
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
691 signal(sig, SIG_DFL); /* Don't catch recursive signals */
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
692 cleanup(); /* Do essential clean-up */
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
693 #ifdef HAVE_GETPID
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
694 kill(getpid(), sig); /* Pretend the signal killed us */
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
695 #else
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
696 exit(1);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
697 #endif
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
698 /*NOTREACHED*/
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
699 }
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
700 #endif
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
701
1319
cd397266dc1c * Makefile: added all: and default: targets.
Guido van Rossum <guido@python.org>
parents: 1289
diff changeset
702 static void
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
703 initsigs()
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
704 {
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
705 RETSIGTYPE (*t)();
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
706 #ifdef HAVE_SIGNAL_H
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
707 #ifdef SIGPIPE
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
708 signal(SIGPIPE, SIG_IGN);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
709 #endif
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
710 #ifdef SIGHUP
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
711 t = signal(SIGHUP, SIG_IGN);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
712 if (t == SIG_DFL)
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
713 signal(SIGHUP, sighandler);
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
714 else
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
715 signal(SIGHUP, t);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
716 #endif
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
717 #ifdef SIGTERM
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
718 t = signal(SIGTERM, SIG_IGN);
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
719 if (t == SIG_DFL)
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
720 signal(SIGTERM, sighandler);
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
721 else
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
722 signal(SIGTERM, t);
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
723 #endif
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
724 #endif /* HAVE_SIGNAL_H */
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
725 initintr(); /* May imply initsignal() */
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
726 }
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
727
3575
e2b3a696d69c Use new names for debug macros. Don't include pythonrun.h.
Guido van Rossum <guido@python.org>
parents: 3489
diff changeset
728 #ifdef Py_TRACE_REFS
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
729 /* Ask a yes/no question */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
730
1015
f3d5e2c3b9a3 Add sys.exitfunc feature. Make askync non-static.
Guido van Rossum <guido@python.org>
parents: 961
diff changeset
731 int
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
732 askyesno(prompt)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
733 char *prompt;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
734 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
735 char buf[256];
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
736
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
737 printf("%s [ny] ", prompt);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
738 if (fgets(buf, sizeof buf, stdin) == NULL)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
739 return 0;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
740 return buf[0] == 'y' || buf[0] == 'Y';
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
741 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
742 #endif
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
743
1839
1f4a86dbcd79 * Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
744 #ifdef MPW
923
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
745
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
746 /* Check for file descriptor connected to interactive device.
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
747 Pretend that stdin is always interactive, other files never. */
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
748
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
749 int
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
750 isatty(fd)
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
751 int fd;
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
752 {
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
753 return fd == fileno(stdin);
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
754 }
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
755
72aceed365d4 * Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff changeset
756 #endif
5108
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
757
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
758 /*
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
759 * The file descriptor fd is considered ``interactive'' if either
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
760 * a) isatty(fd) is TRUE, or
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
761 * b) the -i flag was given, and the filename associated with
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
762 * the descriptor is NULL or "<stdin>" or "???".
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
763 */
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
764 int
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
765 Py_FdIsInteractive(fp, filename)
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
766 FILE *fp;
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
767 char *filename;
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
768 {
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
769 if (isatty((int)fileno(fp)))
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
770 return 1;
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
771 if (!Py_InteractiveFlag)
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
772 return 0;
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
773 return (filename == NULL) ||
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
774 (strcmp(filename, "<stdin>") == 0) ||
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
775 (strcmp(filename, "???") == 0);
a9a6d416b945 Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents: 4596
diff changeset
776 }