summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMichael Droettboom <mdboom@gmail.com>2024-07-30 19:31:05 (GMT)
committerGitHub <noreply@github.com>2024-07-30 19:31:05 (GMT)
commitaf0a00f022d0fb8f1edb4abdda1bc6b915f0448d (patch)
treeb31a38a60fccae419c4ed3b38a18795bb9bed0a0 /Python
parent2b163aa9e796b312bb0549d49145d26e4904768e (diff)
downloadcpython-af0a00f022d0fb8f1edb4abdda1bc6b915f0448d.zip
cpython-af0a00f022d0fb8f1edb4abdda1bc6b915f0448d.tar.gz
cpython-af0a00f022d0fb8f1edb4abdda1bc6b915f0448d.tar.bz2
gh-122188: Move magic number to its own file (#122243)
* gh-122188: Move magic number to its own file * Add versionadded directive * Do work in C * Integrate launcher.c * Make _pyc_magic_number private * Remove metadata * Move sys.implementation -> _imp * Modernize comment * Move _RAW_MAGIC_NUMBER to the C side as well * _pyc_magic_number -> pyc_magic_number * Remove unused import * Update docs * Apply suggestions from code review Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com> * Fix typo in tests --------- Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Diffstat (limited to 'Python')
-rw-r--r--Python/import.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/Python/import.c b/Python/import.c
index 40b7fea..540874a 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -6,6 +6,7 @@
#include "pycore_import.h" // _PyImport_BootstrapImp()
#include "pycore_initconfig.h" // _PyStatus_OK()
#include "pycore_interp.h" // struct _import_runtime_state
+#include "pycore_magic_number.h" // PYC_MAGIC_NUMBER
#include "pycore_namespace.h" // _PyNamespace_Type
#include "pycore_object.h" // _Py_SetImmortal()
#include "pycore_pyerrors.h" // _PyErr_SetString()
@@ -2475,23 +2476,9 @@ _PyImport_GetBuiltinModuleNames(void)
long
PyImport_GetMagicNumber(void)
{
- long res;
- PyInterpreterState *interp = _PyInterpreterState_GET();
- PyObject *external, *pyc_magic;
-
- external = PyObject_GetAttrString(IMPORTLIB(interp), "_bootstrap_external");
- if (external == NULL)
- return -1;
- pyc_magic = PyObject_GetAttrString(external, "_RAW_MAGIC_NUMBER");
- Py_DECREF(external);
- if (pyc_magic == NULL)
- return -1;
- res = PyLong_AsLong(pyc_magic);
- Py_DECREF(pyc_magic);
- return res;
+ return PYC_MAGIC_NUMBER_TOKEN;
}
-
extern const char * _PySys_ImplCacheTag;
const char *
@@ -4823,6 +4810,16 @@ imp_module_exec(PyObject *module)
return -1;
}
+ if (PyModule_AddIntConstant(module, "pyc_magic_number", PYC_MAGIC_NUMBER) < 0) {
+ return -1;
+ }
+
+ if (PyModule_AddIntConstant(
+ module, "pyc_magic_number_token", PYC_MAGIC_NUMBER_TOKEN) < 0)
+ {
+ return -1;
+ }
+
return 0;
}