3 source/interpret.c | 39 +++++++++++++++++++++++++--------------
4 source/interpret.h | 4 ++--
5 2 files changed, 27 insertions(+), 16 deletions(-)
7 diff --quilt old/source/interpret.c new/source/interpret.c
8 --- old/source/interpret.c
9 +++ new/source/interpret.c
10 @@ -860,12 +860,12 @@ Symbol *LookupSymbol(const char *name)
12 Symbol *InstallSymbol(const char *name, enum symTypes type, DataValue value)
16 - s = (Symbol *)malloc(sizeof(Symbol));
17 - s->name = (char *)malloc(strlen(name)+1); /* +1 for '\0' */
18 + /* no +1, because of .name[1] */
19 + s = malloc(sizeof(Symbol) + strlen(name));
20 strcpy(s->name, name);
24 if (type == LOCAL_SYM) {
25 @@ -1221,15 +1221,14 @@ static void restoreContext(RestartData *
26 static void freeSymbolTable(Symbol *symTab)
30 while(symTab != NULL) {
42 #define POP(dataVal) \
45 @@ -2526,11 +2525,11 @@ static int callSubroutineFromSymbol(Symb
46 ** values which are already there.
48 if (sym->type == MACRO_FUNCTION_SYM) {
49 PUSH_CHECK(3 + !haveNamedArgs);
51 - prog = (Program *)sym->value.val.str.rep;
52 + prog = sym->value.val.prog;
55 *(StackP++) = noValue; /* push dummy named arg array */
57 StackP->tag = NO_TAG; /* return PC */
58 @@ -2716,18 +2715,30 @@ int OverlayRoutineFromSymbol(Symbol *sym
59 ** executed in the caller's context from a function in macro.c.
62 int OverlayRoutineFromProg(Program *prog, int nArgs, int removeArgs)
68 + /* no +1, because of .name[1] */
69 + sym = malloc(sizeof(Symbol) + strlen(prog->name));
74 + sym->type = MACRO_FUNCTION_SYM;
75 + strcpy(sym->name, prog->name);
76 + sym->value.val.prog = prog;
80 + ret = OverlayRoutineFromSymbol(sym, nArgs, removeArgs);
82 - sym.type = MACRO_FUNCTION_SYM;
83 - sym.name = prog->name;
84 - sym.value.val.str.rep = (char *)prog;
88 - return OverlayRoutineFromSymbol(&sym, nArgs, removeArgs);
93 ** For special call style where the $args array in the called function is
94 ** assigned from an array in the caller (as "calledFunc(=argsArray)"),
95 diff --quilt old/source/interpret.h new/source/interpret.h
96 --- old/source/interpret.h
97 +++ new/source/interpret.h
98 @@ -106,15 +106,15 @@ typedef struct SparseArrayEntryTag {
102 /* symbol table entry */
103 typedef struct SymbolRec {
107 - struct SymbolRec *next; /* to link to another */
109 + struct SymbolRec *next; /* to link to another */
113 typedef struct ProgramTag {
114 Symbol *localSymList;