blob: 9ce8bef79fa34c49645f57aa3f051620c8a45de4 [file] [log] [blame]
Guido van Rossum667d7041995-08-04 04:20:48 +00001/* Python interpreter main program */
2
3#include "Python.h"
Guido van Rossuma075ce11997-12-05 21:56:45 +00004#include "osdefs.h"
Guido van Rossum393661d2001-08-31 17:40:15 +00005#include "compile.h" /* For CO_FUTURE_DIVISION */
Guido van Rossum667d7041995-08-04 04:20:48 +00006
Guido van Rossum3e7ae7a1997-01-17 22:05:38 +00007#ifdef MS_WINDOWS
8#include <fcntl.h>
9#endif
10
Andrew MacIntyre7bf68332002-03-03 02:59:16 +000011#if (defined(PYOS_OS2) && !defined(PYCC_GCC)) || defined(MS_WINDOWS)
Guido van Rossuma075ce11997-12-05 21:56:45 +000012#define PYTHONHOMEHELP "<prefix>\\lib"
13#else
Andrew MacIntyre7bf68332002-03-03 02:59:16 +000014#if defined(PYOS_OS2) && defined(PYCC_GCC)
15#define PYTHONHOMEHELP "<prefix>/Lib"
16#else
Marc-André Lemburgda4dbc32001-06-12 16:13:51 +000017#define PYTHONHOMEHELP "<prefix>/pythonX.X"
Guido van Rossuma075ce11997-12-05 21:56:45 +000018#endif
Andrew MacIntyre7bf68332002-03-03 02:59:16 +000019#endif
Guido van Rossuma075ce11997-12-05 21:56:45 +000020
Thomas Wouters2cffc7d2000-11-03 08:18:37 +000021#include "pygetopt.h"
22
Guido van Rossuma22865e2000-09-05 04:41:18 +000023#define COPYRIGHT \
Guido van Rossum36002d72001-07-18 16:59:46 +000024 "Type \"help\", \"copyright\", \"credits\" or \"license\" " \
25 "for more information."
Guido van Rossuma22865e2000-09-05 04:41:18 +000026
Guido van Rossumac56b031996-07-21 02:33:38 +000027/* For Py_GetArgcArgv(); set by main() */
Guido van Rossum667d7041995-08-04 04:20:48 +000028static char **orig_argv;
29static int orig_argc;
30
Guido van Rossumbceccf52001-04-10 22:07:43 +000031/* command line options */
Guido van Rossum61c345f2001-09-04 03:26:15 +000032#define BASE_OPTS "c:dEhiOQ:StuUvVW:xX"
Guido van Rossumbceccf52001-04-10 22:07:43 +000033
34#ifndef RISCOS
35#define PROGRAM_OPTS BASE_OPTS
36#else /*RISCOS*/
37/* extra option saying that we are running under a special task window
38 frontend; especially my_readline will behave different */
39#define PROGRAM_OPTS BASE_OPTS "w"
40/* corresponding flag */
Guido van Rossum3ed4c152001-03-02 06:18:03 +000041extern int Py_RISCOSWimpFlag;
Guido van Rossumbceccf52001-04-10 22:07:43 +000042#endif /*RISCOS*/
Guido van Rossum3ed4c152001-03-02 06:18:03 +000043
Guido van Rossum667d7041995-08-04 04:20:48 +000044/* Short usage message (with %s for argv0) */
45static char *usage_line =
Guido van Rossum6b86a421999-01-28 15:07:47 +000046"usage: %s [option] ... [-c cmd | file | -] [arg] ...\n";
Guido van Rossum667d7041995-08-04 04:20:48 +000047
48/* Long usage message, split into parts < 512 bytes */
Guido van Rossum393661d2001-08-31 17:40:15 +000049static char *usage_1 = "\
Guido van Rossum667d7041995-08-04 04:20:48 +000050Options and arguments (and corresponding environment variables):\n\
Guido van Rossum393661d2001-08-31 17:40:15 +000051-c cmd : program passed in as string (terminates option list)\n\
Guido van Rossum667d7041995-08-04 04:20:48 +000052-d : debug output from parser (also PYTHONDEBUG=x)\n\
Guido van Rossum393661d2001-08-31 17:40:15 +000053-E : ignore environment variables (such as PYTHONPATH)\n\
54-h : print this help message and exit\n\
Guido van Rossum775af911997-02-14 19:50:32 +000055-i : inspect interactively after running script, (also PYTHONINSPECT=x)\n\
Guido van Rossumbba92ca1998-04-10 19:39:15 +000056 and force prompts, even if stdin does not appear to be a terminal\n\
Guido van Rossum61c345f2001-09-04 03:26:15 +000057";
58static char *usage_2 = "\
Guido van Rossume7adf3e1998-10-07 14:50:06 +000059-O : optimize generated bytecode (a tad; also PYTHONOPTIMIZE=x)\n\
Guido van Rossum6b86a421999-01-28 15:07:47 +000060-OO : remove doc-strings in addition to the -O optimizations\n\
Guido van Rossum1832de42001-09-04 03:51:09 +000061-Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew\n\
Guido van Rossum7922bd71997-08-29 22:34:47 +000062-S : don't imply 'import site' on initialization\n\
Guido van Rossumbba92ca1998-04-10 19:39:15 +000063-t : issue warnings about inconsistent tab usage (-tt: issue errors)\n\
Guido van Rossumbba92ca1998-04-10 19:39:15 +000064-u : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)\n\
Guido van Rossum393661d2001-08-31 17:40:15 +000065";
66static char *usage_3 = "\
Guido van Rossum7922bd71997-08-29 22:34:47 +000067-v : verbose (trace import statements) (also PYTHONVERBOSE=x)\n\
Barry Warsaw3b2aedb2000-09-15 18:40:42 +000068-V : print the Python version number and exit\n\
Guido van Rossum47f5fdc2000-12-15 22:00:54 +000069-W arg : warning control (arg is action:message:category:module:lineno)\n\
Guido van Rossum393661d2001-08-31 17:40:15 +000070-x : skip first line of source, allowing use of non-Unix forms of #!cmd\n\
Guido van Rossum667d7041995-08-04 04:20:48 +000071file : program read from script file\n\
72- : program read from stdin (default; interactive mode if a tty)\n\
Guido van Rossum7922bd71997-08-29 22:34:47 +000073";
Guido van Rossum393661d2001-08-31 17:40:15 +000074static char *usage_4 = "\
Guido van Rossumbba92ca1998-04-10 19:39:15 +000075arg ...: arguments passed to program in sys.argv[1:]\n\
Guido van Rossum667d7041995-08-04 04:20:48 +000076Other environment variables:\n\
77PYTHONSTARTUP: file executed on interactive startup (no default)\n\
Guido van Rossuma075ce11997-12-05 21:56:45 +000078PYTHONPATH : '%c'-separated list of directories prefixed to the\n\
Guido van Rossum667d7041995-08-04 04:20:48 +000079 default module search path. The result is sys.path.\n\
Guido van Rossuma075ce11997-12-05 21:56:45 +000080PYTHONHOME : alternate <prefix> directory (or <prefix>%c<exec_prefix>).\n\
81 The default module search path uses %s.\n\
Tim Peters793de092001-02-22 00:39:47 +000082PYTHONCASEOK : ignore case in 'import' statements (Windows).\n\
Guido van Rossum667d7041995-08-04 04:20:48 +000083";
84
85
Barry Warsaw3b2aedb2000-09-15 18:40:42 +000086static void
87usage(int exitcode, char* program)
88{
Guido van Rossum393661d2001-08-31 17:40:15 +000089 FILE *f = exitcode ? stderr : stdout;
90
91 fprintf(f, usage_line, program);
92 if (exitcode)
93 fprintf(f, "Try `python -h' for more information.\n");
94 else {
95 fprintf(f, usage_1);
96 fprintf(f, usage_2);
97 fprintf(f, usage_3);
98 fprintf(f, usage_4, DELIM, DELIM, PYTHONHOMEHELP);
99 }
Barry Warsaw3b2aedb2000-09-15 18:40:42 +0000100 exit(exitcode);
101 /*NOTREACHED*/
102}
103
104
Guido van Rossum667d7041995-08-04 04:20:48 +0000105/* Main program */
106
Guido van Rossum9c1201f1998-12-07 14:28:47 +0000107DL_EXPORT(int)
Fredrik Lundh620f3772000-07-09 20:42:34 +0000108Py_Main(int argc, char **argv)
Guido van Rossum667d7041995-08-04 04:20:48 +0000109{
110 int c;
111 int sts;
112 char *command = NULL;
113 char *filename = NULL;
114 FILE *fp = stdin;
115 char *p;
116 int inspect = 0;
117 int unbuffered = 0;
Guido van Rossuma075ce11997-12-05 21:56:45 +0000118 int skipfirstline = 0;
Guido van Rossum775af911997-02-14 19:50:32 +0000119 int stdin_is_interactive = 0;
Barry Warsaw3b2aedb2000-09-15 18:40:42 +0000120 int help = 0;
121 int version = 0;
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +0000122 int saw_inspect_flag = 0;
123 int saw_unbuffered_flag = 0;
Jeremy Hyltonbc320242001-03-22 02:47:58 +0000124 PyCompilerFlags cf;
Guido van Rossum667d7041995-08-04 04:20:48 +0000125
Guido van Rossum393661d2001-08-31 17:40:15 +0000126 cf.cf_flags = 0;
127
Guido van Rossumac56b031996-07-21 02:33:38 +0000128 orig_argc = argc; /* For Py_GetArgcArgv() */
Guido van Rossum667d7041995-08-04 04:20:48 +0000129 orig_argv = argv;
Guido van Rossum667d7041995-08-04 04:20:48 +0000130
Guido van Rossum3ed4c152001-03-02 06:18:03 +0000131#ifdef RISCOS
132 Py_RISCOSWimpFlag = 0;
133#endif
134
Guido van Rossum47f5fdc2000-12-15 22:00:54 +0000135 PySys_ResetWarnOptions();
136
Guido van Rossumbceccf52001-04-10 22:07:43 +0000137 while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) {
Guido van Rossum667d7041995-08-04 04:20:48 +0000138 if (c == 'c') {
139 /* -c is the last option; following arguments
140 that look like options are left for the
141 the command to interpret. */
Thomas Wouters2cffc7d2000-11-03 08:18:37 +0000142 command = malloc(strlen(_PyOS_optarg) + 2);
Guido van Rossum667d7041995-08-04 04:20:48 +0000143 if (command == NULL)
144 Py_FatalError(
145 "not enough memory to copy -c argument");
Thomas Wouters2cffc7d2000-11-03 08:18:37 +0000146 strcpy(command, _PyOS_optarg);
Guido van Rossum667d7041995-08-04 04:20:48 +0000147 strcat(command, "\n");
148 break;
149 }
Guido van Rossum393661d2001-08-31 17:40:15 +0000150
Guido van Rossum667d7041995-08-04 04:20:48 +0000151 switch (c) {
152
153 case 'd':
154 Py_DebugFlag++;
155 break;
156
Guido van Rossum61c345f2001-09-04 03:26:15 +0000157 case 'Q':
Guido van Rossum393661d2001-08-31 17:40:15 +0000158 if (strcmp(_PyOS_optarg, "old") == 0) {
159 Py_DivisionWarningFlag = 0;
160 break;
161 }
162 if (strcmp(_PyOS_optarg, "warn") == 0) {
Guido van Rossum1832de42001-09-04 03:51:09 +0000163 Py_DivisionWarningFlag = 1;
164 break;
165 }
166 if (strcmp(_PyOS_optarg, "warnall") == 0) {
167 Py_DivisionWarningFlag = 2;
Guido van Rossum393661d2001-08-31 17:40:15 +0000168 break;
169 }
170 if (strcmp(_PyOS_optarg, "new") == 0) {
Tim Peters3caca232001-12-06 06:23:26 +0000171 /* This only affects __main__ */
Guido van Rossum393661d2001-08-31 17:40:15 +0000172 cf.cf_flags |= CO_FUTURE_DIVISION;
Tim Peters3caca232001-12-06 06:23:26 +0000173 /* And this tells the eval loop to treat
174 BINARY_DIVIDE as BINARY_TRUE_DIVIDE */
175 _Py_QnewFlag = 1;
Guido van Rossum393661d2001-08-31 17:40:15 +0000176 break;
177 }
178 fprintf(stderr,
Guido van Rossum1832de42001-09-04 03:51:09 +0000179 "-Q option should be `-Qold', "
180 "`-Qwarn', `-Qwarnall', or `-Qnew' only\n");
Guido van Rossum393661d2001-08-31 17:40:15 +0000181 usage(2, argv[0]);
182 /* NOTREACHED */
183
Guido van Rossum667d7041995-08-04 04:20:48 +0000184 case 'i':
185 inspect++;
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +0000186 saw_inspect_flag = 1;
Guido van Rossum775af911997-02-14 19:50:32 +0000187 Py_InteractiveFlag++;
Guido van Rossum667d7041995-08-04 04:20:48 +0000188 break;
189
Guido van Rossum7614da61997-03-03 19:14:45 +0000190 case 'O':
191 Py_OptimizeFlag++;
192 break;
193
Guido van Rossum7922bd71997-08-29 22:34:47 +0000194 case 'S':
195 Py_NoSiteFlag++;
196 break;
197
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +0000198 case 'E':
199 Py_IgnoreEnvironmentFlag++;
200 break;
201
Guido van Rossumbba92ca1998-04-10 19:39:15 +0000202 case 't':
203 Py_TabcheckFlag++;
204 break;
205
Guido van Rossum667d7041995-08-04 04:20:48 +0000206 case 'u':
207 unbuffered++;
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +0000208 saw_unbuffered_flag = 1;
Guido van Rossum667d7041995-08-04 04:20:48 +0000209 break;
210
211 case 'v':
212 Py_VerboseFlag++;
213 break;
214
Guido van Rossum3ed4c152001-03-02 06:18:03 +0000215#ifdef RISCOS
216 case 'w':
217 Py_RISCOSWimpFlag = 1;
218 break;
219#endif
220
Guido van Rossuma075ce11997-12-05 21:56:45 +0000221 case 'x':
222 skipfirstline = 1;
223 break;
224
Guido van Rossumc15a9a12000-05-01 17:54:33 +0000225 case 'U':
226 Py_UnicodeFlag++;
227 break;
Barry Warsaw3b2aedb2000-09-15 18:40:42 +0000228 case 'h':
229 help++;
230 break;
231 case 'V':
232 version++;
233 break;
Guido van Rossumc15a9a12000-05-01 17:54:33 +0000234
Guido van Rossum47f5fdc2000-12-15 22:00:54 +0000235 case 'W':
236 PySys_AddWarnOption(_PyOS_optarg);
237 break;
238
Guido van Rossum667d7041995-08-04 04:20:48 +0000239 /* This space reserved for other options */
240
241 default:
Barry Warsaw3b2aedb2000-09-15 18:40:42 +0000242 usage(2, argv[0]);
Guido van Rossum667d7041995-08-04 04:20:48 +0000243 /*NOTREACHED*/
244
245 }
246 }
247
Barry Warsaw3b2aedb2000-09-15 18:40:42 +0000248 if (help)
249 usage(0, argv[0]);
250
251 if (version) {
252 fprintf(stderr, "Python %s\n", PY_VERSION);
253 exit(0);
254 }
255
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +0000256 if (!saw_inspect_flag &&
257 (p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')
258 inspect = 1;
259 if (!saw_unbuffered_flag &&
260 (p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0')
261 unbuffered = 1;
262
Thomas Wouters2cffc7d2000-11-03 08:18:37 +0000263 if (command == NULL && _PyOS_optind < argc &&
264 strcmp(argv[_PyOS_optind], "-") != 0)
Guido van Rossum775af911997-02-14 19:50:32 +0000265 {
Thomas Wouters2cffc7d2000-11-03 08:18:37 +0000266 filename = argv[_PyOS_optind];
Guido van Rossum775af911997-02-14 19:50:32 +0000267 if (filename != NULL) {
268 if ((fp = fopen(filename, "r")) == NULL) {
269 fprintf(stderr, "%s: can't open file '%s'\n",
270 argv[0], filename);
271 exit(2);
272 }
Guido van Rossuma075ce11997-12-05 21:56:45 +0000273 else if (skipfirstline) {
Guido van Rossumdc8b5691999-04-19 17:54:19 +0000274 int ch;
275 /* Push back first newline so line numbers
276 remain the same */
277 while ((ch = getc(fp)) != EOF) {
278 if (ch == '\n') {
279 (void)ungetc(ch, fp);
280 break;
281 }
282 }
Guido van Rossuma075ce11997-12-05 21:56:45 +0000283 }
Guido van Rossum775af911997-02-14 19:50:32 +0000284 }
285 }
286
287 stdin_is_interactive = Py_FdIsInteractive(stdin, (char *)0);
288
Guido van Rossum667d7041995-08-04 04:20:48 +0000289 if (unbuffered) {
Guido van Rossumf22d7e21997-01-11 19:28:55 +0000290#ifdef MS_WINDOWS
Guido van Rossum3e7ae7a1997-01-17 22:05:38 +0000291 _setmode(fileno(stdin), O_BINARY);
292 _setmode(fileno(stdout), O_BINARY);
Guido van Rossumf22d7e21997-01-11 19:28:55 +0000293#endif
Guido van Rossum667d7041995-08-04 04:20:48 +0000294#ifndef MPW
Guido van Rossum22ffac11998-03-06 15:30:39 +0000295#ifdef HAVE_SETVBUF
Guido van Rossum775af911997-02-14 19:50:32 +0000296 setvbuf(stdin, (char *)NULL, _IONBF, BUFSIZ);
297 setvbuf(stdout, (char *)NULL, _IONBF, BUFSIZ);
298 setvbuf(stderr, (char *)NULL, _IONBF, BUFSIZ);
Guido van Rossum22ffac11998-03-06 15:30:39 +0000299#else /* !HAVE_SETVBUF */
300 setbuf(stdin, (char *)NULL);
301 setbuf(stdout, (char *)NULL);
302 setbuf(stderr, (char *)NULL);
303#endif /* !HAVE_SETVBUF */
304#else /* MPW */
Guido van Rossum667d7041995-08-04 04:20:48 +0000305 /* On MPW (3.2) unbuffered seems to hang */
Guido van Rossum775af911997-02-14 19:50:32 +0000306 setvbuf(stdin, (char *)NULL, _IOLBF, BUFSIZ);
Guido van Rossum667d7041995-08-04 04:20:48 +0000307 setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ);
308 setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ);
Guido van Rossum22ffac11998-03-06 15:30:39 +0000309#endif /* MPW */
Guido van Rossum667d7041995-08-04 04:20:48 +0000310 }
Guido van Rossum2a212191997-04-11 21:57:53 +0000311 else if (Py_InteractiveFlag) {
Guido van Rossumb31c7dc1997-04-11 22:19:12 +0000312#ifdef MS_WINDOWS
313 /* Doesn't have to have line-buffered -- use unbuffered */
Guido van Rossum01b7ced1999-02-09 18:36:51 +0000314 /* Any set[v]buf(stdin, ...) screws up Tkinter :-( */
Guido van Rossumb31c7dc1997-04-11 22:19:12 +0000315 setvbuf(stdout, (char *)NULL, _IONBF, BUFSIZ);
Guido van Rossum22ffac11998-03-06 15:30:39 +0000316#else /* !MS_WINDOWS */
317#ifdef HAVE_SETVBUF
Guido van Rossumb31c7dc1997-04-11 22:19:12 +0000318 setvbuf(stdin, (char *)NULL, _IOLBF, BUFSIZ);
319 setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ);
Guido van Rossum22ffac11998-03-06 15:30:39 +0000320#endif /* HAVE_SETVBUF */
321#endif /* !MS_WINDOWS */
Guido van Rossum775af911997-02-14 19:50:32 +0000322 /* Leave stderr alone - it should be unbuffered anyway. */
323 }
Guido van Rossum667d7041995-08-04 04:20:48 +0000324
Guido van Rossumed52aac1997-07-19 19:20:32 +0000325 Py_SetProgramName(argv[0]);
326 Py_Initialize();
327
Guido van Rossum667d7041995-08-04 04:20:48 +0000328 if (Py_VerboseFlag ||
Guido van Rossum129e91a1997-02-14 21:00:50 +0000329 (command == NULL && filename == NULL && stdin_is_interactive))
Guido van Rossumfe4dfc71997-05-19 18:33:01 +0000330 fprintf(stderr, "Python %s on %s\n%s\n",
Guido van Rossuma22865e2000-09-05 04:41:18 +0000331 Py_GetVersion(), Py_GetPlatform(), COPYRIGHT);
Guido van Rossum393661d2001-08-31 17:40:15 +0000332
Guido van Rossum667d7041995-08-04 04:20:48 +0000333 if (command != NULL) {
Thomas Wouters2cffc7d2000-11-03 08:18:37 +0000334 /* Backup _PyOS_optind and force sys.argv[0] = '-c' */
335 _PyOS_optind--;
336 argv[_PyOS_optind] = "-c";
Guido van Rossum667d7041995-08-04 04:20:48 +0000337 }
338
Thomas Wouters2cffc7d2000-11-03 08:18:37 +0000339 PySys_SetArgv(argc-_PyOS_optind, argv+_PyOS_optind);
Guido van Rossum667d7041995-08-04 04:20:48 +0000340
Guido van Rossum3d26cc91997-09-16 16:11:28 +0000341 if ((inspect || (command == NULL && filename == NULL)) &&
342 isatty(fileno(stdin))) {
343 PyObject *v;
344 v = PyImport_ImportModule("readline");
345 if (v == NULL)
346 PyErr_Clear();
347 else
348 Py_DECREF(v);
349 }
350
Guido van Rossum667d7041995-08-04 04:20:48 +0000351 if (command) {
Guido van Rossum393661d2001-08-31 17:40:15 +0000352 sts = PyRun_SimpleStringFlags(command, &cf) != 0;
Guido van Rossum05f7c501997-08-02 03:00:42 +0000353 free(command);
Guido van Rossum667d7041995-08-04 04:20:48 +0000354 }
355 else {
Guido van Rossum775af911997-02-14 19:50:32 +0000356 if (filename == NULL && stdin_is_interactive) {
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +0000357 char *startup = Py_GETENV("PYTHONSTARTUP");
Guido van Rossum667d7041995-08-04 04:20:48 +0000358 if (startup != NULL && startup[0] != '\0') {
359 FILE *fp = fopen(startup, "r");
360 if (fp != NULL) {
361 (void) PyRun_SimpleFile(fp, startup);
362 PyErr_Clear();
363 fclose(fp);
364 }
365 }
366 }
Jeremy Hyltonbc320242001-03-22 02:47:58 +0000367 /* XXX */
368 sts = PyRun_AnyFileExFlags(
Guido van Rossum775af911997-02-14 19:50:32 +0000369 fp,
Guido van Rossum0df002c2000-08-27 19:21:52 +0000370 filename == NULL ? "<stdin>" : filename,
Jeremy Hyltonbc320242001-03-22 02:47:58 +0000371 filename != NULL, &cf) != 0;
Guido van Rossum667d7041995-08-04 04:20:48 +0000372 }
373
Guido van Rossum775af911997-02-14 19:50:32 +0000374 if (inspect && stdin_is_interactive &&
Guido van Rossum667d7041995-08-04 04:20:48 +0000375 (filename != NULL || command != NULL))
Jeremy Hyltonbc320242001-03-22 02:47:58 +0000376 /* XXX */
377 sts = PyRun_AnyFileFlags(stdin, "<stdin>", &cf) != 0;
Guido van Rossum667d7041995-08-04 04:20:48 +0000378
Guido van Rossum5d1770e1997-08-05 02:23:48 +0000379 Py_Finalize();
Guido van Rossum3ed4c152001-03-02 06:18:03 +0000380#ifdef RISCOS
381 if(Py_RISCOSWimpFlag)
382 fprintf(stderr, "\x0cq\x0c"); /* make frontend quit */
383#endif
Barry Warsaw3e13b1e2001-02-23 16:46:39 +0000384
385#ifdef __INSURE__
386 /* Insure++ is a memory analysis tool that aids in discovering
387 * memory leaks and other memory problems. On Python exit, the
388 * interned string dictionary is flagged as being in use at exit
389 * (which it is). Under normal circumstances, this is fine because
390 * the memory will be automatically reclaimed by the system. Under
391 * memory debugging, it's a huge source of useless noise, so we
392 * trade off slower shutdown for less distraction in the memory
393 * reports. -baw
394 */
395 _Py_ReleaseInternedStrings();
396#endif /* __INSURE__ */
397
Guido van Rossum05f7c501997-08-02 03:00:42 +0000398 return sts;
Guido van Rossum667d7041995-08-04 04:20:48 +0000399}
400
401
Guido van Rossum667d7041995-08-04 04:20:48 +0000402/* Make the *original* argc/argv available to other modules.
403 This is rare, but it is needed by the secureware extension. */
404
405void
Fredrik Lundh620f3772000-07-09 20:42:34 +0000406Py_GetArgcArgv(int *argc, char ***argv)
Guido van Rossum667d7041995-08-04 04:20:48 +0000407{
408 *argc = orig_argc;
409 *argv = orig_argv;
410}