1 Subject: Symbol: embed name into struct
3 This safes a malloc/free pair.
7 source/interpret.c | 37 ++++++++++++++++++++++++-------------
8 source/interpret.h | 4 ++--
9 2 files changed, 26 insertions(+), 15 deletions(-)
11 diff --quilt old/source/interpret.c new/source/interpret.c
12 --- old/source/interpret.c
13 +++ new/source/interpret.c
14 @@ -834,8 +834,8 @@ Symbol *InstallSymbol(const char *name,
18 - s = (Symbol *)malloc(sizeof(Symbol));
19 - s->name = (char *)malloc(strlen(name)+1); /* +1 for '\0' */
20 + /* no +1, because of .name[1] */
21 + s = malloc(sizeof(Symbol) + strlen(name));
22 strcpy(s->name, name);
25 @@ -1226,11 +1226,10 @@ static void freeSymbolTable(Symbol *symT
28 while(symTab != NULL) {
40 /* true, if you can pop n values */
41 @@ -2739,14 +2738,26 @@ int OverlayRoutineFromSymbol(Symbol *sym
43 int OverlayRoutineFromProg(Program *prog, int nArgs, int removeArgs)
49 + /* no +1, because of .name[1] */
50 + sym = malloc(sizeof(Symbol) + strlen(prog->name));
55 + sym->type = MACRO_FUNCTION_SYM;
56 + strcpy(sym->name, prog->name);
57 + sym->value.val.prog = prog;
61 + ret = OverlayRoutineFromSymbol(sym, nArgs, removeArgs);
63 - sym.type = MACRO_FUNCTION_SYM;
64 - sym.name = prog->name;
65 - sym.value.val.prog = prog;
69 - return OverlayRoutineFromSymbol(&sym, nArgs, removeArgs);
74 diff --quilt old/source/interpret.h new/source/interpret.h
75 --- old/source/interpret.h
76 +++ new/source/interpret.h
77 @@ -98,11 +98,11 @@ typedef struct SparseArrayEntryTag {
79 /* symbol table entry */
80 typedef struct SymbolRec {
84 - struct SymbolRec *next; /* to link to another */
86 + struct SymbolRec *next; /* to link to another */
90 typedef struct ProgramTag {