summaryrefslogtreecommitdiffstats
path: root/Objects/obmalloc.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2002-03-24 00:34:21 (GMT)
committerTim Peters <tim.peters@gmail.com>2002-03-24 00:34:21 (GMT)
commite085017ab7121b27be315d36ef0c25ed51484023 (patch)
tree7279d5b0dc878ec3b74df97a8bc633ff84e9cb4f /Objects/obmalloc.c
parentf06f8530f1d2b844d560d7420998780637f3184b (diff)
downloadcpython-e085017ab7121b27be315d36ef0c25ed51484023.zip
cpython-e085017ab7121b27be315d36ef0c25ed51484023.tar.gz
cpython-e085017ab7121b27be315d36ef0c25ed51484023.tar.bz2
_PyMalloc_DebugRealloc(): simplify decl of "fresh".
Assorted: bump the serial number via a trivial new bumpserialno() function. The point is to give a single place to set a breakpoint when waiting for a specific serial number.
Diffstat (limited to 'Objects/obmalloc.c')
-rw-r--r--Objects/obmalloc.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c
index 87b3337..e7d2a90 100644
--- a/Objects/obmalloc.c
+++ b/Objects/obmalloc.c
@@ -691,6 +691,16 @@ _PyMalloc_Del(PyObject *op)
static ulong serialno = 0; /* incremented on each debug {m,re}alloc */
+/* serialno is always incremented via calling this routine. The point is
+ to supply a single place to set a breakpoint.
+*/
+static void
+bumpserialno()
+{
+ ++serialno;
+}
+
+
/* Read 4 bytes at p as a big-endian ulong. */
static ulong
read4(const void *p)
@@ -771,7 +781,7 @@ _PyMalloc_DebugMalloc(size_t nbytes, int family)
assert(family == 0);
- ++serialno;
+ bumpserialno();
total = nbytes + 16;
if (total < nbytes || (total >> 31) > 1) {
/* overflow, or we can't represent it in 4 bytes */
@@ -828,7 +838,7 @@ _PyMalloc_DebugRealloc(void *p, size_t nbytes, int family)
{
uchar *q = (uchar *)p;
size_t original_nbytes;
- uchar *fresh; /* new memory block, if needed */
+ void *fresh; /* new memory block, if needed */
assert(family == 0);
@@ -842,7 +852,7 @@ _PyMalloc_DebugRealloc(void *p, size_t nbytes, int family)
if (nbytes == original_nbytes) {
/* note that this case is likely to be common due to the
way Python appends to lists */
- ++serialno;
+ bumpserialno();
write4(q + nbytes + 4, serialno);
return p;
}
@@ -851,7 +861,7 @@ _PyMalloc_DebugRealloc(void *p, size_t nbytes, int family)
/* shrinking -- leave the guts alone, except to
fill the excess with DEADBYTE */
const size_t excess = original_nbytes - nbytes;
- ++serialno;
+ bumpserialno();
write4(q-8, nbytes);
/* kill the excess bytes plus the trailing 8 pad bytes */
memset(q + nbytes, PYMALLOC_DEADBYTE, excess + 8);
@@ -863,7 +873,7 @@ _PyMalloc_DebugRealloc(void *p, size_t nbytes, int family)
/* More memory is needed: get it, copy over the first original_nbytes
of the original data, and free the original memory. */
- fresh = (uchar *)_PyMalloc_DebugMalloc(nbytes, family);
+ fresh = _PyMalloc_DebugMalloc(nbytes, family);
if (fresh != NULL && original_nbytes > 0)
memcpy(fresh, p, original_nbytes);
_PyMalloc_DebugFree(p, family);