]> granicus.if.org Git - python/commitdiff
This was quite a dark bug in my recent in-place string concatenation
authorArmin Rigo <arigo@tunes.org>
Sat, 7 Aug 2004 20:58:32 +0000 (20:58 +0000)
committerArmin Rigo <arigo@tunes.org>
Sat, 7 Aug 2004 20:58:32 +0000 (20:58 +0000)
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.

Objects/stringobject.c
Python/ceval.c

index e29ed4806fe449bbb500a2ef81110c53670ad1a8..b40351afcbac96bcca806e131707eff0ab412b37 100644 (file)
@@ -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();
index 4dd31ab9bab122bd11b50f661b402d81d028eda4..4c9bdeda1369e267f825be7025a83607058b3529 100644 (file)
@@ -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.
                 */