fix syntax error
[nedit-bw.git] / Symbol-embed-name.patch
blob786f4a5ed2692d1556b44ac47dafd44edb1073a8
1 ---
3 source/interpret.c | 37 ++++++++++++++++++++++++-------------
4 source/interpret.h | 4 ++--
5 2 files changed, 26 insertions(+), 15 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)
14 Symbol *s;
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);
21 s->type = type;
22 s->value = value;
23 s->added = 0;
24 if (type == LOCAL_SYM) {
25 @@ -1223,15 +1223,14 @@ static void restoreContext(RestartData *
26 static void freeSymbolTable(Symbol *symTab)
28 Symbol *s;
30 while(symTab != NULL) {
31 - s = symTab;
32 - free(s->name);
33 - symTab = s->next;
34 - free((char *)s);
35 - }
36 + s = symTab;
37 + symTab = s->next;
38 + free(s);
39 + }
42 #define POP(dataVal) \
43 do { \
44 POP_CHECK(1); \
45 @@ -2720,18 +2719,30 @@ int OverlayRoutineFromSymbol(Symbol *sym
46 ** executed in the caller's context from a function in macro.c.
49 int OverlayRoutineFromProg(Program *prog, int nArgs, int removeArgs)
51 - Symbol sym;
52 + Symbol *sym;
53 + int ret;
55 + /* no +1, because of .name[1] */
56 + sym = malloc(sizeof(Symbol) + strlen(prog->name));
57 + if (NULL == sym) {
58 + return False;
59 + }
61 + sym->type = MACRO_FUNCTION_SYM;
62 + strcpy(sym->name, prog->name);
63 + sym->value.val.prog = prog;
64 + sym->next = NULL;
65 + sym->added = 0;
67 + ret = OverlayRoutineFromSymbol(sym, nArgs, removeArgs);
69 - sym.type = MACRO_FUNCTION_SYM;
70 - sym.name = prog->name;
71 - sym.value.val.str.rep = (char *)prog;
72 - sym.next = NULL;
73 + free(sym);
75 - return OverlayRoutineFromSymbol(&sym, nArgs, removeArgs);
76 + return ret;
80 ** For special call style where the $args array in the called function is
81 ** assigned from an array in the caller (as "calledFunc(=argsArray)"),
82 diff --quilt old/source/interpret.h new/source/interpret.h
83 --- old/source/interpret.h
84 +++ new/source/interpret.h
85 @@ -106,15 +106,15 @@ typedef struct SparseArrayEntryTag {
86 DataValue value;
87 } SparseArrayEntry;
89 /* symbol table entry */
90 typedef struct SymbolRec {
91 - char *name;
92 enum symTypes type;
93 DataValue value;
94 - struct SymbolRec *next; /* to link to another */
95 int added;
96 + struct SymbolRec *next; /* to link to another */
97 + char name[1];
98 } Symbol;
100 typedef struct ProgramTag {
101 Symbol *localSymList;
102 Inst *code;