From ce61607e1125f1fc1f7c74dfa486031bb7c898fa Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 30 Apr 2002 21:02:23 +0000 Subject: [PATCH] NASM 0.98.14 --- assemble.c | 3 +++ nasm.c | 11 +++++----- nasm.h | 4 ++-- preproc.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 76 insertions(+), 11 deletions(-) diff --git a/assemble.c b/assemble.c index f93457d..b9271a4 100644 --- a/assemble.c +++ b/assemble.c @@ -141,7 +141,10 @@ static void out (long offset, long segto, void *data, unsigned long type, } if (src_get(&lineno,&lnfname)) + { outfmt->current_dfmt->linenum(lnfname,lineno,segto); + if (lnfname) nasm_free(lnfname); + } outfmt->output (segto, data, type, segment, wrt); } diff --git a/nasm.c b/nasm.c index 20485d8..9e017fd 100644 --- a/nasm.c +++ b/nasm.c @@ -111,7 +111,7 @@ static char *suppressed_what[1+ERR_WARN_MAX] = { static void no_pp_reset (char *, int, efunc, evalfunc, ListGen *); static char *no_pp_getline (void); -static void no_pp_cleanup (void); +static void no_pp_cleanup (int); static Preproc no_pp = { no_pp_reset, no_pp_getline, @@ -189,7 +189,7 @@ int main(int argc, char **argv) fprintf(stdout, "%s: %s", outname, inname); while ( (line = preproc->getline()) ) nasm_free (line); - preproc->cleanup(); + preproc->cleanup(0); putc('\n', stdout); } break; @@ -233,7 +233,7 @@ int main(int argc, char **argv) nasm_free (line); } nasm_free(file_name); - preproc->cleanup(); + preproc->cleanup(0); if (ofile) fclose(ofile); if (ofile && terminate_after_phase) @@ -1241,7 +1241,7 @@ static void assemble_file (char *fname) if (pass1==2 && global_offset_changed) report_error(ERR_NONFATAL, "phase error detected at end of assembly."); - if (pass1 == 1) preproc->cleanup(); + if (pass1 == 1) preproc->cleanup(1); if (pass1==1 && terminate_after_phase) { fclose(ofile); @@ -1258,6 +1258,7 @@ static void assemble_file (char *fname) } /* for (pass=1; pass<=2; pass++) */ + preproc->cleanup(0); nasmlist.cleanup(); #if 1 if (optimizing>0 && using_debug_info) /* -On and -g switches */ @@ -1494,7 +1495,7 @@ static char *no_pp_getline (void) return buffer; } -static void no_pp_cleanup (void) +static void no_pp_cleanup (int pass) { fclose(no_pp_fp); } diff --git a/nasm.h b/nasm.h index c463879..c0dc0e5 100644 --- a/nasm.h +++ b/nasm.h @@ -13,7 +13,7 @@ #define NASM_MAJOR_VER 0 #define NASM_MINOR_VER 98 -#define NASM_VER "0.98.12" +#define NASM_VER "0.98.14" #ifndef NULL #define NULL 0 @@ -312,7 +312,7 @@ typedef struct { /* * Called at the end of a pass. */ - void (*cleanup) (void); + void (*cleanup) (int); } Preproc; /* diff --git a/preproc.c b/preproc.c index a62fe85..0277a45 100644 --- a/preproc.c +++ b/preproc.c @@ -48,6 +48,7 @@ typedef struct SMacro SMacro; typedef struct MMacro MMacro; typedef struct Context Context; typedef struct Token Token; +typedef struct Blocks Blocks; typedef struct Line Line; typedef struct Include Include; typedef struct Cond Cond; @@ -396,6 +397,12 @@ int any_extrastdmac; */ #define TOKEN_BLOCKSIZE 4096 static Token *freeTokens = NULL; +struct Blocks { + Blocks *next; + void *chunk; +}; + +static Blocks blocks = { NULL, NULL }; /* * Forward declarations. @@ -406,6 +413,8 @@ static Token *expand_id(Token * tline); static Context *get_ctx(char *name, int all_contexts); static void make_tok_num(Token * tok, long val); static void error(int severity, char *fmt, ...); +static void *new_Block(size_t size); +static void delete_Blocks(void); static Token *new_Token(Token * next, int type, char *text, int txtlen); static Token *delete_Token(Token * t); @@ -869,10 +878,56 @@ tokenise(char *line) } line = p; } - return list; } +/* + * this function allocates a new managed block of memory and + * returns a pointer to the block. The managed blocks are + * deleted only all at once by the delete_Blocks function. + */ +static void * +new_Block(size_t size) +{ + Blocks *b = &blocks; + + /* first, get to the end of the linked list */ + while (b->next) + b = b->next; + /* now allocate the requested chunk */ + b->chunk = nasm_malloc(size); + + /* now allocate a new block for the next request */ + b->next = nasm_malloc(sizeof(Blocks)); + /* and initialize the contents of the new block */ + b->next->next = NULL; + b->next->chunk = NULL; + return b->chunk; +} + +/* + * this function deletes all managed blocks of memory + */ +static void +delete_Blocks(void) +{ + Blocks *a,*b = &blocks; + + /* + * keep in mind that the first block, pointed to by blocks + * is a static and not dynamically allocated, so we don't + * free it. + */ + while (b) + { + if (b->chunk) + nasm_free(b->chunk); + a = b; + b = b->next; + if (a != &blocks) + nasm_free(a); + } +} /* * this function creates a new Token and passes a pointer to it @@ -887,7 +942,7 @@ new_Token(Token * next, int type, char *text, int txtlen) if (freeTokens == NULL) { - freeTokens = nasm_malloc(TOKEN_BLOCKSIZE * sizeof(Token)); + freeTokens = (Token *)new_Block(TOKEN_BLOCKSIZE * sizeof(Token)); for (i = 0; i < TOKEN_BLOCKSIZE - 1; i++) freeTokens[i].next = &freeTokens[i + 1]; freeTokens[i].next = NULL; @@ -917,7 +972,6 @@ delete_Token(Token * t) { Token *next = t->next; nasm_free(t->text); -/* t->next = freeTokens ? freeTokens->next : NULL; */ t->next = freeTokens; freeTokens = t; return next; @@ -3169,6 +3223,8 @@ expand_smacro(Token * tline) new_Token(org_tline->next, org_tline->type, org_tline->text, 0); tline->mac = org_tline->mac; + nasm_free(org_tline->text); + org_tline->text = NULL; } again: @@ -4124,7 +4180,7 @@ pp_getline(void) } static void -pp_cleanup(void) +pp_cleanup(int pass) { int h; @@ -4163,6 +4219,11 @@ pp_cleanup(void) } while (cstk) ctx_pop(); + if (pass == 0) + { + free_llist(predef); + delete_Blocks(); + } } void -- 2.7.4