bpo-31650: Remove _Py_CheckHashBasedPycsMode global config var (GH-8608) · python/cpython@80b762f (original) (raw)
6 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -241,7 +241,7 @@ typedef struct { | ||
241 | 241 | valid |
242 | 242 | |
243 | 243 | 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". | |
245 | 245 | |
246 | 246 | See PEP 552 "Deterministic pycs" for more details. */ |
247 | 247 | const char *_check_hash_pycs_mode; |
@@ -286,6 +286,7 @@ typedef struct { | ||
286 | 286 | .buffered_stdio = -1, \ |
287 | 287 | _PyCoreConfig_WINDOWS_INIT \ |
288 | 288 | ._install_importlib = 1, \ |
289 | + ._check_hash_pycs_mode = "default", \ | |
289 | 290 | ._frozen = -1} |
290 | 291 | /* Note: _PyCoreConfig_INIT sets other fields to 0/NULL */ |
291 | 292 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
1 | 1 | #include "Python.h" |
2 | -#include "internal/import.h" | |
3 | 2 | #include "internal/pystate.h" |
4 | 3 | #include "structmember.h" |
5 | 4 | #include "osdefs.h" |
@@ -1352,12 +1351,13 @@ unmarshal_code(PyObject *pathname, PyObject *data, time_t mtime) | ||
1352 | 1351 | |
1353 | 1352 | uint32_t flags = get_uint32(buf + 4); |
1354 | 1353 | if (flags != 0) { |
1354 | +_PyCoreConfig *config = &PyThreadState_GET()->interp->core_config; | |
1355 | 1355 | // Hash-based pyc. We currently refuse to handle checked hash-based |
1356 | 1356 | // pycs. We could validate hash-based pycs against the source, but it |
1357 | 1357 | // seems likely that most people putting hash-based pycs in a zipfile |
1358 | 1358 | // will use unchecked ones. |
1359 | -if (strcmp(_Py_CheckHashBasedPycsMode, "never") && | |
1360 | - (flags != 0x1 | | |
1359 | +if (strcmp(config->_check_hash_pycs_mode, "never") && | |
1360 | + (flags != 0x1 | | |
1361 | 1361 | Py_RETURN_NONE; |
1362 | 1362 | } else if ((mtime != 0 && !eq_mtime(get_uint32(buf + 8), mtime))) { |
1363 | 1363 | if (Py_VerboseFlag) { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -436,8 +436,6 @@ static int test_init_global_config(void) | ||
436 | 436 | /* FIXME: test Py_LegacyWindowsFSEncodingFlag */ |
437 | 437 | /* FIXME: test Py_LegacyWindowsStdioFlag */ |
438 | 438 | |
439 | -/* _Py_CheckHashBasedPycsMode is not public, and so not tested */ | |
440 | - | |
441 | 439 | Py_Initialize(); |
442 | 440 | dump_config(); |
443 | 441 | Py_Finalize(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
1 | 1 | #include "Python.h" |
2 | -#include "internal/import.h" | |
3 | 2 | #include "internal/pystate.h" |
4 | 3 | |
5 | 4 | |
@@ -52,7 +51,6 @@ int Py_IsolatedFlag = 0; /* for -I, isolate from user's env */ | ||
52 | 51 | int Py_LegacyWindowsFSEncodingFlag = 0; /* Uses mbcs instead of utf-8 */ |
53 | 52 | int Py_LegacyWindowsStdioFlag = 0; /* Uses FileIO instead of WindowsConsoleIO */ |
54 | 53 | #endif |
55 | -const char *_Py_CheckHashBasedPycsMode = "default"; | |
56 | 54 | |
57 | 55 | |
58 | 56 | void |
@@ -317,10 +315,6 @@ _PyCoreConfig_GetGlobalConfig(_PyCoreConfig *config) | ||
317 | 315 | COPY_NOT_FLAG(write_bytecode, Py_DontWriteBytecodeFlag); |
318 | 316 | COPY_NOT_FLAG(user_site_directory, Py_NoUserSiteDirectory); |
319 | 317 | |
320 | -if (config->_check_hash_pycs_mode == NULL) { | |
321 | -config->_check_hash_pycs_mode = _Py_CheckHashBasedPycsMode; | |
322 | - } | |
323 | - | |
324 | 318 | #undef COPY_FLAG |
325 | 319 | #undef COPY_NOT_FLAG |
326 | 320 | } |
@@ -359,10 +353,6 @@ _PyCoreConfig_SetGlobalConfig(const _PyCoreConfig *config) | ||
359 | 353 | COPY_NOT_FLAG(write_bytecode, Py_DontWriteBytecodeFlag); |
360 | 354 | COPY_NOT_FLAG(user_site_directory, Py_NoUserSiteDirectory); |
361 | 355 | |
362 | -if (config->_check_hash_pycs_mode != NULL) { | |
363 | -_Py_CheckHashBasedPycsMode = config->_check_hash_pycs_mode; | |
364 | - } | |
365 | - | |
366 | 356 | /* Random or non-zero hash seed */ |
367 | 357 | Py_HashRandomizationFlag = (config->use_hash_seed == 0 | |
368 | 358 | config->hash_seed != 0); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -5,7 +5,6 @@ | ||
5 | 5 | #include "Python-ast.h" |
6 | 6 | #undef Yield /* undefine macro conflicting with winbase.h */ |
7 | 7 | #include "internal/hash.h" |
8 | -#include "internal/import.h" | |
9 | 8 | #include "internal/pystate.h" |
10 | 9 | #include "errcode.h" |
11 | 10 | #include "marshal.h" |
@@ -2290,7 +2289,8 @@ PyInit__imp(void) | ||
2290 | 2289 | d = PyModule_GetDict(m); |
2291 | 2290 | if (d == NULL) |
2292 | 2291 | 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); | |
2294 | 2294 | if (pyc_mode == NULL) { |
2295 | 2295 | goto failure; |
2296 | 2296 | } |