summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2006-05-25 15:49:45 (GMT)
committerFredrik Lundh <fredrik@pythonware.com>2006-05-25 15:49:45 (GMT)
commit4b4e33ef14cecd0bc9c6566ea8b402733e7e445f (patch)
tree2f50b5e84c156f167f44abc7631df89e8a481808 /Objects
parent39ccef607eefbd4955c7fb069f6c921c0fe3516f (diff)
downloadcpython-4b4e33ef14cecd0bc9c6566ea8b402733e7e445f.zip
cpython-4b4e33ef14cecd0bc9c6566ea8b402733e7e445f.tar.gz
cpython-4b4e33ef14cecd0bc9c6566ea8b402733e7e445f.tar.bz2
needforspeed: make new upper/lower work properly for single-character
strings too... (thanks to georg brandl for spotting the exact problem faster than anyone else)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/stringobject.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index d3ab54e..3ec4524 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -2040,14 +2040,16 @@ string_lower(PyStringObject *self)
Py_ssize_t i, n = PyString_GET_SIZE(self);
PyObject *newobj;
- newobj = PyString_FromStringAndSize(PyString_AS_STRING(self), n);
+ newobj = PyString_FromStringAndSize(NULL, n);
if (!newobj)
return NULL;
s = PyString_AS_STRING(newobj);
+ memcpy(s, PyString_AS_STRING(self), n);
+
for (i = 0; i < n; i++) {
- char c = Py_CHARMASK(s[i]);
+ int c = Py_CHARMASK(s[i]);
if (isupper(c))
s[i] = _tolower(c);
}
@@ -2067,14 +2069,16 @@ string_upper(PyStringObject *self)
Py_ssize_t i, n = PyString_GET_SIZE(self);
PyObject *newobj;
- newobj = PyString_FromStringAndSize(PyString_AS_STRING(self), n);
+ newobj = PyString_FromStringAndSize(NULL, n);
if (!newobj)
return NULL;
s = PyString_AS_STRING(newobj);
+ memcpy(s, PyString_AS_STRING(self), n);
+
for (i = 0; i < n; i++) {
- char c = Py_CHARMASK(s[i]);
+ int c = Py_CHARMASK(s[i]);
if (islower(c))
s[i] = _toupper(c);
}