History

Fix pragma once guard

From: Vlad Vissoultchev Date: Mon, 11 Apr 2016 01:26:32 +0300 Subject: Fix pragma once guard when compiling multiple source files When compiling multiple source files directly to executable cached include files guard was incorrectly checked for TOK_once in ifndef_macro member. If two source files included the same header guarded by pragma once, then the second one erroneously skipped it as `cached_includes` is not cleared on second `tcc_compile`

seyko committed 10 years ago

Commit b5b3e891 parent b0296132 files · +6 −3Browse files

Unified · Split

2 files
  1. tcc.c +1 −1
  2. tccpp.c +5 −2
tcc.c+1−1
@@ -344,7 +344,7 @@ int main(int argc, char **argv) · 343 unmodified lines
344344 tcc_parse_args(s, argc - 1, argv + 1);
345345 tcc_set_environment(s);
346346 if (s->output_type != TCC_OUTPUT_OBJ)
347− tcc_error("interlnal error");
347+ tcc_error("internal error");
348348 tcc_set_output_type(s, s->output_type);
349349 }
350350 }
tccpp.c+5−2
@@ -1471,8 +1471,11 @@ static void pragma_parse(TCCState *s1) · 1470 unmodified lines
14711471 tcc_warning("unbalanced #pragma pop_macro");
14721472
14731473 } else if (tok == TOK_once) {
1474− add_cached_include(s1, file->filename, TOK_once);
1474+ char buf1[sizeof file->filename];
14751475
1476+ pstrcpy(buf1, sizeof(buf1), "#once#");
1477+ pstrcat(buf1, sizeof(buf1), file->filename);
1478+ add_cached_include(s1, file->filename, tok_alloc(buf1, strlen(buf1))->tok);
14761479 } else if (s1->ppfp) {
14771480 /* tcc -E: keep pragmas below unchanged */
14781481 unget_tok(' ');
@@ -1670,7 +1673,7 @@ ST_FUNC void preprocess(int is_bof) · 191 unmodified lines
16701673
16711674 pstrcat(buf1, sizeof(buf1), buf);
16721675 e = search_cached_include(s1, buf1);
1673− if (e && (define_find(e->ifndef_macro) || e->ifndef_macro == TOK_once)) {
1676+ if (e && define_find(e->ifndef_macro)) {
16741677 /* no need to parse the include because the 'ifndef macro'
16751678 is defined */
16761679 #ifdef INC_DEBUG

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