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 @@ -813,12 +813,12 @@ Symbol *LookupSymbol(const char *name)
16 Symbol *InstallSymbol(const char *name, enum symTypes type, DataValue value)
20 - s = (Symbol *)malloc(sizeof(Symbol));
21 - s->name = (char *)malloc(strlen(name)+1); /* +1 for '\0' */
22 + /* no +1, because of .name[1] */
23 + s = malloc(sizeof(Symbol) + strlen(name));
24 strcpy(s->name, name);
28 if (type == LOCAL_SYM) {
29 @@ -1205,15 +1205,14 @@ static void restoreContext(RestartData *
30 static void freeSymbolTable(Symbol *symTab)
34 while(symTab != NULL) {
46 /* true, if you can pop n values */
47 #define OK_TO_POP(n) \
48 ((StackP - (n)) >= TheStack)
49 @@ -2750,18 +2749,30 @@ int OverlayRoutineFromSymbol(Symbol *sym
50 ** executed in the caller's context from a function in macro.c.
53 int OverlayRoutineFromProg(Program *prog, int nArgs, int removeArgs)
59 + /* no +1, because of .name[1] */
60 + sym = malloc(sizeof(Symbol) + strlen(prog->name));
65 + sym->type = MACRO_FUNCTION_SYM;
66 + strcpy(sym->name, prog->name);
67 + sym->value.val.prog = prog;
71 + ret = OverlayRoutineFromSymbol(sym, nArgs, removeArgs);
73 - sym.type = MACRO_FUNCTION_SYM;
74 - sym.name = prog->name;
75 - sym.value.val.prog = prog;
79 - return OverlayRoutineFromSymbol(&sym, nArgs, removeArgs);
84 ** For special call style where the $args array in the called function is
85 ** assigned from an array in the caller (as "calledFunc(=argsArray)"),
86 diff --quilt old/source/interpret.h new/source/interpret.h
87 --- old/source/interpret.h
88 +++ new/source/interpret.h
89 @@ -96,15 +96,15 @@ typedef struct SparseArrayEntryTag {
93 /* symbol table entry */
94 typedef struct SymbolRec {
98 - struct SymbolRec *next; /* to link to another */
100 + struct SymbolRec *next; /* to link to another */
104 typedef struct ProgramTag {
105 Symbol *localSymList;