summaryrefslogtreecommitdiff
path: root/Python/import.c
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-07-09 14:22:12 -0400
committerBrett Cannon <brett@python.org>2012-07-09 14:22:12 -0400
commit2218bc0c7a4c4a2df3126cc840b3a2718b0be65e (patch)
tree893bad11e8e09ae912e1fcbab619a4cb7a931393 /Python/import.c
parent07ba56b984dd5933c2e30a6e8bb91c2b67bfcdb7 (diff)
downloadcpython-2218bc0c7a4c4a2df3126cc840b3a2718b0be65e.tar.gz
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.
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c18
1 files changed, 4 insertions, 14 deletions
diff --git a/Python/import.c b/Python/import.c
index c31819dc81..1592045896 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -116,7 +116,7 @@ typedef unsigned short mode_t;
*/
#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 @@ PyImport_GetMagicNumber(void)
}
+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;
}