From 2fc94eecb2415de1d966900fa15af179beb07723 Mon Sep 17 00:00:00 2001 From: Jack Jansen Date: Sun, 22 Jan 1995 16:47:22 +0000 Subject: - Ported to CW5 (which has more unixisms) - Added (rather crummy) malloc debugger --- Mac/mwerks/mwerksglue.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/Mac/mwerks/mwerksglue.c b/Mac/mwerks/mwerksglue.c index ae6c1ff..82f59d9 100644 --- a/Mac/mwerks/mwerksglue.c +++ b/Mac/mwerks/mwerksglue.c @@ -8,9 +8,131 @@ #include #include +#include #include #include +/* #define DBGMALLOC /**/ + +#ifdef DBGMALLOC +#define NMALLOC 50000 +static long m_index; +static long m_addrs[NMALLOC]; +static long m_sizes[NMALLOC]; +static long m_lastaddr; + +#define SSLOP 2 +#define SLOP (SSLOP+0) + +void +m_abort() { + printf("ABORT\n"); + exit(1); +} + +void * +checkrv(ptr, size) + void *ptr; + int size; +{ + long b = (long)ptr, e = (long)ptr + size+SSLOP; + int i; + + if ( m_index >= NMALLOC ) { + printf("too many mallocs\n"); + m_abort(); + } + m_lastaddr = (long)ptr; + for(i=0; i 0 && b < m_addrs[i]+m_sizes[i] && e > m_addrs[i] ) { + printf("overlapping block with %d\n", i); + m_abort(); + } + } + m_sizes[m_index] = size; + m_addrs[m_index++] = (long)ptr; + *(short *)ptr = m_index-1; + return (void *)((char *)ptr+SSLOP); + +} + +void * +checkfree(ptr) + void *ptr; +{ + int i; + + if ( ptr == 0 ) { + printf("free null\n"); + m_abort(); + } + m_lastaddr = (long)ptr; + for(i=0; i