Kaydet (Commit) 618fbf54 authored tarafından Armin Rigo's avatar Armin Rigo

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.
üst 25847813
......@@ -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();
......
......@@ -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.
*/
......
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