]> granicus.if.org Git - python/commitdiff
ensure the attribute name string is initalized before using it (closes #16839)
authorBenjamin Peterson <benjamin@python.org>
Wed, 2 Jan 2013 15:36:23 +0000 (09:36 -0600)
committerBenjamin Peterson <benjamin@python.org>
Wed, 2 Jan 2013 15:36:23 +0000 (09:36 -0600)
Misc/NEWS
Objects/object.c

index 0111cb43fc1e6a99cad8dffd4024e8c5c4ce995f..480744169118c5ce8806975a9c1000c691f2181f 100644 (file)
--- 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.
 
index e732dceff6464890e38eb98f8c61b94a723cf73d..14f4e9f611441d0e16f47fcfab93e3d14e9b847d 100644 (file)
@@ -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;