diff options
Diffstat (limited to 'Modules/main.c')
| -rw-r--r-- | Modules/main.c | 47 | 
1 files changed, 30 insertions, 17 deletions
| diff --git a/Modules/main.c b/Modules/main.c index e4c955e011..b6dcdd0a30 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -42,11 +42,11 @@ static int  orig_argc;  #define PROGRAM_OPTS BASE_OPTS  /* Short usage message (with %s for argv0) */ -static char *usage_line = +static const char usage_line[] =  "usage: %ls [option] ... [-c cmd | -m mod | file | -] [arg] ...\n";  /* Long usage message, split into parts < 512 bytes */ -static char *usage_1 = "\ +static const char usage_1[] = "\  Options and arguments (and corresponding environment variables):\n\  -b     : issue warnings about str(bytes_instance), str(bytearray_instance)\n\           and comparing bytes/bytearray with str. (-bb: issue errors)\n\ @@ -56,7 +56,7 @@ Options and arguments (and corresponding environment variables):\n\  -E     : ignore PYTHON* environment variables (such as PYTHONPATH)\n\  -h     : print this help message and exit (also --help)\n\  "; -static char *usage_2 = "\ +static const char usage_2[] = "\  -i     : inspect interactively after running script; forces a prompt even\n\           if stdin does not appear to be a terminal; also PYTHONINSPECT=x\n\  -I     : isolate Python from the user's environment (implies -E and -s)\n\ @@ -67,7 +67,7 @@ static char *usage_2 = "\  -s     : don't add user site directory to sys.path; also PYTHONNOUSERSITE\n\  -S     : don't imply 'import site' on initialization\n\  "; -static char *usage_3 = "\ +static const char usage_3[] = "\  -u     : unbuffered binary stdout and stderr, stdin always buffered;\n\           also PYTHONUNBUFFERED=x\n\           see man page for details on internal buffering relating to '-u'\n\ @@ -79,7 +79,7 @@ static char *usage_3 = "\  -x     : skip first line of source, allowing use of non-Unix forms of #!cmd\n\  -X opt : set implementation-specific option\n\  "; -static char *usage_4 = "\ +static const char usage_4[] = "\  file   : program read from script file\n\  -      : program read from stdin (default; interactive mode if a tty)\n\  arg ...: arguments passed to program in sys.argv[1:]\n\n\ @@ -88,22 +88,23 @@ PYTHONSTARTUP: file executed on interactive startup (no default)\n\  PYTHONPATH   : '%lc'-separated list of directories prefixed to the\n\                 default module search path.  The result is sys.path.\n\  "; -static char *usage_5 = +static const char usage_5[] =  "PYTHONHOME   : alternate <prefix> directory (or <prefix>%lc<exec_prefix>).\n"  "               The default module search path uses %s.\n"  "PYTHONCASEOK : ignore case in 'import' statements (Windows).\n"  "PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.\n" -"PYTHONFAULTHANDLER: dump the Python traceback on fatal errors.\n\ -"; -static char *usage_6 = "\ -PYTHONHASHSEED: if this variable is set to 'random', a random value is used\n\ -   to seed the hashes of str, bytes and datetime objects.  It can also be\n\ -   set to an integer in the range [0,4294967295] to get hash values with a\n\ -   predictable seed.\n\ -"; +"PYTHONFAULTHANDLER: dump the Python traceback on fatal errors.\n"; +static const char usage_6[] = +"PYTHONHASHSEED: if this variable is set to 'random', a random value is used\n" +"   to seed the hashes of str, bytes and datetime objects.  It can also be\n" +"   set to an integer in the range [0,4294967295] to get hash values with a\n" +"   predictable seed.\n" +"PYTHONMALLOC: set the Python memory allocators and/or install debug hooks\n" +"   on Python memory allocators. Use PYTHONMALLOC=debug to install debug\n" +"   hooks.\n";  static int -usage(int exitcode, wchar_t* program) +usage(int exitcode, const wchar_t* program)  {      FILE *f = exitcode ? stderr : stdout; @@ -341,6 +342,7 @@ Py_Main(int argc, wchar_t **argv)      int help = 0;      int version = 0;      int saw_unbuffered_flag = 0; +    char *opt;      PyCompilerFlags cf;      PyObject *warning_option = NULL;      PyObject *warning_options = NULL; @@ -365,6 +367,13 @@ Py_Main(int argc, wchar_t **argv)          }      } +    opt = Py_GETENV("PYTHONMALLOC"); +    if (_PyMem_SetupAllocators(opt) < 0) { +        fprintf(stderr, +                "Error in PYTHONMALLOC: unknown allocator \"%s\"!\n", opt); +        exit(1); +    } +      Py_HashRandomizationFlag = 1;      _PyRandom_Init(); @@ -654,7 +663,7 @@ Py_Main(int argc, wchar_t **argv)              Py_SetProgramName(wbuf);              /* Don't free wbuf, the argument to Py_SetProgramName -             * must remain valid until the Py_Finalize is called. +             * must remain valid until Py_FinalizeEx is called.               */          } else {              Py_SetProgramName(argv[0]); @@ -785,7 +794,11 @@ Py_Main(int argc, wchar_t **argv)          sts = PyRun_AnyFileFlags(stdin, "<stdin>", &cf) != 0;      } -    Py_Finalize(); +    if (Py_FinalizeEx() < 0) { +        /* Value unlikely to be confused with a non-error exit status or +        other special meaning */ +        sts = 120; +    }  #ifdef __INSURE__      /* Insure++ is a memory analysis tool that aids in discovering | 
