summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2013-01-02 15:36:23 (GMT)
committerBenjamin Peterson <benjamin@python.org>2013-01-02 15:36:23 (GMT)
commit6b3f8d375b9e55727f5a3f62d2bf6204ab8b350a (patch)
tree362949a7c9ec147218457c7e301f92e260d4f311
parent5ca88d2b181fe42ced2f590f2a4115b48860240d (diff)
downloadcpython-6b3f8d375b9e55727f5a3f62d2bf6204ab8b350a.zip
cpython-6b3f8d375b9e55727f5a3f62d2bf6204ab8b350a.tar.gz
cpython-6b3f8d375b9e55727f5a3f62d2bf6204ab8b350a.tar.bz2
ensure the attribute name string is initalized before using it (closes #16839)
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/object.c7
2 files changed, 9 insertions, 1 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index 0111cb4..4807441 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@ What's New in Python 2.7.4
Core and Builtins
-----------------
+- Issue #16839: Fix a segfault when calling unicode() on a classic class early
+ in interpreter initialization.
+
- Issue #16761: Calling ``int()`` and ``long()`` with *base* argument only
now raises TypeError.
diff --git a/Objects/object.c b/Objects/object.c
index e732dce..14f4e9f 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -474,7 +474,7 @@ PyObject_Unicode(PyObject *v)
PyObject *func;
PyObject *str;
int unicode_method_found = 0;
- static PyObject *unicodestr;
+ static PyObject *unicodestr = NULL;
if (v == NULL) {
res = PyString_FromString("<NULL>");
@@ -491,6 +491,11 @@ PyObject_Unicode(PyObject *v)
if (PyInstance_Check(v)) {
/* We're an instance of a classic class */
/* Try __unicode__ from the instance -- alas we have no type */
+ if (!unicodestr) {
+ unicodestr = PyString_InternFromString("__unicode__");
+ if (!unicodestr)
+ return NULL;
+ }
func = PyObject_GetAttr(v, unicodestr);
if (func != NULL) {
unicode_method_found = 1;