diff options
author | Armin Rigo <arigo@tunes.org> | 2004-08-07 20:58:32 +0000 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2004-08-07 20:58:32 +0000 |
commit | 618fbf5469ec6b8013b00989623763db21dd0ce5 (patch) | |
tree | 038a1948057047243f99e38569ec472120f86eda | |
parent | 25847813c18b500d661137364b9041c6b08a75ea (diff) | |
download | cpython-git-618fbf5469ec6b8013b00989623763db21dd0ce5.tar.gz |
This was quite a dark bug in my recent in-place string concatenation
hack: it would resize *interned* strings in-place! This occurred because
their reference counts do not have their expected value -- stringobject.c
hacks them. Mea culpa.
-rw-r--r-- | Objects/stringobject.c | 3 | ||||
-rw-r--r-- | Python/ceval.c | 2 |
2 files changed, 3 insertions, 2 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index e29ed4806f..b40351afcb 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -3513,7 +3513,8 @@ _PyString_Resize(PyObject **pv, int newsize) register PyObject *v; register PyStringObject *sv; v = *pv; - if (!PyString_Check(v) || v->ob_refcnt != 1 || newsize < 0) { + if (!PyString_Check(v) || v->ob_refcnt != 1 || newsize < 0 || + PyString_CHECK_INTERNED(v)) { *pv = 0; Py_DECREF(v); PyErr_BadInternalCall(); diff --git a/Python/ceval.c b/Python/ceval.c index 4dd31ab9ba..4c9bdeda13 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -4253,7 +4253,7 @@ string_concatenate(PyObject *v, PyObject *w, } } - if (v->ob_refcnt == 1) { + if (v->ob_refcnt == 1 && !PyString_CHECK_INTERNED(v)) { /* Now we own the last reference to 'v', so we can resize it * in-place. */ |