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)
assert(family == 0);
- ++serialno;
+ bumpserialno();
total = nbytes + 16;
if (total < nbytes || (total >> 31) > 1) {
/* overflow, or we can't represent it in 4 bytes */
{
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);
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;
}
/* 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);
/* 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);