mirror of
https://github.com/python/cpython.git
synced 2025-09-14 12:46:49 +00:00
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>
This commit is contained in:
parent
2b163aa9e7
commit
af0a00f022
7 changed files with 307 additions and 295 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue