disable OM2.3.1 by default, enable with make bertw OM231=1
[nedit-bw.git] / Symbol-embed-name.patch
blobe00beb218dca008e2a2367b4a39f7d210b1642b9
1 Subject: Symbol: embed name into struct
3 This safes a malloc/free pair.
5 ---
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 @@ -784,12 +784,12 @@ Symbol *LookupSymbol(const char *name)
16 Symbol *InstallSymbol(const char *name, enum symTypes type, DataValue value)
18 Symbol *s;
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);
25 s->type = type;
26 s->value = value;
27 s->added = 0;
28 if (type == LOCAL_SYM) {
29 @@ -1176,15 +1176,14 @@ static void restoreContext(RestartData *
30 static void freeSymbolTable(Symbol *symTab)
32 Symbol *s;
34 while(symTab != NULL) {
35 - s = symTab;
36 - free(s->name);
37 - symTab = s->next;
38 - free((char *)s);
39 - }
40 + s = symTab;
41 + symTab = s->next;
42 + free(s);
43 + }
46 /* true, if you can pop n values */
47 #define OK_TO_POP(n) \
48 ((StackP - (n)) >= TheStack)
49 @@ -2755,18 +2754,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)
55 - Symbol sym;
56 + Symbol *sym;
57 + int ret;
59 + /* no +1, because of .name[1] */
60 + sym = malloc(sizeof(Symbol) + strlen(prog->name));
61 + if (NULL == sym) {
62 + return False;
63 + }
65 + sym->type = MACRO_FUNCTION_SYM;
66 + strcpy(sym->name, prog->name);
67 + sym->value.val.prog = prog;
68 + sym->next = NULL;
69 + sym->added = 0;
71 + ret = OverlayRoutineFromSymbol(sym, nArgs, removeArgs);
73 - sym.type = MACRO_FUNCTION_SYM;
74 - sym.name = prog->name;
75 - sym.value.val.str.rep = (char *)prog;
76 - sym.next = NULL;
77 + free(sym);
79 - return OverlayRoutineFromSymbol(&sym, nArgs, removeArgs);
80 + return ret;
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 {
90 DataValue value;
91 } SparseArrayEntry;
93 /* symbol table entry */
94 typedef struct SymbolRec {
95 - char *name;
96 enum symTypes type;
97 DataValue value;
98 - struct SymbolRec *next; /* to link to another */
99 int added;
100 + struct SymbolRec *next; /* to link to another */
101 + char name[1];
102 } Symbol;
104 typedef struct ProgramTag {
105 Symbol *localSymList;
106 Inst *code;