Skip to content

Commit cb9fbd3

Browse files
authored
bpo-36763: Make _PyCoreConfig.check_hash_pycs_mode public (GH-13052)
_PyCoreConfig: Rename _check_hash_pycs_mode field to check_hash_pycs_mode (make it public) and change its type from "const char*" to "wchar_t*".
1 parent 11e4a94 commit cb9fbd3

File tree

5 files changed

+28
-17
lines changed

5 files changed

+28
-17
lines changed

Include/cpython/coreconfig.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ typedef struct {
363363
Needed by freeze_importlib. */
364364
int _install_importlib;
365365

366-
/* Value of the --check-hash-based-pycs configure option. Valid values:
366+
/* Value of the --check-hash-based-pycs command line option:
367367
368368
- "default" means the 'check_source' flag in hash-based pycs
369369
determines invalidation
@@ -372,11 +372,10 @@ typedef struct {
372372
- "never" causes the interpreter to always assume hash-based pycs are
373373
valid
374374
375-
Set by the --check-hash-based-pycs command line option.
376375
The default value is "default".
377376
378377
See PEP 552 "Deterministic pycs" for more details. */
379-
const char *_check_hash_pycs_mode;
378+
wchar_t *check_hash_pycs_mode;
380379

381380
/* If greater than 0, suppress _PyPathConfig_Calculate() warnings.
382381
@@ -418,7 +417,7 @@ typedef struct {
418417
.user_site_directory = -1, \
419418
.buffered_stdio = -1, \
420419
._install_importlib = 1, \
421-
._check_hash_pycs_mode = "default", \
420+
.check_hash_pycs_mode = NULL, \
422421
._frozen = -1, \
423422
._init_main = 1}
424423
/* Note: _PyCoreConfig_INIT sets other fields to 0/NULL */

Lib/test/test_embed.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
346346
'run_filename': None,
347347

348348
'_install_importlib': 1,
349-
'_check_hash_pycs_mode': 'default',
349+
'check_hash_pycs_mode': 'default',
350350
'_frozen': 0,
351351
'_init_main': 1,
352352
}
@@ -577,7 +577,7 @@ def test_init_from_config(self):
577577
'user_site_directory': 0,
578578
'faulthandler': 1,
579579

580-
'_check_hash_pycs_mode': 'always',
580+
'check_hash_pycs_mode': 'always',
581581
'_frozen': 1,
582582
}
583583
self.check_config("init_from_config", config, preconfig)

Programs/_testembed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ static int test_init_from_config(void)
495495
Py_NoUserSiteDirectory = 0;
496496
config.user_site_directory = 0;
497497

498-
config._check_hash_pycs_mode = "always";
498+
config.check_hash_pycs_mode = L"always";
499499

500500
Py_FrozenFlag = 0;
501501
config._frozen = 1;

Python/coreconfig.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ _PyCoreConfig_Clear(_PyCoreConfig *config)
516516
CLEAR(config->run_command);
517517
CLEAR(config->run_module);
518518
CLEAR(config->run_filename);
519+
CLEAR(config->check_hash_pycs_mode);
519520
#undef CLEAR
520521
}
521522

@@ -686,7 +687,7 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2)
686687
COPY_WSTR_ATTR(run_command);
687688
COPY_WSTR_ATTR(run_module);
688689
COPY_WSTR_ATTR(run_filename);
689-
COPY_ATTR(_check_hash_pycs_mode);
690+
COPY_WSTR_ATTR(check_hash_pycs_mode);
690691
COPY_ATTR(_frozen);
691692
COPY_ATTR(_init_main);
692693

@@ -792,7 +793,7 @@ _PyCoreConfig_AsDict(const _PyCoreConfig *config)
792793
SET_ITEM_WSTR(run_module);
793794
SET_ITEM_WSTR(run_filename);
794795
SET_ITEM_INT(_install_importlib);
795-
SET_ITEM_STR(_check_hash_pycs_mode);
796+
SET_ITEM_WSTR(check_hash_pycs_mode);
796797
SET_ITEM_INT(_frozen);
797798
SET_ITEM_INT(_init_main);
798799

@@ -1711,6 +1712,7 @@ static _PyInitError
17111712
config_parse_cmdline(_PyCoreConfig *config, _PyPreCmdline *precmdline,
17121713
_PyWstrList *warnoptions)
17131714
{
1715+
_PyInitError err;
17141716
const _PyWstrList *argv = &precmdline->argv;
17151717
int print_version = 0;
17161718

@@ -1757,12 +1759,15 @@ config_parse_cmdline(_PyCoreConfig *config, _PyPreCmdline *precmdline,
17571759
case 0:
17581760
// Handle long option.
17591761
assert(longindex == 0); // Only one long option now.
1760-
if (!wcscmp(_PyOS_optarg, L"always")) {
1761-
config->_check_hash_pycs_mode = "always";
1762-
} else if (!wcscmp(_PyOS_optarg, L"never")) {
1763-
config->_check_hash_pycs_mode = "never";
1764-
} else if (!wcscmp(_PyOS_optarg, L"default")) {
1765-
config->_check_hash_pycs_mode = "default";
1762+
if (wcscmp(_PyOS_optarg, L"always") == 0
1763+
|| wcscmp(_PyOS_optarg, L"never") == 0
1764+
|| wcscmp(_PyOS_optarg, L"default") == 0)
1765+
{
1766+
err = _PyCoreConfig_SetWideString(&config->check_hash_pycs_mode,
1767+
_PyOS_optarg);
1768+
if (_Py_INIT_FAILED(err)) {
1769+
return err;
1770+
}
17661771
} else {
17671772
fprintf(stderr, "--check-hash-based-pycs must be one of "
17681773
"'default', 'always', or 'never'\n");
@@ -2131,6 +2136,13 @@ config_read_cmdline(_PyCoreConfig *config, _PyPreCmdline *precmdline)
21312136
goto done;
21322137
}
21332138

2139+
if (config->check_hash_pycs_mode == NULL) {
2140+
err = _PyCoreConfig_SetWideString(&config->check_hash_pycs_mode, L"default");
2141+
if (_Py_INIT_FAILED(err)) {
2142+
goto done;
2143+
}
2144+
}
2145+
21342146
err = _Py_INIT_OK();
21352147

21362148
done:
@@ -2254,7 +2266,7 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
22542266
#ifdef MS_WINDOWS
22552267
assert(config->legacy_windows_stdio >= 0);
22562268
#endif
2257-
assert(config->_check_hash_pycs_mode != NULL);
2269+
assert(config->check_hash_pycs_mode != NULL);
22582270
assert(config->_install_importlib >= 0);
22592271
assert(config->_frozen >= 0);
22602272

Python/import.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2305,7 +2305,7 @@ PyInit__imp(void)
23052305
if (d == NULL)
23062306
goto failure;
23072307
_PyCoreConfig *config = &_PyInterpreterState_Get()->core_config;
2308-
PyObject *pyc_mode = PyUnicode_FromString(config->_check_hash_pycs_mode);
2308+
PyObject *pyc_mode = PyUnicode_FromWideChar(config->check_hash_pycs_mode, -1);
23092309
if (pyc_mode == NULL) {
23102310
goto failure;
23112311
}

0 commit comments

Comments
 (0)