diff options
author | Kevin B Kenny <kennykb@acm.org> | 2003-05-15 21:51:46 (GMT) |
---|---|---|
committer | Kevin B Kenny <kennykb@acm.org> | 2003-05-15 21:51:46 (GMT) |
commit | 6d32bfc2e3607fa604256d127278dc051779c549 (patch) | |
tree | 49e0fa2a9af827e2b90a9260b0cbb7364e6a0f7a | |
parent | 254184a818b32e16b090faa444a90591c81c8c56 (diff) | |
download | tcl-6d32bfc2e3607fa604256d127278dc051779c549.zip tcl-6d32bfc2e3607fa604256d127278dc051779c549.tar.gz tcl-6d32bfc2e3607fa604256d127278dc051779c549.tar.bz2 |
Fixed Tcl bug 736425
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | generic/tclDate.c | 88 | ||||
-rw-r--r-- | generic/tclGetDate.y | 84 | ||||
-rw-r--r-- | unix/Makefile.in | 5 |
4 files changed, 179 insertions, 5 deletions
@@ -1,3 +1,10 @@ +2003-05-15 Kevin B. Kenny <kennykb@hippolyta> + + * generic/tclGetDate.y: added further hackery to the yacc + * generic/tclDate.c: post-processing to arrange for the + * unix/Makefile.in: code to set up exit handlers to free + the stacks [Bug 736425]. + 2003-05-15 Jeff Hobbs <jeffh@ActiveState.com> * doc/socket.n: diff --git a/generic/tclDate.c b/generic/tclDate.c index 31576d2..d6f8d45 100644 --- a/generic/tclDate.c +++ b/generic/tclDate.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclDate.c,v 1.20 2001/10/18 20:20:28 hobbs Exp $ + * RCS: @(#) */ #include "tclInt.h" @@ -117,6 +117,88 @@ static int TclDatelex _ANSI_ARGS_((void)); int TclDateparse _ANSI_ARGS_((void)); + +/* + *---------------------------------------------------------------------- + * + * TclDateCleanup -- + * + * Clean up allocated memory on process exit. + * + * Results: + * None. + * + * Side effects: + * Frees the block of memory passed in as client data. + * + *---------------------------------------------------------------------- + */ + +static void +TclDateCleanup( ClientData clientData ) +{ + ckfree( (char*) clientData ); +} + +/* + *---------------------------------------------------------------------- + * + * TclDateAlloc -- + * + * Special purpose allocator for the two YACC stacks. + * + * Results: + * Returns a pointer to a block of memory. + * + * Side effects: + * Allocates the requested number of bytes, and + * sets up to delete the allocated memory on process exit. + * + * The YACC system is set up to free memory in its stacks only by + * abandonment. This procedure sets up to free it explicitly on exit + * from Tcl, as when unloading. + * + *---------------------------------------------------------------------- + */ + +static char* +TclDateAlloc( size_t n ) +{ + char* pointer = ckalloc( n ); + Tcl_CreateExitHandler( TclDateCleanup, (ClientData) pointer ); + return pointer; +} + +/* + *---------------------------------------------------------------------- + * + * TclDateRealloc -- + * + * Special purpose allocator for the two YACC stacks. + * + * Results: + * Returns a pointer to a block of memory. + * + * Side effects: + * Allocates the requested number of bytes, and + * sets up to delete the allocated memory on process exit. + * + * The YACC system is set up to free memory in its stacks only by + * abandonment. This procedure sets up to free it explicitly on exit + * from Tcl, as when unloading. + * + *---------------------------------------------------------------------- + */ +static char* +TclDateRealloc( char* oldPointer, size_t n ) +{ + char* newPointer; + Tcl_DeleteExitHandler( TclDateCleanup, (ClientData) oldPointer ); + newPointer = ckrealloc( oldPointer, n ); + Tcl_CreateExitHandler( TclDateCleanup, (ClientData) newPointer ); + return newPointer; +} + typedef union #ifdef __cplusplus YYSTYPE @@ -1146,11 +1228,11 @@ char * TclDatereds[] = goto TclDatenewstate;\ } #define YYRECOVERING() (!!TclDateerrflag) -#define YYNEW(type) malloc(sizeof(type) * TclDatenewmax) +#define YYNEW(type) TclDateAlloc(sizeof(type) * TclDatenewmax) #define YYCOPY(to, from, type) \ (type *) memcpy(to, (char *) from, TclDatemaxdepth * sizeof (type)) #define YYENLARGE( from, type) \ - (type *) realloc((char *) from, TclDatenewmax * sizeof(type)) + (type *) TclDateRealloc((char *) from, TclDatenewmax * sizeof(type)) #ifndef YYDEBUG # define YYDEBUG 1 /* make debugging available */ #endif diff --git a/generic/tclGetDate.y b/generic/tclGetDate.y index 14b9869..3a7d032 100644 --- a/generic/tclGetDate.y +++ b/generic/tclGetDate.y @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclGetDate.y,v 1.18 2001/10/18 20:20:28 hobbs Exp $ + * RCS: @(#) $Id: tclGetDate.y,v 1.19 2003/05/15 21:51:46 kennykb Exp $ */ %{ @@ -134,6 +134,88 @@ static int yylex _ANSI_ARGS_((void)); int yyparse _ANSI_ARGS_((void)); + +/* + *---------------------------------------------------------------------- + * + * TclDateCleanup -- + * + * Clean up allocated memory on process exit. + * + * Results: + * None. + * + * Side effects: + * Frees the block of memory passed in as client data. + * + *---------------------------------------------------------------------- + */ + +static void +TclDateCleanup( ClientData clientData ) +{ + ckfree( (char*) clientData ); +} + +/* + *---------------------------------------------------------------------- + * + * TclDateAlloc -- + * + * Special purpose allocator for the two YACC stacks. + * + * Results: + * Returns a pointer to a block of memory. + * + * Side effects: + * Allocates the requested number of bytes, and + * sets up to delete the allocated memory on process exit. + * + * The YACC system is set up to free memory in its stacks only by + * abandonment. This procedure sets up to free it explicitly on exit + * from Tcl, as when unloading. + * + *---------------------------------------------------------------------- + */ + +static char* +TclDateAlloc( size_t n ) +{ + char* pointer = ckalloc( n ); + Tcl_CreateExitHandler( TclDateCleanup, (ClientData) pointer ); + return pointer; +} + +/* + *---------------------------------------------------------------------- + * + * TclDateRealloc -- + * + * Special purpose allocator for the two YACC stacks. + * + * Results: + * Returns a pointer to a block of memory. + * + * Side effects: + * Allocates the requested number of bytes, and + * sets up to delete the allocated memory on process exit. + * + * The YACC system is set up to free memory in its stacks only by + * abandonment. This procedure sets up to free it explicitly on exit + * from Tcl, as when unloading. + * + *---------------------------------------------------------------------- + */ +static char* +TclDateRealloc( char* oldPointer, size_t n ) +{ + char* newPointer; + Tcl_DeleteExitHandler( TclDateCleanup, (ClientData) oldPointer ); + newPointer = ckrealloc( oldPointer, n ); + Tcl_CreateExitHandler( TclDateCleanup, (ClientData) newPointer ); + return newPointer; +} + %} %union { diff --git a/unix/Makefile.in b/unix/Makefile.in index 8401624..24eabc0 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -5,7 +5,7 @@ # "autoconf" program (constructs like "@foo@" will get replaced in the # actual Makefile. # -# RCS: @(#) $Id: Makefile.in,v 1.125 2003/05/14 19:21:25 das Exp $ +# RCS: @(#) $Id: Makefile.in,v 1.126 2003/05/15 21:51:46 kennykb Exp $ VERSION = @TCL_VERSION@ MAJOR_VERSION = @TCL_MAJOR_VERSION@ @@ -354,6 +354,7 @@ GENERIC_SRCS = \ $(GENERIC_DIR)/tclCompile.c \ $(GENERIC_DIR)/tclDate.c \ $(GENERIC_DIR)/tclDictObj.c \ + $(GENERIC_DIR)/tclDToA.c \ $(GENERIC_DIR)/tclEncoding.c \ $(GENERIC_DIR)/tclEnv.c \ $(GENERIC_DIR)/tclEvent.c \ @@ -564,6 +565,8 @@ gendate: -e '/#ifdef __STDC__/,/#endif/d' -e '/TclDateerrlab:/d' \ -e '/TclDatenewstate:/d' -e '/#pragma/d' \ -e '/#include <inttypes.h>/d' -e 's/const /CONST /g' \ + -e '/#define YYNEW/s/malloc/TclDateAlloc/g' \ + -e '/#define YYENLARGE/,/realloc/s/realloc/TclDateRealloc/g' \ <y.tab.c >$(GENERIC_DIR)/tclDate.c rm y.tab.c |