History

Revert "* and #pragma pop_macro("macro_name")"

- pop_macro incorrect with initially undefined macro - horrible implementation (tcc_open_bf) - crashes eventually (abuse of Sym->prev_tok) - the (unrelated) asm_label part is the opposite of a fix (Despite of its name this variable has nothing to do with the built-in assembler) This reverts commit 0c8447db7970813292a8be74ee50e49091be5d15.

grischka committed 11 years ago

Commit 7c271861 parent 059aea58 files · +2 −68Browse files

Unified · Split

8 files
  1. tcc.h +0 −1
  2. tccasm.c +0 −3
  3. tccgen.c +1 −0
  4. tccpp.c +0 −32
  5. tcctok.h +0 −2
  6. tests/tests2/77_push_pop_macro.c +0 −23
  7. tests/tests2/77_push_pop_macro.expect +0 −5
  8. tests/tests2/Makefile +1 −2
tcc.h+0−1
@@ -326,7 +326,6 @@ · 325 unmodified lines
326typedef struct TokenSym {326typedef struct TokenSym {
327 struct TokenSym *hash_next;327 struct TokenSym *hash_next;
328 struct Sym *sym_define; /* direct pointer to define */328 struct Sym *sym_define; /* direct pointer to define */
329 struct Sym *sym_define_stack; /* direct pointer to a push_macro stack */
330 struct Sym *sym_label; /* direct pointer to label */329 struct Sym *sym_label; /* direct pointer to label */
331 struct Sym *sym_struct; /* direct pointer to structure */330 struct Sym *sym_struct; /* direct pointer to structure */
332 struct Sym *sym_identifier; /* direct pointer to identifier */331 struct Sym *sym_identifier; /* direct pointer to identifier */
tccasm.c+0−3
@@ -305,9 +305,6 @@ static void asm_free_labels(TCCState *st) · 304 unmodified lines
305 }305 }
306 /* remove label */306 /* remove label */
307 table_ident[s->v - TOK_IDENT]->sym_label = NULL;307 table_ident[s->v - TOK_IDENT]->sym_label = NULL;
308 if (s->asm_label) {
309 tcc_free(s->asm_label);
310 }
311 sym_free(s);308 sym_free(s);
312 }309 }
313 st->asm_labels = NULL;310 st->asm_labels = NULL;
tccgen.c+1−0
@@ -152,6 +152,7 @@ static inline Sym *sym_malloc(void) · 151 unmodified lines
152ST_INLN void sym_free(Sym *sym)152ST_INLN void sym_free(Sym *sym)
153{153{
154 sym->next = sym_free_first;154 sym->next = sym_free_first;
155 tcc_free(sym->asm_label);
155 sym_free_first = sym;156 sym_free_first = sym;
156}157}
157 158
tccpp.c+0−32
@@ -222,7 +222,6 @@ static TokenSym *tok_alloc_new(TokenSym **pts, const char *str, int len) · 221 unmodified lines
222 table_ident[i] = ts;222 table_ident[i] = ts;
223 ts->tok = tok_ident++;223 ts->tok = tok_ident++;
224 ts->sym_define = NULL;224 ts->sym_define = NULL;
225 ts->sym_define_stack = NULL;
226 ts->sym_label = NULL;225 ts->sym_label = NULL;
227 ts->sym_struct = NULL;226 ts->sym_struct = NULL;
228 ts->sym_identifier = NULL;227 ts->sym_identifier = NULL;
@@ -1447,37 +1446,6 @@ static void pragma_parse(TCCState *s1) · 1218 unmodified lines
1447 } else {1446 } else {
1448 tcc_warning("#pragma comment(lib) is ignored");1447 tcc_warning("#pragma comment(lib) is ignored");
1449 }1448 }
1450 } else if ((tok == TOK_push_macro) || (tok == TOK_pop_macro)) {
1451 int push_macro = (tok == TOK_push_macro);
1452 next();
1453 skip('(');
1454 if (tok != TOK_STR) {
1455 expect("\"");
1456 } else {
1457 int len = strlen((char *)tokc.cstr->data);
1458 tcc_open_bf(s1, "<push_pop_macro>", len);
1459 memcpy(file->buffer, tokc.cstr->data, len);
1460 ch = file->buf_ptr[0];
1461 next_nomacro();
1462 if (tok >= TOK_IDENT) {
1463 Sym *s = table_ident[tok - TOK_IDENT]->sym_define;
1464 Sym *ss = table_ident[tok - TOK_IDENT]->sym_define_stack;
1465 if (push_macro) {
1466 if (s) {
1467 s->prev_tok = ss;
1468 table_ident[tok - TOK_IDENT]->sym_define_stack = s;
1469 }
1470 } else {
1471 if (ss) {
1472 table_ident[tok - TOK_IDENT]->sym_define = ss;
1473 table_ident[tok - TOK_IDENT]->sym_define_stack = ss->prev_tok;
1474 }
1475 }
1476 }
1477 tcc_close();
1478 }
1479 next();
1480 skip(')');
1481 } else if (tok == TOK_once) {1449 } else if (tok == TOK_once) {
1482 add_cached_include(s1, file->filename, TOK_once);1450 add_cached_include(s1, file->filename, TOK_once);
1483 } else {1451 } else {
tcctok.h+0−2
@@ -155,8 +155,6 @@ · 154 unmodified lines
155#endif155#endif
156 DEF(TOK_comment, "comment")156 DEF(TOK_comment, "comment")
157 DEF(TOK_lib, "lib")157 DEF(TOK_lib, "lib")
158 DEF(TOK_push_macro, "push_macro")
159 DEF(TOK_pop_macro, "pop_macro")
160 DEF(TOK_once, "once")158 DEF(TOK_once, "once")
161 159
162/* builtin functions or variables */160/* builtin functions or variables */
tests/tests2/77_push_pop_macro.c+0−23
@@ -1,23 +0,0 @@
1#include <stdio.h>
2
3int main()
4{
5 #define abort "111"
6 printf("abort = %s\n", abort);
7
8 #pragma push_macro("abort")
9 #undef abort
10 #define abort "222"
11 printf("abort = %s\n", abort);
12
13 #pragma push_macro("abort")
14 #undef abort
15 #define abort "333"
16 printf("abort = %s\n", abort);
17
18 #pragma pop_macro("abort")
19 printf("abort = %s\n", abort);
20
21 #pragma pop_macro("abort")
22 printf("abort = %s\n", abort);
23}
tests/tests2/77_push_pop_macro.expect+0−5
@@ -1,5 +0,0 @@
1abort = 111
2abort = 222
3abort = 333
4abort = 222
5abort = 111
tests/tests2/Makefile+1−2
@@ -95,8 +95,7 @@ TESTS = \ · 94 unmodified lines
95 73_arm64.test \95 73_arm64.test \
96 74_nocode_wanted.test \96 74_nocode_wanted.test \
97 75_array_in_struct_init.test \97 75_array_in_struct_init.test \
98 76_dollars_in_identifiers.test \98 76_dollars_in_identifiers.test
99 77_push_pop_macro.test
100 99
101# 34_array_assignment.test -- array assignment is not in C standard100# 34_array_assignment.test -- array assignment is not in C standard
102 101

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t