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*".
This commit is contained in:
parent
11e4a941e9
commit
cb9fbd3588
|
@ -363,7 +363,7 @@ typedef struct {
|
||||||
Needed by freeze_importlib. */
|
Needed by freeze_importlib. */
|
||||||
int _install_importlib;
|
int _install_importlib;
|
||||||
|
|
||||||
/* Value of the --check-hash-based-pycs configure option. Valid values:
|
/* Value of the --check-hash-based-pycs command line option:
|
||||||
|
|
||||||
- "default" means the 'check_source' flag in hash-based pycs
|
- "default" means the 'check_source' flag in hash-based pycs
|
||||||
determines invalidation
|
determines invalidation
|
||||||
|
@ -372,11 +372,10 @@ typedef struct {
|
||||||
- "never" causes the interpreter to always assume hash-based pycs are
|
- "never" causes the interpreter to always assume hash-based pycs are
|
||||||
valid
|
valid
|
||||||
|
|
||||||
Set by the --check-hash-based-pycs command line option.
|
|
||||||
The default value is "default".
|
The default value is "default".
|
||||||
|
|
||||||
See PEP 552 "Deterministic pycs" for more details. */
|
See PEP 552 "Deterministic pycs" for more details. */
|
||||||
const char *_check_hash_pycs_mode;
|
wchar_t *check_hash_pycs_mode;
|
||||||
|
|
||||||
/* If greater than 0, suppress _PyPathConfig_Calculate() warnings.
|
/* If greater than 0, suppress _PyPathConfig_Calculate() warnings.
|
||||||
|
|
||||||
|
@ -418,7 +417,7 @@ typedef struct {
|
||||||
.user_site_directory = -1, \
|
.user_site_directory = -1, \
|
||||||
.buffered_stdio = -1, \
|
.buffered_stdio = -1, \
|
||||||
._install_importlib = 1, \
|
._install_importlib = 1, \
|
||||||
._check_hash_pycs_mode = "default", \
|
.check_hash_pycs_mode = NULL, \
|
||||||
._frozen = -1, \
|
._frozen = -1, \
|
||||||
._init_main = 1}
|
._init_main = 1}
|
||||||
/* Note: _PyCoreConfig_INIT sets other fields to 0/NULL */
|
/* Note: _PyCoreConfig_INIT sets other fields to 0/NULL */
|
||||||
|
|
|
@ -346,7 +346,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
|
||||||
'run_filename': None,
|
'run_filename': None,
|
||||||
|
|
||||||
'_install_importlib': 1,
|
'_install_importlib': 1,
|
||||||
'_check_hash_pycs_mode': 'default',
|
'check_hash_pycs_mode': 'default',
|
||||||
'_frozen': 0,
|
'_frozen': 0,
|
||||||
'_init_main': 1,
|
'_init_main': 1,
|
||||||
}
|
}
|
||||||
|
@ -577,7 +577,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
|
||||||
'user_site_directory': 0,
|
'user_site_directory': 0,
|
||||||
'faulthandler': 1,
|
'faulthandler': 1,
|
||||||
|
|
||||||
'_check_hash_pycs_mode': 'always',
|
'check_hash_pycs_mode': 'always',
|
||||||
'_frozen': 1,
|
'_frozen': 1,
|
||||||
}
|
}
|
||||||
self.check_config("init_from_config", config, preconfig)
|
self.check_config("init_from_config", config, preconfig)
|
||||||
|
|
|
@ -495,7 +495,7 @@ static int test_init_from_config(void)
|
||||||
Py_NoUserSiteDirectory = 0;
|
Py_NoUserSiteDirectory = 0;
|
||||||
config.user_site_directory = 0;
|
config.user_site_directory = 0;
|
||||||
|
|
||||||
config._check_hash_pycs_mode = "always";
|
config.check_hash_pycs_mode = L"always";
|
||||||
|
|
||||||
Py_FrozenFlag = 0;
|
Py_FrozenFlag = 0;
|
||||||
config._frozen = 1;
|
config._frozen = 1;
|
||||||
|
|
|
@ -516,6 +516,7 @@ _PyCoreConfig_Clear(_PyCoreConfig *config)
|
||||||
CLEAR(config->run_command);
|
CLEAR(config->run_command);
|
||||||
CLEAR(config->run_module);
|
CLEAR(config->run_module);
|
||||||
CLEAR(config->run_filename);
|
CLEAR(config->run_filename);
|
||||||
|
CLEAR(config->check_hash_pycs_mode);
|
||||||
#undef CLEAR
|
#undef CLEAR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -686,7 +687,7 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2)
|
||||||
COPY_WSTR_ATTR(run_command);
|
COPY_WSTR_ATTR(run_command);
|
||||||
COPY_WSTR_ATTR(run_module);
|
COPY_WSTR_ATTR(run_module);
|
||||||
COPY_WSTR_ATTR(run_filename);
|
COPY_WSTR_ATTR(run_filename);
|
||||||
COPY_ATTR(_check_hash_pycs_mode);
|
COPY_WSTR_ATTR(check_hash_pycs_mode);
|
||||||
COPY_ATTR(_frozen);
|
COPY_ATTR(_frozen);
|
||||||
COPY_ATTR(_init_main);
|
COPY_ATTR(_init_main);
|
||||||
|
|
||||||
|
@ -792,7 +793,7 @@ _PyCoreConfig_AsDict(const _PyCoreConfig *config)
|
||||||
SET_ITEM_WSTR(run_module);
|
SET_ITEM_WSTR(run_module);
|
||||||
SET_ITEM_WSTR(run_filename);
|
SET_ITEM_WSTR(run_filename);
|
||||||
SET_ITEM_INT(_install_importlib);
|
SET_ITEM_INT(_install_importlib);
|
||||||
SET_ITEM_STR(_check_hash_pycs_mode);
|
SET_ITEM_WSTR(check_hash_pycs_mode);
|
||||||
SET_ITEM_INT(_frozen);
|
SET_ITEM_INT(_frozen);
|
||||||
SET_ITEM_INT(_init_main);
|
SET_ITEM_INT(_init_main);
|
||||||
|
|
||||||
|
@ -1711,6 +1712,7 @@ static _PyInitError
|
||||||
config_parse_cmdline(_PyCoreConfig *config, _PyPreCmdline *precmdline,
|
config_parse_cmdline(_PyCoreConfig *config, _PyPreCmdline *precmdline,
|
||||||
_PyWstrList *warnoptions)
|
_PyWstrList *warnoptions)
|
||||||
{
|
{
|
||||||
|
_PyInitError err;
|
||||||
const _PyWstrList *argv = &precmdline->argv;
|
const _PyWstrList *argv = &precmdline->argv;
|
||||||
int print_version = 0;
|
int print_version = 0;
|
||||||
|
|
||||||
|
@ -1757,12 +1759,15 @@ config_parse_cmdline(_PyCoreConfig *config, _PyPreCmdline *precmdline,
|
||||||
case 0:
|
case 0:
|
||||||
// Handle long option.
|
// Handle long option.
|
||||||
assert(longindex == 0); // Only one long option now.
|
assert(longindex == 0); // Only one long option now.
|
||||||
if (!wcscmp(_PyOS_optarg, L"always")) {
|
if (wcscmp(_PyOS_optarg, L"always") == 0
|
||||||
config->_check_hash_pycs_mode = "always";
|
|| wcscmp(_PyOS_optarg, L"never") == 0
|
||||||
} else if (!wcscmp(_PyOS_optarg, L"never")) {
|
|| wcscmp(_PyOS_optarg, L"default") == 0)
|
||||||
config->_check_hash_pycs_mode = "never";
|
{
|
||||||
} else if (!wcscmp(_PyOS_optarg, L"default")) {
|
err = _PyCoreConfig_SetWideString(&config->check_hash_pycs_mode,
|
||||||
config->_check_hash_pycs_mode = "default";
|
_PyOS_optarg);
|
||||||
|
if (_Py_INIT_FAILED(err)) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "--check-hash-based-pycs must be one of "
|
fprintf(stderr, "--check-hash-based-pycs must be one of "
|
||||||
"'default', 'always', or 'never'\n");
|
"'default', 'always', or 'never'\n");
|
||||||
|
@ -2131,6 +2136,13 @@ config_read_cmdline(_PyCoreConfig *config, _PyPreCmdline *precmdline)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config->check_hash_pycs_mode == NULL) {
|
||||||
|
err = _PyCoreConfig_SetWideString(&config->check_hash_pycs_mode, L"default");
|
||||||
|
if (_Py_INIT_FAILED(err)) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = _Py_INIT_OK();
|
err = _Py_INIT_OK();
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
@ -2254,7 +2266,7 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
assert(config->legacy_windows_stdio >= 0);
|
assert(config->legacy_windows_stdio >= 0);
|
||||||
#endif
|
#endif
|
||||||
assert(config->_check_hash_pycs_mode != NULL);
|
assert(config->check_hash_pycs_mode != NULL);
|
||||||
assert(config->_install_importlib >= 0);
|
assert(config->_install_importlib >= 0);
|
||||||
assert(config->_frozen >= 0);
|
assert(config->_frozen >= 0);
|
||||||
|
|
||||||
|
|
|
@ -2305,7 +2305,7 @@ PyInit__imp(void)
|
||||||
if (d == NULL)
|
if (d == NULL)
|
||||||
goto failure;
|
goto failure;
|
||||||
_PyCoreConfig *config = &_PyInterpreterState_Get()->core_config;
|
_PyCoreConfig *config = &_PyInterpreterState_Get()->core_config;
|
||||||
PyObject *pyc_mode = PyUnicode_FromString(config->_check_hash_pycs_mode);
|
PyObject *pyc_mode = PyUnicode_FromWideChar(config->check_hash_pycs_mode, -1);
|
||||||
if (pyc_mode == NULL) {
|
if (pyc_mode == NULL) {
|
||||||
goto failure;
|
goto failure;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue