tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] [PATCH v2] Introduce VIP sysinclude paths which are alway


From: Steffen Nurpmeso
Subject: [Tinycc-devel] [PATCH v2] Introduce VIP sysinclude paths which are always searched first
Date: Sat, 30 Sep 2017 16:34:22 +0200
Date: Sat, 30 Sep 2017 00:13:05 +0200
User-agent: mail v14.9.4

---
Changes:
  None, except for adjusted line numbers.

 libtcc.c | 11 ++++++++++-
 libtcc.h |  3 +++
 tcc.c    |  2 ++
 tcc.h    | 18 +++++++++++++-----
 tccpp.c  | 12 +++++++++---
 5 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/libtcc.c b/libtcc.c
index dcc398f..876e3c4 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -906,6 +906,7 @@ LIBTCCAPI void tcc_delete(TCCState *s1)
 
     /* free include paths */
     dynarray_reset(&s1->cached_includes, &s1->nb_cached_includes);
+    dynarray_reset(&s1->sysinclude_vip_paths, &s1->nb_sysinclude_vip_paths);
     dynarray_reset(&s1->include_paths, &s1->nb_include_paths);
     dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);
     dynarray_reset(&s1->cmd_include_files, &s1->nb_cmd_include_files);
@@ -946,6 +947,7 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int 
output_type)
     if (!s->nostdinc) {
         /* default include paths */
         /* -isystem paths have already been handled */
+        tcc_add_sysinclude_vip_path(s, CONFIG_TCC_SYSINCLUDEVIPPATHS);
         tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS);
     }
 
@@ -983,6 +985,13 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int 
output_type)
     return 0;
 }
 
+LIBTCCAPI int tcc_add_sysinclude_vip_path(TCCState *s, const char *pathname)
+{
+    tcc_split_path(s, &s->sysinclude_vip_paths, &s->nb_sysinclude_vip_paths,
+        pathname);
+    return 0;
+}
+
 LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname)
 {
     tcc_split_path(s, &s->include_paths, &s->nb_include_paths, pathname);
@@ -1821,7 +1830,7 @@ reparse:
             break;
         case TCC_OPTION_iwithprefix:
             snprintf(buf, sizeof buf, "{B}/%s", optarg);
-            tcc_add_sysinclude_path(s, buf);
+            tcc_add_sysinclude_vip_path(s, buf);
             break;
        case TCC_OPTION_include:
            dynarray_add(&s->cmd_include_files,
diff --git a/libtcc.h b/libtcc.h
index a1b31e3..b06fb4c 100644
--- a/libtcc.h
+++ b/libtcc.h
@@ -32,6 +32,9 @@ LIBTCCAPI void tcc_set_options(TCCState *s, const char *str);
 /*****************************/
 /* preprocessor */
 
+/* add in system include path, searched before anything else */
+LIBTCCAPI int tcc_add_sysinclude_vip_path(TCCState *s, const char *pathname);
+
 /* add include path */
 LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname);
 
diff --git a/tcc.c b/tcc.c
index 4c7235a..b051ef3 100644
--- a/tcc.c
+++ b/tcc.c
@@ -181,6 +181,8 @@ static void print_search_dirs(TCCState *s)
 {
     printf("install: %s\n", s->tcc_lib_path);
     /* print_dirs("programs", NULL, 0); */
+    print_dirs("include-first", s->sysinclude_vip_paths,
+        s->nb_sysinclude_vip_paths);
     print_dirs("include", s->sysinclude_paths, s->nb_sysinclude_paths);
     print_dirs("libraries", s->library_paths, s->nb_library_paths);
 #ifndef TCC_TARGET_PE
diff --git a/tcc.h b/tcc.h
index c25d342..6534f4b 100644
--- a/tcc.h
+++ b/tcc.h
@@ -195,13 +195,18 @@ extern long double strtold (const char *__nptr, char 
**__endptr);
 /* Below: {B} is substituted by CONFIG_TCCDIR (rsp. -B option) */
 
 /* system include paths */
-#ifndef CONFIG_TCC_SYSINCLUDEPATHS
+#ifndef CONFIG_TCC_SYSINCLUDEVIPPATHS
 # ifdef TCC_TARGET_PE
-#  define CONFIG_TCC_SYSINCLUDEPATHS "{B}/include;{B}/include/winapi"
+#  define CONFIG_TCC_SYSINCLUDEVIPPATHS "{B}/include;{B}/include/winapi"
 # else
+#  define CONFIG_TCC_SYSINCLUDEVIPPATHS "{B}/include"
+# endif
+#endif
+
+#ifndef CONFIG_TCC_SYSINCLUDEPATHS
+# ifndef TCC_TARGET_PE
 #  define CONFIG_TCC_SYSINCLUDEPATHS \
-        "{B}/include" \
-    ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/include") \
+    ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/include") \
     ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/include")
 # endif
 #endif
@@ -715,7 +720,10 @@ struct TCCState {
     DLLReference **loaded_dlls;
     int nb_loaded_dlls;
 
-    /* include paths */
+    /* include paths, search order */
+    char **sysinclude_vip_paths;
+    int nb_sysinclude_vip_paths;
+
     char **include_paths;
     int nb_include_paths;
 
diff --git a/tccpp.c b/tccpp.c
index 39386f4..c3cc5f4 100644
--- a/tccpp.c
+++ b/tccpp.c
@@ -1803,7 +1803,8 @@ ST_FUNC void preprocess(int is_bof)
         /* store current file in stack, but increment stack later below */
         *s1->include_stack_ptr = file;
         i = tok == TOK_INCLUDE_NEXT ? file->include_next_index : 0;
-        n = 2 + s1->nb_include_paths + s1->nb_sysinclude_paths;
+        n = 2 + s1->nb_sysinclude_vip_paths + s1->nb_include_paths +
+               s1->nb_sysinclude_paths;
         for (; i < n; ++i) {
             char buf1[sizeof file->filename];
             CachedInclude *e;
@@ -1825,8 +1826,13 @@ ST_FUNC void preprocess(int is_bof)
 
             } else {
                 /* search in all the include paths */
-                int j = i - 2, k = j - s1->nb_include_paths;
-                path = k < 0 ? s1->include_paths[j] : s1->sysinclude_paths[k];
+                int k, j = i - 2;
+               if (j < (k = s1->nb_sysinclude_vip_paths))
+                       path = s1->sysinclude_vip_paths[j];
+               else if ((j -= k) < s1->nb_include_paths)
+                       path = s1->include_paths[j];
+               else if ((j -= s1->nb_include_paths) < s1->nb_sysinclude_paths)
+                       path = s1->sysinclude_paths[j];
                 pstrcpy(buf1, sizeof(buf1), path);
                 pstrcat(buf1, sizeof(buf1), "/");
             }
-- 
2.14.2


--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]