Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9abaf4d

Browse files
committed
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
This patch changes to logic to: if env.var. set and non-empty: if env.var. is an integer: set flag to that integer if flag is zero: # [actually, <= 0 --GvR] set flag to 1 Under this patch, anyone currently using PYTHONVERBOSE=yes will get the same output as before. PYTHONVERBNOSE=2 will generate more verbosity than before. The only unusual case that the following three are still all equivalent: PYTHONVERBOSE=yespleas PYTHONVERBOSE=1 PYTHONVERBOSE=0
1 parent 1566a17 commit 9abaf4d

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

Misc/python.man

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,14 @@ Set this to a non-empty string to cause the \fItime\fP module to
339339
require dates specified as strings to include 4-digit years, otherwise
340340
2-digit years are converted based on rules described in the \fItime\fP
341341
module documnetation.
342+
.IP PYTHONOPTIMIZE
343+
If this is set to a non-empty string it is equivalent to specifying
344+
the \fB\-O\fP option. If set to an integer, it is equivalent to
345+
specifying \fB\-O\fP multiple times.
342346
.IP PYTHONDEBUG
343347
If this is set to a non-empty string it is equivalent to specifying
344-
the \fB\-d\fP option.
348+
the \fB\-d\fP option. If set to an integer, it is equivalent to
349+
specifying \fB\-d\fP multiple times.
345350
.IP PYTHONINSPECT
346351
If this is set to a non-empty string it is equivalent to specifying
347352
the \fB\-i\fP option.
@@ -350,7 +355,8 @@ If this is set to a non-empty string it is equivalent to specifying
350355
the \fB\-u\fP option.
351356
.IP PYTHONVERBOSE
352357
If this is set to a non-empty string it is equivalent to specifying
353-
the \fB\-v\fP option.
358+
the \fB\-v\fP option. If set to an integer, it is equivalent to
359+
specifying \fB\-v\fP multiple times.
354360
.SH AUTHOR
355361
.nf
356362
Guido van Rossum

Python/pythonrun.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ Py_IsInitialized(void)
8787
8888
*/
8989

90+
static int
91+
add_flag(int flag, const char *envs)
92+
{
93+
int env = atoi(envs);
94+
if (flag < env)
95+
flag = env;
96+
if (flag < 1)
97+
flag = 1;
98+
return flag;
99+
}
100+
90101
void
91102
Py_Initialize(void)
92103
{
@@ -101,11 +112,11 @@ Py_Initialize(void)
101112
initialized = 1;
102113

103114
if ((p = Py_GETENV("PYTHONDEBUG")) && *p != '\0')
104-
Py_DebugFlag = Py_DebugFlag ? Py_DebugFlag : 1;
115+
Py_DebugFlag = add_flag(Py_DebugFlag, p);
105116
if ((p = Py_GETENV("PYTHONVERBOSE")) && *p != '\0')
106-
Py_VerboseFlag = Py_VerboseFlag ? Py_VerboseFlag : 1;
117+
Py_VerboseFlag = add_flag(Py_VerboseFlag, p);
107118
if ((p = Py_GETENV("PYTHONOPTIMIZE")) && *p != '\0')
108-
Py_OptimizeFlag = Py_OptimizeFlag ? Py_OptimizeFlag : 1;
119+
Py_OptimizeFlag = add_flag(Py_OptimizeFlag, p);
109120

110121
interp = PyInterpreterState_New();
111122
if (interp == NULL)

0 commit comments

Comments
 (0)