]> granicus.if.org Git - python/commitdiff
Return the orginal string only if it's a real str or unicode
authorWalter Dörwald <walter@livinglogic.de>
Mon, 15 Apr 2002 18:42:15 +0000 (18:42 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Mon, 15 Apr 2002 18:42:15 +0000 (18:42 +0000)
instance, otherwise make a copy.

Objects/stringobject.c
Objects/unicodeobject.c

index 1af96b109f5a58523cc767b3e2f60422a6371b59..6a0eece665e1782f38192eed38a743d69b2b1d1f 100644 (file)
@@ -2401,8 +2401,15 @@ string_zfill(PyStringObject *self, PyObject *args)
         return NULL;
 
     if (PyString_GET_SIZE(self) >= width) {
-        Py_INCREF(self);
-        return (PyObject*) self;
+        if (PyString_CheckExact(self)) {
+            Py_INCREF(self);
+            return (PyObject*) self;
+        }
+        else
+            return PyString_FromStringAndSize(
+                PyString_AS_STRING(self),
+                PyString_GET_SIZE(self)
+            );
     }
 
     fill = width - PyString_GET_SIZE(self);
index 361612b16f0ceeafd6f800230434253e1b73932c..29ba2e449848d8cb21046aad150e9d19064e6ebe 100644 (file)
@@ -4841,8 +4841,15 @@ unicode_zfill(PyUnicodeObject *self, PyObject *args)
         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;