import MultipleAssignment.diff from ajbj
[nedit-bw.git] / Symbol-embed-name.patch
blob5d2e410e7696c39678b203736974cd869c844fa9
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 @@ -834,8 +834,8 @@ Symbol *InstallSymbol(const char *name,
16 Symbol *s;
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);
23 s->type = type;
24 s->value = value;
25 @@ -1226,11 +1226,10 @@ static void freeSymbolTable(Symbol *symT
26 Symbol *s;
28 while(symTab != NULL) {
29 - s = symTab;
30 - free(s->name);
31 - symTab = s->next;
32 - free((char *)s);
33 - }
34 + s = symTab;
35 + symTab = s->next;
36 + free(s);
37 + }
40 /* true, if you can pop n values */
41 @@ -2771,14 +2770,26 @@ int OverlayRoutineFromSymbol(Symbol *sym
43 int OverlayRoutineFromProg(Program *prog, int nArgs, int removeArgs)
45 - Symbol sym;
46 + Symbol *sym;
47 + int ret;
49 + /* no +1, because of .name[1] */
50 + sym = malloc(sizeof(Symbol) + strlen(prog->name));
51 + if (NULL == sym) {
52 + return STAT_ERROR;
53 + }
55 + sym->type = MACRO_FUNCTION_SYM;
56 + strcpy(sym->name, prog->name);
57 + sym->value.val.prog = prog;
58 + sym->next = NULL;
59 + sym->added = 0;
61 + ret = OverlayRoutineFromSymbol(sym, nArgs, removeArgs);
63 - sym.type = MACRO_FUNCTION_SYM;
64 - sym.name = prog->name;
65 - sym.value.val.prog = prog;
66 - sym.next = NULL;
67 + free(sym);
69 - return OverlayRoutineFromSymbol(&sym, nArgs, removeArgs);
70 + return ret;
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 {
81 - char *name;
82 enum symTypes type;
83 DataValue value;
84 - struct SymbolRec *next; /* to link to another */
85 int added;
86 + struct SymbolRec *next; /* to link to another */
87 + char name[1];
88 } Symbol;
90 typedef struct ProgramTag {