blob: 5f71ee2c0aaddba11abc424d7bbaefd16f3c047a [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 Rossum66a70131996-12-09 18:46:58 +00007#ifdef HAVE_UNISTD_H
8#include <unistd.h>
9#endif
Guido van Rossum667d7041995-08-04 04:20:48 +000010
Guido van Rossum3e7ae7a1997-01-17 22:05:38 +000011#ifdef MS_WINDOWS
12#include <fcntl.h>
13#endif
14
Guido van Rossuma075ce11997-12-05 21:56:45 +000015#if defined(PYOS_OS2) || defined(MS_WINDOWS)
16#define PYTHONHOMEHELP "<prefix>\\lib"
17#else
Marc-André Lemburgda4dbc32001-06-12 16:13:51 +000018#define PYTHONHOMEHELP "<prefix>/pythonX.X"
Guido van Rossuma075ce11997-12-05 21:56:45 +000019#endif
20
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 Rossumc15a9a12000-05-01 17:54:33 +000067-U : Unicode literals: treats '...' literals like u'...'\n\
Guido van Rossum7922bd71997-08-29 22:34:47 +000068-v : verbose (trace import statements) (also PYTHONVERBOSE=x)\n\
Barry Warsaw3b2aedb2000-09-15 18:40:42 +000069-V : print the Python version number and exit\n\
Guido van Rossum47f5fdc2000-12-15 22:00:54 +000070-W arg : warning control (arg is action:message:category:module:lineno)\n\
Guido van Rossum393661d2001-08-31 17:40:15 +000071-x : skip first line of source, allowing use of non-Unix forms of #!cmd\n\
Guido van Rossum667d7041995-08-04 04:20:48 +000072file : program read from script file\n\
73- : program read from stdin (default; interactive mode if a tty)\n\
Guido van Rossum7922bd71997-08-29 22:34:47 +000074";
Guido van Rossum393661d2001-08-31 17:40:15 +000075static char *usage_4 = "\
Guido van Rossumbba92ca1998-04-10 19:39:15 +000076arg ...: arguments passed to program in sys.argv[1:]\n\
Guido van Rossum667d7041995-08-04 04:20:48 +000077Other environment variables:\n\
78PYTHONSTARTUP: file executed on interactive startup (no default)\n\
Guido van Rossuma075ce11997-12-05 21:56:45 +000079PYTHONPATH : '%c'-separated list of directories prefixed to the\n\
Guido van Rossum667d7041995-08-04 04:20:48 +000080 default module search path. The result is sys.path.\n\
Guido van Rossuma075ce11997-12-05 21:56:45 +000081PYTHONHOME : alternate <prefix> directory (or <prefix>%c<exec_prefix>).\n\
82 The default module search path uses %s.\n\
Tim Peters793de092001-02-22 00:39:47 +000083PYTHONCASEOK : ignore case in 'import' statements (Windows).\n\
Guido van Rossum667d7041995-08-04 04:20:48 +000084";
85
86
Barry Warsaw3b2aedb2000-09-15 18:40:42 +000087static void
88usage(int exitcode, char* program)
89{
Guido van Rossum393661d2001-08-31 17:40:15 +000090 FILE *f = exitcode ? stderr : stdout;
91
92 fprintf(f, usage_line, program);
93 if (exitcode)
94 fprintf(f, "Try `python -h' for more information.\n");
95 else {
96 fprintf(f, usage_1);
97 fprintf(f, usage_2);
98 fprintf(f, usage_3);
99 fprintf(f, usage_4, DELIM, DELIM, PYTHONHOMEHELP);
100 }
Barry Warsaw3b2aedb2000-09-15 18:40:42 +0000101 exit(exitcode);
102 /*NOTREACHED*/
103}
104
105
Guido van Rossum667d7041995-08-04 04:20:48 +0000106/* Main program */
107
Guido van Rossum9c1201f1998-12-07 14:28:47 +0000108DL_EXPORT(int)
Fredrik Lundh620f3772000-07-09 20:42:34 +0000109Py_Main(int argc, char **argv)
Guido van Rossum667d7041995-08-04 04:20:48 +0000110{
111 int c;
112 int sts;
113 char *command = NULL;
114 char *filename = NULL;
115 FILE *fp = stdin;
116 char *p;
117 int inspect = 0;
118 int unbuffered = 0;
Guido van Rossuma075ce11997-12-05 21:56:45 +0000119 int skipfirstline = 0;
Guido van Rossum775af911997-02-14 19:50:32 +0000120 int stdin_is_interactive = 0;
Barry Warsaw3b2aedb2000-09-15 18:40:42 +0000121 int help = 0;
122 int version = 0;
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +0000123 int saw_inspect_flag = 0;
124 int saw_unbuffered_flag = 0;
Jeremy Hyltonbc320242001-03-22 02:47:58 +0000125 PyCompilerFlags cf;
Guido van Rossum667d7041995-08-04 04:20:48 +0000126
Guido van Rossum393661d2001-08-31 17:40:15 +0000127 cf.cf_flags = 0;
128
Guido van Rossumac56b031996-07-21 02:33:38 +0000129 orig_argc = argc; /* For Py_GetArgcArgv() */
Guido van Rossum667d7041995-08-04 04:20:48 +0000130 orig_argv = argv;
Guido van Rossum667d7041995-08-04 04:20:48 +0000131
Guido van Rossum3ed4c152001-03-02 06:18:03 +0000132#ifdef RISCOS
133 Py_RISCOSWimpFlag = 0;
134#endif
135
Guido van Rossum47f5fdc2000-12-15 22:00:54 +0000136 PySys_ResetWarnOptions();
137
Guido van Rossumbceccf52001-04-10 22:07:43 +0000138 while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) {
Guido van Rossum667d7041995-08-04 04:20:48 +0000139 if (c == 'c') {
140 /* -c is the last option; following arguments
141 that look like options are left for the
142 the command to interpret. */
Thomas Wouters2cffc7d2000-11-03 08:18:37 +0000143 command = malloc(strlen(_PyOS_optarg) + 2);
Guido van Rossum667d7041995-08-04 04:20:48 +0000144 if (command == NULL)
145 Py_FatalError(
146 "not enough memory to copy -c argument");
Thomas Wouters2cffc7d2000-11-03 08:18:37 +0000147 strcpy(command, _PyOS_optarg);
Guido van Rossum667d7041995-08-04 04:20:48 +0000148 strcat(command, "\n");
149 break;
150 }
Guido van Rossum393661d2001-08-31 17:40:15 +0000151
Guido van Rossum667d7041995-08-04 04:20:48 +0000152 switch (c) {
153
154 case 'd':
155 Py_DebugFlag++;
156 break;
157
Guido van Rossum61c345f2001-09-04 03:26:15 +0000158 case 'Q':
Guido van Rossum393661d2001-08-31 17:40:15 +0000159 if (strcmp(_PyOS_optarg, "old") == 0) {
160 Py_DivisionWarningFlag = 0;
161 break;
162 }
163 if (strcmp(_PyOS_optarg, "warn") == 0) {
Guido van Rossum1832de42001-09-04 03:51:09 +0000164 Py_DivisionWarningFlag = 1;
165 break;
166 }
167 if (strcmp(_PyOS_optarg, "warnall") == 0) {
168 Py_DivisionWarningFlag = 2;
Guido van Rossum393661d2001-08-31 17:40:15 +0000169 break;
170 }
171 if (strcmp(_PyOS_optarg, "new") == 0) {
Tim Peters3caca232001-12-06 06:23:26 +0000172 /* This only affects __main__ */
Guido van Rossum393661d2001-08-31 17:40:15 +0000173 cf.cf_flags |= CO_FUTURE_DIVISION;
Tim Peters3caca232001-12-06 06:23:26 +0000174 /* And this tells the eval loop to treat
175 BINARY_DIVIDE as BINARY_TRUE_DIVIDE */
176 _Py_QnewFlag = 1;
Guido van Rossum393661d2001-08-31 17:40:15 +0000177 break;
178 }
179 fprintf(stderr,
Guido van Rossum1832de42001-09-04 03:51:09 +0000180 "-Q option should be `-Qold', "
181 "`-Qwarn', `-Qwarnall', or `-Qnew' only\n");
Guido van Rossum393661d2001-08-31 17:40:15 +0000182 usage(2, argv[0]);
183 /* NOTREACHED */
184
Guido van Rossum667d7041995-08-04 04:20:48 +0000185 case 'i':
186 inspect++;
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +0000187 saw_inspect_flag = 1;
Guido van Rossum775af911997-02-14 19:50:32 +0000188 Py_InteractiveFlag++;
Guido van Rossum667d7041995-08-04 04:20:48 +0000189 break;
190
Guido van Rossum7614da61997-03-03 19:14:45 +0000191 case 'O':
192 Py_OptimizeFlag++;
193 break;
194
Guido van Rossum7922bd71997-08-29 22:34:47 +0000195 case 'S':
196 Py_NoSiteFlag++;
197 break;
198
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +0000199 case 'E':
200 Py_IgnoreEnvironmentFlag++;
201 break;
202
Guido van Rossumbba92ca1998-04-10 19:39:15 +0000203 case 't':
204 Py_TabcheckFlag++;
205 break;
206
Guido van Rossum667d7041995-08-04 04:20:48 +0000207 case 'u':
208 unbuffered++;
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +0000209 saw_unbuffered_flag = 1;
Guido van Rossum667d7041995-08-04 04:20:48 +0000210 break;
211
212 case 'v':
213 Py_VerboseFlag++;
214 break;
215
Guido van Rossum3ed4c152001-03-02 06:18:03 +0000216#ifdef RISCOS
217 case 'w':
218 Py_RISCOSWimpFlag = 1;
219 break;
220#endif
221
Guido van Rossuma075ce11997-12-05 21:56:45 +0000222 case 'x':
223 skipfirstline = 1;
224 break;
225
Guido van Rossumc15a9a12000-05-01 17:54:33 +0000226 case 'U':
227 Py_UnicodeFlag++;
228 break;
Barry Warsaw3b2aedb2000-09-15 18:40:42 +0000229 case 'h':
230 help++;
231 break;
232 case 'V':
233 version++;
234 break;
Guido van Rossumc15a9a12000-05-01 17:54:33 +0000235
Guido van Rossum47f5fdc2000-12-15 22:00:54 +0000236 case 'W':
237 PySys_AddWarnOption(_PyOS_optarg);
238 break;
239
Guido van Rossum667d7041995-08-04 04:20:48 +0000240 /* This space reserved for other options */
241
242 default:
Barry Warsaw3b2aedb2000-09-15 18:40:42 +0000243 usage(2, argv[0]);
Guido van Rossum667d7041995-08-04 04:20:48 +0000244 /*NOTREACHED*/
245
246 }
247 }
248
Barry Warsaw3b2aedb2000-09-15 18:40:42 +0000249 if (help)
250 usage(0, argv[0]);
251
252 if (version) {
253 fprintf(stderr, "Python %s\n", PY_VERSION);
254 exit(0);
255 }
256
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +0000257 if (!saw_inspect_flag &&
258 (p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')
259 inspect = 1;
260 if (!saw_unbuffered_flag &&
261 (p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0')
262 unbuffered = 1;
263
Thomas Wouters2cffc7d2000-11-03 08:18:37 +0000264 if (command == NULL && _PyOS_optind < argc &&
265 strcmp(argv[_PyOS_optind], "-") != 0)
Guido van Rossum775af911997-02-14 19:50:32 +0000266 {
Thomas Wouters2cffc7d2000-11-03 08:18:37 +0000267 filename = argv[_PyOS_optind];
Guido van Rossum775af911997-02-14 19:50:32 +0000268 if (filename != NULL) {
269 if ((fp = fopen(filename, "r")) == NULL) {
270 fprintf(stderr, "%s: can't open file '%s'\n",
271 argv[0], filename);
272 exit(2);
273 }
Guido van Rossuma075ce11997-12-05 21:56:45 +0000274 else if (skipfirstline) {
Guido van Rossumdc8b5691999-04-19 17:54:19 +0000275 int ch;
276 /* Push back first newline so line numbers
277 remain the same */
278 while ((ch = getc(fp)) != EOF) {
279 if (ch == '\n') {
280 (void)ungetc(ch, fp);
281 break;
282 }
283 }
Guido van Rossuma075ce11997-12-05 21:56:45 +0000284 }
Guido van Rossum775af911997-02-14 19:50:32 +0000285 }
286 }
287
288 stdin_is_interactive = Py_FdIsInteractive(stdin, (char *)0);
289
Guido van Rossum667d7041995-08-04 04:20:48 +0000290 if (unbuffered) {
Guido van Rossumf22d7e21997-01-11 19:28:55 +0000291#ifdef MS_WINDOWS
Guido van Rossum3e7ae7a1997-01-17 22:05:38 +0000292 _setmode(fileno(stdin), O_BINARY);
293 _setmode(fileno(stdout), O_BINARY);
Guido van Rossumf22d7e21997-01-11 19:28:55 +0000294#endif
Guido van Rossum667d7041995-08-04 04:20:48 +0000295#ifndef MPW
Guido van Rossum22ffac11998-03-06 15:30:39 +0000296#ifdef HAVE_SETVBUF
Guido van Rossum775af911997-02-14 19:50:32 +0000297 setvbuf(stdin, (char *)NULL, _IONBF, BUFSIZ);
298 setvbuf(stdout, (char *)NULL, _IONBF, BUFSIZ);
299 setvbuf(stderr, (char *)NULL, _IONBF, BUFSIZ);
Guido van Rossum22ffac11998-03-06 15:30:39 +0000300#else /* !HAVE_SETVBUF */
301 setbuf(stdin, (char *)NULL);
302 setbuf(stdout, (char *)NULL);
303 setbuf(stderr, (char *)NULL);
304#endif /* !HAVE_SETVBUF */
305#else /* MPW */
Guido van Rossum667d7041995-08-04 04:20:48 +0000306 /* On MPW (3.2) unbuffered seems to hang */
Guido van Rossum775af911997-02-14 19:50:32 +0000307 setvbuf(stdin, (char *)NULL, _IOLBF, BUFSIZ);
Guido van Rossum667d7041995-08-04 04:20:48 +0000308 setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ);
309 setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ);
Guido van Rossum22ffac11998-03-06 15:30:39 +0000310#endif /* MPW */
Guido van Rossum667d7041995-08-04 04:20:48 +0000311 }
Guido van Rossum2a212191997-04-11 21:57:53 +0000312 else if (Py_InteractiveFlag) {
Guido van Rossumb31c7dc1997-04-11 22:19:12 +0000313#ifdef MS_WINDOWS
314 /* Doesn't have to have line-buffered -- use unbuffered */
Guido van Rossum01b7ced1999-02-09 18:36:51 +0000315 /* Any set[v]buf(stdin, ...) screws up Tkinter :-( */
Guido van Rossumb31c7dc1997-04-11 22:19:12 +0000316 setvbuf(stdout, (char *)NULL, _IONBF, BUFSIZ);
Guido van Rossum22ffac11998-03-06 15:30:39 +0000317#else /* !MS_WINDOWS */
318#ifdef HAVE_SETVBUF
Guido van Rossumb31c7dc1997-04-11 22:19:12 +0000319 setvbuf(stdin, (char *)NULL, _IOLBF, BUFSIZ);
320 setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ);
Guido van Rossum22ffac11998-03-06 15:30:39 +0000321#endif /* HAVE_SETVBUF */
322#endif /* !MS_WINDOWS */
Guido van Rossum775af911997-02-14 19:50:32 +0000323 /* Leave stderr alone - it should be unbuffered anyway. */
324 }
Guido van Rossum667d7041995-08-04 04:20:48 +0000325
Guido van Rossumed52aac1997-07-19 19:20:32 +0000326 Py_SetProgramName(argv[0]);
327 Py_Initialize();
328
Guido van Rossum667d7041995-08-04 04:20:48 +0000329 if (Py_VerboseFlag ||
Guido van Rossum129e91a1997-02-14 21:00:50 +0000330 (command == NULL && filename == NULL && stdin_is_interactive))
Guido van Rossumfe4dfc71997-05-19 18:33:01 +0000331 fprintf(stderr, "Python %s on %s\n%s\n",
Guido van Rossuma22865e2000-09-05 04:41:18 +0000332 Py_GetVersion(), Py_GetPlatform(), COPYRIGHT);
Guido van Rossum393661d2001-08-31 17:40:15 +0000333
Guido van Rossum667d7041995-08-04 04:20:48 +0000334 if (command != NULL) {
Thomas Wouters2cffc7d2000-11-03 08:18:37 +0000335 /* Backup _PyOS_optind and force sys.argv[0] = '-c' */
336 _PyOS_optind--;
337 argv[_PyOS_optind] = "-c";
Guido van Rossum667d7041995-08-04 04:20:48 +0000338 }
339
Thomas Wouters2cffc7d2000-11-03 08:18:37 +0000340 PySys_SetArgv(argc-_PyOS_optind, argv+_PyOS_optind);
Guido van Rossum667d7041995-08-04 04:20:48 +0000341
Guido van Rossum3d26cc91997-09-16 16:11:28 +0000342 if ((inspect || (command == NULL && filename == NULL)) &&
343 isatty(fileno(stdin))) {
344 PyObject *v;
345 v = PyImport_ImportModule("readline");
346 if (v == NULL)
347 PyErr_Clear();
348 else
349 Py_DECREF(v);
350 }
351
Guido van Rossum667d7041995-08-04 04:20:48 +0000352 if (command) {
Guido van Rossum393661d2001-08-31 17:40:15 +0000353 sts = PyRun_SimpleStringFlags(command, &cf) != 0;
Guido van Rossum05f7c501997-08-02 03:00:42 +0000354 free(command);
Guido van Rossum667d7041995-08-04 04:20:48 +0000355 }
356 else {
Guido van Rossum775af911997-02-14 19:50:32 +0000357 if (filename == NULL && stdin_is_interactive) {
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +0000358 char *startup = Py_GETENV("PYTHONSTARTUP");
Guido van Rossum667d7041995-08-04 04:20:48 +0000359 if (startup != NULL && startup[0] != '\0') {
360 FILE *fp = fopen(startup, "r");
361 if (fp != NULL) {
362 (void) PyRun_SimpleFile(fp, startup);
363 PyErr_Clear();
364 fclose(fp);
365 }
366 }
367 }
Jeremy Hyltonbc320242001-03-22 02:47:58 +0000368 /* XXX */
369 sts = PyRun_AnyFileExFlags(
Guido van Rossum775af911997-02-14 19:50:32 +0000370 fp,
Guido van Rossum0df002c2000-08-27 19:21:52 +0000371 filename == NULL ? "<stdin>" : filename,
Jeremy Hyltonbc320242001-03-22 02:47:58 +0000372 filename != NULL, &cf) != 0;
Guido van Rossum667d7041995-08-04 04:20:48 +0000373 }
374
Guido van Rossum775af911997-02-14 19:50:32 +0000375 if (inspect && stdin_is_interactive &&
Guido van Rossum667d7041995-08-04 04:20:48 +0000376 (filename != NULL || command != NULL))
Jeremy Hyltonbc320242001-03-22 02:47:58 +0000377 /* XXX */
378 sts = PyRun_AnyFileFlags(stdin, "<stdin>", &cf) != 0;
Guido van Rossum667d7041995-08-04 04:20:48 +0000379
Guido van Rossum5d1770e1997-08-05 02:23:48 +0000380 Py_Finalize();
Guido van Rossum3ed4c152001-03-02 06:18:03 +0000381#ifdef RISCOS
382 if(Py_RISCOSWimpFlag)
383 fprintf(stderr, "\x0cq\x0c"); /* make frontend quit */
384#endif
Barry Warsaw3e13b1e2001-02-23 16:46:39 +0000385
386#ifdef __INSURE__
387 /* Insure++ is a memory analysis tool that aids in discovering
388 * memory leaks and other memory problems. On Python exit, the
389 * interned string dictionary is flagged as being in use at exit
390 * (which it is). Under normal circumstances, this is fine because
391 * the memory will be automatically reclaimed by the system. Under
392 * memory debugging, it's a huge source of useless noise, so we
393 * trade off slower shutdown for less distraction in the memory
394 * reports. -baw
395 */
396 _Py_ReleaseInternedStrings();
397#endif /* __INSURE__ */
398
Guido van Rossum05f7c501997-08-02 03:00:42 +0000399 return sts;
Guido van Rossum667d7041995-08-04 04:20:48 +0000400}
401
402
Guido van Rossum667d7041995-08-04 04:20:48 +0000403/* Make the *original* argc/argv available to other modules.
404 This is rare, but it is needed by the secureware extension. */
405
406void
Fredrik Lundh620f3772000-07-09 20:42:34 +0000407Py_GetArgcArgv(int *argc, char ***argv)
Guido van Rossum667d7041995-08-04 04:20:48 +0000408{
409 *argc = orig_argc;
410 *argv = orig_argv;
411}