Remove the custom malloc/free system

Remove commit history from comment headers
This commit is contained in:
Daniel Stenberg 2011-05-09 10:41:40 +02:00
parent 96e325a259
commit cb6929f773
8 changed files with 438 additions and 1115 deletions

181
cpp1.c
View File

@ -1,5 +1,5 @@
/******************************************************************************
Copyright (c) 1999 Daniel Stenberg
Copyright (c) 1993 - 2011 Daniel Stenberg
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -19,173 +19,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
/******************************************************************************
* FREXXWARE
* ----------------------------------------------------------------------------
*
* Project: Frexx C Preprocessor
* $Source: /home/user/start/cpp/RCS/cpp1.c,v $
* $Revision: 1.8 $
* $Date: 1994/06/02 09:10:34 $
* $Author: start $
* $State: Exp $
* $Locker: $
*
* ----------------------------------------------------------------------------
* $Log: cpp1.c,v $
* Revision 1.8 1994/06/02 09:10:34 start
* Made the function definition prinout to be more verbose
*
* Revision 1.7 1994/06/02 08:48:55 start
* Made the initial function routine work
* Added initial function exclusion list
* Added function names output
*
* Revision 1.6 1994/01/24 09:32:22 start
* Fixed the #line-option a bit.
*
* Revision 1.5 1993/12/06 13:50:39 start
* A lot of new stuff (too much to mention)
*
* Revision 1.5 1993/12/06 13:50:39 start
* A lot of new stuff (too much to mention)
*
* Revision 1.4 1993/12/02 15:10:56 start
* Lots of new features.
*
* Revision 1.3 1993/11/29 14:00:32 start
* new
*
* Revision 1.2 1993/11/11 07:16:39 start
* New stuff
*
* Revision 1.1 1993/11/03 09:13:08 start
* Initial revision
*
*
*****************************************************************************/
/*
* CPP main program.
*
* Edit history
* 21-May-84 MM "Field test" release
* 23-May-84 MM Some minor hacks.
* 30-May-84 ARF Didn't get enough memory for __DATE__
* Added code to read stdin if no input
* files are provided.
* 29-Jun-84 MM Added ARF's suggestions, Unixifying cpp.
* 11-Jul-84 MM "Official" first release (that's what I thought!)
* 22-Jul-84 MM/ARF/SCK Fixed line number bugs, added cpp recognition
* of #line, fixed problems with #include.
* 23-Jul-84 MM More (minor) include hacking, some documentation.
* Also, redid cpp's #include files
* 25-Jul-84 MM #line filename isn't used for #include searchlist
* #line format is <number> <optional name>
* 25-Jul-84 ARF/MM Various bugs, mostly serious. Removed homemade doprint
* 01-Aug-84 MM Fixed recursion bug, remove extra newlines and
* leading whitespace from cpp output.
* 02-Aug-84 MM Hacked (i.e. optimized) out blank lines and unneeded
* whitespace in general. Cleaned up unget()'s.
* 03-Aug-84 Keie Several bug fixes from Ed Keizer, Vrije Universitet.
* -- corrected arg. count in -D and pre-defined
* macros. Also, allow \n inside macro actual parameter
* lists.
* 06-Aug-84 MM If debugging, dump the preset vector at startup.
* 12-Aug-84 MM/SCK Some small changes from Sam Kendall
* 15-Aug-84 Keie/MM cerror, cwarn, etc. take a single string arg.
* cierror, etc. take a single int. arg.
* changed LINE_PREFIX slightly so it can be
* changed in the makefile.
* 31-Aug-84 MM USENET net.sources release.
* 7-Sep-84 SCH/ado Lint complaints
* 10-Sep-84 Keie Char's can't be signed in some implementations
* 11-Sep-84 ado Added -C flag, pathological line number fix
* 13-Sep-84 ado Added -E flag (does nothing) and "-" file for stdin.
* 14-Sep-84 MM Allow # 123 as a synonym for #line 123
* 19-Sep-84 MM scanid always reads to token, make sure #line is
* written to a new line, even if -C switch given.
* Also, cpp - - reads stdin, writes stdout.
* 03-Oct-84 ado/MM Several changes to line counting and keepcomments
* stuff. Also a rewritten control() hasher -- much
* simpler and no less "perfect". Note also changes
* in cpp3.c to fix numeric scanning.
* 04-Oct-84 MM Added recognition of macro formal parameters if
* they are the only thing in a string, per the
* draft standard.
* 08-Oct-84 MM One more attack on scannumber
* 15-Oct-84 MM/ado Added -N to disable predefined symbols. Fixed
* linecount if COMMENT_INVISIBLE enabled.
* 22-Oct-84 MM Don't evaluate the #if/#ifdef argument if
* compilation is supressed. This prevents
* unnecessary error messages in sequences such as
* #ifdef FOO -- undefined
* #if FOO == 10 -- shouldn't print warning
* 25-Oct-84 MM Fixed bug in false ifdef supression. On vms,
* #include <foo> should open foo.h -- this duplicates
* the behavior of Vax-C
* 31-Oct-84 ado/MM Parametized $ in indentifiers. Added a better
* token concatenator and took out the trial
* concatenation code. Also improved #ifdef code
* and cleaned up the macro recursion tester.
* 2-Nov-84 MM/ado Some bug fixes in token concatenation, also
* a variety of minor (uninteresting) hacks.
* 6-Nov-84 MM Happy Birthday. Broke into 4 files and added
* #if sizeof (basic_types)
* 9-Nov-84 MM Added -S* for pointer type sizes
* 13-Nov-84 MM Split cpp1.c, added vms defaulting
* 23-Nov-84 MM/ado -E supresses error exit, added CPP_INCLUDE,
* fixed strncpy bug.
* 3-Dec-84 ado/MM Added OLD_PREPROCESSOR
* 7-Dec-84 MM Stuff in Nov 12 Draft Standard
* 17-Dec-84 george Fixed problems with recursive macros
* 17-Dec-84 MM Yet another attack on #if's (f/t)level removed.
* 07-Jan-85 ado Init defines before doing command line options
* so -Uunix works.
* 21-Oct-85 RMS Rename `token' to `tokenbuf'.
* Allocate it dynamically, with size in `tokenbsize'.
* 23-Oct-85 RMS Do not print message about number of errors.
* 14-Mar-85 FNF Incorporate macro based C debugging package.
* Port to Commodore AMIGA.
* 20-Aug-88 Ois Changed format of documentation.
* Feb-93 DST
Daniel Stenberg. Started enhancing the `cpp' in February 1993:
o Allows C++ comments.
o Ported to ANSI C and to SAS/C 6.0.
o Changed entire indent- and statement- layout previously used!
o Changed hash sizing to any-number-hash-size.
o Removed every global variable.
o Made the cpp startable by creating a taglist and call the cpp.
o Made a shared library of it, called FPP: "Frexx PreProcessor"
o Changed the amiga version to use realloc().
o Removed all VMS defines. Who wants such?
o Changed it from Public Domain to Freeware.
o Moved out the include directory assigning to only be a part of
the taglist and _no_ internal at all!
o Made `fpp' accept input from a user specified function instead
of always the stdin stream. This makes it possible to preprocess
almost anything. An output routine is also implemented.
o I have discovered that this program needs a lot of re-writing
since a amiga shared library can't exit() as this `cpp'
does on a fatal error... I made all necessary changes! Now most functions
leave a return code telling success/failure (*MAJOR* re-writing! :-().
o The original 50-60 gotos in the source codes have been decreased
to only a few. I *HATE* gotos in C programs!
o Changed all cwarn(), cerror() cfatal(), ciwarn(), cierror() functions to
the one and all function `cerror()', which will accept a variable number
of arguments to build message from.
o Moved all error/warning/fatal texts to domsg().
o All error output can be received in the error function (and have to in the
amiga library version!).
o Found out that my test.c caused 53 malloc() but only 25 free()... Inserted
my own Malloc(), Free(), FreeAll() and Realloc() to always remove alloced
memory when finishing the preprocessing (ok, malloc/free does that for us,
but I don't want to use/depend on them).
o Compiling into a shared library under AmigaDos still needs some changes.
fopen() and other similar function in SAS/C use symbols I don't want it
to... eg. _ProgramName and _XCEXIT!
*/
#include <stdio.h>
#include <ctype.h>
@ -211,7 +44,7 @@ int PREFIX fppPreProcess(REG(a0) struct fppTag *tags)
ReturnCode ret; /* cpp return code */
struct Global *global;
global=(struct Global *)Malloc(sizeof(struct Global));
global=(struct Global *)malloc(sizeof(struct Global));
if(!global)
return(FPP_OUT_OF_MEMORY);
@ -311,8 +144,6 @@ int PREFIX fppPreProcess(REG(a0) struct fppTag *tags)
fflush(stdout);
fclose(stdout);
FreeAll(); /* free all unfreed memory! */
if (global->errors > 0 && !global->eflag)
return(IO_ERROR);
return(IO_NORMAL); /* No errors or -E option set */
@ -348,17 +179,17 @@ ReturnCode cppmain(struct Global *global)
/* Initialize for reading tokens */
global->tokenbsize = 50;
global->tokenbuf = Getmem(global, global->tokenbsize + 1);
global->tokenbuf = malloc(global->tokenbsize + 1);
if(!global->tokenbuf)
return(FPP_OUT_OF_MEMORY);
global->functionname = Getmem(global, global->tokenbsize + 1);
global->functionname = malloc(global->tokenbsize + 1);
if(!global->functionname)
return(FPP_OUT_OF_MEMORY);
global->functionname[0] = '\0';
if(global->showspace) {
global->spacebuf = (char *)Getmem(global, MAX_SPACE_SIZE);
global->spacebuf = (char *)malloc(MAX_SPACE_SIZE);
if(!global->spacebuf)
return(FPP_OUT_OF_MEMORY);
}
@ -747,7 +578,7 @@ void sharp(struct Global *global)
if (global->sharpfilename == NULL
|| (global->sharpfilename != NULL && !streq(name, global->sharpfilename))) {
if (global->sharpfilename != NULL)
Freemem(global->sharpfilename);
free(global->sharpfilename);
global->sharpfilename = savestring(global, name);
/* printf(" \"%s\"", name); */
Putstring(global, " \"");

56
cpp2.c
View File

@ -19,60 +19,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
/******************************************************************************
* FREXXWARE
* ----------------------------------------------------------------------------
*
* Project: Frexx C Preprocessor
* $Source: /home/user/start/cpp/RCS/cpp2.c,v $
* $Revision: 1.5 $
* $Date: 1994/01/24 09:32:54 $
* $Author: start $
* $State: Exp $
* $Locker: start $
*
* ----------------------------------------------------------------------------
* $Log: cpp2.c,v $
* Revision 1.5 1994/01/24 09:32:54 start
* Fixed AmigaDOS include file routine.
*
* Revision 1.4 1993/12/06 13:50:39 start
* A lot of new stuff (too much to mention)
*
* Revision 1.4 1993/12/06 13:50:39 start
* A lot of new stuff (too much to mention)
*
* Revision 1.3 1993/11/29 14:00:32 start
* new
*
* Revision 1.2 1993/11/11 07:16:39 start
* New stuff
*
* Revision 1.1 1993/11/03 09:13:08 start
* Initial revision
*
*
*****************************************************************************/
/*
* C P P 2 . C
*
* Process #control lines
*
* Edit history
* 13-Nov-84 MM Split from cpp1.c
* 21-Oct-85 RMS Do not turn on `instring' while reading #include arg.
* Rename `token' to `tokenbuf'.
* Flush tabs at end of #include line, like spaces.
* 14-Mar-86 FNF Incorporate macro based C debugging package.
* Port to Commodore AMIGA.
* 25-May-86 FNF Change handling of fully qualified include file
* pathnames (like "/usr/include/stdio.h" for unix,
* or "df0:include/stdio.h" for the Amiga) to be
* used verbatum in the first open attempt.
* 20-Aug-88 Ois Added #error. Passed unrecognized # commands.
* Added \n when those lines are passed.
*/
#include <stdio.h>
#include <ctype.h>
#include "cppdef.h"
@ -292,7 +238,7 @@ ReturnCode control( struct Global *global,
if( global->infile->progname != NULL )
/* Give up the old name if it's allocated. */
Freemem( global->infile->progname );
free( global->infile->progname );
global->infile->progname = savestring( global, tp );
}

54
cpp3.c
View File

@ -19,56 +19,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
/******************************************************************************
* FREXXWARE
* ----------------------------------------------------------------------------
*
* Project: Frexx C Preprocessor
* $Source: /home/user/start/cpp/RCS/cpp3.c,v $
* $Revision: 1.6 $
* $Date: 1994/06/02 08:50:08 $
* $Author: start $
* $State: Exp $
* $Locker: $
*
* ----------------------------------------------------------------------------
* $Log: cpp3.c,v $
* Revision 1.6 1994/06/02 08:50:08 start
* Added the new command line options
*
* Revision 1.5 1994/01/24 09:33:15 start
* Added the FPPTAG_RIGHTCONCAT tag.
*
* Revision 1.4 1993/12/06 13:50:39 start
* A lot of new stuff (too much to mention)
*
* Revision 1.4 1993/12/06 13:50:39 start
* A lot of new stuff (too much to mention)
*
* Revision 1.3 1993/11/29 14:00:32 start
* new
*
* Revision 1.2 1993/11/11 07:16:39 start
* New stuff
*
* Revision 1.1 1993/11/03 09:13:08 start
* Initial revision
*
*
*****************************************************************************/
/*
* C P P 3 . C
*
* File open and command line options
*
* Edit history
* 13-Nov-84 MM Split from cpp1.c
* 21-Oct-85 rms Make -g command arg not cause an error.
* 14-Mar-86 FNF Incorporate macro based C debugging package.
* Port to the Commodore AMIGA.
* 20-Aug-88 Ois Added __TIME__, and changed __DATE__ to standard.
*/
#include <stdio.h>
#include <ctype.h>
#include <time.h> /*OIS*0.92*/
@ -376,7 +326,7 @@ ReturnCode initdefines(struct Global *global)
* Define __DATE__ as today's date.
*/
dp = defendel(global, "__DATE__", FALSE);
tp = Getmem(global, 14);
tp = malloc(14);
if(!tp || !dp)
return(FPP_OUT_OF_MEMORY);
dp->repl = tp;
@ -392,7 +342,7 @@ ReturnCode initdefines(struct Global *global)
* Define __TIME__ as this moment's time.
*/
dp = defendel(global, "__TIME__", FALSE);
tp = Getmem(global, 11);
tp = malloc(11);
if(!tp || !dp)
return(FPP_OUT_OF_MEMORY);
dp->repl = tp;

49
cpp4.c
View File

@ -19,53 +19,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
/******************************************************************************
* FREXXWARE
* ----------------------------------------------------------------------------
*
* Project: Frexx C Preprocessor
* $Source: /home/user/start/cpp/RCS/cpp4.c,v $
* $Revision: 1.3 $
* $Date: 1994/06/02 08:50:52 $
* $Author: start $
* $State: Exp $
* $Locker: $
*
* ----------------------------------------------------------------------------
* $Log: cpp4.c,v $
* Revision 1.3 1994/06/02 08:50:52 start
* Changed a few things to make the initial function routine to run
*
* Revision 1.2 1994/01/24 09:34:03 start
* Made a bunch of functions FILE_LOCAL and INLINE.
*
* Revision 1.1 1993/11/03 09:13:08 start
* Initial revision
*
*
*****************************************************************************/
/*
* C P P 4 . C
* M a c r o D e f i n i t i o n s
*
* Edit History
* 31-Aug-84 MM USENET net.sources release
* 04-Oct-84 MM __LINE__ and __FILE__ must call ungetstring()
* so they work correctly with token concatenation.
* Added string formal recognition.
* 25-Oct-84 MM "Short-circuit" evaluate #if's so that we
* don't print unnecessary error messages for
* #if !defined(FOO) && FOO != 0 && 10 / FOO ...
* 31-Oct-84 ado/MM Added token concatenation
* 6-Nov-84 MM Split off eval stuff
* 21-Oct-85 RMS Rename `token' to `tokenbuf'.
* In doundef, don't complain if arg already not defined.
* 14-Mar-86 FNF Incorporate macro based C debugging package.
* Port to Commodore AMIGA.
* 21-Aug-88 Ois Changed concatenation operator to ##. Changed hand-
* ling of tokens following ##. Added new meaning of #.
*/
#include <stdio.h>
#include <ctype.h>
#include "cppdef.h"
@ -265,7 +218,7 @@ ReturnCode dodefine(struct Global *global)
cerror(global, ERROR_REDEFINE, dp->name);
}
if (old != NULL) /* We don't need the */
Freemem(old); /* old definition now. */
free(old); /* old definition now. */
}
return(FPP_OK);
}

44
cpp5.c
View File

@ -19,50 +19,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
/******************************************************************************
* FREXXWARE
* ----------------------------------------------------------------------------
*
* Project: Frexx C Preprocessor
* $Source: /home/user/start/cpp/RCS/cpp5.c,v $
* $Revision: 1.2 $
* $Date: 1994/01/24 09:35:02 $
* $Author: start $
* $State: Exp $
* $Locker: $
*
* ----------------------------------------------------------------------------
* $Log: cpp5.c,v $
* Revision 1.2 1994/01/24 09:35:02 start
* Made a bunch of functions FILE_LOCAL and INLINE.
*
* Revision 1.1 1993/11/03 09:13:08 start
* Initial revision
*
*
*****************************************************************************/
/*
* C P P 5 . C
* E x p r e s s i o n E v a l u a t i o n
*
* Edit History
* 31-Aug-84 MM USENET net.sources release
* 04-Oct-84 MM __LINE__ and __FILE__ must call ungetstring()
* so they work correctly with token concatenation.
* Added string formal recognition.
* 25-Oct-84 MM "Short-circuit" evaluate #if's so that we
* don't print unnecessary error messages for
* #if !defined(FOO) && FOO != 0 && 10 / FOO ...
* 31-Oct-84 ado/MM Added token concatenation
* 6-Nov-84 MM Split from #define stuff, added sizeof stuff
* 19-Nov-84 ado #if error returns TRUE for (sigh) compatibility
* 21-Oct-85 RMS Rename `token' to `tokenbuf'
* 23-Oct-85 RMS Treat undefined symbols as having value zero.
* 14-Mar-86 FNF Incorporate macro based C debugging package.
* Port to Commodore Amiga.
* 20-Aug-88 Ois Conditionally compile sizeof stuff.
*/
#include <stdio.h>
#include <ctype.h>
#include "cppdef.h"

121
cpp6.c
View File

@ -19,69 +19,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
/******************************************************************************
* FREXXWARE
* ----------------------------------------------------------------------------
*
* Project: Frexx C Preprocessor
* $Source: /home/user/start/cpp/RCS/cpp6.c,v $
* $Revision: 1.5 $
* $Date: 1994/01/24 09:35:17 $
* $Author: start $
* $State: Exp $
* $Locker: $
*
* ----------------------------------------------------------------------------
* $Log: cpp6.c,v $
* Revision 1.5 1994/01/24 09:35:17 start
* Made the FPPTAG_RIGHTCONCAT work.
*
* Revision 1.4 1993/12/06 13:50:39 start
* A lot of new stuff (too much to mention)
*
* Revision 1.4 1993/12/06 13:50:39 start
* A lot of new stuff (too much to mention)
*
* Revision 1.3 1993/11/29 14:00:32 start
* new
*
* Revision 1.2 1993/11/11 07:16:39 start
* New stuff
*
* Revision 1.1 1993/11/03 09:13:08 start
* Initial revision
*
*
*****************************************************************************/
/*
* C P P 6 . C
* S u p p o r t R o u t i n e s
*
* Edit History
* 25-May-84 MM Added 8-bit support to type table.
* 30-May-84 ARF sharp() should output filename in quotes
* 02-Aug-84 MM Newline and #line hacking. sharp() now in cpp1.c
* 31-Aug-84 MM USENET net.sources release
* 11-Sep-84 ado/MM Keepcomments, also line number pathological
* 12-Sep-84 ado/MM bug if comment changes to space and we unget later.
* 03-Oct-84 gkr/MM Fixed scannumber bug for '.e' (as in struct.element).
* 04-Oct-84 MM Added ungetstring() for token concatenation
* 08-Oct-84 MM Yet another attack on number scanning
* 31-Oct-84 ado Parameterized $ in identifiers
* 2-Nov-84 MM Token concatenation is messier than I thought
* 6-Dec-84 MM \<nl> is everywhere invisible.
* 21-Oct-85 RMS Rename `token' to `tokenbuf'.
* Dynamically allocate it, and make it as big as needed.
* 23-Oct-85 RMS Fix bugs storing into tokenbuf as it gets bigger.
* Change error msg to cpp: "FILE", line LINE: MSG
* 24-Oct-85 RMS Turn off warnings about / then * inside a comment.
* 16-Mar-86 FNF Incorporate macro based C debugging package.
* Port to Commodore Amiga.
* 20-Aug-88 Ois Added time routines (or actually deleted stubs).
* 20-Aug-88 Ois Changed handling of token following ## to match Cpp4.
* 16-Feb-93 DSt Changed case of getmem() to Getmem().
*/
#include <stdio.h>
#include <ctype.h>
#include "cppdef.h"
@ -232,7 +169,7 @@ void scanid(struct Global *global,
do
{
if (ct == global->tokenbsize)
global->tokenbuf = incmem (global, global->tokenbuf, 1 +
global->tokenbuf = realloc(global->tokenbuf, 1 +
(global->tokenbsize *= 2));
global->tokenbuf[ct++] = c;
c = get(global);
@ -327,7 +264,7 @@ int catenate(struct Global *global, ReturnCode *ret)
* new (concatenated) token after freeing token1.
* Finally, setup to read the new token.
*/
Freemem(token1); /* Free up memory */
free(token1); /* Free up memory */
*ret=ungetstring(global, global->work); /* Unget the new thing, */
if(*ret)
return(FALSE);
@ -545,8 +482,7 @@ char *savestring(struct Global *global, char *text)
*/
char *result;
result = Getmem(global, strlen(text) + 1);
result = malloc(strlen(text) + 1);
strcpy(result, text);
return (result);
}
@ -569,7 +505,7 @@ ReturnCode getfile(struct Global *global,
size = strlen(name);
}
*file = (FILEINFO *) Getmem(global, (int)(sizeof (FILEINFO) + bufsize + size));
*file = (FILEINFO *) malloc((int)(sizeof (FILEINFO) + bufsize + size));
if(!*file)
return(FPP_OUT_OF_MEMORY);
(*file)->parent = global->infile; /* Chain files together */
@ -587,41 +523,6 @@ ReturnCode getfile(struct Global *global,
return(FPP_OK); /* All done. */
}
void Freemem(void *ptr)
{
/*
* Free a block of memory!
*/
Free(ptr);
}
char *Getmem(struct Global *global, int size)
{
/*
* Get a block of free memory.
*/
char *result;
if ((result = (char *)Malloc((unsigned) size)) == NULL)
cfatal(global, FATAL_OUT_OF_MEMORY);
return(result);
}
FILE_LOCAL
char *incmem(struct Global *global, char *obj, int size)
{
/*
* Get a block of free memory.
*/
char *result;
if ((result = Realloc(obj, (unsigned) size)) == NULL)
cfatal(global, FATAL_OUT_OF_MEMORY);
return(result);
}
/*
* C P P S y m b o l T a b l e s
*/
@ -646,7 +547,7 @@ DEFBUF *lookid(struct Global *global,
ct = 0;
do {
if (ct == global->tokenbsize)
global->tokenbuf = incmem(global, global->tokenbuf, 1 + (global->tokenbsize *= 2));
global->tokenbuf = realloc(global->tokenbuf, 1 + (global->tokenbsize *= 2));
global->tokenbuf[ct++] = c; /* Store token byte */
nhash += c; /* Update hash value */
c = get(global);
@ -697,15 +598,15 @@ DEFBUF *defendel(struct Global *global,
else {
*prevp = dp->link; /* Found, unlink and */
if (dp->repl != NULL) /* Free the replacement */
Freemem(dp->repl); /* if any, and then */
Freemem((char *) dp); /* Free the symbol */
free(dp->repl); /* if any, and then */
free((char *) dp); /* Free the symbol */
}
break;
}
prevp = &dp->link;
}
if (!delete) {
dp = (DEFBUF *) Getmem(global, (int) (sizeof (DEFBUF) + size));
dp = (DEFBUF *) malloc((int) (sizeof (DEFBUF) + size));
dp->link = *prevp;
*prevp = dp;
dp->hash = nhash;
@ -871,10 +772,10 @@ int get(struct Global *global)
* Free up space used by the (finished) file or macro and
* restart input from the parent file/macro, if any.
*/
Freemem(file->filename); /* Free name and */
free(file->filename); /* Free name and */
if (file->progname != NULL) /* if a #line was seen, */
Freemem(file->progname); /* free it, too. */
Freemem(file); /* Free file space */
free(file->progname); /* free it, too. */
free(file); /* Free file space */
if (global->infile == NULL) /* If at end of file */
return (EOF_CHAR); /* Return end of file */
global->line = global->infile->line; /* Reset line number */

View File

@ -42,8 +42,8 @@ CFLAGS = $(DEBUGFLAG) $(DEFINES)
AR = ar
ARFLAGS = rv
.SUFFIXES: .o .c .c~ .h .h~ .a .i
OBJS = cpp1.o cpp2.o cpp3.o cpp4.o cpp5.o cpp6.o memory.o
FILEOBJS = cpp1.o cpp2.o cpp3.o cpp4.o cpp5.o cpp6.o memory.o usecpp.o
OBJS = cpp1.o cpp2.o cpp3.o cpp4.o cpp5.o cpp6.o
FILEOBJS = cpp1.o cpp2.o cpp3.o cpp4.o cpp5.o cpp6.o usecpp.o
# ** compile cpp
#

214
memory.c
View File

@ -1,214 +0,0 @@
/******************************************************************************
Copyright (c) 1999 Daniel Stenberg
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
/******************************************************************************
* FREXXWARE
* ----------------------------------------------------------------------------
*
* Project: Frexx C Preprocessor
* $Source: /home/user/start/cpp/RCS/memory.c,v $
* $Revision: 1.2 $
* $Date: 1994/01/24 09:36:46 $
* $Author: start $
* $State: Exp $
* $Locker: $
*
* ----------------------------------------------------------------------------
* $Log: memory.c,v $
* Revision 1.2 1994/01/24 09:36:46 start
* Made it run with OS9 properly.
*
* Revision 1.1 1993/11/03 09:13:08 start
* Initial revision
*
*
*****************************************************************************/
#include <string.h>
#include <stdlib.h>
#if defined(OS9)
#include <types.h>
#elif defined(UNIX)
#include <sys/types.h>
#elif defined(AMIGA)
#include <exec/types.h>
#include <proto/exec.h>
#endif
#include <stdio.h>
#include "memory.h"
#ifdef DEBUG
int mem;
int maxmem;
int malloc_count=0;
#endif
/*
* We have two mallockey pointers because we have two different kinds of
* Malloc()s! One for each execution and one for each fplInit().
*/
static struct MemInfo *MallocKey=NULL;
void *Realloc(void *ptr, int size)
{
struct MemInfo *point;
void *new;
/* `point' points to the MemInfo structure: */
point=(struct MemInfo *)((char *)ptr-sizeof(struct MemInfo));
if(size<=point->size)
/*
* To increase performance, don't care about reallocing
* to smaller sizes!
*/
return(ptr);
new=Malloc(size); /* allocate new storage */
if(!new)
return(NULL); /* fail! */
memcpy(new, ptr, point->size); /* copy contents */
Free(ptr); /* free old area */
return(new); /* return new pointer */
}
void *Malloc(int size)
{
char *alloc;
struct MemInfo *point;
#ifdef DEBUG
size+=MEMORY_COOKIE; /* add extra bytes after the block! */
#endif
#ifdef AMIGA
alloc=(char *)AllocMem(size+sizeof(struct MemInfo), 0L);
#elif defined(UNIX)
alloc=(char *)malloc(size+sizeof(struct MemInfo));
#endif
if(!alloc)
return(NULL);
point=(struct MemInfo *)alloc;
point->prev=MallocKey; /* previous */
point->next=NULL; /* next */
point->size=size; /* size */
#ifdef DEBUG
malloc_count++;
mem+=size+sizeof(struct MemInfo);
if(mem>maxmem)
maxmem=mem;
memset((void *)((char *)point+sizeof(struct MemInfo)), 0xbb, size);
#endif
if(MallocKey)
point->prev->next=point;
MallocKey = (void *)point;
alloc = ((char *)point+sizeof(struct MemInfo));
return ((void *)alloc);
}
void Free(void *ptr)
{
struct MemInfo *point;
/* `point' points to the MemInfo structure: */
point=(struct MemInfo *)((char *)ptr-sizeof(struct MemInfo));
if(MallocKey==point) {
/* if this is the last Malloc, set `last' to `prev' */
MallocKey=point->prev;
if(MallocKey)
MallocKey->next=NULL;
} else {
/* point the previous' `next' to our `next', and our next `previous'
to our `previous'. Unlink us from the chain */
if(point->prev)
/* only if we aren't the _first_ Malloc() ! */
point->prev->next=point->next;
if(point->next)
/* only if there is a next! */
point->next->prev=point->prev;
}
#ifdef DEBUG
mem-=point->size+sizeof(struct MemInfo);
CheckMem(ptr);
#endif
#ifdef AMIGA
FreeMem(point, point->size+sizeof(struct MemInfo));
#elif UNIX
free(point);
#endif
}
#ifdef DEBUG
void CheckMem(void *ptr)
{
int i;
int b=0;
struct MemInfo *point;
/* `point' points to the MemInfo structure: */
point=(struct MemInfo *)((char *)ptr-sizeof(struct MemInfo));
for(i=0;i<MEMORY_COOKIE; i++)
if(*((unsigned char *)point+sizeof(struct MemInfo)+i+point->size-MEMORY_COOKIE)!= 0xbb)
b++;
if(b) {
#if defined(UNIX)
fprintf(stderr, "Memory violation: malloc(%d) was abused %d bytes!\n",
point->size-MEMORY_COOKIE-sizeof(struct MemInfo), b);
#elif defined(AMIGA)
/* ERROR */;
#endif
}
}
#endif
void FreeAll(void)
{
struct MemInfo *point;
void *prev;
if(!MallocKey)
return;
do {
point=MallocKey;
/* `point' points to the MemInfo structure! */
prev=(void *)point->prev;
#ifdef DEBUG
mem-=point->size+sizeof(struct MemInfo);
#endif
#ifdef AMIGA
FreeMem(MallocKey, point->size+sizeof(struct MemInfo));
#elif UNIX
free((char *)MallocKey);
#endif
} while(MallocKey=prev);
}