]> granicus.if.org Git - python/commitdiff
bpo-31650: Remove _Py_CheckHashBasedPycsMode global config var (GH-8608)
authorVictor Stinner <vstinner@redhat.com>
Wed, 1 Aug 2018 16:18:07 +0000 (18:18 +0200)
committerGitHub <noreply@github.com>
Wed, 1 Aug 2018 16:18:07 +0000 (18:18 +0200)
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.

Include/coreconfig.h
Include/internal/import.h [deleted file]
Modules/zipimport.c
Programs/_testembed.c
Python/coreconfig.c
Python/import.c

index 4401729d76f77662d4c90bbc0b68885d2600e4d2..b2799075f930ffa3b8d143bd5793badc430f3075 100644 (file)
@@ -241,7 +241,7 @@ typedef struct {
          valid
 
        Set by the --check-hash-based-pycs command line option.
-       If set to NULL (default), inherit _Py_CheckHashBasedPycsMode value.
+       The default value is "default".
 
        See PEP 552 "Deterministic pycs" for more details. */
     const char *_check_hash_pycs_mode;
@@ -286,6 +286,7 @@ typedef struct {
         .buffered_stdio = -1, \
         _PyCoreConfig_WINDOWS_INIT \
         ._install_importlib = 1, \
+        ._check_hash_pycs_mode = "default", \
         ._frozen = -1}
 /* Note: _PyCoreConfig_INIT sets other fields to 0/NULL */
 
diff --git a/Include/internal/import.h b/Include/internal/import.h
deleted file mode 100644 (file)
index 4746e75..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef Py_INTERNAL_IMPORT_H
-#define Py_INTERNAL_IMPORT_H
-
-extern const char *_Py_CheckHashBasedPycsMode;
-
-#endif
index 85013665d1f4bc796deb41a45032607856f7e5c9..57e7a13137f45b5da9ad8fa651a5ea5b6a784f20 100644 (file)
@@ -1,5 +1,4 @@
 #include "Python.h"
-#include "internal/import.h"
 #include "internal/pystate.h"
 #include "structmember.h"
 #include "osdefs.h"
@@ -1352,12 +1351,13 @@ unmarshal_code(PyObject *pathname, PyObject *data, time_t mtime)
 
     uint32_t flags = get_uint32(buf + 4);
     if (flags != 0) {
+        _PyCoreConfig *config = &PyThreadState_GET()->interp->core_config;
         // Hash-based pyc. We currently refuse to handle checked hash-based
         // pycs. We could validate hash-based pycs against the source, but it
         // seems likely that most people putting hash-based pycs in a zipfile
         // will use unchecked ones.
-        if (strcmp(_Py_CheckHashBasedPycsMode, "never") &&
-            (flags != 0x1 || !strcmp(_Py_CheckHashBasedPycsMode, "always")))
+        if (strcmp(config->_check_hash_pycs_mode, "never") &&
+            (flags != 0x1 || !strcmp(config->_check_hash_pycs_mode, "always")))
             Py_RETURN_NONE;
     } else if ((mtime != 0 && !eq_mtime(get_uint32(buf + 8), mtime))) {
         if (Py_VerboseFlag) {
index 1c72580b9c67c79a4a7a67d3ad37dbf67d953102..3ed42d67f834a88c85a9d3379d010e99f50e31d4 100644 (file)
@@ -436,8 +436,6 @@ static int test_init_global_config(void)
     /* FIXME: test Py_LegacyWindowsFSEncodingFlag */
     /* FIXME: test Py_LegacyWindowsStdioFlag */
 
-    /* _Py_CheckHashBasedPycsMode is not public, and so not tested */
-
     Py_Initialize();
     dump_config();
     Py_Finalize();
index 7dabe5f9644747723e4e313e04bd72800d207b33..829592c3c9b2aba1dc5c03a4215a985e85f58f01 100644 (file)
@@ -1,5 +1,4 @@
 #include "Python.h"
-#include "internal/import.h"
 #include "internal/pystate.h"
 
 
@@ -52,7 +51,6 @@ int Py_IsolatedFlag = 0; /* for -I, isolate from user's env */
 int Py_LegacyWindowsFSEncodingFlag = 0; /* Uses mbcs instead of utf-8 */
 int Py_LegacyWindowsStdioFlag = 0; /* Uses FileIO instead of WindowsConsoleIO */
 #endif
-const char *_Py_CheckHashBasedPycsMode = "default";
 
 
 void
@@ -317,10 +315,6 @@ _PyCoreConfig_GetGlobalConfig(_PyCoreConfig *config)
     COPY_NOT_FLAG(write_bytecode, Py_DontWriteBytecodeFlag);
     COPY_NOT_FLAG(user_site_directory, Py_NoUserSiteDirectory);
 
-    if (config->_check_hash_pycs_mode == NULL) {
-        config->_check_hash_pycs_mode = _Py_CheckHashBasedPycsMode;
-    }
-
 #undef COPY_FLAG
 #undef COPY_NOT_FLAG
 }
@@ -359,10 +353,6 @@ _PyCoreConfig_SetGlobalConfig(const _PyCoreConfig *config)
     COPY_NOT_FLAG(write_bytecode, Py_DontWriteBytecodeFlag);
     COPY_NOT_FLAG(user_site_directory, Py_NoUserSiteDirectory);
 
-    if (config->_check_hash_pycs_mode != NULL) {
-        _Py_CheckHashBasedPycsMode = config->_check_hash_pycs_mode;
-    }
-
     /* Random or non-zero hash seed */
     Py_HashRandomizationFlag = (config->use_hash_seed == 0 ||
                                 config->hash_seed != 0);
index de132a347e054cd6786ed602a03d6e4072907df7..71d5ea192dbf381949afd64b1941746954e0e1e4 100644 (file)
@@ -5,7 +5,6 @@
 #include "Python-ast.h"
 #undef Yield /* undefine macro conflicting with winbase.h */
 #include "internal/hash.h"
-#include "internal/import.h"
 #include "internal/pystate.h"
 #include "errcode.h"
 #include "marshal.h"
@@ -2290,7 +2289,8 @@ PyInit__imp(void)
     d = PyModule_GetDict(m);
     if (d == NULL)
         goto failure;
-    PyObject *pyc_mode = PyUnicode_FromString(_Py_CheckHashBasedPycsMode);
+    _PyCoreConfig *config = &PyThreadState_GET()->interp->core_config;
+    PyObject *pyc_mode = PyUnicode_FromString(config->_check_hash_pycs_mode);
     if (pyc_mode == NULL) {
         goto failure;
     }