Skip to content

Commit 9851227

Browse files
authored
bpo-34170: Rename _PyCoreConfig.unbuffered_stdip (GH-8594)
* Rename _PyCoreConfig.unbuffered_stdio to buffered_stdio * Rename _PyCoreConfig.debug to parser_debug
1 parent a4d20b2 commit 9851227

File tree

4 files changed

+33
-28
lines changed

4 files changed

+33
-28
lines changed

‎Include/pystate.h‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ typedef struct {
148148
Incremented by the -d command line option. Set by the PYTHONDEBUG
149149
environment variable. If set to -1 (default), inherit Py_DebugFlag
150150
value. */
151-
int debug;
151+
int parser_debug;
152152

153153
/* If equal to 0, Python won't try to write ``.pyc`` files on the
154154
import of source modules.
@@ -185,13 +185,13 @@ typedef struct {
185185
!Py_NoUserSiteDirectory. */
186186
int user_site_directory;
187187

188-
/* If greater than 0, enable unbuffered mode: force the stdout and stderr
188+
/* If equal to 0, enable unbuffered mode: force the stdout and stderr
189189
streams to be unbuffered.
190190
191-
Set to 1 by the -u option. Set by the PYTHONUNBUFFERED environment
192-
variable. If set to -1 (default), inherit Py_UnbufferedStdioFlag
193-
value. */
194-
int unbuffered_stdio;
191+
Set to 0 by the -u option. Set by the PYTHONUNBUFFERED environment
192+
variable.
193+
If set to -1 (default), it is set to !Py_UnbufferedStdioFlag. */
194+
int buffered_stdio;
195195

196196
#ifdef MS_WINDOWS
197197
/* If greater than 1, use the "mbcs" encoding instead of the UTF-8
@@ -268,12 +268,12 @@ typedef struct {
268268
.inspect = -1, \
269269
.interactive = -1, \
270270
.optimization_level = -1, \
271-
.debug= -1, \
271+
.parser_debug= -1, \
272272
.write_bytecode = -1, \
273273
.verbose = -1, \
274274
.quiet = -1, \
275275
.user_site_directory = -1, \
276-
.unbuffered_stdio = -1, \
276+
.buffered_stdio = -1, \
277277
_PyCoreConfig_WINDOWS_INIT \
278278
._install_importlib = 1, \
279279
._frozen = -1}

‎Lib/test/test_embed.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,12 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
280280
'inspect': 0,
281281
'interactive': 0,
282282
'optimization_level': 0,
283-
'debug': 0,
283+
'parser_debug': 0,
284284
'write_bytecode': 1,
285285
'verbose': 0,
286286
'quiet': 0,
287287
'user_site_directory': 1,
288-
'unbuffered_stdio': 0,
288+
'buffered_stdio': 1,
289289

290290
'_install_importlib': 1,
291291
'_check_hash_pycs_mode': 'default',
@@ -328,7 +328,7 @@ def test_init_global_config(self):
328328
'write_bytecode': 0,
329329
'verbose': 1,
330330
'quiet': 1,
331-
'unbuffered_stdio': 1,
331+
'buffered_stdio': 0,
332332
'utf8_mode': 1,
333333
'user_site_directory': 0,
334334
'_frozen': 1,
@@ -361,7 +361,7 @@ def test_init_from_config(self):
361361
'write_bytecode': 0,
362362
'verbose': 1,
363363
'quiet': 1,
364-
'unbuffered_stdio': 1,
364+
'buffered_stdio': 0,
365365
'user_site_directory': 0,
366366
'faulthandler': 1,
367367

@@ -384,7 +384,7 @@ def test_init_env(self):
384384
'pycache_prefix': 'env_pycache_prefix',
385385
'write_bytecode': 0,
386386
'verbose': 1,
387-
'unbuffered_stdio': 1,
387+
'buffered_stdio': 0,
388388
'user_site_directory': 0,
389389
'faulthandler': 1,
390390
'dev_mode': 1,

‎Modules/main.c‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -565,17 +565,17 @@ _PyCoreConfig_GetGlobalConfig(_PyCoreConfig *config)
565565
COPY_FLAG(inspect, Py_InspectFlag);
566566
COPY_FLAG(interactive, Py_InteractiveFlag);
567567
COPY_FLAG(optimization_level, Py_OptimizeFlag);
568-
COPY_FLAG(debug, Py_DebugFlag);
568+
COPY_FLAG(parser_debug, Py_DebugFlag);
569569
COPY_FLAG(verbose, Py_VerboseFlag);
570570
COPY_FLAG(quiet, Py_QuietFlag);
571-
COPY_FLAG(unbuffered_stdio, Py_UnbufferedStdioFlag);
572571
#ifdef MS_WINDOWS
573572
COPY_FLAG(legacy_windows_fs_encoding, Py_LegacyWindowsFSEncodingFlag);
574573
COPY_FLAG(legacy_windows_stdio, Py_LegacyWindowsStdioFlag);
575574
#endif
576575
COPY_FLAG(_frozen, Py_FrozenFlag);
577576

578577
COPY_NOT_FLAG(use_environment, Py_IgnoreEnvironmentFlag);
578+
COPY_NOT_FLAG(buffered_stdio, Py_UnbufferedStdioFlag);
579579
COPY_NOT_FLAG(site_import, Py_NoSiteFlag);
580580
COPY_NOT_FLAG(write_bytecode, Py_DontWriteBytecodeFlag);
581581
COPY_NOT_FLAG(user_site_directory, Py_NoUserSiteDirectory);
@@ -608,16 +608,16 @@ _PyCoreConfig_SetGlobalConfig(const _PyCoreConfig *config)
608608
COPY_FLAG(inspect, Py_InspectFlag);
609609
COPY_FLAG(interactive, Py_InteractiveFlag);
610610
COPY_FLAG(optimization_level, Py_OptimizeFlag);
611-
COPY_FLAG(debug, Py_DebugFlag);
611+
COPY_FLAG(parser_debug, Py_DebugFlag);
612612
COPY_FLAG(verbose, Py_VerboseFlag);
613613
COPY_FLAG(quiet, Py_QuietFlag);
614-
COPY_FLAG(unbuffered_stdio, Py_UnbufferedStdioFlag);
615614
#ifdef MS_WINDOWS
616615
COPY_FLAG(legacy_windows_fs_encoding, Py_LegacyWindowsFSEncodingFlag);
617616
COPY_FLAG(legacy_windows_stdio, Py_LegacyWindowsStdioFlag);
618617
#endif
619618

620619
COPY_NOT_FLAG(use_environment, Py_IgnoreEnvironmentFlag);
620+
COPY_NOT_FLAG(buffered_stdio, Py_UnbufferedStdioFlag);
621621
COPY_NOT_FLAG(site_import, Py_NoSiteFlag);
622622
COPY_NOT_FLAG(write_bytecode, Py_DontWriteBytecodeFlag);
623623
COPY_NOT_FLAG(user_site_directory, Py_NoUserSiteDirectory);
@@ -749,12 +749,12 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2)
749749
COPY_ATTR(inspect);
750750
COPY_ATTR(interactive);
751751
COPY_ATTR(optimization_level);
752-
COPY_ATTR(debug);
752+
COPY_ATTR(parser_debug);
753753
COPY_ATTR(write_bytecode);
754754
COPY_ATTR(verbose);
755755
COPY_ATTR(quiet);
756756
COPY_ATTR(user_site_directory);
757-
COPY_ATTR(unbuffered_stdio);
757+
COPY_ATTR(buffered_stdio);
758758
#ifdef MS_WINDOWS
759759
COPY_ATTR(legacy_windows_fs_encoding);
760760
COPY_ATTR(legacy_windows_stdio);
@@ -990,7 +990,7 @@ pymain_parse_cmdline_impl(_PyMain *pymain, _PyCoreConfig *config,
990990
break;
991991

992992
case 'd':
993-
config->debug++;
993+
config->parser_debug++;
994994
break;
995995

996996
case 'i':
@@ -1029,7 +1029,7 @@ pymain_parse_cmdline_impl(_PyMain *pymain, _PyCoreConfig *config,
10291029
break;
10301030

10311031
case 'u':
1032-
config->unbuffered_stdio = 1;
1032+
config->buffered_stdio = 0;
10331033
break;
10341034

10351035
case 'v':
@@ -1287,7 +1287,7 @@ pymain_init_stdio(_PyMain *pymain, _PyCoreConfig *config)
12871287
_setmode(fileno(stderr), O_BINARY);
12881288
#endif
12891289

1290-
if (config->unbuffered_stdio) {
1290+
if (!config->buffered_stdio) {
12911291
#ifdef HAVE_SETVBUF
12921292
setvbuf(stdin, (char *)NULL, _IONBF, BUFSIZ);
12931293
setvbuf(stdout, (char *)NULL, _IONBF, BUFSIZ);
@@ -1905,7 +1905,7 @@ config_read_env_vars(_PyCoreConfig *config)
19051905
assert(config->use_environment > 0);
19061906

19071907
/* Get environment variables */
1908-
get_env_flag(config, &config->debug, "PYTHONDEBUG");
1908+
get_env_flag(config, &config->parser_debug, "PYTHONDEBUG");
19091909
get_env_flag(config, &config->verbose, "PYTHONVERBOSE");
19101910
get_env_flag(config, &config->optimization_level, "PYTHONOPTIMIZE");
19111911
get_env_flag(config, &config->inspect, "PYTHONINSPECT");
@@ -1922,7 +1922,12 @@ config_read_env_vars(_PyCoreConfig *config)
19221922
config->user_site_directory = 0;
19231923
}
19241924

1925-
get_env_flag(config, &config->unbuffered_stdio, "PYTHONUNBUFFERED");
1925+
int unbuffered_stdio = 0;
1926+
get_env_flag(config, &unbuffered_stdio, "PYTHONUNBUFFERED");
1927+
if (unbuffered_stdio) {
1928+
config->buffered_stdio = 0;
1929+
}
1930+
19261931
#ifdef MS_WINDOWS
19271932
get_env_flag(config, &config->legacy_windows_fs_encoding,
19281933
"PYTHONLEGACYWINDOWSFSENCODING");

‎Programs/_testembed.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,13 @@ dump_config(void)
356356
printf("inspect = %i\n", config->inspect);
357357
printf("interactive = %i\n", config->interactive);
358358
printf("optimization_level = %i\n", config->optimization_level);
359-
printf("debug = %i\n", config->debug);
359+
printf("parser_debug = %i\n", config->parser_debug);
360360
printf("write_bytecode = %i\n", config->write_bytecode);
361361
printf("verbose = %i\n", config->verbose);
362362
ASSERT_EQUAL(config->verbose, Py_VerboseFlag);
363363
printf("quiet = %i\n", config->quiet);
364364
printf("user_site_directory = %i\n", config->user_site_directory);
365-
printf("unbuffered_stdio = %i\n", config->unbuffered_stdio);
365+
printf("buffered_stdio = %i\n", config->buffered_stdio);
366366
/* FIXME: test legacy_windows_fs_encoding */
367367
/* FIXME: test legacy_windows_stdio */
368368

@@ -509,7 +509,7 @@ static int test_init_from_config(void)
509509
Py_OptimizeFlag = 1;
510510
config.optimization_level = 2;
511511

512-
/* FIXME: test debug */
512+
/* FIXME: test parser_debug */
513513

514514
putenv("PYTHONDONTWRITEBYTECODE=");
515515
Py_DontWriteBytecodeFlag = 0;
@@ -520,7 +520,7 @@ static int test_init_from_config(void)
520520

521521
putenv("PYTHONUNBUFFERED=");
522522
Py_UnbufferedStdioFlag = 0;
523-
config.unbuffered_stdio = 1;
523+
config.buffered_stdio = 0;
524524

525525
putenv("PYTHONNOUSERSITE=");
526526
Py_NoUserSiteDirectory = 0;

0 commit comments

Comments
 (0)