summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
Diffstat (limited to 'Objects')
-rw-r--r--Objects/object.c47
-rw-r--r--Objects/unicodeobject.c1
2 files changed, 48 insertions, 0 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 3cad241..20950c1 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -568,6 +568,53 @@ get_inprogress_dict(void)
return inprogress;
}
+PyObject *
+PyObject_Unicode(PyObject *v)
+{
+ PyObject *res;
+
+ if (v == NULL)
+ res = PyString_FromString("<NULL>");
+ else if (PyUnicode_Check(v)) {
+ Py_INCREF(v);
+ return v;
+ }
+ else if (PyString_Check(v))
+ res = v;
+ else if (v->ob_type->tp_str != NULL)
+ res = (*v->ob_type->tp_str)(v);
+ else {
+ PyObject *func;
+ static PyObject *strstr;
+ if (strstr == NULL) {
+ strstr= PyString_InternFromString("__str__");
+ if (strstr == NULL)
+ return NULL;
+ }
+ if (!PyInstance_Check(v) ||
+ (func = PyObject_GetAttr(v, strstr)) == NULL) {
+ PyErr_Clear();
+ res = PyObject_Repr(v);
+ }
+ else {
+ res = PyEval_CallObject(func, (PyObject *)NULL);
+ Py_DECREF(func);
+ }
+ }
+ if (res == NULL)
+ return NULL;
+ if (!PyUnicode_Check(res)) {
+ PyObject* str;
+ str = PyUnicode_FromObject(res);
+ Py_DECREF(res);
+ if (str)
+ res = str;
+ else
+ return NULL;
+ }
+ return res;
+}
+
static PyObject *
make_pair(PyObject *v, PyObject *w)
{
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index a3678d5..c1f3d54 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -413,6 +413,7 @@ PyObject *PyUnicode_FromEncodedObject(register PyObject *obj,
}
else
v = PyUnicode_Decode(s, len, encoding, errors);
+
done:
if (owned) {
Py_DECREF(obj);