Mercurial > cpython-lru_cache-weakref
diff Modules/main.c @ 75143:88aede44ded1
Fix test failure in test_cmd_line by initializing the hash secret at the earliest point.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Tue, 21 Feb 2012 19:08:26 +0100 |
| parents | ed76dc34b39d 0e8bd4785ea0 |
| children | 198e31774f0f |
line wrap: on
line diff
--- a/Modules/main.c Tue Feb 21 18:49:10 2012 +0100 +++ b/Modules/main.c Tue Feb 21 19:08:26 2012 +0100 @@ -339,7 +339,33 @@ orig_argc = argc; /* For Py_GetArgcArgv() */ orig_argv = argv; + /* Hash randomization needed early for all string operations + (including -W and -X options). */ + while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) { + if (c == 'm' || c == 'c') { + /* -c / -m is the last option: following arguments are + not interpreter options. */ + break; + } + switch (c) { + case 'E': + Py_IgnoreEnvironmentFlag++; + break; + case 'R': + Py_HashRandomizationFlag++; + break; + } + } + /* The variable is only tested for existence here; _PyRandom_Init will + check its value further. */ + if (!Py_HashRandomizationFlag && + (p = Py_GETENV("PYTHONHASHSEED")) && *p != '\0') + Py_HashRandomizationFlag = 1; + + _PyRandom_Init(); + PySys_ResetWarnOptions(); + _PyOS_ResetGetOpt(); while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) { if (c == 'c') { @@ -400,7 +426,7 @@ break; case 'E': - Py_IgnoreEnvironmentFlag++; + /* Already handled above */ break; case 't': @@ -442,7 +468,7 @@ break; case 'R': - Py_HashRandomizationFlag++; + /* Already handled above */ break; /* This space reserved for other options */
