diff Python/import.c @ 78029:ee01fd98b5b0

Issue #15242: Have PyImport_GetMagicTag() return a const char * defined in sysmodule.c instead of straight out of a Unicode object. Thanks to Amaury Forgeot d'Arc for noticing the bug and Eric Snow for writing the patch.
author Brett Cannon <brett@python.org>
date Mon, 09 Jul 2012 14:22:12 -0400
parents 8c877ad00bc4
children efb5e6ab10f4
line wrap: on
line diff
--- a/Python/import.c	Mon Jul 09 14:15:32 2012 -0400
+++ b/Python/import.c	Mon Jul 09 14:22:12 2012 -0400
@@ -116,7 +116,7 @@
 */
 #define MAGIC (3230 | ((long)'\r'<<16) | ((long)'\n'<<24))
 #define CACHEDIR "__pycache__"
-/* Current magic word and string tag as globals. */
+/* Current magic word as global. */
 static long pyc_magic = MAGIC;
 
 /* See _PyImport_FixupExtensionObject() below */
@@ -520,22 +520,12 @@
 }
 
 
+extern const char * _PySys_ImplCacheTag;
+
 const char *
 PyImport_GetMagicTag(void)
 {
-    PyObject *impl, *tag;
-    const char *raw_tag;
-
-    /* We could also pull it from imp or importlib. */
-    impl = PySys_GetObject("implementation");
-    if (impl == NULL)
-        return NULL;
-    tag = PyObject_GetAttrString(impl, "cache_tag");
-    if (tag == NULL)
-        return NULL;
-    raw_tag = PyUnicode_DATA(tag);
-    Py_DECREF(tag);
-    return raw_tag;
+    return _PySys_ImplCacheTag;
 }