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
1528 int i, c, n, saved_parse_flags;1528 int i, c, n, saved_parse_flags;
1529 char buf[1024], *q;1529 char buf[1024], *q;
1530 Sym *s;1530 Sym *s;
1531 int include_next_count = 0;1531 char *p3 = 0;
1532 1532
1533 saved_parse_flags = parse_flags;1533 saved_parse_flags = parse_flags;
1534 parse_flags = PARSE_FLAG_PREPROCESS1534 parse_flags = PARSE_FLAG_PREPROCESS
@@ -1618,6 +1618,11 @@ ST_FUNC void preprocess(int is_bof) · 83 unmodified lines
1618 /* store current file in stack, but increment stack later below */1618 /* store current file in stack, but increment stack later below */
1619 *s1->include_stack_ptr = file;1619 *s1->include_stack_ptr = file;
1620 1620
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
1621 n = s1->nb_include_paths + s1->nb_sysinclude_paths;1626 n = s1->nb_include_paths + s1->nb_sysinclude_paths;
1622 for (i = -2; i < n; ++i) {1627 for (i = -2; i < n; ++i) {
1623 char buf1[sizeof file->filename];1628 char buf1[sizeof file->filename];
@@ -1649,36 +1654,67 @@ ST_FUNC void preprocess(int is_bof) · 25 unmodified lines
1649 pstrcat(buf1, sizeof(buf1), "/");1654 pstrcat(buf1, sizeof(buf1), "/");
1650 }1655 }
1651 1656
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
1652 pstrcat(buf1, sizeof(buf1), buf);1662 pstrcat(buf1, sizeof(buf1), buf);
1653 1663
1654 if (tok == TOK_INCLUDE_NEXT) {1664 if (tok == TOK_INCLUDE_NEXT) {
1655 for (f = s1->include_stack_ptr; f >= s1->include_stack; --f)1665 char *p1 = buf1;
1656 if (0 == PATHCMP((*f)->filename, buf1)) {1666 if ((p1[0] == '.') && IS_DIRSEP(p1[1])) p1 += 2;
1657#ifdef INC_DEBUG1667
1658 printf("%s: #include_next skipping %s\n", file->filename, buf1);1668 if (p3) {
1659#endif1669 if (0 == PATHCMP(p1, p3)) {
1660 include_next_count++;1670 #ifdef INC_DEBUG
1671 printf("%s (3) include_next skipping <%s>\n", file->filename, p1);
1672 #endif
1661 goto include_trynext;1673 goto include_trynext;
1662 }1674 }
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
1663 }1693 }
1664 1694
1665 e = search_cached_include(s1, buf1);1695 e = search_cached_include(s1, buf1);
1666 if (e && (define_find(e->ifndef_macro) || e->ifndef_macro == TOK_once)) {1696 if (e && (define_find(e->ifndef_macro) || e->ifndef_macro == TOK_once)) {
1667 /* no need to parse the include because the 'ifndef macro'1697 /* no need to parse the include because the 'ifndef macro'
1668 is defined */1698 is defined */
1669#ifdef INC_DEBUG1699
1670 printf("%s: skipping cached %s\n", file->filename, buf1);1700 #ifdef INC_DEBUG
1671#endif1701 printf("%s: skipping cached <%s>\n", file->filename, buf1);
1702 #endif
1672 goto include_done;1703 goto include_done;
1673 }1704 }
1674 1705
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
1676include_trynext:1710include_trynext:
1677 continue;1711 continue;
1712 }
1713
1714 #ifdef INC_DEBUG
1715 printf("%s: including <%s>\n", file->prev->filename, file->filename);
1716 #endif
1678 1717
1679#ifdef INC_DEBUG
1680 printf("%s: including %s\n", file->prev->filename, file->filename);
1681#endif
1682 /* update target deps */1718 /* update target deps */
1683 dynarray_add((void ***)&s1->target_deps, &s1->nb_target_deps,1719 dynarray_add((void ***)&s1->target_deps, &s1->nb_target_deps,
1684 tcc_strdup(buf1));1720 tcc_strdup(buf1));
@@ -1691,8 +1727,7 @@ include_trynext: · 6 unmodified lines
1691 ch = file->buf_ptr[0];1727 ch = file->buf_ptr[0];
1692 goto the_end;1728 goto the_end;
1693 }1729 }
1694 if (include_next_count == 0)1730 tcc_error("include file '%s' not found", buf);
1695 tcc_error("include file '%s' not found", buf);
1696include_done:1731include_done:
1697 break;1732 break;
1698 case TOK_IFNDEF:1733 case TOK_IFNDEF:
@@ -1709,9 +1744,9 @@ include_done: · 10 unmodified lines
1709 tcc_error("invalid argument for '#if%sdef'", c ? "n" : "");1744 tcc_error("invalid argument for '#if%sdef'", c ? "n" : "");
1710 if (is_bof) {1745 if (is_bof) {
1711 if (c) {1746 if (c) {
1712#ifdef INC_DEBUG1747 #ifdef INC_DEBUG
1713 printf("#ifndef %s\n", get_tok_str(tok, NULL));1748 printf("#ifndef %s\n", get_tok_str(tok, NULL));
1714#endif1749 #endif
1715 file->ifndef_macro = tok;1750 file->ifndef_macro = tok;
1716 }1751 }
1717 }1752 }

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