Kaydet (Commit) 0fe940c8 authored tarafından Walter Dörwald's avatar Walter Dörwald

Return the orginal string only if it's a real str or unicode

instance, otherwise make a copy.
üst 8a5e6790
...@@ -2401,8 +2401,15 @@ string_zfill(PyStringObject *self, PyObject *args) ...@@ -2401,8 +2401,15 @@ string_zfill(PyStringObject *self, PyObject *args)
return NULL; return NULL;
if (PyString_GET_SIZE(self) >= width) { if (PyString_GET_SIZE(self) >= width) {
Py_INCREF(self); if (PyString_CheckExact(self)) {
return (PyObject*) 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); fill = width - PyString_GET_SIZE(self);
......
...@@ -4841,8 +4841,15 @@ unicode_zfill(PyUnicodeObject *self, PyObject *args) ...@@ -4841,8 +4841,15 @@ unicode_zfill(PyUnicodeObject *self, PyObject *args)
return NULL; return NULL;
if (self->length >= width) { if (self->length >= width) {
Py_INCREF(self); if (PyUnicode_CheckExact(self)) {
return (PyObject*) self; Py_INCREF(self);
return (PyObject*) self;
}
else
return PyUnicode_FromUnicode(
PyUnicode_AS_UNICODE(self),
PyUnicode_GET_SIZE(self)
);
} }
fill = width - self->length; fill = width - self->length;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment