# HG changeset patch # User David A. Holland # Date 1370914367 14400 # Node ID 05a94332f08b82a374df573472801690129d2bc3 # Parent 27c9aafcaca1b846f04e64ac5f174355efe89f84 In #if/#elif, prune comments *after* macro expansion. Also prune comments again in #include if we get as far as trying macro expansion. diff -r 27c9aafcaca1 -r 05a94332f08b directive.c --- a/directive.c Mon Jun 10 21:30:20 2013 -0400 +++ b/directive.c Mon Jun 10 21:32:47 2013 -0400 @@ -175,9 +175,15 @@ char *expr; bool val; struct place p3 = *p2; + size_t oldlen; - uncomment(line); expr = macroexpand(p2, line, strlen(line), true); + + oldlen = strlen(expr); + uncomment(expr); + /* trim to fit, so the malloc debugging won't complain */ + expr = dorealloc(expr, oldlen + 1, strlen(expr) + 1); + val = eval(&p3, expr); ifstate_push(p, val); dostrfree(expr); @@ -207,6 +213,7 @@ { char *expr; struct place p3 = *p2; + size_t oldlen; if (ifstate->seenelse) { complain(p, "#elif after #else"); @@ -216,8 +223,13 @@ if (ifstate->evertrue) { ifstate->curtrue = false; } else { - uncomment(line); expr = macroexpand(p2, line, strlen(line), true); + + oldlen = strlen(expr); + uncomment(expr); + /* trim to fit, so the malloc debugging won't complain */ + expr = dorealloc(expr, oldlen + 1, strlen(expr) + 1); + ifstate->curtrue = eval(&p3, expr); ifstate->evertrue = ifstate->curtrue; dostrfree(expr); @@ -355,12 +367,19 @@ d_include(struct place *p, struct place *p2, char *line) { char *text; + size_t oldlen; uncomment(line); if (tryinclude(p, line)) { return; } text = macroexpand(p2, line, strlen(line), false); + + oldlen = strlen(text); + uncomment(text); + /* trim to fit, so the malloc debugging won't complain */ + text = dorealloc(text, oldlen + 1, strlen(text) + 1); + if (tryinclude(p, text)) { dostrfree(text); return;