comparison Python/sysmodule.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 d63a80abfbec
children dca92e8a011a d2127cdec10e
comparison
equal deleted inserted replaced
78028:43f2ada6ee87 78029:ee01fd98b5b0
1476 return NULL; 1476 return NULL;
1477 } 1477 }
1478 return version_info; 1478 return version_info;
1479 } 1479 }
1480 1480
1481 static PyObject * 1481 /* sys.implementation values */
1482 make_impl_info(PyObject *version_info)
1483 {
1484 int res;
1485 PyObject *impl_info, *value, *ns;
1486
1487 impl_info = PyDict_New();
1488 if (impl_info == NULL)
1489 return NULL;
1490
1491 /* populate the dict */
1492
1493 #define NAME "cpython" 1482 #define NAME "cpython"
1483 const char *_PySys_ImplName = NAME;
1494 #define QUOTE(arg) #arg 1484 #define QUOTE(arg) #arg
1495 #define STRIFY(name) QUOTE(name) 1485 #define STRIFY(name) QUOTE(name)
1496 #define MAJOR STRIFY(PY_MAJOR_VERSION) 1486 #define MAJOR STRIFY(PY_MAJOR_VERSION)
1497 #define MINOR STRIFY(PY_MINOR_VERSION) 1487 #define MINOR STRIFY(PY_MINOR_VERSION)
1498 #define TAG NAME "-" MAJOR MINOR 1488 #define TAG NAME "-" MAJOR MINOR;
1499 value = PyUnicode_FromString(NAME); 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
1497 static PyObject *
1498 make_impl_info(PyObject *version_info)
1499 {
1500 int res;
1501 PyObject *impl_info, *value, *ns;
1502
1503 impl_info = PyDict_New();
1504 if (impl_info == NULL)
1505 return NULL;
1506
1507 /* populate the dict */
1508
1509 value = PyUnicode_FromString(_PySys_ImplName);
1500 if (value == NULL) 1510 if (value == NULL)
1501 goto error; 1511 goto error;
1502 res = PyDict_SetItemString(impl_info, "name", value); 1512 res = PyDict_SetItemString(impl_info, "name", value);
1503 Py_DECREF(value); 1513 Py_DECREF(value);
1504 if (res < 0) 1514 if (res < 0)
1505 goto error; 1515 goto error;
1506 1516
1507 value = PyUnicode_FromString(TAG); 1517 value = PyUnicode_FromString(_PySys_ImplCacheTag);
1508 if (value == NULL) 1518 if (value == NULL)
1509 goto error; 1519 goto error;
1510 res = PyDict_SetItemString(impl_info, "cache_tag", value); 1520 res = PyDict_SetItemString(impl_info, "cache_tag", value);
1511 Py_DECREF(value); 1521 Py_DECREF(value);
1512 if (res < 0) 1522 if (res < 0)
1513 goto error; 1523 goto error;
1514 #undef NAME
1515 #undef QUOTE
1516 #undef STRIFY
1517 #undef MAJOR
1518 #undef MINOR
1519 #undef TAG
1520 1524
1521 res = PyDict_SetItemString(impl_info, "version", version_info); 1525 res = PyDict_SetItemString(impl_info, "version", version_info);
1522 if (res < 0) 1526 if (res < 0)
1523 goto error; 1527 goto error;
1524 1528