diff options
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/object.c | 6 | ||||
-rw-r--r-- | Objects/stringobject.c | 23 |
2 files changed, 21 insertions, 8 deletions
diff --git a/Objects/object.c b/Objects/object.c index be8eb07..af0c0bb 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -261,12 +261,6 @@ PyObject_Str(PyObject *v) Py_INCREF(v); return v; } - if (PyString_Check(v)) { - /* For a string subtype that's not a string, return a true - string with the same string data. */ - PyStringObject *s = (PyStringObject *)v; - return PyString_FromStringAndSize(s->ob_sval, s->ob_size); - } if (v->ob_type->tp_str == NULL) return PyObject_Repr(v); diff --git a/Objects/stringobject.c b/Objects/stringobject.c index aea31ac..0a3155e 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -566,7 +566,18 @@ string_print(PyStringObject *op, FILE *fp, int flags) int i; char c; int quote; + /* XXX Ought to check for interrupts when writing long strings */ + if (! PyString_CheckExact(op)) { + int ret; + /* A str subclass may have its own __str__ method. */ + op = (PyStringObject *) PyObject_Str((PyObject *)op); + if (op == NULL) + return -1; + ret = string_print(op, fp, flags); + Py_DECREF(op); + return ret; + } if (flags & Py_PRINT_RAW) { fwrite(op->ob_sval, 1, (int) op->ob_size, fp); return 0; @@ -651,8 +662,16 @@ string_repr(register PyStringObject *op) static PyObject * string_str(PyObject *s) { - Py_INCREF(s); - return s; + assert(PyString_Check(s)); + if (PyString_CheckExact(s)) { + Py_INCREF(s); + return s; + } + else { + /* Subtype -- return genuine string with the same value. */ + PyStringObject *t = (PyStringObject *) s; + return PyString_FromStringAndSize(t->ob_sval, t->ob_size); + } } static int |