Mercurial > cpython-lru_cache-weakref
diff Objects/stringobject.c @ 71:ac4522e99ca9 legacy-trunk
Fixed resizestring() to work if reference tracing is turned on.
The realloc() call would move the list head without fixing the
pointers to in the the chain of allocated objects...
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sun, 18 Nov 1990 17:30:23 +0000 |
| parents | 82c7bab78bb1 |
| children | 554ac659b2cb |
line wrap: on
line diff
--- a/Objects/stringobject.c Sun Nov 18 17:28:24 1990 +0000 +++ b/Objects/stringobject.c Sun Nov 18 17:30:23 1990 +0000 @@ -296,24 +296,31 @@ object **pv; int newsize; { - register stringobject *v; - v = (stringobject *) *pv; + register object *v; + register stringobject *sv; + v = *pv; if (!is_stringobject(v) || v->ob_refcnt != 1) { *pv = 0; DECREF(v); err_badcall(); return -1; } + /* XXX UNREF/NEWREF interface should be more symmetrical */ +#ifdef TRACE_REFS + --ref_total; +#endif + UNREF(v); *pv = (object *) realloc((char *)v, sizeof(stringobject) + newsize * sizeof(char)); if (*pv == NULL) { - DECREF(v); + DEL(v); err_nomem(); return -1; } - v = (stringobject *) *pv; - v->ob_size = newsize; - v->ob_sval[newsize] = '\0'; + NEWREF(*pv); + sv = (stringobject *) *pv; + sv->ob_size = newsize; + sv->ob_sval[newsize] = '\0'; return 0; }
