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
326326 typedef struct TokenSym {
327327 struct TokenSym *hash_next;
328328 struct Sym *sym_define; /* direct pointer to define */
329− struct Sym *sym_define_stack; /* direct pointer to a push_macro stack */
330329 struct Sym *sym_label; /* direct pointer to label */
331330 struct Sym *sym_struct; /* direct pointer to structure */
332331 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
305305 }
306306 /* remove label */
307307 table_ident[s->v - TOK_IDENT]->sym_label = NULL;
308− if (s->asm_label) {
309− tcc_free(s->asm_label);
310− }
311308 sym_free(s);
312309 }
313310 st->asm_labels = NULL;
tccgen.c+1−0
@@ -152,6 +152,7 @@ static inline Sym *sym_malloc(void) · 151 unmodified lines
152152 ST_INLN void sym_free(Sym *sym)
153153 {
154154 sym->next = sym_free_first;
155+ tcc_free(sym->asm_label);
155156 sym_free_first = sym;
156157 }
157158
tccpp.c+0−32
@@ -222,7 +222,6 @@ static TokenSym *tok_alloc_new(TokenSym **pts, const char *str, int len) · 221 unmodified lines
222222 table_ident[i] = ts;
223223 ts->tok = tok_ident++;
224224 ts->sym_define = NULL;
225− ts->sym_define_stack = NULL;
226225 ts->sym_label = NULL;
227226 ts->sym_struct = NULL;
228227 ts->sym_identifier = NULL;
@@ -1447,37 +1446,6 @@ static void pragma_parse(TCCState *s1) · 1218 unmodified lines
14471446 } else {
14481447 tcc_warning("#pragma comment(lib) is ignored");
14491448 }
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(')');
14811449 } else if (tok == TOK_once) {
14821450 add_cached_include(s1, file->filename, TOK_once);
14831451 } else {
tcctok.h+0−2
@@ -155,8 +155,6 @@ · 154 unmodified lines
155155 #endif
156156 DEF(TOK_comment, "comment")
157157 DEF(TOK_lib, "lib")
158− DEF(TOK_push_macro, "push_macro")
159− DEF(TOK_pop_macro, "pop_macro")
160158 DEF(TOK_once, "once")
161159
162160 /* builtin functions or variables */
tests/tests2/77_push_pop_macro.c+0−23
@@ -1,23 +0,0 @@
1−#include <stdio.h>
2−
3−int 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 @@
1−abort = 111
2−abort = 222
3−abort = 333
4−abort = 222
5−abort = 111
tests/tests2/Makefile+1−2
@@ -95,8 +95,7 @@ TESTS = \ · 94 unmodified lines
9595 73_arm64.test \
9696 74_nocode_wanted.test \
9797 75_array_in_struct_init.test \
98− 76_dollars_in_identifiers.test \
99− 77_push_pop_macro.test
98+ 76_dollars_in_identifiers.test
10099
101100 # 34_array_assignment.test -- array assignment is not in C standard
102101

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