This set of diffs allows dbmalloc pl 14 (available from comp.sources.misc, volume 32) to be built using the standard Configure mechanism under Linux. It was tested under RedHat 2.1, i.e. kernel 1.2.13, ELF libc 5.0.9, gcc 2.7.x. It should work with current a.out setups too, I would guess. If you haven't heard of dbmalloc, from the README: This package is a collection of routines which are a drop-in replacement for the malloc(3), memory(3), string(3), and bstring(3) library functions. These replacement modules are different from the original modules in that they provide a full set of debugging features which detect malloc memory overruns and other types of misuse. It differs from the dbmalloc-14L version available on tsx-11 (patched by Harald Dunkel, ) in that it can configure and build from scratch without Linux-specific hacks; it also includes a bug fix or two. Support for exiting via _exit() (as was used in 14L) was not included in this version as it appears not to be necessary with libc 5.0.9. The attached diffs do the following: o (Configure) add test for const as "__const" to support gcc -traditional; the Linux include files use __const for prototyping library functions. o (Configure, cctest.c, malloc.h.org, dgmalloc.c, memory.c) test separately for bcopy/bzero's return value and length arguments, since they may differ from memcpy's. I add a test to see if they return "void" (BCOPYVOID) and to see if the length is simply "int" (like classic BSD) rather than "size_t". o (Configure, cctest.c) when testing for write()'s prototype, you have to also iterate over "char *" and "void *" for the buffer pointer, or else you can't get a warning-free compile under systems using "void *". (There was also a typo, "$siztype", in the defaulting clause.) o (cctest.c) include when testing for free(), since otherwise the printf() causes an error when compiling with g++. o (malloc.h.org) undef memccpy before redefining it, since may have defined it as __memccpy under optimization. o (string.c) call debug_malloc() to forward the file and line information instead of just calling malloc(). o (Makefile) update the include directory to default to $(INSTDIR)/include/debug to be more in line with the spirit of the FSSTND, change ranlib to default to /usr/bin, and update the arguments to cproto to conform to the most recent version. Chris Metcalf -- MIT Lab for Computer Science, +1 617 253 7766 metcalf@lcs.mit.edu -- http://cag-www.lcs.mit.edu/~metcalf --- Configure 1995/12/13 13:10:37 1.1 +++ Configure 1995/12/13 14:10:08 @@ -340,5 +340,14 @@ const=const else - const= + $cc -DCONSTTEST -Dconst=__const -c cctest.c > ${TMPCC} 2>&1 + cc_result=$? + egrep "${WARN_REGEXP}" ${TMPCC} > /dev/null 2>&1 + grep_result=$? + + if [ $cc_result = 0 -a $grep_result != 0 ] ; then + const=__const + else + const= + fi fi @@ -768,4 +777,61 @@ # + # check bcopy return value and length + # + rm -f ${TMPDEF} + for bcopyvoid in "" -DBCOPYVOID + do + for bcopysize in $sizetype int + do + # + # compile the test module + # + $cc -DMEMDATA="$datatype" $bcopyvoid \ + -DBCOPYSIZE="$bcopysize" \ + -DCONST="$const" -DBCOPY_COMPILETEST \ + $fileinc -c cctest.c >${TMPCC} 2>&1 + result=$? + if [ $debug -gt 10 ]; then + cat ${TMPCC} + fi + if [ $result = 0 ]; then + egrep "${WARN_REGEXP}" ${TMPCC} > /dev/null 2>&1 + if [ $? != 0 ]; then + if [ "x$bcopyvoid" = x ]; then + echo "#undef BCOPYVOID" > ${TMPDEF} + else + echo "#define BCOPYVOID 1" > ${TMPDEF} + fi + echo "#define BCOPYSIZE $bcopysize" >> ${TMPDEF} + break + fi + fi + + done + + if [ -s ${TMPDEF} ]; then + break + fi + done + + if [ ! -s ${TMPDEF} ]; then + # + # guess at what the correct settings should be; just + # default to the same as memcpy(). + + echo "${SP}Couldn't determine the correct settings for return value" + echo "${SP} and sizetype parameters for bcopy, etc. functions, I will" + echo "${SP} guess that it returns $datatype and sizetyep is $sizetype" + + # + # put the guesses into the tmpdef file and flag them as a guess + # + echo "#undef BCOPYVOID /* *GUESS* */" > ${TMPDEF} + echo "#define BCOPYSIZE $sizetype /* *GUESS* */" >> ${TMPDEF} + fi + + cat < ${TMPDEF} >> ${TMPSET} + + # # check memory comparison setting # @@ -925,20 +991,24 @@ for sizetype in size_t "unsigned int" int long "unsigned long" do - # - # compile the test module - # - $cc -DWRTSIZE="$sizetype" $fileinc -DCONST="$const" \ - ${USE_UNISTD} ${USE_STDLIB} \ - -DWRT_COMPILETEST -c cctest.c >${TMPCC} 2>&1 - - if [ $? = 0 ]; then - if egrep "${WARN_REGEXP}" ${TMPCC} >/dev/null; then - rm ${TMPCC}; - else - echo "#define WRTSIZE $sizetype" > ${TMPDEF} - break + for datatype in char void + do + # + # compile the test module + # + $cc -DWRTSIZE="$sizetype" \ + -DWRTDATA="$datatype" $fileinc \ + -DCONST="$const" ${USE_UNISTD} ${USE_STDLIB} \ + -DWRT_COMPILETEST -c cctest.c >${TMPCC} 2>&1 + + if [ $? = 0 ]; then + if egrep "${WARN_REGEXP}" ${TMPCC} >/dev/null; then + rm ${TMPCC}; + else + echo "#define WRTSIZE $sizetype" > ${TMPDEF} + break + fi fi - fi + done done done @@ -958,5 +1028,5 @@ # put the guesses into the tmpdef file and flag them as a guess # - echo "#define WRTSIZE $siztype /* *GUESS* */" > ${TMPDEF} + echo "#define WRTSIZE $sizetype /* *GUESS* */" > ${TMPDEF} fi --- Makefile 1995/12/13 12:54:37 1.1 +++ Makefile 1995/12/13 13:57:40 @@ -81,7 +81,7 @@ INSTDIR=$(DESTDIR)/usr/local LIBINSTDIR=$(INSTDIR)/lib -INCINSTDIR=$(INSTDIR)/debug_include +INCINSTDIR=$(INSTDIR)/include/debug MANINSTDIR=$(INSTDIR)/man/man3 -RANLIB=/usr/local/bin/ranlib +RANLIB=/usr/bin/ranlib MANINSTNAME=dbmalloc.3 MANINSTVER=malloc.3 @@ -298,5 +298,5 @@ cp /dev/null prototypes.h $(CPROTO) -Dforce_cproto_to_use_defines -D__STDC__ \ - -DDONT_USE_ASM -m__stdcargs -f4 $(LIBSRCS) \ + -DDONT_USE_ASM -m -M__stdcargs -f3 $(LIBSRCS) \ | sed -e "s/const/CONST/g" > prototypes.new mv prototypes.new prototypes.h --- cctest.c 1995/12/13 13:09:36 1.1 +++ cctest.c 1995/12/13 14:17:51 @@ -267,4 +267,6 @@ #ifdef FREE_COMPILETEST +#include + #if __cplusplus FREETYPE free( DATATYPE *data) @@ -316,4 +318,34 @@ #endif /* MEM_COMPILETEST */ +#ifdef BCOPY_COMPILETEST + +#ifdef BCOPYVOID +#define BCOPYRETVAL void +#define BCOPYRETURN +#else +#define BCOPYRETVAL MEMDATA * +#define BCOPYRETURN return +#endif + +BCOPYRETVAL bcopy __stdcargs((CONST MEMDATA *ptr1, MEMDATA *ptr2, BCOPYSIZE len)); + +#if __cplusplus +BCOPYRETVAL memccpy( + CONST MEMDATA * ptr1, + MEMDATA * ptr2, + BCOPYSIZE len ) +#else +BCOPYRETVAL +bcopy(ptr1,ptr2,len) + CONST MEMDATA * ptr1; + MEMDATA * ptr2; + BCOPYSIZE len; +#endif +{ + BCOPYRETURN memcpy(ptr2, ptr1, len); +} + +#endif /* BCOPY_COMPILETEST */ + #ifdef STR_COMPILETEST @@ -338,14 +370,14 @@ #ifdef WRT_COMPILETEST #if __cplusplus -int write(int fd, CONST char * buf, WRTSIZE size) +int write(int fd, CONST WRTDATA * buf, WRTSIZE size) #else int write(fd,buf,size) int fd; - CONST char * buf; + CONST WRTDATA * buf; WRTSIZE size; #endif { - if( buf[fd] == (CONST char) size) + if( ((CONST char *)buf)[fd] == (CONST char) size) { return(1); --- dgmalloc.c 1995/12/13 14:26:36 1.1 +++ dgmalloc.c 1995/12/13 14:28:42 @@ -68,19 +68,25 @@ } -MEMDATA * +#ifdef BCOPYVOID +#define BCOPYRETURN +#else +#define BCOPYRETURN return +#endif + +BCOPYRETVAL _bcopy(ptr2, ptr1, len) CONST MEMDATA * ptr2; MEMDATA * ptr1; - MEMSIZE len; + BCOPYSIZE len; { - return( DBbcopy((char *)NULL,0,ptr2,ptr1,len) ); + BCOPYRETURN DBbcopy((char *)NULL,0,ptr2,ptr1,len); } -MEMDATA * +BCOPYRETVAL _bzero(ptr1, len) MEMDATA * ptr1; - MEMSIZE len; + BCOPYSIZE len; { - return( DBbzero((char *)NULL,0,ptr1,len) ); + BCOPYRETURN DBbzero((char *)NULL,0,ptr1,len); } @@ -89,24 +95,24 @@ CONST MEMDATA * ptr1; CONST MEMDATA * ptr2; - MEMSIZE len; + BCOPYSIZE len; { return( DBbcmp((char *)NULL,0,ptr2, ptr1, len) ); } -MEMDATA * +BCOPYRETVAL __dg_bcopy(ptr2, ptr1, len) CONST MEMDATA * ptr2; MEMDATA * ptr1; - MEMSIZE len; + BCOPYSIZE len; { - return( DBbcopy((char *)NULL,0,ptr2,ptr1,len) ); + BCOPYRETURN DBbcopy((char *)NULL,0,ptr2,ptr1,len); } -MEMDATA * +BCOPYRETVAL __dg_bzero(ptr1, len) MEMDATA * ptr1; - MEMSIZE len; + BCOPYSIZE len; { - return( DBbzero((char *)NULL,0,ptr1,len) ); + BCOPYRETURN DBbzero((char *)NULL,0,ptr1,len); } @@ -115,5 +121,5 @@ CONST MEMDATA * ptr1; CONST MEMDATA * ptr2; - MEMSIZE len; + BCOPYSIZE len; { return( DBbcmp((char *)NULL,0,ptr2, ptr1, len) ); --- malloc.h.org 1995/12/13 13:33:44 1.1 +++ malloc.h.org 1995/12/13 14:25:43 @@ -32,4 +32,5 @@ typedef char MEMDATA; typedef int MEMSIZE; +typedef int BCOPYSIZE; typedef int STRSIZE; typedef int FREETYPE; @@ -83,4 +84,10 @@ #endif /* force_cproto_to_use_defines */ +#ifdef BCOPYVOID +typedef void BCOPYRETVAL; +#else +typedef MEMDATA * BCOPYRETVAL; +#endif + #define VOIDCAST (VOIDTYPE) @@ -285,12 +292,12 @@ MEMDATA * DBmemset __STDCARGS((CONST char *file, int line, MEMDATA *ptr1, int ch, MEMSIZE len)); -MEMDATA * DBbcopy __STDCARGS((CONST char *file, int line, +BCOPYRETVAL DBbcopy __STDCARGS((CONST char *file, int line, CONST MEMDATA *ptr2, MEMDATA *ptr1, - MEMSIZE len)); -MEMDATA * DBbzero __STDCARGS((CONST char *file, int line, - MEMDATA *ptr1, MEMSIZE len)); + BCOPYSIZE len)); +BCOPYRETVAL DBbzero __STDCARGS((CONST char *file, int line, + MEMDATA *ptr1, BCOPYSIZE len)); int DBbcmp __STDCARGS((CONST char *file, int line, CONST MEMDATA *ptr2, - CONST MEMDATA *ptr1, MEMSIZE len)); + CONST MEMDATA *ptr1, BCOPYSIZE len)); /* @@ -394,4 +401,7 @@ #ifdef bcmp #undef bcmp +#endif +#ifdef memccpy +#undef memccpy #endif #define memccpy(ptr1,ptr2,ch,len) DBmemccpy(__FILE__,__LINE__,ptr1,ptr2,ch,len) --- memory.c 1995/12/13 13:54:05 1.1 +++ memory.c 1995/12/13 14:30:12 @@ -288,19 +288,25 @@ } +#ifdef BCOPYVOID +#define BCOPYRETURN +#else +#define BCOPYRETURN return +#endif + #ifndef ibm032 /* * bcopy - copy memory block to another area */ -MEMDATA * +BCOPYRETVAL bcopy(ptr2,ptr1,len) CONST MEMDATA * ptr2; MEMDATA * ptr1; - MEMSIZE len; + BCOPYSIZE len; { - return( DBbcopy((char *)NULL,0,ptr2,ptr1,len) ); + BCOPYRETURN DBbcopy((char *)NULL,0,ptr2,ptr1,len); } #endif /* ibm032 */ -MEMDATA * +BCOPYRETVAL DBbcopy(file,line,ptr2,ptr1,len) CONST char * file; @@ -308,7 +314,7 @@ CONST MEMDATA * ptr2; MEMDATA * ptr1; - MEMSIZE len; + BCOPYSIZE len; { - return( DBFmemcpy("bcopy",file,line,ptr1,ptr2,len)); + BCOPYRETURN DBFmemcpy("bcopy",file,line,ptr1,ptr2,len); } @@ -316,20 +322,20 @@ * bzero - clear block of memory to zeros */ -MEMDATA * +BCOPYRETVAL bzero(ptr1,len) MEMDATA * ptr1; - MEMSIZE len; + BCOPYSIZE len; { - return( DBbzero((char *)NULL,0,ptr1,len) ); + BCOPYRETURN DBbzero((char *)NULL,0,ptr1,len); } -MEMDATA * +BCOPYRETVAL DBbzero(file,line,ptr1,len) CONST char * file; int line; MEMDATA * ptr1; - MEMSIZE len; + BCOPYSIZE len; { - return( DBFmemset("bzero",file,line,ptr1,'\0',len) ); + BCOPYRETURN DBFmemset("bzero",file,line,ptr1,'\0',len); } @@ -341,5 +347,5 @@ CONST MEMDATA * ptr1; CONST MEMDATA * ptr2; - MEMSIZE len; + BCOPYSIZE len; { return( DBbcmp((char *)NULL,0,ptr2, ptr1, len) ); @@ -352,5 +358,5 @@ CONST MEMDATA * ptr1; CONST MEMDATA * ptr2; - MEMSIZE len; + BCOPYSIZE len; { return( DBFmemcmp("bcmp",file,line,ptr1,ptr2,len) ); --- prototypes.h 1995/12/13 13:55:57 1.1 +++ prototypes.h 1995/12/13 14:30:31 @@ -1,6 +1,6 @@ -#if defined(__STDC__) || defined(__cplusplus) -# define __stdcargs(s) s +#if __STDC__ || defined(__cplusplus) +#define __stdcargs(s) s #else -# define __stdcargs(s) () +#define __stdcargs(s) () #endif @@ -30,10 +30,10 @@ void _free __stdcargs((DATATYPE *cptr)); int _mallopt __stdcargs((int cmd, union dbmalloptarg value)); -MEMDATA *_bcopy __stdcargs((CONST MEMDATA *ptr2, MEMDATA *ptr1, MEMSIZE len)); -MEMDATA *_bzero __stdcargs((MEMDATA *ptr1, MEMSIZE len)); -int _bcmp __stdcargs((CONST MEMDATA *ptr2, CONST MEMDATA *ptr1, MEMSIZE len)); -MEMDATA *__dg_bcopy __stdcargs((CONST MEMDATA *ptr2, MEMDATA *ptr1, MEMSIZE len)); -MEMDATA *__dg_bzero __stdcargs((MEMDATA *ptr1, MEMSIZE len)); -int __dg_bcmp __stdcargs((CONST MEMDATA *ptr2, CONST MEMDATA *ptr1, MEMSIZE len)); +BCOPYRETVAL _bcopy __stdcargs((CONST MEMDATA *ptr2, MEMDATA *ptr1, BCOPYSIZE len)); +BCOPYRETVAL _bzero __stdcargs((MEMDATA *ptr1, BCOPYSIZE len)); +int _bcmp __stdcargs((CONST MEMDATA *ptr2, CONST MEMDATA *ptr1, BCOPYSIZE len)); +BCOPYRETVAL __dg_bcopy __stdcargs((CONST MEMDATA *ptr2, MEMDATA *ptr1, BCOPYSIZE len)); +BCOPYRETVAL __dg_bzero __stdcargs((MEMDATA *ptr1, BCOPYSIZE len)); +int __dg_bcmp __stdcargs((CONST MEMDATA *ptr2, CONST MEMDATA *ptr1, BCOPYSIZE len)); /* fill.c */ VOIDTYPE FillInit __stdcargs((void)); @@ -123,10 +123,10 @@ MEMDATA *DBmemset __stdcargs((CONST char *file, int line, MEMDATA *ptr1, register int ch, register MEMSIZE len)); MEMDATA *DBFmemset __stdcargs((CONST char *func, CONST char *file, int line, MEMDATA *ptr1, register int ch, register MEMSIZE len)); -MEMDATA *bcopy __stdcargs((CONST MEMDATA *ptr2, MEMDATA *ptr1, MEMSIZE len)); -MEMDATA *DBbcopy __stdcargs((CONST char *file, int line, CONST MEMDATA *ptr2, MEMDATA *ptr1, MEMSIZE len)); -MEMDATA *bzero __stdcargs((MEMDATA *ptr1, MEMSIZE len)); -MEMDATA *DBbzero __stdcargs((CONST char *file, int line, MEMDATA *ptr1, MEMSIZE len)); -int bcmp __stdcargs((CONST MEMDATA *ptr2, CONST MEMDATA *ptr1, MEMSIZE len)); -int DBbcmp __stdcargs((CONST char *file, int line, CONST MEMDATA *ptr2, CONST MEMDATA *ptr1, MEMSIZE len)); +BCOPYRETVAL bcopy __stdcargs((CONST MEMDATA *ptr2, MEMDATA *ptr1, BCOPYSIZE len)); +BCOPYRETVAL DBbcopy __stdcargs((CONST char *file, int line, CONST MEMDATA *ptr2, MEMDATA *ptr1, BCOPYSIZE len)); +BCOPYRETVAL bzero __stdcargs((MEMDATA *ptr1, BCOPYSIZE len)); +BCOPYRETVAL DBbzero __stdcargs((CONST char *file, int line, MEMDATA *ptr1, BCOPYSIZE len)); +int bcmp __stdcargs((CONST MEMDATA *ptr2, CONST MEMDATA *ptr1, BCOPYSIZE len)); +int DBbcmp __stdcargs((CONST char *file, int line, CONST MEMDATA *ptr2, CONST MEMDATA *ptr1, BCOPYSIZE len)); /* tostring.c */ int tostring __stdcargs((char *buf, unsigned long val, int len, int base, int fill)); @@ -160,4 +160,5 @@ void XtFree __stdcargs((char *ptr)); void debug_XtFree __stdcargs((CONST char *file, int line, char *ptr)); +void NeverCalledFunctionFromAnywhere __stdcargs((void)); /* xheap.c */ void _XtHeapInit __stdcargs((Heap *heap)); --- string.c 1995/12/13 13:31:49 1.1 +++ string.c 1995/12/13 13:32:28 @@ -152,5 +152,5 @@ in_string_code++; - rtn = str2 = malloc((SIZETYPE)strlen(str1)+1); + rtn = str2 = debug_malloc(file, line, (SIZETYPE)strlen(str1)+1); in_string_code--;