File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -178,7 +178,8 @@ Importing Modules
178178.. c:function:: const char * PyImport_GetMagicTag()
179179
180180 Return the magic tag string for :pep:`3147` format Python bytecode file
181- names.
181+ names. Keep in mind that the value at ``sys.implementation.cache_tag`` is
182+ authoritative and should be used instead of this function.
182183
183184 .. versionadded:: 3.2
184185
Original file line number Diff line number Diff line change @@ -116,7 +116,7 @@ typedef unsigned short mode_t;
116116*/
117117#define MAGIC (3230 | ((long)'\r'<<16) | ((long)'\n'<<24))
118118#define CACHEDIR "__pycache__"
119- /* Current magic word and string tag as globals . */
119+ /* Current magic word as global . */
120120static long pyc_magic = MAGIC ;
121121
122122/* See _PyImport_FixupExtensionObject() below */
@@ -520,22 +520,12 @@ PyImport_GetMagicNumber(void)
520520}
521521
522522
523+ extern const char * _PySys_ImplCacheTag ;
524+
523525const char *
524526PyImport_GetMagicTag (void )
525527{
526- PyObject * impl , * tag ;
527- const char * raw_tag ;
528-
529- /* We could also pull it from imp or importlib. */
530- impl = PySys_GetObject ("implementation" );
531- if (impl == NULL )
532- return NULL ;
533- tag = PyObject_GetAttrString (impl , "cache_tag" );
534- if (tag == NULL )
535- return NULL ;
536- raw_tag = PyUnicode_DATA (tag );
537- Py_DECREF (tag );
538- return raw_tag ;
528+ return _PySys_ImplCacheTag ;
539529}
540530
541531
Original file line number Diff line number Diff line change @@ -1478,6 +1478,22 @@ make_version_info(void)
14781478 return version_info ;
14791479}
14801480
1481+ /* sys.implementation values */
1482+ #define NAME "cpython"
1483+ const char * _PySys_ImplName = NAME ;
1484+ #define QUOTE (arg ) #arg
1485+ #define STRIFY (name ) QUOTE(name)
1486+ #define MAJOR STRIFY(PY_MAJOR_VERSION)
1487+ #define MINOR STRIFY(PY_MINOR_VERSION)
1488+ #define TAG NAME "-" MAJOR MINOR;
1489+ const char * _PySys_ImplCacheTag = TAG ;
1490+ #undef NAME
1491+ #undef QUOTE
1492+ #undef STRIFY
1493+ #undef MAJOR
1494+ #undef MINOR
1495+ #undef TAG
1496+
14811497static PyObject *
14821498make_impl_info (PyObject * version_info )
14831499{
@@ -1490,33 +1506,21 @@ make_impl_info(PyObject *version_info)
14901506
14911507 /* populate the dict */
14921508
1493- #define NAME "cpython"
1494- #define QUOTE (arg ) #arg
1495- #define STRIFY (name ) QUOTE(name)
1496- #define MAJOR STRIFY(PY_MAJOR_VERSION)
1497- #define MINOR STRIFY(PY_MINOR_VERSION)
1498- #define TAG NAME "-" MAJOR MINOR
1499- value = PyUnicode_FromString (NAME );
1509+ value = PyUnicode_FromString (_PySys_ImplName );
15001510 if (value == NULL )
15011511 goto error ;
15021512 res = PyDict_SetItemString (impl_info , "name" , value );
15031513 Py_DECREF (value );
15041514 if (res < 0 )
15051515 goto error ;
15061516
1507- value = PyUnicode_FromString (TAG );
1517+ value = PyUnicode_FromString (_PySys_ImplCacheTag );
15081518 if (value == NULL )
15091519 goto error ;
15101520 res = PyDict_SetItemString (impl_info , "cache_tag" , value );
15111521 Py_DECREF (value );
15121522 if (res < 0 )
15131523 goto error ;
1514- #undef NAME
1515- #undef QUOTE
1516- #undef STRIFY
1517- #undef MAJOR
1518- #undef MINOR
1519- #undef TAG
15201524
15211525 res = PyDict_SetItemString (impl_info , "version" , version_info );
15221526 if (res < 0 )
You can’t perform that action at this time.
0 commit comments