Skip to content

Commit 80b762f

Browse files
authored
bpo-31650: Remove _Py_CheckHashBasedPycsMode global config var (GH-8608)
bpo-31650, bpo-34170: Replace _Py_CheckHashBasedPycsMode with _PyCoreConfig._check_hash_pycs_mode. Modify PyInit__imp() and zipimport to get the parameter from the current interpreter core configuration. Remove Include/internal/import.h file.
1 parent 6c785c0 commit 80b762f

File tree

6 files changed

+7
-24
lines changed

6 files changed

+7
-24
lines changed

Include/coreconfig.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ typedef struct {
241241
valid
242242
243243
Set by the --check-hash-based-pycs command line option.
244-
If set to NULL (default), inherit _Py_CheckHashBasedPycsMode value.
244+
The default value is "default".
245245
246246
See PEP 552 "Deterministic pycs" for more details. */
247247
const char *_check_hash_pycs_mode;
@@ -286,6 +286,7 @@ typedef struct {
286286
.buffered_stdio = -1, \
287287
_PyCoreConfig_WINDOWS_INIT \
288288
._install_importlib = 1, \
289+
._check_hash_pycs_mode = "default", \
289290
._frozen = -1}
290291
/* Note: _PyCoreConfig_INIT sets other fields to 0/NULL */
291292

Include/internal/import.h

Lines changed: 0 additions & 6 deletions
This file was deleted.

Modules/zipimport.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "Python.h"
2-
#include "internal/import.h"
32
#include "internal/pystate.h"
43
#include "structmember.h"
54
#include "osdefs.h"
@@ -1352,12 +1351,13 @@ unmarshal_code(PyObject *pathname, PyObject *data, time_t mtime)
13521351

13531352
uint32_t flags = get_uint32(buf + 4);
13541353
if (flags != 0) {
1354+
_PyCoreConfig *config = &PyThreadState_GET()->interp->core_config;
13551355
// Hash-based pyc. We currently refuse to handle checked hash-based
13561356
// pycs. We could validate hash-based pycs against the source, but it
13571357
// seems likely that most people putting hash-based pycs in a zipfile
13581358
// will use unchecked ones.
1359-
if (strcmp(_Py_CheckHashBasedPycsMode, "never") &&
1360-
(flags != 0x1 || !strcmp(_Py_CheckHashBasedPycsMode, "always")))
1359+
if (strcmp(config->_check_hash_pycs_mode, "never") &&
1360+
(flags != 0x1 || !strcmp(config->_check_hash_pycs_mode, "always")))
13611361
Py_RETURN_NONE;
13621362
} else if ((mtime != 0 && !eq_mtime(get_uint32(buf + 8), mtime))) {
13631363
if (Py_VerboseFlag) {

Programs/_testembed.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,6 @@ static int test_init_global_config(void)
436436
/* FIXME: test Py_LegacyWindowsFSEncodingFlag */
437437
/* FIXME: test Py_LegacyWindowsStdioFlag */
438438

439-
/* _Py_CheckHashBasedPycsMode is not public, and so not tested */
440-
441439
Py_Initialize();
442440
dump_config();
443441
Py_Finalize();

Python/coreconfig.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "Python.h"
2-
#include "internal/import.h"
32
#include "internal/pystate.h"
43

54

@@ -52,7 +51,6 @@ int Py_IsolatedFlag = 0; /* for -I, isolate from user's env */
5251
int Py_LegacyWindowsFSEncodingFlag = 0; /* Uses mbcs instead of utf-8 */
5352
int Py_LegacyWindowsStdioFlag = 0; /* Uses FileIO instead of WindowsConsoleIO */
5453
#endif
55-
const char *_Py_CheckHashBasedPycsMode = "default";
5654

5755

5856
void
@@ -317,10 +315,6 @@ _PyCoreConfig_GetGlobalConfig(_PyCoreConfig *config)
317315
COPY_NOT_FLAG(write_bytecode, Py_DontWriteBytecodeFlag);
318316
COPY_NOT_FLAG(user_site_directory, Py_NoUserSiteDirectory);
319317

320-
if (config->_check_hash_pycs_mode == NULL) {
321-
config->_check_hash_pycs_mode = _Py_CheckHashBasedPycsMode;
322-
}
323-
324318
#undef COPY_FLAG
325319
#undef COPY_NOT_FLAG
326320
}
@@ -359,10 +353,6 @@ _PyCoreConfig_SetGlobalConfig(const _PyCoreConfig *config)
359353
COPY_NOT_FLAG(write_bytecode, Py_DontWriteBytecodeFlag);
360354
COPY_NOT_FLAG(user_site_directory, Py_NoUserSiteDirectory);
361355

362-
if (config->_check_hash_pycs_mode != NULL) {
363-
_Py_CheckHashBasedPycsMode = config->_check_hash_pycs_mode;
364-
}
365-
366356
/* Random or non-zero hash seed */
367357
Py_HashRandomizationFlag = (config->use_hash_seed == 0 ||
368358
config->hash_seed != 0);

Python/import.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "Python-ast.h"
66
#undef Yield /* undefine macro conflicting with winbase.h */
77
#include "internal/hash.h"
8-
#include "internal/import.h"
98
#include "internal/pystate.h"
109
#include "errcode.h"
1110
#include "marshal.h"
@@ -2290,7 +2289,8 @@ PyInit__imp(void)
22902289
d = PyModule_GetDict(m);
22912290
if (d == NULL)
22922291
goto failure;
2293-
PyObject *pyc_mode = PyUnicode_FromString(_Py_CheckHashBasedPycsMode);
2292+
_PyCoreConfig *config = &PyThreadState_GET()->interp->core_config;
2293+
PyObject *pyc_mode = PyUnicode_FromString(config->_check_hash_pycs_mode);
22942294
if (pyc_mode == NULL) {
22952295
goto failure;
22962296
}

0 commit comments

Comments
 (0)