[Python-checkins] cpython: Issue #18408: slot_tp_str() must not fallback on slot_tp_repr() on error

victor.stinner python-checkins at python.org
Thu Jul 11 22:46:48 CEST 2013


http://hg.python.org/cpython/rev/01a46dc00fc8
changeset:   84561:01a46dc00fc8
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Thu Jul 11 22:46:11 2013 +0200
summary:
  Issue #18408: slot_tp_str() must not fallback on slot_tp_repr() on error

type->tp_str must not point to slot_tp_str() if type has no __str__ attribute,
so there is no reason for slot_tp_str() to fallback on slot_tp_str() on lookup
error. Moreover, calling PyErr_Clear() may hide a real bug like MemoryError.

If __str__ attribute is removed, slots must be updated (which is done by
type_setattro()).

files:
  Objects/typeobject.c |  21 ++-------------------
  1 files changed, 2 insertions(+), 19 deletions(-)


diff --git a/Objects/typeobject.c b/Objects/typeobject.c
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -5274,29 +5274,12 @@
     _Py_IDENTIFIER(__str__);
 
     func = lookup_method(self, &PyId___str__);
-    if (func != NULL) {
+    if (func == NULL)
+        return NULL;
         res = PyEval_CallObject(func, NULL);
         Py_DECREF(func);
         return res;
     }
-    else {
-        /* PyObject *ress; */
-        PyErr_Clear();
-        res = slot_tp_repr(self);
-        if (!res)
-            return NULL;
-        /* XXX this is non-sensical. Why should we return
-           a bytes object from __str__. Is this code even
-           used? - mvl */
-        assert(0);
-        return res;
-        /*
-        ress = _PyUnicode_AsDefaultEncodedString(res);
-        Py_DECREF(res);
-        return ress;
-        */
-    }
-}
 
 static Py_hash_t
 slot_tp_hash(PyObject *self)

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list