diff options
author | Walter Dörwald <walter@livinglogic.de> | 2002-04-15 18:42:15 +0000 |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2002-04-15 18:42:15 +0000 |
commit | 0fe940c862fef8729f07b5686847e7e952b40fe6 (patch) | |
tree | 320a56eae714fc456178ce2e31c44ab754301c1e /Objects/stringobject.c | |
parent | 8a5e6790d959cac49ab66cf4973b6ab6c3f397fd (diff) | |
download | cpython-git-0fe940c862fef8729f07b5686847e7e952b40fe6.tar.gz |
Return the orginal string only if it's a real str or unicode
instance, otherwise make a copy.
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r-- | Objects/stringobject.c | 11 |
1 files changed, 9 insertions, 2 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); |