[hackers] [scc] Free cpp symbols after undefining them || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 11 Aug 2015 17:57:55 +0200 (CEST)

commit e7f022e3a196d7473765f5f456da2e19057a7e82
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Aug 11 17:27:15 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Aug 11 17:27:15 2015 +0200

    Free cpp symbols after undefining them
    
    Due to the previous data structures used it was hard to free
    symbols out of popctx(), but cpp symbols are not anymore in any list.
    They are in the hash table (and usually at the beginning of the
    collision list), so it is very easy to free them now.

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 3d91eaf..17c23ac 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -307,6 +307,7 @@ extern Symbol *newsym(unsigned ns);
 extern void pushctx(void), popctx(void);
 extern void ikeywords(void);
 extern Symbol *addmacro(void);
+extern void delmacro(Symbol *sym);
 
 /* stmt.c */
 extern void compound(Symbol *lbreak, Symbol *lcont, Caselist *lswitch);
diff --git a/cc1/cpp.c b/cc1/cpp.c
index 64e0cd6..ae55236 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
_AT_@ -531,16 +531,14 @@ elif(void)
 static void
 undef(void)
 {
- Symbol *sym;
-
         if (cppoff)
                 return;
         if (yytoken != IDEN) {
                 error("no macro name given in #undef directive");
                 return;
         }
- sym = lookup(NS_CPP);
- sym->flags &= ~ISDECLARED;
+ if (yylval.sym->ns == NS_CPP)
+ delmacro(yylval.sym);
         next();
 }
 
diff --git a/cc1/symbol.c b/cc1/symbol.c
index 001a471..2286a96 100644
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
_AT_@ -222,6 +222,14 @@ addmacro(void)
         curctx = ctx;
         return sym;
 }
+
+void
+delmacro(Symbol *sym)
+{
+ unlinkhash(sym);
+ free(sym->name);
+ free(sym->u.s);
+ free(sym);
 }
 
 Symbol *
Received on Tue Aug 11 2015 - 17:57:55 CEST

This archive was generated by hypermail 2.3.0 : Tue Aug 11 2015 - 18:00:22 CEST