Mercurial > cpython-lru_cache-weakref
diff Objects/typeobject.c @ 41769:b29d71d43c80
Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
PyString_Concat() and PyString_ConcatAndDel() (the name PyUnicode_Concat()
was already taken).
Change PyObject_Repr() to always return a unicode object.
Update all repr implementations to return unicode objects.
Add a function PyObject_ReprStr8() that calls PyObject_Repr() and converts
the result to an 8bit string.
Use PyObject_ReprStr8() where using PyObject_Repr() can't be done
straightforward.
| author | Walter Dörwald <walter@livinglogic.de> |
|---|---|
| date | Fri, 18 May 2007 17:15:44 +0000 |
| parents | 00c02c4488ce |
| children | 24b60622b944 |
line wrap: on
line diff
--- a/Objects/typeobject.c Fri May 18 17:04:42 2007 +0000 +++ b/Objects/typeobject.c Fri May 18 17:15:44 2007 +0000 @@ -385,13 +385,13 @@ kind = "type"; if (mod != NULL && strcmp(PyString_AS_STRING(mod), "__builtin__")) { - rtn = PyString_FromFormat("<%s '%s.%s'>", + rtn = PyUnicode_FromFormat("<%s '%s.%s'>", kind, PyString_AS_STRING(mod), PyString_AS_STRING(name)); } else - rtn = PyString_FromFormat("<%s '%s'>", kind, type->tp_name); + rtn = PyUnicode_FromFormat("<%s '%s'>", kind, type->tp_name); Py_XDECREF(mod); Py_DECREF(name); @@ -1006,7 +1006,7 @@ if (name == NULL) { PyErr_Clear(); Py_XDECREF(name); - name = PyObject_Repr(cls); + name = PyObject_ReprStr8(cls); } if (name == NULL) return NULL; @@ -2481,12 +2481,12 @@ if (name == NULL) return NULL; if (mod != NULL && strcmp(PyString_AS_STRING(mod), "__builtin__")) - rtn = PyString_FromFormat("<%s.%s object at %p>", + rtn = PyUnicode_FromFormat("<%s.%s object at %p>", PyString_AS_STRING(mod), PyString_AS_STRING(name), self); else - rtn = PyString_FromFormat("<%s object at %p>", + rtn = PyUnicode_FromFormat("<%s object at %p>", type->tp_name, self); Py_XDECREF(mod); Py_DECREF(name); @@ -4645,7 +4645,7 @@ return res; } PyErr_Clear(); - return PyString_FromFormat("<%s object at %p>", + return PyUnicode_FromFormat("<%s object at %p>", self->ob_type->tp_name, self); } @@ -4662,8 +4662,14 @@ return res; } else { + PyObject *ress; PyErr_Clear(); - return slot_tp_repr(self); + res = slot_tp_repr(self); + if (!res) + return NULL; + ress = _PyUnicode_AsDefaultEncodedString(res, NULL); + Py_DECREF(res); + return ress; } } @@ -5692,12 +5698,12 @@ superobject *su = (superobject *)self; if (su->obj_type) - return PyString_FromFormat( + return PyUnicode_FromFormat( "<super: <class '%s'>, <%s object>>", su->type ? su->type->tp_name : "NULL", su->obj_type->tp_name); else - return PyString_FromFormat( + return PyUnicode_FromFormat( "<super: <class '%s'>, NULL>", su->type ? su->type->tp_name : "NULL"); }
