home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-04-05 | 75.2 KB | 2,168 lines |
- Newsgroups: comp.sources.unix
- From: gray@antaire.com (Gray Watson)
- Subject: v26i100: malloc - debugging version of malloc, V1.2.0, Part03/05
- Sender: unix-sources-moderator@vix.com
- Approved: paul@vix.com
-
- Submitted-By: gray@antaire.com (Gray Watson)
- Posting-Number: Volume 26, Issue 100
- Archive-Name: malloc-1.2.0/part03
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 3 (of 5)."
- # Contents: configure error.c error.h error_str.h error_val.h
- # malloc.info
- # Wrapped by gray@toaster.antaire.com on Tue Apr 6 01:24:06 1993
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'configure' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'configure'\"
- else
- echo shar: Extracting \"'configure'\" \(16715 characters\)
- sed "s/^X//" >'configure' <<'END_OF_FILE'
- X#!/bin/sh
- X# Guess values for system-dependent variables and create Makefiles.
- X# Generated automatically using autoconf.
- X# Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
- X
- X# This program is free software; you can redistribute it and/or modify
- X# it under the terms of the GNU General Public License as published by
- X# the Free Software Foundation; either version 2, or (at your option)
- X# any later version.
- X
- X# This program is distributed in the hope that it will be useful,
- X# but WITHOUT ANY WARRANTY; without even the implied warranty of
- X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X# GNU General Public License for more details.
- X
- X# You should have received a copy of the GNU General Public License
- X# along with this program; if not, write to the Free Software
- X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X
- X# Usage: configure [--srcdir=DIR] [--host=HOST] [--gas] [--nfp] [--no-create]
- X# [--prefix=PREFIX] [--exec-prefix=PREFIX] [--with-PACKAGE] [TARGET]
- X# Ignores all args except --srcdir, --prefix, --exec-prefix, --no-create, and
- X# --with-PACKAGE unless this script has special code to handle it.
- X
- X
- Xfor arg
- Xdo
- X # Handle --exec-prefix with a space before the argument.
- X if test x$next_exec_prefix = xyes; then exec_prefix=$arg; next_exec_prefix=
- X # Handle --host with a space before the argument.
- X elif test x$next_host = xyes; then next_host=
- X # Handle --prefix with a space before the argument.
- X elif test x$next_prefix = xyes; then prefix=$arg; next_prefix=
- X # Handle --srcdir with a space before the argument.
- X elif test x$next_srcdir = xyes; then srcdir=$arg; next_srcdir=
- X else
- X case $arg in
- X # For backward compatibility, also recognize exact --exec_prefix.
- X -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* | --exec=* | --exe=* | --ex=* | --e=*)
- X exec_prefix=`echo $arg | sed 's/[-a-z_]*=//'` ;;
- X -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- | --exec | --exe | --ex | --e)
- X next_exec_prefix=yes ;;
- X
- X -gas | --gas | --ga | --g) ;;
- X
- X -host=* | --host=* | --hos=* | --ho=* | --h=*) ;;
- X -host | --host | --hos | --ho | --h)
- X next_host=yes ;;
- X
- X -nfp | --nfp | --nf) ;;
- X
- X -no-create | --no-create | --no-creat | --no-crea | --no-cre | --no-cr | --no-c | --no- | --no)
- X no_create=1 ;;
- X
- X -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
- X prefix=`echo $arg | sed 's/[-a-z_]*=//'` ;;
- X -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
- X next_prefix=yes ;;
- X
- X -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=* | --s=*)
- X srcdir=`echo $arg | sed 's/[-a-z_]*=//'` ;;
- X -srcdir | --srcdir | --srcdi | --srcd | --src | --sr | --s)
- X next_srcdir=yes ;;
- X
- X -with-* | --with-*)
- X package=`echo $arg|sed 's/-*with-//'`
- X # Delete all the valid chars; see if any are left.
- X if test -n "`echo $package|sed 's/[-a-zA-Z0-9_]*//g'`"; then
- X echo "configure: $package: invalid package name" >&2; exit 1
- X fi
- X eval "with_`echo $package|sed s/-/_/g`=1" ;;
- X
- X *) ;;
- X esac
- X fi
- Xdone
- X
- Xtrap 'rm -f conftest* core; exit 1' 1 3 15
- X
- Xrm -f conftest*
- Xcompile='${CC-cc} $DEFS conftest.c -o conftest $LIBS >/dev/null 2>&1'
- X
- X# A filename unique to this package, relative to the directory that
- X# configure is in, which we can look for to find out if srcdir is correct.
- Xunique_file=malloc.c
- X
- X# Find the source files, if location was not specified.
- Xif test -z "$srcdir"; then
- X srcdirdefaulted=yes
- X # Try the directory containing this script, then `..'.
- X prog=$0
- X confdir=`echo $prog|sed 's%/[^/][^/]*$%%'`
- X test "X$confdir" = "X$prog" && confdir=.
- X srcdir=$confdir
- X if test ! -r $srcdir/$unique_file; then
- X srcdir=..
- X fi
- Xfi
- Xif test ! -r $srcdir/$unique_file; then
- X if test x$srcdirdefaulted = xyes; then
- X echo "configure: Can not find sources in \`${confdir}' or \`..'." 1>&2
- X else
- X echo "configure: Can not find sources in \`${srcdir}'." 1>&2
- X fi
- X exit 1
- Xfi
- X# Preserve a srcdir of `.' to avoid automounter screwups with pwd.
- X# But we can't avoid them for `..', to make subdirectories work.
- Xcase $srcdir in
- X .|/*|~*) ;;
- X *) srcdir=`cd $srcdir; pwd` ;; # Make relative path absolute.
- Xesac
- X
- X
- Xecho Configuring for the malloc-debug library
- Xecho .
- Xecho checking programs:
- Xif test -z "$CC"; then
- X echo checking for gcc
- X saveifs="$IFS"; IFS="${IFS}:"
- X for dir in $PATH; do
- X test -z "$dir" && dir=.
- X if test -f $dir/gcc; then
- X CC="gcc"
- X break
- X fi
- X done
- X IFS="$saveifs"
- Xfi
- Xtest -z "$CC" && CC="cc"
- X
- X# Find out if we are using GNU C, under whatever name.
- Xcat > conftest.c <<EOF
- X#ifdef __GNUC__
- X yes
- X#endif
- XEOF
- X${CC-cc} -E conftest.c > conftest.out 2>&1
- Xif egrep yes conftest.out >/dev/null 2>&1; then
- X GCC=1 # For later tests.
- Xfi
- Xrm -f conftest*
- X
- X# Make sure to not get the incompatible SysV /etc/install and
- X# /usr/sbin/install, which might be in PATH before a BSD-like install,
- X# or the SunOS /usr/etc/install directory, or the AIX /bin/install,
- X# or the AFS install, which mishandles nonexistent args. (Sigh.)
- Xif test -z "$INSTALL"; then
- X echo checking for install
- X saveifs="$IFS"; IFS="${IFS}:"
- X for dir in $PATH; do
- X test -z "$dir" && dir=.
- X case $dir in
- X /etc|/usr/sbin|/usr/etc|/usr/afsws/bin) ;;
- X *)
- X if test -f $dir/install; then
- X if grep dspmsg $dir/install >/dev/null 2>&1; then
- X : # AIX
- X else
- X INSTALL="$dir/install -c"
- X INSTALL_PROGRAM='$(INSTALL)'
- X INSTALL_DATA='$(INSTALL) -m 644'
- X break
- X fi
- X fi
- X ;;
- X esac
- X done
- X IFS="$saveifs"
- Xfi
- XINSTALL=${INSTALL-cp}
- XINSTALL_PROGRAM=${INSTALL_PROGRAM-'$(INSTALL)'}
- XINSTALL_DATA=${INSTALL_DATA-'$(INSTALL)'}
- X
- Xif test -z "$RANLIB"; then
- X echo checking for ranlib
- X saveifs="$IFS"; IFS="${IFS}:"
- X for dir in $PATH; do
- X test -z "$dir" && dir=.
- X if test -f $dir/ranlib; then
- X RANLIB="ranlib"
- X break
- X fi
- X done
- X IFS="$saveifs"
- Xfi
- Xtest -z "$RANLIB" && RANLIB="@:"
- X
- Xecho .
- Xecho checking functions:
- Xfor func in bcmp bcopy memcmp memcpy memset
- Xdo
- Xtrfunc=HAVE_`echo $func | tr '[a-z]' '[A-Z]'`
- Xecho checking for ${func}
- Xcat > conftest.c <<EOF
- X#include <stdio.h>
- Xmain() { exit(0); }
- Xt() {
- X#ifdef __stub_${func}
- Xchoke me
- X#else
- X/* Override any gcc2 internal prototype to avoid an error. */
- Xextern char ${func}(); ${func}();
- X#endif
- X }
- XEOF
- Xif eval $compile; then
- X DEFS="$DEFS -D${trfunc}=1"
- XSEDDEFS="${SEDDEFS}\${SEDdA}${trfunc}\${SEDdB}${trfunc}\${SEDdC}1\${SEDdD}
- X\${SEDuA}${trfunc}\${SEDuB}${trfunc}\${SEDuC}1\${SEDuD}
- X\${SEDeA}${trfunc}\${SEDeB}${trfunc}\${SEDeC}1\${SEDeD}
- X"
- Xfi
- Xrm -f conftest*
- X#endif
- Xdone
- X
- Xecho checking for _index
- Xcat > conftest.c <<EOF
- X
- Xmain() { exit(0); }
- Xt() {
- X#ifdef __stub_index
- Xchoke me
- X#else
- X/* Override any gcc2 internal prototype to avoid an error. */
- Xextern char index(); index();
- X#endif
- X }
- X
- XEOF
- Xeval $compile
- Xif test -s conftest && (./conftest; exit) 2>/dev/null; then
- X
- XDEFS="$DEFS -DHAVE_INDEX=1"
- XSEDDEFS="${SEDDEFS}\${SEDdA}HAVE_INDEX\${SEDdB}HAVE_INDEX\${SEDdC}1\${SEDdD}
- X\${SEDuA}HAVE_INDEX\${SEDuB}HAVE_INDEX\${SEDuC}1\${SEDuD}
- X\${SEDeA}HAVE_INDEX\${SEDeB}HAVE_INDEX\${SEDeC}1\${SEDeD}
- X"
- X
- Xelse
- X
- XDEFS="$DEFS -DHAVE_INDEX=0"
- XSEDDEFS="${SEDDEFS}\${SEDdA}HAVE_INDEX\${SEDdB}HAVE_INDEX\${SEDdC}0\${SEDdD}
- X\${SEDuA}HAVE_INDEX\${SEDuB}HAVE_INDEX\${SEDuC}0\${SEDuD}
- X\${SEDeA}HAVE_INDEX\${SEDeB}HAVE_INDEX\${SEDeC}0\${SEDeD}
- X"
- X
- Xfi
- Xrm -f conftest*
- Xfor func in rindex
- Xdo
- Xtrfunc=HAVE_`echo $func | tr '[a-z]' '[A-Z]'`
- Xecho checking for ${func}
- Xcat > conftest.c <<EOF
- X#include <stdio.h>
- Xmain() { exit(0); }
- Xt() {
- X#ifdef __stub_${func}
- Xchoke me
- X#else
- X/* Override any gcc2 internal prototype to avoid an error. */
- Xextern char ${func}(); ${func}();
- X#endif
- X }
- XEOF
- Xif eval $compile; then
- X DEFS="$DEFS -D${trfunc}=1"
- XSEDDEFS="${SEDDEFS}\${SEDdA}${trfunc}\${SEDdB}${trfunc}\${SEDdC}1\${SEDdD}
- X\${SEDuA}${trfunc}\${SEDuB}${trfunc}\${SEDuC}1\${SEDuD}
- X\${SEDeA}${trfunc}\${SEDeB}${trfunc}\${SEDeC}1\${SEDeD}
- X"
- Xfi
- Xrm -f conftest*
- X#endif
- Xdone
- X
- Xfor func in strcat strcmp strlen strtok
- Xdo
- Xtrfunc=HAVE_`echo $func | tr '[a-z]' '[A-Z]'`
- Xecho checking for ${func}
- Xcat > conftest.c <<EOF
- X#include <stdio.h>
- Xmain() { exit(0); }
- Xt() {
- X#ifdef __stub_${func}
- Xchoke me
- X#else
- X/* Override any gcc2 internal prototype to avoid an error. */
- Xextern char ${func}(); ${func}();
- X#endif
- X }
- XEOF
- Xif eval $compile; then
- X DEFS="$DEFS -D${trfunc}=1"
- XSEDDEFS="${SEDDEFS}\${SEDdA}${trfunc}\${SEDdB}${trfunc}\${SEDdC}1\${SEDdD}
- X\${SEDuA}${trfunc}\${SEDuB}${trfunc}\${SEDuC}1\${SEDuD}
- X\${SEDeA}${trfunc}\${SEDeB}${trfunc}\${SEDeC}1\${SEDeD}
- X"
- Xfi
- Xrm -f conftest*
- X#endif
- Xdone
- X
- Xecho .
- Xecho checking various functions for string checking
- Xfor func in bzero
- Xdo
- Xtrfunc=HAVE_`echo $func | tr '[a-z]' '[A-Z]'`
- Xecho checking for ${func}
- Xcat > conftest.c <<EOF
- X#include <stdio.h>
- Xmain() { exit(0); }
- Xt() {
- X#ifdef __stub_${func}
- Xchoke me
- X#else
- X/* Override any gcc2 internal prototype to avoid an error. */
- Xextern char ${func}(); ${func}();
- X#endif
- X }
- XEOF
- Xif eval $compile; then
- X DEFS="$DEFS -D${trfunc}=1"
- XSEDDEFS="${SEDDEFS}\${SEDdA}${trfunc}\${SEDdB}${trfunc}\${SEDdC}1\${SEDdD}
- X\${SEDuA}${trfunc}\${SEDuB}${trfunc}\${SEDuC}1\${SEDuD}
- X\${SEDeA}${trfunc}\${SEDeB}${trfunc}\${SEDeC}1\${SEDeD}
- X"
- Xfi
- Xrm -f conftest*
- X#endif
- Xdone
- X
- Xfor func in memccpy memchr
- Xdo
- Xtrfunc=HAVE_`echo $func | tr '[a-z]' '[A-Z]'`
- Xecho checking for ${func}
- Xcat > conftest.c <<EOF
- X#include <stdio.h>
- Xmain() { exit(0); }
- Xt() {
- X#ifdef __stub_${func}
- Xchoke me
- X#else
- X/* Override any gcc2 internal prototype to avoid an error. */
- Xextern char ${func}(); ${func}();
- X#endif
- X }
- XEOF
- Xif eval $compile; then
- X DEFS="$DEFS -D${trfunc}=1"
- XSEDDEFS="${SEDDEFS}\${SEDdA}${trfunc}\${SEDdB}${trfunc}\${SEDdC}1\${SEDdD}
- X\${SEDuA}${trfunc}\${SEDuB}${trfunc}\${SEDuC}1\${SEDuD}
- X\${SEDeA}${trfunc}\${SEDeB}${trfunc}\${SEDeC}1\${SEDeD}
- X"
- Xfi
- Xrm -f conftest*
- X#endif
- Xdone
- X
- Xfor func in strchr strrchr strcpy strncpy strcasecmp strncasecmp
- Xdo
- Xtrfunc=HAVE_`echo $func | tr '[a-z]' '[A-Z]'`
- Xecho checking for ${func}
- Xcat > conftest.c <<EOF
- X#include <stdio.h>
- Xmain() { exit(0); }
- Xt() {
- X#ifdef __stub_${func}
- Xchoke me
- X#else
- X/* Override any gcc2 internal prototype to avoid an error. */
- Xextern char ${func}(); ${func}();
- X#endif
- X }
- XEOF
- Xif eval $compile; then
- X DEFS="$DEFS -D${trfunc}=1"
- XSEDDEFS="${SEDDEFS}\${SEDdA}${trfunc}\${SEDdB}${trfunc}\${SEDdC}1\${SEDdD}
- X\${SEDuA}${trfunc}\${SEDuB}${trfunc}\${SEDuC}1\${SEDuD}
- X\${SEDeA}${trfunc}\${SEDeB}${trfunc}\${SEDeC}1\${SEDeD}
- X"
- Xfi
- Xrm -f conftest*
- X#endif
- Xdone
- X
- Xfor func in strspn strcspn strncat strncmp strpbrk strstr
- Xdo
- Xtrfunc=HAVE_`echo $func | tr '[a-z]' '[A-Z]'`
- Xecho checking for ${func}
- Xcat > conftest.c <<EOF
- X#include <stdio.h>
- Xmain() { exit(0); }
- Xt() {
- X#ifdef __stub_${func}
- Xchoke me
- X#else
- X/* Override any gcc2 internal prototype to avoid an error. */
- Xextern char ${func}(); ${func}();
- X#endif
- X }
- XEOF
- Xif eval $compile; then
- X DEFS="$DEFS -D${trfunc}=1"
- XSEDDEFS="${SEDDEFS}\${SEDdA}${trfunc}\${SEDdB}${trfunc}\${SEDdC}1\${SEDdD}
- X\${SEDuA}${trfunc}\${SEDuB}${trfunc}\${SEDuC}1\${SEDuD}
- X\${SEDeA}${trfunc}\${SEDeB}${trfunc}\${SEDeC}1\${SEDeD}
- X"
- Xfi
- Xrm -f conftest*
- X#endif
- Xdone
- X
- Xecho .
- Xecho PLEASE WATCH: checking for very important functionality:
- Xfor func in sbrk
- Xdo
- Xtrfunc=HAVE_`echo $func | tr '[a-z]' '[A-Z]'`
- Xecho checking for ${func}
- Xcat > conftest.c <<EOF
- X#include <stdio.h>
- Xmain() { exit(0); }
- Xt() {
- X#ifdef __stub_${func}
- Xchoke me
- X#else
- X/* Override any gcc2 internal prototype to avoid an error. */
- Xextern char ${func}(); ${func}();
- X#endif
- X }
- XEOF
- Xif eval $compile; then
- X DEFS="$DEFS -D${trfunc}=1"
- XSEDDEFS="${SEDDEFS}\${SEDdA}${trfunc}\${SEDdB}${trfunc}\${SEDdC}1\${SEDdD}
- X\${SEDuA}${trfunc}\${SEDuB}${trfunc}\${SEDuC}1\${SEDuD}
- X\${SEDeA}${trfunc}\${SEDeB}${trfunc}\${SEDeC}1\${SEDeD}
- X"
- Xfi
- Xrm -f conftest*
- X#endif
- Xdone
- X
- Xecho checking for heap ordering...
- Xcat > conftest.c <<EOF
- X
- Xmain()
- X{
- X char * first, *next;
- X first = sbrk(1024);
- X next = sbrk(1024);
- X if (next > first)
- X exit(0);
- X else
- X exit(1);
- X}
- X
- XEOF
- Xeval $compile
- Xif test -s conftest && (./conftest; exit) 2>/dev/null; then
- X
- XDEFS="$DEFS -DHEAP_GROWS_UP=1"
- XSEDDEFS="${SEDDEFS}\${SEDdA}HEAP_GROWS_UP\${SEDdB}HEAP_GROWS_UP\${SEDdC}1\${SEDdD}
- X\${SEDuA}HEAP_GROWS_UP\${SEDuB}HEAP_GROWS_UP\${SEDuC}1\${SEDuD}
- X\${SEDeA}HEAP_GROWS_UP\${SEDeB}HEAP_GROWS_UP\${SEDeC}1\${SEDeD}
- X"
- Xecho ' FYI: your heap seems to grow up.'
- X
- Xelse
- X
- XDEFS="$DEFS -DHEAP_GROWS_UP=0"
- XSEDDEFS="${SEDDEFS}\${SEDdA}HEAP_GROWS_UP\${SEDdB}HEAP_GROWS_UP\${SEDdC}0\${SEDdD}
- X\${SEDuA}HEAP_GROWS_UP\${SEDuB}HEAP_GROWS_UP\${SEDuC}0\${SEDuD}
- X\${SEDeA}HEAP_GROWS_UP\${SEDeB}HEAP_GROWS_UP\${SEDeC}0\${SEDeD}
- X"
- Xecho ' FYI: your heap seems to grow down.'
- Xecho ' WARNING: the library has little support for this.'
- X
- Xfi
- Xrm -f conftest*
- Xecho .
- Xif test -n "$prefix"; then
- X test -z "$exec_prefix" && exec_prefix='${prefix}'
- X prsub="s%^prefix\\([ ]*\\)=\\([ ]*\\).*$%prefix\\1=\\2$prefix%"
- Xfi
- Xif test -n "$exec_prefix"; then
- X prsub="$prsub
- Xs%^exec_prefix\\([ ]*\\)=\\([ ]*\\).*$%\
- Xexec_prefix\\1=\\2$exec_prefix%"
- Xfi
- X
- Xtrap 'rm -f config.status; exit 1' 1 3 15
- Xecho creating config.status
- Xrm -f config.status
- Xcat > config.status <<EOF
- X#!/bin/sh
- X# Generated automatically by configure.
- X# Run this file to recreate the current configuration.
- X# This directory was configured as follows,
- X# on host `(hostname || uname -n) 2>/dev/null`:
- X#
- X# $0 $*
- X
- Xfor arg
- Xdo
- X case "\$arg" in
- X -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
- X exec /bin/sh $0 $* ;;
- X *) echo "Usage: config.status --recheck" 2>&1; exit 1 ;;
- X esac
- Xdone
- X
- Xtrap 'rm -f Makefile conf.h conftest*; exit 1' 1 3 15
- XCC='$CC'
- XINSTALL='$INSTALL'
- XINSTALL_PROGRAM='$INSTALL_PROGRAM'
- XINSTALL_DATA='$INSTALL_DATA'
- XRANLIB='$RANLIB'
- XLIBS='$LIBS'
- Xsrcdir='$srcdir'
- Xprefix='$prefix'
- Xexec_prefix='$exec_prefix'
- Xprsub='$prsub'
- XEOF
- Xcat >> config.status <<\EOF
- X
- Xtop_srcdir=$srcdir
- Xfor file in .. Makefile; do if [ "x$file" != "x.." ]; then
- X srcdir=$top_srcdir
- X # Remove last slash and all that follows it. Not all systems have dirname.
- X dir=`echo $file|sed 's%/[^/][^/]*$%%'`
- X if test "$dir" != "$file"; then
- X test "$top_srcdir" != . && srcdir=$top_srcdir/$dir
- X test ! -d $dir && mkdir $dir
- X fi
- X echo creating $file
- X rm -f $file
- X echo "# Generated automatically from `echo $file|sed 's|.*/||'`.in by configure." > $file
- X sed -e "
- X$prsub
- Xs%@CC@%$CC%g
- Xs%@INSTALL@%$INSTALL%g
- Xs%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g
- Xs%@INSTALL_DATA@%$INSTALL_DATA%g
- Xs%@RANLIB@%$RANLIB%g
- Xs%@LIBS@%$LIBS%g
- Xs%@srcdir@%$srcdir%g
- Xs%@DEFS@%-DHAVE_CONFIG_H%" $top_srcdir/${file}.in >> $file
- Xfi; done
- X
- Xecho creating conf.h
- X# These sed commands are put into SEDDEFS when defining a macro.
- X# They are broken into pieces to make the sed script easier to manage.
- X# They are passed to sed as "A NAME B NAME C VALUE D", where NAME
- X# is the cpp macro being defined and VALUE is the value it is being given.
- X# Each defining turns into a single global substitution command.
- X#
- X# SEDd sets the value in "#define NAME VALUE" lines.
- XSEDdA='s@^\([ ]*\)#\([ ]*define[ ][ ]*\)'
- XSEDdB='\([ ][ ]*\)[^ ]*@\1#\2'
- XSEDdC='\3'
- XSEDdD='@g'
- X# SEDu turns "#undef NAME" with trailing blanks into "#define NAME VALUE".
- XSEDuA='s@^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)'
- XSEDuB='\([ ]\)@\1#\2define\3'
- XSEDuC=' '
- XSEDuD='\4@g'
- X# SEDe turns "#undef NAME" without trailing blanks into "#define NAME VALUE".
- XSEDeA='s@^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)'
- XSEDeB='$@\1#\2define\3'
- XSEDeC=' '
- XSEDeD='@g'
- Xrm -f conftest.sed
- Xcat > conftest.sed <<CONFEOF
- XEOF
- X# Turn off quoting long enough to insert the sed commands.
- Xcat >> config.status <<EOF
- X$SEDDEFS
- XEOF
- Xcat >> config.status <<\EOF
- XCONFEOF
- Xrm -f conftest.h
- X# Break up the sed commands because old seds have small limits.
- Xcp $top_srcdir/conf.h.in conftest.h1
- Xwhile :
- Xdo
- X lines=`grep -c . conftest.sed`
- X if test -z "$lines" || test "$lines" -eq 0; then break; fi
- X rm -f conftest.s1 conftest.s2 conftest.h2
- X sed 40q conftest.sed > conftest.s1 # Like head -40.
- X sed 1,40d conftest.sed > conftest.s2 # Like tail +41.
- X sed -f conftest.s1 < conftest.h1 > conftest.h2
- X rm -f conftest.s1 conftest.h1 conftest.sed
- X mv conftest.h2 conftest.h1
- X mv conftest.s2 conftest.sed
- Xdone
- Xrm -f conftest.sed conftest.h
- Xecho "/* conf.h. Generated automatically by configure. */" > conftest.h
- Xcat conftest.h1 >> conftest.h
- Xrm -f conftest.h1
- Xif cmp -s conf.h conftest.h 2>/dev/null; then
- X # The file exists and we would not be changing it.
- X rm -f conftest.h
- Xelse
- X rm -f conf.h
- X mv conftest.h conf.h
- Xfi
- X
- XEOF
- Xchmod +x config.status
- Xtest -n "$no_create" || ./config.status
- X
- Xecho .
- Xecho Done!!
- Xecho created conf.h and Makefile.
- Xecho Please check-out Makefile and especially conf.h to make sure that
- Xecho sane configuration values were a result.
- END_OF_FILE
- if test 16715 -ne `wc -c <'configure'`; then
- echo shar: \"'configure'\" unpacked with wrong size!
- fi
- chmod +x 'configure'
- # end of 'configure'
- fi
- if test -f 'error.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'error.c'\"
- else
- echo shar: Extracting \"'error.c'\" \(3964 characters\)
- sed "s/^X//" >'error.c' <<'END_OF_FILE'
- X/*
- X * error and message routines
- X *
- X * Copyright 1992 by Gray Watson and the Antaire Corporation
- X *
- X * This file is part of the malloc-debug package.
- X *
- X * This library is free software; you can redistribute it and/or
- X * modify it under the terms of the GNU Library General Public
- X * License as published by the Free Software Foundation; either
- X * version 2 of the License, or (at your option) any later version.
- X *
- X * This library is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- X * Library General Public License for more details.
- X *
- X * You should have received a copy of the GNU Library General Public
- X * License along with this library (see COPYING-LIB); if not, write to the
- X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X *
- X * The author of the program may be contacted at gray.watson@antaire.com
- X */
- X
- X/*
- X * This file contains the routines needed for processing error codes
- X * produced by the compiler.
- X */
- X
- X#include <fcntl.h> /* for O_WRONLY, etc. */
- X#include <signal.h> /* for kill signals */
- X#include <stdarg.h> /* for message vsprintf */
- X
- X#define MALLOC_DEBUG_DISABLE
- X
- X#include "malloc.h"
- X#include "malloc_loc.h"
- X
- X#include "chunk.h"
- X#include "compat.h"
- X#include "conf.h"
- X#include "dbg_values.h"
- X#include "error.h"
- X
- X#if INCLUDE_RCS_IDS
- XLOCAL char *rcs_id =
- X "$Id: error.c,v 1.19 1993/04/05 22:30:07 gray Exp $";
- X#endif
- X
- X/*
- X * exported variables
- X */
- X/* global debug flags that are set my MALLOC_DEBUG environ variable */
- XEXPORT int _malloc_debug = 0;
- X
- X/*
- X * message writer with printf like arguments
- X */
- XEXPORT void _malloc_message(const char * format, ...)
- X{
- X static int outfile = -1;
- X int len;
- X char str[1024];
- X va_list args;
- X
- X /* no logpath then no workie */
- X if (malloc_logpath == NULL
- X && ! BIT_IS_SET(_malloc_debug, DEBUG_PRINT_PERROR))
- X return;
- X
- X /* write the format + info into str */
- X va_start(args, format);
- X (void)vsprintf(str, format, args);
- X va_end(args);
- X
- X /* find the length of str, if empty then return */
- X len = strlen(str);
- X if (len == 0)
- X return;
- X
- X /* tack on a '\n' if necessary */
- X if (str[len - 1] != '\n') {
- X str[len++] = '\n';
- X str[len] = NULLC;
- X }
- X
- X /* do we need to log the message? */
- X if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_PERROR) && malloc_logpath != NULL) {
- X /*
- X * do we need to open the outfile?
- X * it will be closed by _exit(). yeach.
- X */
- X if (outfile < 0) {
- X outfile = open(malloc_logpath, O_WRONLY | O_CREAT | O_TRUNC, 0666);
- X if (outfile < 0) {
- X (void)sprintf(str, "%s:%d: could not open '%s'\n",
- X __FILE__, __LINE__, malloc_logpath);
- X (void)write(STDERR, str, strlen(str));
- X exit(1);
- X }
- X }
- X
- X /* write str to the outfile */
- X (void)write(outfile, str, len);
- X }
- X
- X /* do we need to print the message? */
- X if (BIT_IS_SET(_malloc_debug, DEBUG_PRINT_PERROR)) {
- X (void)write(STDERR, str, strlen(str));
- X }
- X}
- X
- X/*
- X * kill the program because of an internal malloc error
- X */
- XEXPORT void _malloc_die(void)
- X{
- X /* do I need to drop core? */
- X if (BIT_IS_SET(_malloc_debug, DEBUG_ERROR_ABORT))
- X (void)kill(getpid(), SIGABRT);
- X
- X /*
- X * NOTE: this should not be exit() because fclose will free, etc
- X */
- X _exit(1);
- X}
- X
- X/*
- X * malloc version of perror of an error in STR
- X */
- XEXPORT void _malloc_perror(const char * func)
- X{
- X /* do we need to log or print the error? */
- X if ((BIT_IS_SET(_malloc_debug, DEBUG_LOG_PERROR) && malloc_logpath != NULL)
- X || BIT_IS_SET(_malloc_debug, DEBUG_PRINT_PERROR)) {
- X
- X /* default str value */
- X if (func == NULL)
- X func = "malloc_perror";
- X
- X /* print the malloc error message */
- X _malloc_message("ERROR: %s: %s(%d)",
- X func, malloc_strerror(malloc_errno), malloc_errno);
- X }
- X
- X /* do I need to abort? */
- X if (BIT_IS_SET(_malloc_debug, DEBUG_ERROR_ABORT))
- X _malloc_die();
- X}
- END_OF_FILE
- if test 3964 -ne `wc -c <'error.c'`; then
- echo shar: \"'error.c'\" unpacked with wrong size!
- fi
- # end of 'error.c'
- fi
- if test -f 'error.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'error.h'\"
- else
- echo shar: Extracting \"'error.h'\" \(1737 characters\)
- sed "s/^X//" >'error.h' <<'END_OF_FILE'
- X/*
- X * defines for the error and message code.
- X *
- X * Copyright 1992 by Gray Watson and the Antaire Corporation
- X *
- X * This file is part of the malloc-debug package.
- X *
- X * This library is free software; you can redistribute it and/or
- X * modify it under the terms of the GNU Library General Public
- X * License as published by the Free Software Foundation; either
- X * version 2 of the License, or (at your option) any later version.
- X *
- X * This library is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- X * Library General Public License for more details.
- X *
- X * You should have received a copy of the GNU Library General Public
- X * License along with this library (see COPYING-LIB); if not, write to the
- X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X *
- X * The author of the program may be contacted at gray.watson@antaire.com
- X *
- X * $Id: error.h,v 1.7 1993/04/05 22:30:08 gray Exp $
- X */
- X
- X#ifndef __ERROR_H__
- X#define __ERROR_H__
- X
- X#include <stdarg.h> /* for ... */
- X#include "malloc.h" /* for IMPORT */
- X
- X/*<<<<<<<<<< The below prototypes are auto-generated by fillproto */
- X
- X/* global debug flags that are set my MALLOC_DEBUG environ variable */
- XIMPORT int _malloc_debug;
- X
- X/*
- X * message writer with printf like arguments
- X */
- XIMPORT void _malloc_message(const char * format, ...);
- X
- X/*
- X * kill the program because of an internal malloc error
- X */
- XIMPORT void _malloc_die(void);
- X
- X/*
- X * malloc version of perror of an error in STR
- X */
- XIMPORT void _malloc_perror(const char * func);
- X
- X/*<<<<<<<<<< This is end of the auto-generated output from fillproto. */
- X
- X#endif /* ! __ERROR_H__ */
- END_OF_FILE
- if test 1737 -ne `wc -c <'error.h'`; then
- echo shar: \"'error.h'\" unpacked with wrong size!
- fi
- # end of 'error.h'
- fi
- if test -f 'error_str.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'error_str.h'\"
- else
- echo shar: Extracting \"'error_str.h'\" \(3288 characters\)
- sed "s/^X//" >'error_str.h' <<'END_OF_FILE'
- X/*
- X * array of error messages for the malloc internal errors.
- X *
- X * Copyright 1992 by Gray Watson and the Antaire Corporation
- X *
- X * This file is part of the malloc-debug package.
- X *
- X * This library is free software; you can redistribute it and/or
- X * modify it under the terms of the GNU Library General Public
- X * License as published by the Free Software Foundation; either
- X * version 2 of the License, or (at your option) any later version.
- X *
- X * This library is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- X * Library General Public License for more details.
- X *
- X * You should have received a copy of the GNU Library General Public
- X * License along with this library (see COPYING-LIB); if not, write to the
- X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X *
- X * The author of the program may be contacted at gray.watson@antaire.com
- X *
- X * $Id: error_str.h,v 1.5 1993/04/05 22:30:10 gray Exp $
- X */
- X
- X#ifndef __ERROR_STR_H__
- X#define __ERROR_STR_H__
- X
- X/* string error codes which apply to error codes in error_val.h */
- XLOCAL char *malloc_errlist[] = {
- X "no error",
- X
- X /* administrative errors */
- X "initialization sanity checks on setup values failed",
- X "malloc domain has been entered twice",
- X "errno value passed in by user is out-of-bounds",
- X
- X /* pointer verification errors */
- X "pointer is null",
- X "pointer is not pointing into the heap data space",
- X "cannot locate pointer in the heap",
- X "found pointer the user was looking for",
- X "possibly bad .c filename pointer",
- X "possibly bad .c file line-number",
- X "failed UNDER picket-fence magic-number checking",
- X "failed OVER picket-fence magic-number checking",
- X "pointer will exceed allocation",
- X
- X /* allocation errors */
- X "invalid allocation size",
- X "largest maximum allocation size exceeded",
- X "user allocated space contiguous block error",
- X "could allocate more memory, heap extension failed",
- X "bad size in information structure",
- X
- X /* free errors */
- X "pointer is not on a block boundary",
- X "tried to free pointer which is already freed",
- X "pointer does not point to start of user-allocated space",
- X "pointer does not point to user-allocated space",
- X "inconsistency with free linked-list",
- X "free space contiguous block error",
- X "bad basic-block memory pointer in the free-list",
- X "space that should be free has been overwritten",
- X
- X /* dblock errors */
- X "bad divided-block chunk size",
- X "bad divided-block pointer",
- X "bad basic-block memory pointer in dblock struct",
- X "bad divided-block admin pointer",
- X "bad divided-block admin magic numbers",
- X "bad divided-block chunk admin information structure",
- X
- X /* administrative errors */
- X "admin structure pointer out of bounds",
- X "bad admin structure list",
- X "bad magic number in admin structure",
- X "bad basic-block count value in admin structure",
- X "bad basic-block administration pointer",
- X "bad basic-block administration counter",
- X
- X /* heap check verification */
- X "bad basic-block allocation order",
- X "basic-block has bad flag value",
- X
- X "PROBLEM - BAD ERRNO VALUE",
- X "PROBLEM - BAD ERRNO VALUE",
- X "PROBLEM - BAD ERRNO VALUE",
- X};
- X
- X#endif /* ! __ERROR_STR_H__ */
- END_OF_FILE
- if test 3288 -ne `wc -c <'error_str.h'`; then
- echo shar: \"'error_str.h'\" unpacked with wrong size!
- fi
- # end of 'error_str.h'
- fi
- if test -f 'error_val.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'error_val.h'\"
- else
- echo shar: Extracting \"'error_val.h'\" \(3812 characters\)
- sed "s/^X//" >'error_val.h' <<'END_OF_FILE'
- X/*
- X * global error codes for chunk allocation problems
- X *
- X * Copyright 1992 by Gray Watson and the Antaire Corporation
- X *
- X * This file is part of the malloc-debug package.
- X *
- X * This library is free software; you can redistribute it and/or
- X * modify it under the terms of the GNU Library General Public
- X * License as published by the Free Software Foundation; either
- X * version 2 of the License, or (at your option) any later version.
- X *
- X * This library is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- X * Library General Public License for more details.
- X *
- X * You should have received a copy of the GNU Library General Public
- X * License along with this library (see COPYING-LIB); if not, write to the
- X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X *
- X * The author of the program may be contacted at gray.watson@antaire.com
- X *
- X * $Id: error_val.h,v 1.2 1993/04/05 22:30:12 gray Exp $
- X */
- X
- X#ifndef __ERROR_VAL_H__
- X#define __ERROR_VAL_H__
- X
- X/*
- X * malloc error codes
- X */
- X#define MALLOC_NO_ERROR 0 /* no error */
- X
- X/* administrative errors */
- X#define MALLOC_BAD_SETUP 1 /* bad setup value */
- X#define MALLOC_IN_TWICE 2 /* in malloc domain twice */
- X#define MALLOC_BAD_ERRNO 3 /* bad errno value */
- X
- X/* pointer verification errors */
- X#define MALLOC_POINTER_NULL 4 /* pointer is not in heap */
- X#define MALLOC_POINTER_NOT_IN_HEAP 5 /* pointer is not in heap */
- X#define MALLOC_POINTER_NOT_FOUND 6 /* pointer not-found */
- X#define MALLOC_POINTER_FOUND 7 /* found special pointer */
- X#define MALLOC_BAD_FILEP 8 /* bad bblock file-name */
- X#define MALLOC_BAD_LINE 9 /* bad bblock line-number */
- X#define MALLOC_UNDER_FENCE 10 /* failed picket fence lower */
- X#define MALLOC_OVER_FENCE 11 /* failed picket fence upper */
- X#define MALLOC_WOULD_OVERWRITE 12 /* would overwrite fence */
- X
- X/* allocation errors */
- X#define MALLOC_BAD_SIZE 13 /* bad bblock size value */
- X#define MALLOC_TOO_BIG 14 /* allocation too large */
- X#define MALLOC_USER_NON_CONTIG 15 /* user space contig error */
- X#define MALLOC_ALLOC_FAILED 16 /* could not get more space */
- X#define MALLOC_BAD_SIZE_INFO 17 /* info doesn't match size */
- X
- X/* free errors */
- X#define MALLOC_NOT_ON_BLOCK 18 /* not on block boundary */
- X#define MALLOC_ALREADY_FREE 19 /* already in free list */
- X#define MALLOC_NOT_START_USER 20 /* not start of user alloc */
- X#define MALLOC_NOT_USER 21 /* not user allocated */
- X#define MALLOC_BAD_FREE_LIST 22 /* free-list mess-up */
- X#define MALLOC_FREE_NON_CONTIG 23 /* free space contig error */
- X#define MALLOC_BAD_FREE_MEM 24 /* bad memory pointer */
- X#define MALLOC_FREE_NON_BLANK 25 /* free space should be 0's */
- X
- X/* dblock errors */
- X#define MALLOC_BAD_DBLOCK_SIZE 26 /* dblock bad size */
- X#define MALLOC_BAD_DBLOCK_POINTER 27 /* bad dblock pointer */
- X#define MALLOC_BAD_DBLOCK_MEM 28 /* bad memory pointer */
- X#define MALLOC_BAD_DBADMIN_POINTER 29 /* bad dblock admin pointer */
- X#define MALLOC_BAD_DBADMIN_MAGIC 30 /* bad dblock admin pointer */
- X#define MALLOC_BAD_DBADMIN_SLOT 31 /* bad dblock slot info */
- X
- X/* administrative errors */
- X#define MALLOC_BAD_ADMINP 32 /* out of bounds */
- X#define MALLOC_BAD_ADMIN_LIST 33 /* out of bounds */
- X#define MALLOC_BAD_ADMIN_MAGIC 34 /* bad magic numbers */
- X#define MALLOC_BAD_ADMIN_COUNT 35 /* bad count number */
- X#define MALLOC_BAD_BLOCK_ADMINP 36 /* bblock adminp bad */
- X#define MALLOC_BAD_BLOCK_ADMINC 37 /* bblock adminp->count bad */
- X
- X/* heap check verification */
- X#define MALLOC_BAD_BLOCK_ORDER 38 /* block allocation bad */
- X#define MALLOC_BAD_FLAG 39 /* bad basic-block flag */
- X
- X#define IS_MALLOC_ERRNO(e) ((e) >= MALLOC_NO_ERROR && \
- X (e) <= MALLOC_BAD_FLAG)
- X
- X#endif /* ! __ERROR_VAL_H__ */
- END_OF_FILE
- if test 3812 -ne `wc -c <'error_val.h'`; then
- echo shar: \"'error_val.h'\" unpacked with wrong size!
- fi
- # end of 'error_val.h'
- fi
- if test -f 'malloc.info' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'malloc.info'\"
- else
- echo shar: Extracting \"'malloc.info'\" \(41835 characters\)
- sed "s/^X//" >'malloc.info' <<'END_OF_FILE'
- XThis is Info file malloc.info, produced by Makeinfo-1.49 from the input
- Xfile malloc.texi.
- X
- X This file is an introduction to the Malloc library which handles
- Xgeneral memory heap management.
- X
- X Copyright (C) 1992 by Gray Watson and the Antaire Corporation.
- X
- X Permission is granted to make and distribute verbatim copies of this
- Xmanual provided the copyright notice and this permission notice are
- Xpreserved on all copies.
- X
- X Permission is granted to copy and distribute modified versions of
- Xthis manual under the conditions for verbatim copying, provided also
- Xthat the section entitled "Copying" are included exactly as in the
- Xoriginal, and provided that the entire resulting derived work is
- Xdistributed under the terms of a permission notice identical to this
- Xone.
- X
- X Permission is granted to copy and distribute translations of this
- Xmanual into another language, under the above conditions for modified
- Xversions, except that the section entitled "Copying" may be included in
- Xa translation approved by the author instead of in the original English.
- X
- X
- XFile: malloc.info, Node: Top, Next: Copying, Prev: (dir), Up: (dir)
- X
- XMalloc Debug Library
- X********************
- X
- X This file documents the general-usage and the inner-workings of the
- Xmemory allocation or "malloc" library it accompanies.
- X
- X This malloc library has been designed as a drop in replacement for
- Xthe system's malloc, realloc, calloc, free and other memory management
- Xroutines. For more information about their capabilities, do a `man 3
- Xmalloc' to read the system's manual pages.
- X
- X What is unique about this library is that it contains a number of
- Xpowerful debugging facilities including very comprehensive heap testing
- Xand excellent run-time debugging information. We have found these
- Xcapabilities to be superb development tools.
- X
- X I can be reached at `<gray.watson@antaire.com>' with any questions
- Xor general comments.
- X
- X Gray Watson, Antaire Corporation.
- X
- X* Menu:
- X
- X* Copying:: Library copying conditions.
- X* Allocation Basics:: Basic description of terms and functions.
- X* Features:: Description of the benefits of the library.
- X* Usage:: How to run programs with the library.
- X* Code:: Information on the source and general concerns.
- X* Plugs:: A couple soapbox comments.
- X
- X
- XFile: malloc.info, Node: Copying, Next: Allocation Basics, Prev: Top, Up: Top
- X
- XLibrary Copying Conditions.
- X***************************
- X
- X This package is covered by the GNU Library Public License. See the
- Xfile `COPYING-LIB' for details. If you would like to do something with
- Xthis package that you feel is reasonable but prohibited by the license,
- Xplease contact me to see if we can work it out.
- X
- X *NOTICE*: this is not the GNU Public License but the *library*
- Xpublic license. This license allows you to do more with the library
- Xthan the standard public license distributed with most GNU software.
- XPlease read `COPYING-LIB' or contact me for more information.
- X
- X The rest of this section contains some messages from the Free
- XSoftware Foundation. If you find this stuff offensive or annoying,
- Xremember that you probably did not spend any money to get this library
- Xso feel free to heave it into the bit bucket.
- X
- X The licenses for most software are designed to take away your
- Xfreedom to share and change it. By contrast, the GNU General Public
- XLicenses are intended to guarantee your freedom to share and change
- Xfree software--to make sure the software is free for all its users.
- X
- X This license, the Library General Public License, applies to some
- Xspecially designated Free Software Foundation software, and to any other
- Xlibraries whose authors decide to use it. You can use it for your
- Xlibraries, too.
- X
- X When we speak of free software, we are referring to freedom, not
- Xprice. Our General Public Licenses are designed to make sure that you
- Xhave the freedom to distribute copies of free software (and charge for
- Xthis service if you wish), that you receive source code or can get it
- Xif you want it, that you can change the software or use pieces of it in
- Xnew free programs; and that you know you can do these things.
- X
- X To protect your rights, we need to make restrictions that forbid
- Xanyone to deny you these rights or to ask you to surrender the rights.
- XThese restrictions translate to certain responsibilities for you if you
- Xdistribute copies of the library, or if you modify it.
- X
- X For example, if you distribute copies of the library, whether gratis
- Xor for a fee, you must give the recipients all the rights that we gave
- Xyou. You must make sure that they, too, receive or can get the source
- Xcode. If you link a program with the library, you must provide complete
- Xobject files to the recipients so that they can relink them with the
- Xlibrary, after making changes to the library and recompiling it. And
- Xyou must show them these terms so they know their rights.
- X
- X Our method of protecting your rights has two steps: (1) copyright the
- Xlibrary, and (2) offer you this license which gives you legal permission
- Xto copy, distribute and/or modify the library.
- X
- X Also, for each distributor's protection, we want to make certain that
- Xeveryone understands that there is no warranty for this free library.
- XIf the library is modified by someone else and passed on, we want its
- Xrecipients to know that what they have is not the original version, so
- Xthat any problems introduced by others will not reflect on the original
- Xauthors' reputations.
- X
- X
- XFile: malloc.info, Node: Allocation Basics, Next: Features, Prev: Copying, Up: Top
- X
- XBasic Description of Terms and Functions.
- X*****************************************
- X
- X This section provides a basic definition of terms used throughout the
- Xmanual as well as a brief overview of the basic malloc functions and
- Xexamples of their use. It is quite unnecessary for you to read this
- Xsection if you are familiar with using the heap allocation functions.
- X
- X* Menu:
- X
- X* Basic definitions:: For defining general terms and concepts.
- X* Malloc functions:: Functionality supported by all malloc libs.
- X
- X
- XFile: malloc.info, Node: Basic definitions, Next: Malloc functions, Up: Allocation Basics
- X
- XFor Defining General Terms and Concepts.
- X========================================
- X
- X Any program can be divided into 2 logical parts: text and data.
- XText is the actual program code in machine-readable format and data is
- Xthe information that the text operates on when it is executing. The
- Xdata, in turn, can be divided into 3 logical parts according to where
- Xit is stored: "static", "stack", and "heap".
- X
- X Static data is the information whose storage space is compiled into
- Xthe program.
- X /* global variables are allocated as static data */
- X int numbers[10];
- X
- X main()
- X {
- X ...
- X }
- X Stack data is data allocated at run-time to hold information used
- Xinside of functions. This data is managed by the system in the space
- Xcalled stack space.
- X
- X void foo()
- X {
- X /* this local variable is allocated on the stack */
- X float total;
- X
- X ...
- X }
- X Heap data is also allocated at run-time and provides a programmer
- Xwith dynamic memory capabilities.
- X
- X main()
- X {
- X char * string;
- X ...
- X
- X /* allocate a string of 10 bytes */
- X string = (char *)malloc(10);
- X ...
- X /* de-allocate the string now that I'm done with it */
- X (void)free(string);
- X
- X ...
- X }
- X It is the heap data that is managed by this library.
- X
- X Although the above is an example of how to use the malloc and free
- Xcommands, it is not a good example of why using the heap for run-time
- Xstorage is useful.
- X
- X Consider this: You write a program that reads a file into memory,
- Xprocesses it, and displays results. You would like to handle files with
- Xarbitrary size (from 10 bytes to 1.2 megabytes and more). One problem,
- Xhowever, is that the entire file must be in memory at one time to do the
- Xcalculations. You don't want to have to allocate 1.2 megabytes when you
- Xmight only be reading in a 10 byte file because it is wasteful of system
- Xresources. Also, you are worried that your program might have to handle
- Xfiles of more than 1.2 megabytes.
- X
- X A solution: first checkout the file's size and then, using the
- Xheap-allocation routines, get enough storage to read the entire file
- Xinto memory. The program will only be using the system resources
- Xnecessary for the job and you will be guaranteed that your program can
- Xhandle any sized file.
- X
- X
- XFile: malloc.info, Node: Malloc functions, Prev: Basic definitions, Up: Allocation Basics
- X
- XFunctionality Supported by all Malloc Libraries.
- X================================================
- X
- X All malloc libraries support 4 basic memory allocation commands.
- XThese include "malloc", "calloc", "realloc", and "free".
- X
- X`malloc'
- X Usage: `pnt = (type *)malloc(unsigned int size);'
- X
- X The malloc routine is the basic memory allocation routine. It
- X allocates an area of size bytes. It will return a pointer to the
- X space requested.
- X
- X`calloc'
- X Usage: `pnt = (type *)calloc(unsigned int number, unsigned int
- X size);'
- X
- X The calloc routine allocates a certain number of items, each of
- X size bytes, and returns a pointer to the space. It is appropriate
- X to pass in a `sizeof(type)' value as the size argument.
- X
- X Also, calloc nulls the space that it returns, assuring that the
- X memory is all zeros.
- X
- X`realloc'
- X Usage: `new_pnt = (type *)realloc(void * old_pnt, unsigned int
- X new_size);'
- X
- X The realloc function expands or shrinks the memory allocation in
- X old_pnt to new_size number of bytes. Realloc copies the
- X information in old_pnt into the new_pnt space up to new_size bytes
- X or until it copies all of the information from old_pnt.
- X
- X`free'
- X Usage: `(void)free(void * pnt);'
- X
- X The free routine releases an allocation returned by malloc,
- X calloc, or realloc back to the heap. This allows other parts of
- X the program to re-use memory that is not needed anymore. It also
- X guarantees that the process does not grow too big and swallow a
- X large portion of the system resources.
- X
- X *NOTE*: the returned address from the memory allocation/reallocation
- Xfunctions should *always* be cast to the appropriate pointer type for
- Xthe variable being assigned.
- X
- X *WARNING*: there is a quite common myth that all of the space that
- Xis returned by malloc libraries has already been cleared. *Only* the
- Xcalloc routine will zero the memory space it returns.
- X
- X
- XFile: malloc.info, Node: Features, Next: Usage, Prev: Allocation Basics, Up: Top
- X
- XDescription of the Benefits of the Library.
- X*******************************************
- X
- X* Menu:
- X
- X* Overview:: General debugging concepts.
- X* Environment variables:: The variable names and their features.
- X* malloc_dbg program:: Env variable setting utility.
- X* RC file:: Format of the run-time configuration file.
- X* Debug tokens:: Description of the debugging token flags.
- X* Argument checking:: Special checking of function arguments.
- X
- X
- XFile: malloc.info, Node: Overview, Next: Environment variables, Up: Features
- X
- XGeneral Debugging Concepts.
- X===========================
- X
- X The features of this library are controlled by a number of
- Xenvironmental variables. They enable the memory debugging features at
- Xruntime to help locate problems, chart memory leaks, provide basic
- Xbounds checking, log statistics, etc.. *Note Environment variables::.
- X
- X The debugging features that are available can be broken down into a
- Xcouple basic classifications:
- X
- X`file and line number information'
- X One of the nice things about a good debugger is its ability to
- X provide the file and line number of an offending piece of code.
- X This library attempts to give this functionality with the help of
- X "cpp", the C preprocessor. If the file `malloc.h' is included,
- X the library can provide file and line information for the warning
- X messages and errors it generates.
- X
- X`fence-post (i.e. bounds) checking'
- X "Fence-post" memory is the area immediately above or below memory
- X allocations. I have found it all to easy to write code that
- X accesses above or below an allocation (especially when dealing
- X with arrays or strings). The library can write special values in
- X the areas around every allocation so it will notice when these
- X areas have been overwritten.
- X
- X *NOTE*: The library cannot notice when the program reads from these
- X areas, only when it writes values. Also, fence-post checking will
- X increase the amount of memory the program allocates.
- X
- X`heap-constancy verification'
- X The administration of the library is reasonably complex. If any
- X of the heap-maintenance information is corrupted, the program will
- X either crash or give unpredictable results.
- X
- X By enabling heap-consistency checking, the library will run
- X through its administrative structures to make sure all is in
- X order. This will mean that problems will be caught faster and
- X diagnosed better.
- X
- X The drawback of this is, of course, that the library often takes
- X quite a long time to do this. It is suitable to enable this only
- X during development and debugging sessions.
- X
- X *NOTE*: the heap checking routines cannot guarantee that the tests
- X will not cause a segmentation-fault if the heap administration
- X structures are properly (or improperly if you will) overwritten.
- X In other words, they will verify that everything is okay but may
- X not inform the user of problems in a graceful manner.
- X
- X`logging statistics'
- X One of the initial reasons why I personally wanted malloc-debug
- X capabilities is to track my programs' memory usage; specifically to
- X locate memory "leaks" which are places where allocated memory is
- X never getting freed.
- X
- X The library has a number of logging capabilities that can track
- X run-time memory usage, administrative actions, final program
- X statistics, as well as un-freed memory pointers. This information
- X is also good at providing more general debugging feedback.
- X
- X`examining unfreed memory'
- X Another common problem with programs is that they free a memory
- X pointer but then use go on to use it again by mistake. This can
- X lead to mysterious crashes and unexplained problems.
- X
- X To combat this, the library can write special values into a block
- X of memory after it has been freed. This serves two purposes: it
- X will make sure that the program will get garbage data if it trying
- X to access the area again, and it will allow the library to verify
- X the area later for signs of overwriting.
- X
- X If any of the above debugging features detect an error, the library
- Xwill try to recover. If logging is enabled then an error will be
- Xlogged with as much information as possible.
- X
- X The error messages that the library displays are designed to give the
- Xmost information for developers. If the error message is not
- Xunderstood, then it is most likely just trying to indicate that a part
- Xof the heap has been corrupted. The bug is most likely near the last
- Xcall made to the library so reviewing the code around this area is
- Xrecommended.
- X
- X The library can be configured to quit immediately when an error is
- Xdetected and to dump a core file or memory-image. This can be examined
- Xwith a debugger to determine the source of the problem.
- X
- X When running our programs in a debugger such as gdb (the *excellent*
- XGNU debugger), I always put a break-point in `_malloc_perror()' which
- Xis the internal error routine for the library. The program will then
- Xhit the break-point as soon as a memory problem is detected.
- X
- X Other malloc-debug libraries also support the ability to dump core
- Xand then continue running. I decided not to support this once it was
- Xdetermined that some versions of `fork' make calls to malloc which
- Xwould cause the library to go recursive.
- X
- X *NOTE*: do not be surprised if the library catches problems with
- Xyour system's library routines. It took me four hours once to finally
- Xcome to the conclusion that the localtime call, included in SunOS
- Xrelease 4.1, was overwriting one of its fence-post markers.
- X
- X
- XFile: malloc.info, Node: Environment variables, Next: malloc_dbg program, Prev: Overview, Up: Features
- X
- XEnvironment Variables - Their Names and Features.
- X=================================================
- X
- X "Environment variables" are variables that are part of the user's
- Xworking environment and are shared by all the programs. The below
- Xvariables are used by the malloc library to enable or disable the memory
- Xdebugging features, at runtime.
- X
- X They can be set either by hand or with the help of the malloc_dbg
- Xprogram. *Note malloc_dbg program::.
- X
- X To set them by hand, C shell (or tcsh) users need to invoke:
- X
- X setenv variable value;
- X Bourne shell (or bash, ksh) users should use:
- X
- X variable=value;
- X export variable;
- X
- X`MALLOC_DEBUG'
- X This env variable should be set to a value in hexadecimal which
- X corresponds to a set of functionality tokens. *Note Debug
- X tokens::. For instance, if the user wanted to enabled logging of
- X memory transactions (value `0x008') and wanted to check fence-post
- X memory (value `0x400') then `MALLOC_DEBUG' should be set to
- X `0x408'.
- X
- X Don't worry about remembering all the hex values of the tokens, the
- X malloc_dbg program automates the setting of this variable
- X especially.
- X
- X`MALLOC_LOGFILE'
- X Set this variable to a filename so that if `MALLOC_DEBUG' has
- X logging enabled, the library can log transactions, administration
- X information, and/or errors to the file so memory problems and
- X usage can be tracked.
- X
- X`MALLOC_ADDRESS'
- X When this env variable is set to a hex address (taken from the
- X malloc log-file for instance) malloc will abort when it finds
- X itself either allocating or freeing that address.
- X
- X The address can also have an `:number' argument. For instance, if
- X it was set it to `0x3e45:10', the library will kill itself the 10th
- X time it sees address `0x3e45'.
- X
- X This makes it easier to track down specific addresses not being
- X freed.
- X
- X`MALLOC_INTERVAL'
- X By setting this env variable to a number X, malloc will only check
- X the heap every X times. This means a number of `MALLOC_DEBUG'
- X features can be enabled while still running the program within a
- X finite amount of time.
- X
- X I have found that a setting of `100' works well with reasonably
- X memory intensive programs. This of course means that the library
- X will not catch errors exactly when they happen but possibly 100
- X library calls later.
- X
- X`MALLOC_START'
- X Set this env variable to a number X and malloc will begin checking
- X the heap after X times. This means the intensive debugging can be
- X started after a certain point in a program.
- X
- X `MALLOC_START' also has the format file:line. For instance, if it
- X is set to `malloc_t.c:126' malloc will start checking the heap
- X after it sees a malloc call from the `malloc_t.c' file, line number
- X 126. If line number is 0 then malloc will start checking the heap
- X after it sees a call from anywhere in the `malloc_t.c' file.
- X
- X This allows the intensive debugging to be started after a certain
- X routine or file has been reached in the program.
- X
- X
- XFile: malloc.info, Node: malloc_dbg program, Next: RC file, Prev: Environment variables, Up: Features
- X
- XEnv Variable Setting Utility.
- X=============================
- X
- X The malloc_dbg program is designed to assist in the setting of the
- Xenvironmental variables, especially `MALLOC_DEBUG'. *Note Environment
- Xvariables::. It is designed to print the shell commands necessary to
- Xmake the appropriate changes to the environment. Unfortunately, it
- Xcannot make the changes on its own so the output from malloc_dbg should
- Xbe sent through the `eval' shell command which will do the commands.
- X
- X With shells that have aliasing or macro capabilities: csh, tcsh,
- Xbash, ksh, etc., setting up an alias to malloc_dbg to do the eval call
- Xis recommended. csh/tcsh users (for example) should put the following
- Xin their `.cshrc' file:
- X
- X alias malloc 'eval `malloc_dbg \!*`'
- X This allows the user to execute `malloc args'.
- X
- X The most basic usage for the program is `malloc_dbg [-b] tag'. The
- X-b flag is for generating Bourne-shell type commands (C-shell type are
- Xthe default). The tag argument should match a line from the user's
- Xrun-time configuration file. *Note RC file::.
- X
- X Here is a detailed list of the flags that can passed to malloc_dbg:
- X
- X`-a address'
- X Set the `MALLOC_ADDRESS' variable with the string address (or
- X alternatively address:number).
- X
- X`-b'
- X Output Bourne-shell type commands. (C-shell type output is the
- X default).
- X
- X`-c'
- X Clear/unset all of the variables not specified with other
- X arguments.
- X
- X *NOTE*: clear will never unset the `MALLOC_DEBUG' variable. Use
- X `-d 0' or a tag to `none' to achieve this.
- X
- X`-d bitmask'
- X Set the MALLOC_DEBUG to the bitmask value which should be in hex.
- X This is overridden (and unnecessary) if a tag is specified.
- X
- X`-e errno'
- X Print the malloc error string that corresponds to errno.
- X
- X`-f filename'
- X Use this configuration file instead of the RC file
- X `$HOME/.mallocrc'.
- X
- X`-i number'
- X Set the `MALLOC_INTERVAL' env variable to number.
- X
- X`-l filename'
- X Set the `MALLOC_LOGFILE' env variable to filename.
- X
- X`-s number'
- X Set the `MALLOC_START' env variable to number (alternatively
- X file:line).
- X
- X If no arguments are specified, malloc_dbg dumps out the current
- Xsettings that you have for the malloc environmental variables. For
- Xexample:
- X
- X MALLOC_DEBUG == '0x6417' (debug1)
- X MALLOC_ADDRESS == '0'
- X MALLOC_INTERVAL not set
- X MALLOC_LOGFILE == 'malloc'
- X MALLOC_START not set
- X
- X
- XFile: malloc.info, Node: RC file, Next: Debug tokens, Prev: malloc_dbg program, Up: Features
- X
- XFormat of the Run-Time Configuration File.
- X==========================================
- X
- X The name of default "RC file" (or run-time configuration file) is
- X`$HOME/.mallocrc'. The `$HOME' environmental variable should be set by
- Xthe system to point to your home-directory.
- X
- X The rc file file should contain lines in the general form of:
- X
- X `tag token1, token2, ...'
- X
- X tag is to be matched with the tag argument passed to the malloc_dbg
- Xprogram, token1, token2, ... are debug capability tokens. *Note
- Xmalloc_dbg program:: and *Note Debug tokens::.
- X
- X A line can be finished with a '\' meaning it continues onto the next
- Xline. Lines beginning with '#' are treated as comments and are ignored
- Xalong with empty lines.
- X
- X I have the below contents in my `.mallocrc' file:
- X
- X #
- X # Malloc run-time configuration file for our malloc-debug library
- X #
- X
- X # no debugging
- X none none
- X
- X # basic debugging
- X debug1 log-stats, log-non-free, log-perror, log-bad-pnt, check-fence
- X
- X # more logging and some heap checking
- X debug2 log-stats, log-non-free, log-perror, log-trans, log-bad-pnt, \
- X check-fence, check-heap, check-lists, error-abort
- X
- X # good utilities
- X debug3 log-stats, log-non-free, log-perror, log-trans, log-bad-pnt, \
- X log-admin, check-fence, check-heap, check-lists, realloc-copy, \
- X free-blank, error-abort
- X
- X ...
- X With the above file, when I say `eval `malloc_dbg debug1`', I enable
- Xthe logging of statistics, the logging of non-freed memory, logging of
- Xerrors, logging of bad pointer information, and the checking of
- Xfence-post memory areas.
- X
- X When I say `eval `malloc_dbg none`', all memory debugging features
- Xare disabled.
- X
- X
- XFile: malloc.info, Node: Debug tokens, Next: Argument Checking, Prev: RC file, Up: Features
- X
- XDescription of the Debugging Token Flags.
- X=========================================
- X
- X The below tokens and their corresponding descriptions are for the
- Xsetting of the `MALLOC_DEBUG' environmental variable *Note Environment
- Xvariables::. They should be specified in the user's `.mallocrc' file
- X*Note RC file::.
- X
- X`none'
- X no debugging functionality
- X
- X`log-stats'
- X log general statistics when malloc_shutdown is called
- X
- X`log-non-free'
- X log non-freed memory pointers when malloc_shutdown is called
- X
- X`log-perror'
- X log internal error-messages
- X
- X`log-trans'
- X log general memory transactions
- X
- X`log-bad-pnt'
- X log information about bad-pointers
- X
- X`log-admin'
- X log full administrative information
- X
- X`log-blocks'
- X log detailed block information when malloc_heap_map is called
- X
- X`log-unknown'
- X like log-non-free but logs unknown non-freed memory pointers
- X
- X`check-fence'
- X check fence-post memory areas
- X
- X`check-heap'
- X verify heap administrative structure
- X
- X`check-lists'
- X examine internal heap linked-lists
- X
- X`check-dblock'
- X do detailed checking on small allocations
- X
- X`check-dblock-fence'
- X check the fence-post areas of small allocations
- X
- X`check-free'
- X check to see if free space has been overwritten
- X
- X`check-funcs'
- X check the arguments of some functions (mostly string operations)
- X looking for bad pointers
- X
- X`realloc-copy'
- X always copy data to a new pointer when realloc
- X
- X`free-blank'
- X write special values (non-0) into space when it is freed
- X
- X`error-abort'
- X abort the program (and dump core) on errors
- X
- X`alloc-blank'
- X write special values (non-0) into space when it is alloced
- X
- X`heap-check-map'
- X log a heap-map to the logfile every time the heap is checked
- X
- X`print-perror'
- X log any errors and messages to the screen via standard-error
- X
- X
- XFile: malloc.info, Node: Argument Checking, Prev: Debug tokens, Up: Features
- X
- XCheck Certain Function Arguments.
- X=================================
- X
- X One potential problem with the library and its multitude of checks
- Xand diagnoses is that they only get performed when a malloc function is
- Xcalled. One solution this is to include `malloc.h' and compile your
- Xsource code with the `MALLOC_FUNC_CHECK' flag defined and enable the
- X`check-funcs' token *Note Debug tokens::.
- X
- X gcc -DMALLOC_FUNC_CHECK file.c
- X Once you have compiled your source with FUNC_CHECK enabled, you will
- Xhave to recompile with it off to disconnect the library *Note Disabling
- Xthe Library::.
- X
- X When this is defined malloc will override a number of functions and
- Xwill insert a routine which knowns how to check its own arguments and
- Xthen call the real function. Malloc can check such functions as bcopy,
- Xindex, strcat, and strcasecmp (for the full list see the end of
- X`malloc.h').
- X
- X When you call strlen, for instance, malloc will make sure the string
- Xargument's fence-post areas have not been overwritten, its file and line
- Xnumber locations are good, etc. With bcopy, malloc will make sure that
- Xthe destination string has enough space to store the number of bytes
- Xspecified.
- X
- X For all of the arguments checked, if the pointer is not in the heap
- Xthen it is ignored since malloc does know anything about it.
- X
- X *NOTE*: this is one of the newest parts of the library so problems
- Xmay still be lurking.
- X
- X
- XFile: malloc.info, Node: Usage, Next: Code, Prev: Features, Up: Top
- X
- XHow to Run Programs With the Library.
- X*************************************
- X
- X* Menu:
- X
- X* Allocation macros:: For providing file and line information.
- X* Extensions:: Additional non-standard routines.
- X* Disabling the Library:: How to compile/link without the library.
- X
- X
- XFile: malloc.info, Node: Allocation macros, Next: Extensions, Up: Usage
- X
- XFor Providing File/Line Debugging Information.
- X==============================================
- X
- X By including `malloc.h' in your C files, your calls to calloc, free,
- Xmalloc, or realloc are replaced with calls to _calloc_leap, _free_leap,
- X_malloc_leap, and _realloc_leap.
- X
- X These leap macros use the c-preprocessor `__FILE__' and `__LINE__'
- Xmacros which get replaced at compilation time with the current file and
- Xline-number of the source code in question. The leap routines take
- Xthis information and pass it on to the library making it able to
- Xproduce verbose reports on memory not freed:
- X
- X not freed: 0x38410 ( 22 bytes) from 'malloc_t.c:92'
- X not freed: 0x38600 ( 10232 bytes) from 'malloc_t.c:104'
- X These lines from a log file shows that two allocations were not
- Xfreed. One at address 0x38410 of size 22 bytes in source file
- X`malloc_t.c' at line 92 and another at address 0x38600 of size 10232
- Xbytes at line 104 of `malloc_t.c'.
- X
- X Along with the above leap macros, `malloc.h' also contains the
- Xfollowing macros which I have been using for all our memory allocation
- Xneeds for some time now. They take care of all the type-casting and
- Xmake the code look much cleaner (IMHO).
- X
- X`ALLOC(type, count)'
- X Usage: `long_pnt = ALLOC(long, 30);'. This means allocate space
- X for 30 longs.
- X
- X`MALLOC(size)'
- X Usage: `char_pnt = MALLOC(1000);'. This is like ALLOC but for
- X characters only. It means allocate space for 1000 characters.
- X
- X`CALLOC(type, count)'
- X Usage: `infp = CALLOC(struct info_st, 100);'. This means allocate
- X space for 100 info_st structures and zero them all.
- X
- X *NOTE*: the arguments for the CALLOC macro are sort of reversed
- X from calloc(unsigned int count, unsigned int size).
- X
- X`REALLOC(pnt, type, count)'
- X Usage: `long_pnt = REALLOC(old_pnt, long, 10);'. This takes
- X old_pnt and and changes its size to accommodate 10 longs.
- X
- X`REMALLOC(pnt, size)'
- X Usage: `char_pnt = REMALLOC(char_pnt, 100);'. This is like REALLOC
- X but for characters only. It takes char_pnt and changes its size
- X to 100 characters.
- X
- X`FREE(pnt)'
- X Usage: `(void)FREE(pnt);'. This frees memory pointers.
- X
- X`STRDUP(string)'
- X Usage: `char_pnt = STRDUP("hello");'. This macro duplicates the
- X functionality of the `strdup' function. string can be either a
- X static string like "hello" or a character pointer. Non-gcc users
- X should use `STRDUP("hello", char_pnt);' where char_pnt is the
- X variable which will be assigned to the pointer to the copy of
- X "hello".
- X
- X`BDUP(pnt, size)'
- X Usage: `new_item_pnt = BDUP(&item, sizeof(item));'. This allocates
- X space for size bytes, copies size bytes from pnt into the new
- X allocation and returns it. It is like strdup but for non-strings.
- X Non-gcc users should use `BDUP(&item, sizeof(item),
- X new_item_pnt);' where new_item_pnt is the variable which will be
- X assigned the pointer to the copy of item.
- X
- X In the above macro list, I have also included a STRDUP and a BDUP
- Xmacro. STRDUP, for those who are not familiar with the strdup function,
- Xtakes a string, allocates enough information to store the string (along
- Xwith its null character), and then copies the string into the new
- Xspace. This macro does not actually call strdup but provides the same
- Xfunctionality and provides file and line memory information to the
- Xlibrary.
- X
- X BDUP is a function that I invented. I use it to duplicate
- Xstructures or other elements that are not strings. A pointer to an
- Xelement and its size are passed in and the macro returns an allocated
- Xcopy of it.
- X
- X gcc (GNUs c-compiler) has a neat feature in that it understands
- Xreturn-values from macros. I have included a gcc form of these 2 macros
- X(which makes them a lot more functional) as well as a non-gcc version.
- X
- X *NOTE*: I would like to strongly recommend the usage of gcc. It is
- Xa superior compiler and future releases of this library may require its
- Xuse.
- X
- X
- XFile: malloc.info, Node: Extensions, Next: Disabling the Library, Prev: Allocation macros, Up: Usage
- X
- XAdditional Non-Standard Routines.
- X=================================
- X
- X The library has a number of variables and routines that are not a
- Xstandard part of most malloc libraries:
- X
- X`char * malloc_logpath;'
- X This variable can be used to set the malloc log filename. The env
- X variable MALLOC_LOGFILE overrides this variable.
- X
- X`int malloc_errno;'
- X This variable stores the internal malloc library error number like
- X errno does for the system calls. It can be passed to
- X `malloc_strerror()' (see below) to get a string version of the
- X error. It will have a value of zero if the library has not
- X detected any problems.
- X
- X`void malloc_shutdown(void);'
- X This routine shuts the library down and logs the final statistics
- X and information especially the non-freed memory pointers. It
- X should be run right before `exit()' or as the last function in
- X `main()'.
- X
- X main()
- X {
- X ...
- X malloc_shutdown();
- X exit(0);
- X }
- X
- X`int malloc_heap_map(void);'
- X This routine will log to the logfile (if it is enabled) a graphical
- X representation of the current heap space. It needs some work but
- X should provide some good information.
- X
- X`int malloc_verify(char * pnt);'
- X Use `malloc_verify' to verify individual memory pointers that are
- X suspect of memory problems. To check the entire heap pass in a
- X NULL or 0 pointer.
- X
- X *NOTE*: `malloc_verify' can only check the heap with the functions
- X that have been enabled. For example, if fence-post checking is
- X not enabled in the `MALLOC_DEBUG' variable, `malloc_verify' cannot
- X check the fence-post areas in the heap.
- X
- X`int malloc_debug(long debug);'
- X With this routine, the value in the `MALLOC_DEBUG' variable can be
- X overridden and the library debugging features set explicitly. For
- X instance, if debugging should never be enabled for a program, a
- X call to `malloc_debug(0);' as the first call in `main()' will
- X disable all the memory debugging from that point on.
- X
- X One problem however is that some compilers (gcc for instance) make
- X calls to memory allocation functions *before* `main()' is reached
- X and `malloc_debug()' called meaning some debugging information may
- X be generated regardless.
- X
- X`int malloc_examine(char * pnt, int * size, char ** file, int * line);'
- X This routine provides some very interesting functionality. It
- X returns the size of a pnt's allocation as well as the file and
- X line from which it was allocated.
- X
- X *NOTE*: This function is *certainly* not portable and is not
- X provided by other malloc libraries.
- X
- X`char * malloc_strerror(int errnum);'
- X `malloc_strerror' returns the string representation of the error
- X value in errnum (which probably should be malloc_errno). This
- X allows the logging of more verbose memory error messages.
- X
- X You can also display the string representation of an error value
- X by a call to the `malloc_dbg' program with a `-e #' option *Note
- X malloc_dbg program::.
- X
- X
- XFile: malloc.info, Node: Disabling the Library, Prev: Extensions, Up: Usage
- X
- XHow to Compile/Link Without the Library.
- X========================================
- X
- X When you are finished with the development and debugging sessions,
- Xyou may want to disable the malloc-debug library and put in its place
- Xeither the system's memory-allocation routines, gnu-malloc, or maybe
- Xyour own. I have tried to make this a reasonably painless process. The
- Xease of the extraction depends heavily on how many of the library's
- Xfeatures your made use of during your coding.
- X
- X I am open to any reasonable suggestions as to how to improve this
- Xprocess while maintaining the effectiveness of the debugging.
- X
- X * If you compiled any of your source modules with `MALLOC_FUNC_CHECK'
- X defined then you must first recompile all those modules without
- X the flag enabled.
- X
- X * If you are using any of the special functions provided by the
- X malloc-debug library (such as `malloc_shutdown()'), then you will
- X need to `#ifdef', remove, or comment them out of your code.
- X
- X * If you want to *totally* disable the malloc-debug library then you
- X will need to recompile all the C files that include `malloc.h'
- X while defining `MALLOC_DEBUG_DISABLE'. This will cause the malloc
- X leap macros to not be applied *Note Allocation macros::.
- X
- X gcc -O -g -DMALLOC_DEBUG_DISABLE main.c
- X
- X * Now you are ready to relink with a new library. If you have not
- X compiled all your source with `MALLOC_DEBUG_DISABLED' defined then
- X you need to include the `malloc_lp.o' file on the link line.
- X
- X gcc -O -g main.o malloc_lp.o -L/usr/local/lib -lgmalloc
- X If you have disabled malloc with the `MALLOC_DEBUG_DISABLED' flag
- X or never included `malloc.h' in any of your C files, then you will
- X not need to include the `malloc_lp.o' file on the link line.
- X
- X gcc -O -g main.o -L/usr/local/lib -lgmalloc
- X If you get unresolved references like `_malloc_leap' or
- X `_malloc_bcopy' then something was not disabled as it should have
- X been.
- X
- X
- XFile: malloc.info, Node: Code, Next: Plugs, Prev: Usage, Up: Top
- X
- XInformation on the Source and General Concerns.
- X***********************************************
- X
- X* Menu:
- X
- X* Definitions:: Some terms and other information.
- X* Compatibility:: General compatibility concerns.
- X* Portability:: Issues important for porting the library.
- X
- X
- XFile: malloc.info, Node: Definitions, Next: Compatibility, Up: Code
- X
- XSome Terms and Other Information.
- X=================================
- X
- X Here are a couple definitions and other information for those
- Xinterested in "picking the brain" of the library. The code is a little
- Xugly here and there and it conforms to the Gray-Watson handbook of
- Xcoding standards only.
- X
- X"bblock"
- X basic block containing 2 ^ BASIC_BLOCK bytes of info
- X
- X"bblock_adm"
- X administration for a set of basic blocks
- X
- X"dblock"
- X divided block containing some base 2 number of blocks smaller than
- X a basic block.
- X
- X"dblock_adm"
- X administration for a set of divided blocks
- X
- X"chunk"
- X some anonymous amount of memory
- X
- X
- XFile: malloc.info, Node: Compatibility, Next: Portability, Prev: Definitions, Up: Code
- X
- XGeneral Compatibility Concerns.
- X===============================
- X
- X * Realloc() backwards compatibility with being able to realloc from
- X the last freed block is *not* supported.
- X
- X * Realloc() of a NULL pointer is supported in which case the library
- X will just make a call to malloc(). This is a compilation option
- X in the `conf.h' file.
- X
- X * The library does *not* provide memalign() nor valloc() support as
- X of yet, but may in future releases. I would be interested to know
- X who is using these functions, which architectures they are
- X supported on, and for what reason they are being used.
- X
- X * Aside from possibly being slower than the system's memory
- X allocation functions, the library should be fully compatible with
- X the standard memory routines. If this is *not* the case please
- X bring this to my attention.
- X
- X
- XFile: malloc.info, Node: Portability, Prev: Compatibility, Up: Code
- X
- XIssues Important for Porting the Library.
- X=========================================
- X
- X General compatibility issues center around:
- X
- X * sbrk or compatible function usages
- X
- X * Whether the systems's heap grows towards high or low memory. The
- X chunk.c code is designed (loosely) around the fact that consecutive
- X calls to sbrk should give higher memory addresses.
- X
- X I have not been able to test the library on a system whose heap
- X grows towards low memory. If you are trying to run the library on
- X such a system I would be interested in talking with you.
- X
- X
- XFile: malloc.info, Node: Plugs, Prev: Code, Up: Top
- X
- XSoapbox Comments.
- X*****************
- X
- X Since I have your attention I would like to talk for a second about a
- Xcouple of things that I feel strongly about. If you would like any more
- Xinformation about the below, please mail to the supplied addresses or
- Xdrop me a line with any questions.
- X
- X`The Free Software Foundation <gnu@prep.ai.mit.edu>'
- X As you should be able to tell by now, I am a FSF supporter. The
- X FSF's goal, as I see and support it, is to encourage the exchange
- X of free source code. The organization and its individuals have
- X volunteered an amazing amount of time toward this. If you use
- X emacs, gcc, gdb, patch, perl, bison, or any of their many programs
- X and libraries then you have benefited from the movement. Please
- X consider supporting it.
- X
- X`Berkeley Software Design, Inc. <bsdi-info@bsdi.com>'
- X We at the Antaire Corporation are the proud and enthusiastic
- X owners of the BSD/386 operating system. For $1k you get a
- X *complete* BSD-flavor operating system with *full source* for 386
- X and 486 systems (binary licenses are available). Along with the
- X obvious benefits of full source code come excellent customer
- X support/service and system features such as a MS-DOG runtime
- X environment, complete tcp/ip networking facilities including nfs,
- X full software development utilities, X, etc.
- X
- X
- X
- XTag Table:
- XNode: Top1056
- XNode: Copying2320
- XNode: Allocation Basics5479
- XNode: Basic definitions6079
- XNode: Malloc functions8689
- XNode: Features10723
- XNode: Overview11324
- XNode: Environment variables16472
- XNode: malloc_dbg program19671
- XNode: RC file22230
- XNode: Debug tokens24054
- XNode: Argument Checking25962
- XNode: Usage27456
- XNode: Allocation macros27830
- XNode: Extensions31857
- XNode: Disabling the Library35092
- XNode: Code37188
- XNode: Definitions37547
- XNode: Compatibility38256
- XNode: Portability39208
- XNode: Plugs39861
- X
- XEnd Tag Table
- END_OF_FILE
- echo shar: 44 control characters may be missing from \"'malloc.info'\"
- if test 41835 -ne `wc -c <'malloc.info'`; then
- echo shar: \"'malloc.info'\" unpacked with wrong size!
- fi
- # end of 'malloc.info'
- fi
- echo shar: End of archive 3 \(of 5\).
- cp /dev/null ark3isdone
- MISSING=""
- for I in 1 2 3 4 5 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 5 archives.
- echo "Do a 'sh ./configure' to configure the library"
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-