diff Objects/unicodeobject.c @ 23051:19ea00feda33 legacy-trunk

Return the orginal string only if it's a real str or unicode instance, otherwise make a copy.
author Walter Dörwald <walter@livinglogic.de>
date Mon, 15 Apr 2002 18:42:15 +0000
parents 8b1268bc371a
children f1d6142128d3
line wrap: on
line diff
--- a/Objects/unicodeobject.c	Mon Apr 15 18:41:31 2002 +0000
+++ b/Objects/unicodeobject.c	Mon Apr 15 18:42:15 2002 +0000
@@ -4841,8 +4841,15 @@
         return NULL;
 
     if (self->length >= width) {
-        Py_INCREF(self);
-        return (PyObject*) self;
+        if (PyUnicode_CheckExact(self)) {
+            Py_INCREF(self);
+            return (PyObject*) self;
+        }
+        else
+            return PyUnicode_FromUnicode(
+                PyUnicode_AS_UNICODE(self),
+                PyUnicode_GET_SIZE(self)
+            );
     }
 
     fill = width - self->length;