diff options
author | Guido van Rossum <guido@python.org> | 1990-11-18 17:30:23 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1990-11-18 17:30:23 (GMT) |
commit | 921842f2c2a4f4124ff80f95e3f613c3f0dcc8d5 (patch) | |
tree | 744cb42248c39e56137ca7fbf44fc0abb104f84f | |
parent | da0c6bdfe36a58e9f6ba3408e843d1afb3733056 (diff) | |
download | cpython-921842f2c2a4f4124ff80f95e3f613c3f0dcc8d5.zip cpython-921842f2c2a4f4124ff80f95e3f613c3f0dcc8d5.tar.gz cpython-921842f2c2a4f4124ff80f95e3f613c3f0dcc8d5.tar.bz2 |
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...
-rw-r--r-- | Objects/stringobject.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 7b02dc8..cceed75 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -296,24 +296,31 @@ resizestring(pv, newsize) 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; } |