From: Akim Demaille Date: Sat, 22 Sep 2001 17:19:03 +0000 (+0000) Subject: * configure.in: Invoke AM_LIB_DMALLOC. X-Git-Tag: BISON-1_29b~11 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/f2632e420f295bf6680a3e2e4994d331fa40d982?ds=inline * configure.in: Invoke AM_LIB_DMALLOC. * src/system.h: Use dmalloc. * src/LR0.c: Be sure to have pointers initialized to NULL. (allocate_itemsets): Allocate kernel_items only if needed. --- diff --git a/ChangeLog b/ChangeLog index 0823b5aa..6512f08f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2001-09-22 Akim Demaille + + * configure.in: Invoke AM_LIB_DMALLOC. + * src/system.h: Use dmalloc. + * src/LR0.c: Be sure to have pointers initialized to NULL. + (allocate_itemsets): Allocate kernel_items only if needed. + 2001-09-22 Akim Demaille * configure.in: Bump to 1.29b. diff --git a/Makefile.in b/Makefile.in index 7daeea72..e053875a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -153,7 +153,7 @@ $(top_builddir)/config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) $(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES) cd $(srcdir) && $(AUTOCONF) -$(ACLOCAL_M4): configure.in m4/c-bs-a.m4 m4/codeset.m4 m4/error.m4 m4/gettext.m4 m4/glibc21.m4 m4/iconv.m4 m4/isc-posix.m4 m4/lcmessage.m4 m4/m4.m4 m4/malloc.m4 m4/mbstate_t.m4 m4/prereq.m4 m4/progtest.m4 m4/realloc.m4 m4/strerror_r.m4 m4/warning.m4 +$(ACLOCAL_M4): configure.in m4/c-bs-a.m4 m4/codeset.m4 m4/dmalloc.m4 m4/error.m4 m4/gettext.m4 m4/glibc21.m4 m4/iconv.m4 m4/isc-posix.m4 m4/lcmessage.m4 m4/m4.m4 m4/malloc.m4 m4/mbstate_t.m4 m4/prereq.m4 m4/progtest.m4 m4/realloc.m4 m4/strerror_r.m4 m4/warning.m4 cd $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) config.h: stamp-h @if test ! -f $@; then \ diff --git a/aclocal.m4 b/aclocal.m4 index e3c6c4a7..01cda9d2 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -937,6 +937,25 @@ if test $ac_cv_func_strerror_r = yes; then fi ])# AC_FUNC_STRERROR_R + +# serial 1 + +AC_DEFUN([AM_WITH_DMALLOC], +[AC_MSG_CHECKING([if malloc debugging is wanted]) +AC_ARG_WITH(dmalloc, +[ --with-dmalloc use dmalloc, as in + http://www.dmalloc.com/dmalloc.tar.gz], +[if test "$withval" = yes; then + AC_MSG_RESULT(yes) + AC_DEFINE(WITH_DMALLOC,1, + [Define if using the dmalloc debugging malloc package]) + LIBS="$LIBS -ldmalloc" + LDFLAGS="$LDFLAGS -g" +else + AC_MSG_RESULT(no) +fi], [AC_MSG_RESULT(no)]) +]) + # Macro to add for using GNU gettext. # Ulrich Drepper , 1995. # diff --git a/config.hin b/config.hin index 5f926faa..b38aa387 100644 --- a/config.hin +++ b/config.hin @@ -250,6 +250,9 @@ /* Version number of package */ #undef VERSION +/* Define if using the dmalloc debugging malloc package */ +#undef WITH_DMALLOC + /* Define to 1 for GNU C library extensions. */ #undef _GNU_SOURCE diff --git a/configure b/configure index 7ada1a96..44fad5bd 100755 --- a/configure +++ b/configure @@ -739,6 +739,8 @@ Optional Features: Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) + --with-dmalloc use dmalloc, as in + http://www.dmalloc.com/dmalloc.tar.gz --with-libiconv-prefix=DIR search for libiconv in DIR/include and DIR/lib --with-included-gettext use the GNU gettext library included here @@ -6619,6 +6621,31 @@ _ACEOF fi fi +echo "$as_me:$LINENO: checking if malloc debugging is wanted" >&5 +echo $ECHO_N "checking if malloc debugging is wanted... $ECHO_C" >&6 + +# Check whether --with-dmalloc or --without-dmalloc was given. +if test "${with_dmalloc+set}" = set; then + withval="$with_dmalloc" + if test "$withval" = yes; then + echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 + +cat >>confdefs.h <<\_ACEOF +#define WITH_DMALLOC 1 +_ACEOF + + LIBS="$LIBS -ldmalloc" + LDFLAGS="$LDFLAGS -g" +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi; + ALL_LINGUAS="de es et fr ja nl tr ru" # Make sure we can run config.sub. $ac_config_sub sun4 >/dev/null 2>&1 || diff --git a/configure.in b/configure.in index 548f3a98..db2d5a73 100644 --- a/configure.in +++ b/configure.in @@ -88,6 +88,7 @@ jm_FUNC_MALLOC jm_FUNC_REALLOC jm_PREREQ_QUOTEARG jm_PREREQ_ERROR +AM_WITH_DMALLOC ALL_LINGUAS="de es et fr ja nl tr ru" AM_GNU_GETTEXT diff --git a/m4/Makefile.am b/m4/Makefile.am index 3ed90aa4..a476511c 100644 --- a/m4/Makefile.am +++ b/m4/Makefile.am @@ -2,6 +2,7 @@ EXTRA_DIST = \ c-bs-a.m4 \ codeset.m4 \ +dmalloc.m4 \ error.m4 \ gettext.m4 \ glibc21.m4 \ diff --git a/m4/Makefile.in b/m4/Makefile.in index 40e050d6..479108ff 100644 --- a/m4/Makefile.in +++ b/m4/Makefile.in @@ -99,6 +99,7 @@ install_sh = @install_sh@ EXTRA_DIST = \ c-bs-a.m4 \ codeset.m4 \ +dmalloc.m4 \ error.m4 \ gettext.m4 \ glibc21.m4 \ diff --git a/m4/dmalloc.m4 b/m4/dmalloc.m4 new file mode 100644 index 00000000..f7246708 --- /dev/null +++ b/m4/dmalloc.m4 @@ -0,0 +1,22 @@ +## ----------------------------------- ## +## Check if --with-dmalloc was given. ## +## From Franc,ois Pinard ## +## ----------------------------------- ## + +# serial 1 + +AC_DEFUN([AM_WITH_DMALLOC], +[AC_MSG_CHECKING([if malloc debugging is wanted]) +AC_ARG_WITH(dmalloc, +[ --with-dmalloc use dmalloc, as in + http://www.dmalloc.com/dmalloc.tar.gz], +[if test "$withval" = yes; then + AC_MSG_RESULT(yes) + AC_DEFINE(WITH_DMALLOC,1, + [Define if using the dmalloc debugging malloc package]) + LIBS="$LIBS -ldmalloc" + LDFLAGS="$LDFLAGS -g" +else + AC_MSG_RESULT(no) +fi], [AC_MSG_RESULT(no)]) +]) diff --git a/src/LR0.c b/src/LR0.c index b37594e6..644d2644 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -33,39 +33,39 @@ int nstates; int final_state; -core *first_state; -shifts *first_shift; -reductions *first_reduction; +core *first_state = NULL; +shifts *first_shift = NULL; +reductions *first_reduction = NULL; -static core *this_state; -static core *last_state; -static shifts *last_shift; -static reductions *last_reduction; +static core *this_state = NULL; +static core *last_state = NULL; +static shifts *last_shift = NULL; +static reductions *last_reduction = NULL; static int nshifts; -static short *shift_symbol; +static short *shift_symbol = NULL; -static short *redset; -static short *shiftset; +static short *redset = NULL; +static short *shiftset = NULL; -static short **kernel_base; -static short **kernel_end; -static short *kernel_items; +static short **kernel_base = NULL; +static short **kernel_end = NULL; +static short *kernel_items = NULL; /* hash table for states, to recognize equivalent ones. */ #define STATE_TABLE_SIZE 1009 -static core **state_table; +static core **state_table = NULL; static void allocate_itemsets (void) { - short *itemp; + short *itemp = NULL; int symbol; int i; int count; - short *symbol_count; + short *symbol_count = NULL; count = 0; symbol_count = XCALLOC (short, nsyms); @@ -89,7 +89,8 @@ allocate_itemsets (void) We allocate that much space for each symbol. */ kernel_base = XCALLOC (short *, nsyms); - kernel_items = XCALLOC (short, count); + if (count) + kernel_items = XCALLOC (short, count); count = 0; for (i = 0; i < nsyms; i++) diff --git a/src/system.h b/src/system.h index f5724789..5d15969a 100644 --- a/src/system.h +++ b/src/system.h @@ -143,8 +143,6 @@ size_t strnlen PARAMS ((const char *s, size_t maxlen)); # define LOCALEDIR "/usr/local/share/locale" #endif -#endif /* BISON_SYSTEM_H */ - /*-----------. | Booleans. | @@ -264,3 +262,17 @@ do { \ # define BISON_HAIRY "c:/usr/local/lib/bison.hairy" # endif #endif + + +/*---------------------------------. +| Debugging the memory allocator. | +`---------------------------------*/ + +# if WITH_DMALLOC +# define DMALLOC_FUNC_CHECK +# include + +# endif /* WITH_DMALLOC */ + + +#endif /* BISON_SYSTEM_H */