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,
fprintf(stdout, "%s: %s", outname, inname);
while ( (line = preproc->getline()) )
nasm_free (line);
- preproc->cleanup();
+ preproc->cleanup(0);
putc('\n', stdout);
}
break;
nasm_free (line);
}
nasm_free(file_name);
- preproc->cleanup();
+ preproc->cleanup(0);
if (ofile)
fclose(ofile);
if (ofile && terminate_after_phase)
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);
} /* for (pass=1; pass<=2; pass++) */
+ preproc->cleanup(0);
nasmlist.cleanup();
#if 1
if (optimizing>0 && using_debug_info) /* -On and -g switches */
return buffer;
}
-static void no_pp_cleanup (void)
+static void no_pp_cleanup (int pass)
{
fclose(no_pp_fp);
}
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;
*/
#define TOKEN_BLOCKSIZE 4096
static Token *freeTokens = NULL;
+struct Blocks {
+ Blocks *next;
+ void *chunk;
+};
+
+static Blocks blocks = { NULL, NULL };
/*
* Forward declarations.
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);
}
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
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;
{
Token *next = t->next;
nasm_free(t->text);
-/* t->next = freeTokens ? freeTokens->next : NULL; */
t->next = freeTokens;
freeTokens = t;
return next;
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:
}
static void
-pp_cleanup(void)
+pp_cleanup(int pass)
{
int h;
}
while (cstk)
ctx_pop();
+ if (pass == 0)
+ {
+ free_llist(predef);
+ delete_Blocks();
+ }
}
void