[Python-checkins] python/dist/src/Objects obmalloc.c,2.35,2.36
tim_one@sourceforge.net
tim_one@sourceforge.net
Fri, 12 Apr 2002 00:38:56 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv8602/python/Objects
Modified Files:
obmalloc.c
Log Message:
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
prefix. These symbols are private to the file, and the PYMALLOC_ gets
in the way (overly long code lines, comments, and error messages).
Index: obmalloc.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/obmalloc.c,v
retrieving revision 2.35
retrieving revision 2.36
diff -C2 -d -r2.35 -r2.36
*** obmalloc.c 12 Apr 2002 03:10:20 -0000 2.35
--- obmalloc.c 12 Apr 2002 07:38:53 -0000 2.36
***************
*** 877,883 ****
*/
! #define PYMALLOC_CLEANBYTE 0xCB /* uninitialized memory */
! #define PYMALLOC_DEADBYTE 0xDB /* free()ed memory */
! #define PYMALLOC_FORBIDDENBYTE 0xFB /* unusable memory */
static ulong serialno = 0; /* incremented on each debug {m,re}alloc */
--- 877,890 ----
*/
! /* Special bytes broadcast into debug memory blocks at appropriate times.
! * Strings of these are unlikely to be valid addresses, floats, ints or
! * 7-bit ASCII.
! */
! #undef CLEANBYTE
! #undef DEADBYTE
! #undef FORBIDDENBYTE
! #define CLEANBYTE 0xCB /* clean (newly allocated) memory */
! #define DEADBYTE 0xDB /* deed (newly freed) memory */
! #define FORBIDDENBYTE 0xFB /* untouchable bytes at each end of a block */
static ulong serialno = 0; /* incremented on each debug {m,re}alloc */
***************
*** 923,936 ****
big-endian (easier to read in a memory dump).
p[4:8]
! Copies of PYMALLOC_FORBIDDENBYTE. Used to catch under- writes
! and reads.
p[8:8+n]
! The requested memory, filled with copies of PYMALLOC_CLEANBYTE.
Used to catch reference to uninitialized memory.
&p[8] is returned. Note that this is 8-byte aligned if pymalloc
handled the request itself.
p[8+n:8+n+4]
! Copies of PYMALLOC_FORBIDDENBYTE. Used to catch over- writes
! and reads.
p[8+n+4:8+n+8]
A serial number, incremented by 1 on each call to _PyObject_DebugMalloc
--- 930,941 ----
big-endian (easier to read in a memory dump).
p[4:8]
! Copies of FORBIDDENBYTE. Used to catch under- writes and reads.
p[8:8+n]
! The requested memory, filled with copies of CLEANBYTE.
Used to catch reference to uninitialized memory.
&p[8] is returned. Note that this is 8-byte aligned if pymalloc
handled the request itself.
p[8+n:8+n+4]
! Copies of FORBIDDENBYTE. Used to catch over- writes and reads.
p[8+n+4:8+n+8]
A serial number, incremented by 1 on each call to _PyObject_DebugMalloc
***************
*** 965,975 ****
write4(p, nbytes);
! p[4] = p[5] = p[6] = p[7] = PYMALLOC_FORBIDDENBYTE;
if (nbytes > 0)
! memset(p+8, PYMALLOC_CLEANBYTE, nbytes);
tail = p + 8 + nbytes;
! tail[0] = tail[1] = tail[2] = tail[3] = PYMALLOC_FORBIDDENBYTE;
write4(tail + 4, serialno);
--- 970,980 ----
write4(p, nbytes);
! p[4] = p[5] = p[6] = p[7] = FORBIDDENBYTE;
if (nbytes > 0)
! memset(p+8, CLEANBYTE, nbytes);
tail = p + 8 + nbytes;
! tail[0] = tail[1] = tail[2] = tail[3] = FORBIDDENBYTE;
write4(tail + 4, serialno);
***************
*** 978,983 ****
/* The debug free first checks the 8 bytes on each end for sanity (in
! particular, that the PYMALLOC_FORBIDDENBYTEs are still intact).
! Then fills the original bytes with PYMALLOC_DEADBYTE.
Then calls the underlying free.
*/
--- 983,988 ----
/* The debug free first checks the 8 bytes on each end for sanity (in
! particular, that the FORBIDDENBYTEs are still intact).
! Then fills the original bytes with DEADBYTE.
Then calls the underlying free.
*/
***************
*** 993,997 ****
nbytes = read4(q-8);
if (nbytes > 0)
! memset(q, PYMALLOC_DEADBYTE, nbytes);
PyObject_Free(q-8);
}
--- 998,1002 ----
nbytes = read4(q-8);
if (nbytes > 0)
! memset(q, DEADBYTE, nbytes);
PyObject_Free(q-8);
}
***************
*** 1025,1031 ****
/* kill the excess bytes plus the trailing 8 pad bytes */
q += nbytes;
! q[0] = q[1] = q[2] = q[3] = PYMALLOC_FORBIDDENBYTE;
write4(q+4, serialno);
! memset(q+8, PYMALLOC_DEADBYTE, excess);
return p;
}
--- 1030,1036 ----
/* kill the excess bytes plus the trailing 8 pad bytes */
q += nbytes;
! q[0] = q[1] = q[2] = q[3] = FORBIDDENBYTE;
write4(q+4, serialno);
! memset(q+8, DEADBYTE, excess);
return p;
}
***************
*** 1060,1064 ****
for (i = 4; i >= 1; --i) {
! if (*(q-i) != PYMALLOC_FORBIDDENBYTE) {
msg = "bad leading pad byte";
goto error;
--- 1065,1069 ----
for (i = 4; i >= 1; --i) {
! if (*(q-i) != FORBIDDENBYTE) {
msg = "bad leading pad byte";
goto error;
***************
*** 1070,1074 ****
const uchar *tail = q + nbytes;
for (i = 0; i < 4; ++i) {
! if (tail[i] != PYMALLOC_FORBIDDENBYTE) {
msg = "bad trailing pad byte";
goto error;
--- 1075,1079 ----
const uchar *tail = q + nbytes;
for (i = 0; i < 4; ++i) {
! if (tail[i] != FORBIDDENBYTE) {
msg = "bad trailing pad byte";
goto error;
***************
*** 1104,1120 ****
fputs(" the 4 pad bytes at p-4 are ", stderr);
! if (*(q-4) == PYMALLOC_FORBIDDENBYTE &&
! *(q-3) == PYMALLOC_FORBIDDENBYTE &&
! *(q-2) == PYMALLOC_FORBIDDENBYTE &&
! *(q-1) == PYMALLOC_FORBIDDENBYTE) {
! fputs("PYMALLOC_FORBIDDENBYTE, as expected\n", stderr);
}
else {
! fprintf(stderr, "not all PYMALLOC_FORBIDDENBYTE (0x%02x):\n",
! PYMALLOC_FORBIDDENBYTE);
for (i = 4; i >= 1; --i) {
const uchar byte = *(q-i);
fprintf(stderr, " at p-%d: 0x%02x", i, byte);
! if (byte != PYMALLOC_FORBIDDENBYTE)
fputs(" *** OUCH", stderr);
fputc('\n', stderr);
--- 1109,1125 ----
fputs(" the 4 pad bytes at p-4 are ", stderr);
! if (*(q-4) == FORBIDDENBYTE &&
! *(q-3) == FORBIDDENBYTE &&
! *(q-2) == FORBIDDENBYTE &&
! *(q-1) == FORBIDDENBYTE) {
! fputs("FORBIDDENBYTE, as expected\n", stderr);
}
else {
! fprintf(stderr, "not all FORBIDDENBYTE (0x%02x):\n",
! FORBIDDENBYTE);
for (i = 4; i >= 1; --i) {
const uchar byte = *(q-i);
fprintf(stderr, " at p-%d: 0x%02x", i, byte);
! if (byte != FORBIDDENBYTE)
fputs(" *** OUCH", stderr);
fputc('\n', stderr);
***************
*** 1124,1141 ****
tail = q + nbytes;
fprintf(stderr, " the 4 pad bytes at tail=%p are ", tail);
! if (tail[0] == PYMALLOC_FORBIDDENBYTE &&
! tail[1] == PYMALLOC_FORBIDDENBYTE &&
! tail[2] == PYMALLOC_FORBIDDENBYTE &&
! tail[3] == PYMALLOC_FORBIDDENBYTE) {
! fputs("PYMALLOC_FORBIDDENBYTE, as expected\n", stderr);
}
else {
! fprintf(stderr, "not all PYMALLOC_FORBIDDENBYTE (0x%02x):\n",
! PYMALLOC_FORBIDDENBYTE);
for (i = 0; i < 4; ++i) {
const uchar byte = tail[i];
fprintf(stderr, " at tail+%d: 0x%02x",
i, byte);
! if (byte != PYMALLOC_FORBIDDENBYTE)
fputs(" *** OUCH", stderr);
fputc('\n', stderr);
--- 1129,1146 ----
tail = q + nbytes;
fprintf(stderr, " the 4 pad bytes at tail=%p are ", tail);
! if (tail[0] == FORBIDDENBYTE &&
! tail[1] == FORBIDDENBYTE &&
! tail[2] == FORBIDDENBYTE &&
! tail[3] == FORBIDDENBYTE) {
! fputs("FORBIDDENBYTE, as expected\n", stderr);
}
else {
! fprintf(stderr, "not all FORBIDDENBYTE (0x%02x):\n",
! FORBIDDENBYTE);
for (i = 0; i < 4; ++i) {
const uchar byte = tail[i];
fprintf(stderr, " at tail+%d: 0x%02x",
i, byte);
! if (byte != FORBIDDENBYTE)
fputs(" *** OUCH", stderr);
fputc('\n', stderr);