History

fix for the #include_next, v4 (final)

This version looks rigth. Comparing to the original algorithm: 1) Loop breaking. We remember a start point after wich we can try next path. Do not search include stack after this. 2) But compare next file patch with the start point. Skip if it the same. Remove "./" before comparing. PS: a problems with compaling a coreutils-8.24.51-8802e remain. There are errors messages like: src/chgrp src/chown-core.c:42: multiple definition of `make_timespec' src/chgrp.c:42: first defined here A problem is in the lib/config.h #define _GL_INLINE_ extern inline // gcc #define _GL_INLINE_ inline // tcc A long description from the lib/config.h * suppress extern inline with HP-UX cc, as it appears to be broken * suppress extern inline with Sun C in standards-conformance mode * suppress extern inline on configurations that mistakenly use 'static inline' to implement functions or macros in standard C headers like <ctype.h>. GCC and Clang are excluded from this list. Why not tcc?

seyko committed 11 years ago

Commit 003c5321 parent ad1c01f1 file · +54 −19Browse files

Unified · Split

tccpp.c+54−19
@@ -1528,7 +1528,7 @@ ST_FUNC void preprocess(int is_bof) · 1527 unmodified lines
15281528 int i, c, n, saved_parse_flags;
15291529 char buf[1024], *q;
15301530 Sym *s;
1531− int include_next_count = 0;
1531+ char *p3 = 0;
15321532
15331533 saved_parse_flags = parse_flags;
15341534 parse_flags = PARSE_FLAG_PREPROCESS
@@ -1618,6 +1618,11 @@ ST_FUNC void preprocess(int is_bof) · 83 unmodified lines
16181618 /* store current file in stack, but increment stack later below */
16191619 *s1->include_stack_ptr = file;
16201620
1621+ #ifdef INC_DEBUG
1622+ if (tok == TOK_INCLUDE_NEXT)
1623+ printf("%s (1) include_next file %s\n", file->filename, buf);
1624+ #endif
1625+
16211626 n = s1->nb_include_paths + s1->nb_sysinclude_paths;
16221627 for (i = -2; i < n; ++i) {
16231628 char buf1[sizeof file->filename];
@@ -1649,36 +1654,67 @@ ST_FUNC void preprocess(int is_bof) · 25 unmodified lines
16491654 pstrcat(buf1, sizeof(buf1), "/");
16501655 }
16511656
1657+ #ifdef INC_DEBUG
1658+ if (tok == TOK_INCLUDE_NEXT)
1659+ printf("%s (2) include_next path <%s> name <%s>\n", file->filename, buf1, buf);
1660+ #endif
1661+
16521662 pstrcat(buf1, sizeof(buf1), buf);
16531663
16541664 if (tok == TOK_INCLUDE_NEXT) {
1655− for (f = s1->include_stack_ptr; f >= s1->include_stack; --f)
1656− if (0 == PATHCMP((*f)->filename, buf1)) {
1657−#ifdef INC_DEBUG
1658− printf("%s: #include_next skipping %s\n", file->filename, buf1);
1659−#endif
1660− include_next_count++;
1665+ char *p1 = buf1;
1666+ if ((p1[0] == '.') && IS_DIRSEP(p1[1])) p1 += 2;
1667+
1668+ if (p3) {
1669+ if (0 == PATHCMP(p1, p3)) {
1670+ #ifdef INC_DEBUG
1671+ printf("%s (3) include_next skipping <%s>\n", file->filename, p1);
1672+ #endif
16611673 goto include_trynext;
16621674 }
1675+ }
1676+ else {
1677+ for (f = s1->include_stack_ptr; f >= s1->include_stack; --f) {
1678+ char *p2 = (*f)->filename;
1679+ if ((p2[0] == '.') && IS_DIRSEP(p2[1])) p2 += 2;
1680+ if (0 == PATHCMP(p2, p1)) {
1681+ p3 = p2;
1682+ break;
1683+ }
1684+ }
1685+ #ifdef INC_DEBUG
1686+ printf("%s: (4) include_next skipping <%s> (p3=%p)\n", file->filename, buf1, p3);
1687+ #endif
1688+ goto include_trynext;
1689+ }
1690+ #ifdef INC_DEBUG
1691+ printf("%s (5) include_next considering <%s>\n", file->filename, buf1);
1692+ #endif
16631693 }
16641694
16651695 e = search_cached_include(s1, buf1);
16661696 if (e && (define_find(e->ifndef_macro) || e->ifndef_macro == TOK_once)) {
16671697 /* no need to parse the include because the 'ifndef macro'
16681698 is defined */
1669−#ifdef INC_DEBUG
1670− printf("%s: skipping cached %s\n", file->filename, buf1);
1671−#endif
1699+
1700+ #ifdef INC_DEBUG
1701+ printf("%s: skipping cached <%s>\n", file->filename, buf1);
1702+ #endif
16721703 goto include_done;
16731704 }
16741705
1675− if (tcc_open(s1, buf1) < 0)
1706+ if (tcc_open(s1, buf1) < 0) {
1707+ #ifdef INC_DEBUG
1708+ printf("%s: include open failed <%s>\n", file->filename, buf1);
1709+ #endif
16761710 include_trynext:
16771711 continue;
1712+ }
1713+
1714+ #ifdef INC_DEBUG
1715+ printf("%s: including <%s>\n", file->prev->filename, file->filename);
1716+ #endif
16781717
1679−#ifdef INC_DEBUG
1680− printf("%s: including %s\n", file->prev->filename, file->filename);
1681−#endif
16821718 /* update target deps */
16831719 dynarray_add((void ***)&s1->target_deps, &s1->nb_target_deps,
16841720 tcc_strdup(buf1));
@@ -1691,8 +1727,7 @@ include_trynext: · 6 unmodified lines
16911727 ch = file->buf_ptr[0];
16921728 goto the_end;
16931729 }
1694− if (include_next_count == 0)
1695− tcc_error("include file '%s' not found", buf);
1730+ tcc_error("include file '%s' not found", buf);
16961731 include_done:
16971732 break;
16981733 case TOK_IFNDEF:
@@ -1709,9 +1744,9 @@ include_done: · 10 unmodified lines
17091744 tcc_error("invalid argument for '#if%sdef'", c ? "n" : "");
17101745 if (is_bof) {
17111746 if (c) {
1712−#ifdef INC_DEBUG
1713− printf("#ifndef %s\n", get_tok_str(tok, NULL));
1714−#endif
1747+ #ifdef INC_DEBUG
1748+ printf("#ifndef %s\n", get_tok_str(tok, NULL));
1749+ #endif
17151750 file->ifndef_macro = tok;
17161751 }
17171752 }

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