From 0fe940c862fef8729f07b5686847e7e952b40fe6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Walter=20D=C3=B6rwald?= Date: Mon, 15 Apr 2002 18:42:15 +0000 Subject: [PATCH] Return the orginal string only if it's a real str or unicode instance, otherwise make a copy. --- Objects/stringobject.c | 11 +++++++++-- Objects/unicodeobject.c | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 1af96b109f..6a0eece665 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -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); diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 361612b16f..29ba2e4498 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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; -- 2.50.1