merge heads
diff --git a/Misc/NEWS b/Misc/NEWS
index 1f0c244..5e719e5 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,8 +9,11 @@
Core and Builtins
-----------------
-- Issue #16761: Calling int() and long() with base argument only now raises
- TypeError.
+- 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.
- Issue #16759: Support the full DWORD (unsigned long) range in Reg2Py
when retreiving a REG_DWORD value. This corrects functions like
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 *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;