[Python-checkins] cpython (2.7): ensure the attribute name string is initalized before using it (closes #16839)
benjamin.peterson
python-checkins at python.org
Wed Jan 2 16:37:53 CET 2013
http://hg.python.org/cpython/rev/0012d4f0ca59
changeset: 81237:0012d4f0ca59
branch: 2.7
parent: 81218:f6e74759d740
user: Benjamin Peterson <benjamin at python.org>
date: Wed Jan 02 09:36:23 2013 -0600
summary:
ensure the attribute name string is initalized before using it (closes #16839)
files:
Misc/NEWS | 3 +++
Objects/object.c | 7 ++++++-
2 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@
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
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -474,7 +474,7 @@
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 @@
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;
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list