summaryrefslogtreecommitdiffstats
path: root/Objects/stringobject.c
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2002-04-15 18:42:15 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2002-04-15 18:42:15 (GMT)
commit0fe940c862fef8729f07b5686847e7e952b40fe6 (patch)
tree320a56eae714fc456178ce2e31c44ab754301c1e /Objects/stringobject.c
parent8a5e6790d959cac49ab66cf4973b6ab6c3f397fd (diff)
downloadcpython-0fe940c862fef8729f07b5686847e7e952b40fe6.zip
cpython-0fe940c862fef8729f07b5686847e7e952b40fe6.tar.gz
cpython-0fe940c862fef8729f07b5686847e7e952b40fe6.tar.bz2
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.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 1af96b1..6a0eece 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);