logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0003-Prevent-duplicate-definitions-of-global-variables.patch (5363B)


  1. From 159e026212ba551981dc522690901b9291b8e235 Mon Sep 17 00:00:00 2001
  2. From: Michael Forney <mforney@mforney.org>
  3. Date: Sun, 16 Jun 2019 01:49:32 -0700
  4. Subject: [PATCH] Prevent duplicate definitions of global variables
  5. Upstream: https://github.com/ggreer/the_silver_searcher/pull/1324
  6. Multiple external definitions of an object is invalid in ISO C[0].
  7. These are visible when linking with -Wl,--warn-common.
  8. [0] http://port70.net/~nsz/c/c11/n1570.html#6.9p5
  9. ---
  10. src/ignore.c | 2 ++
  11. src/ignore.h | 2 +-
  12. src/log.c | 2 ++
  13. src/log.h | 2 +-
  14. src/options.c | 2 ++
  15. src/options.h | 2 +-
  16. src/search.c | 13 +++++++++++++
  17. src/search.h | 20 ++++++++++----------
  18. src/util.c | 3 +++
  19. src/util.h | 4 ++--
  20. 10 files changed, 37 insertions(+), 15 deletions(-)
  21. diff --git a/src/ignore.c b/src/ignore.c
  22. index bdb03b4..56c102a 100644
  23. --- a/src/ignore.c
  24. +++ b/src/ignore.c
  25. @@ -22,6 +22,8 @@ const int fnmatch_flags = FNM_PATHNAME;
  26. /* TODO: build a huge-ass list of files we want to ignore by default (build cache stuff, pyc files, etc) */
  27. +ignores *root_ignores;
  28. +
  29. const char *evil_hardcoded_ignore_files[] = {
  30. ".",
  31. "..",
  32. diff --git a/src/ignore.h b/src/ignore.h
  33. index 20d5a6a..8db0f37 100644
  34. --- a/src/ignore.h
  35. +++ b/src/ignore.h
  36. @@ -29,7 +29,7 @@ struct ignores {
  37. };
  38. typedef struct ignores ignores;
  39. -ignores *root_ignores;
  40. +extern ignores *root_ignores;
  41. extern const char *evil_hardcoded_ignore_files[];
  42. extern const char *ignore_pattern_files[];
  43. diff --git a/src/log.c b/src/log.c
  44. index 1481b6d..aef0b54 100644
  45. --- a/src/log.c
  46. +++ b/src/log.c
  47. @@ -4,6 +4,8 @@
  48. #include "log.h"
  49. #include "util.h"
  50. +pthread_mutex_t print_mtx;
  51. +
  52. static enum log_level log_threshold = LOG_LEVEL_ERR;
  53. void set_log_level(enum log_level threshold) {
  54. diff --git a/src/log.h b/src/log.h
  55. index 85847ee..318622c 100644
  56. --- a/src/log.h
  57. +++ b/src/log.h
  58. @@ -9,7 +9,7 @@
  59. #include <pthread.h>
  60. #endif
  61. -pthread_mutex_t print_mtx;
  62. +extern pthread_mutex_t print_mtx;
  63. enum log_level {
  64. LOG_LEVEL_DEBUG = 10,
  65. diff --git a/src/options.c b/src/options.c
  66. index e63985e..70ef448 100644
  67. --- a/src/options.c
  68. +++ b/src/options.c
  69. @@ -16,6 +16,8 @@
  70. #include "print.h"
  71. #include "util.h"
  72. +cli_options opts;
  73. +
  74. const char *color_line_number = "\033[1;33m"; /* bold yellow */
  75. const char *color_match = "\033[30;43m"; /* black with yellow background */
  76. const char *color_path = "\033[1;32m"; /* bold green */
  77. diff --git a/src/options.h b/src/options.h
  78. index db3e896..fd7d1f0 100644
  79. --- a/src/options.h
  80. +++ b/src/options.h
  81. @@ -91,7 +91,7 @@ typedef struct {
  82. } cli_options;
  83. /* global options. parse_options gives it sane values, everything else reads from it */
  84. -cli_options opts;
  85. +extern cli_options opts;
  86. typedef struct option option_t;
  87. diff --git a/src/search.c b/src/search.c
  88. index ff5e386..2245818 100644
  89. --- a/src/search.c
  90. +++ b/src/search.c
  91. @@ -2,6 +2,19 @@
  92. #include "print.h"
  93. #include "scandir.h"
  94. +size_t alpha_skip_lookup[256];
  95. +size_t *find_skip_lookup;
  96. +uint8_t h_table[H_SIZE] __attribute__((aligned(64)));
  97. +
  98. +work_queue_t *work_queue;
  99. +work_queue_t *work_queue_tail;
  100. +int done_adding_files;
  101. +pthread_cond_t files_ready;
  102. +pthread_mutex_t stats_mtx;
  103. +pthread_mutex_t work_queue_mtx;
  104. +
  105. +symdir_t *symhash;
  106. +
  107. void search_buf(const char *buf, const size_t buf_len,
  108. const char *dir_full_path) {
  109. int binary = -1; /* 1 = yes, 0 = no, -1 = don't know */
  110. diff --git a/src/search.h b/src/search.h
  111. index 1071114..a1bc5d7 100644
  112. --- a/src/search.h
  113. +++ b/src/search.h
  114. @@ -31,9 +31,9 @@
  115. #include "uthash.h"
  116. #include "util.h"
  117. -size_t alpha_skip_lookup[256];
  118. -size_t *find_skip_lookup;
  119. -uint8_t h_table[H_SIZE] __attribute__((aligned(64)));
  120. +extern size_t alpha_skip_lookup[256];
  121. +extern size_t *find_skip_lookup;
  122. +extern uint8_t h_table[H_SIZE] __attribute__((aligned(64)));
  123. struct work_queue_t {
  124. char *path;
  125. @@ -41,12 +41,12 @@ struct work_queue_t {
  126. };
  127. typedef struct work_queue_t work_queue_t;
  128. -work_queue_t *work_queue;
  129. -work_queue_t *work_queue_tail;
  130. -int done_adding_files;
  131. -pthread_cond_t files_ready;
  132. -pthread_mutex_t stats_mtx;
  133. -pthread_mutex_t work_queue_mtx;
  134. +extern work_queue_t *work_queue;
  135. +extern work_queue_t *work_queue_tail;
  136. +extern int done_adding_files;
  137. +extern pthread_cond_t files_ready;
  138. +extern pthread_mutex_t stats_mtx;
  139. +extern pthread_mutex_t work_queue_mtx;
  140. /* For symlink loop detection */
  141. @@ -64,7 +64,7 @@ typedef struct {
  142. UT_hash_handle hh;
  143. } symdir_t;
  144. -symdir_t *symhash;
  145. +extern symdir_t *symhash;
  146. void search_buf(const char *buf, const size_t buf_len,
  147. const char *dir_full_path);
  148. diff --git a/src/util.c b/src/util.c
  149. index cb23914..103be46 100644
  150. --- a/src/util.c
  151. +++ b/src/util.c
  152. @@ -21,6 +21,9 @@
  153. } \
  154. return ptr;
  155. +FILE *out_fd;
  156. +ag_stats stats;
  157. +
  158. void *ag_malloc(size_t size) {
  159. void *ptr = malloc(size);
  160. CHECK_AND_RETURN(ptr)
  161. diff --git a/src/util.h b/src/util.h
  162. index 0c9b9b1..338b05f 100644
  163. --- a/src/util.h
  164. +++ b/src/util.h
  165. @@ -12,7 +12,7 @@
  166. #include "log.h"
  167. #include "options.h"
  168. -FILE *out_fd;
  169. +extern FILE *out_fd;
  170. #ifndef TRUE
  171. #define TRUE 1
  172. @@ -51,7 +51,7 @@ typedef struct {
  173. } ag_stats;
  174. -ag_stats stats;
  175. +extern ag_stats stats;
  176. /* Union to translate between chars and words without violating strict aliasing */
  177. typedef union {
  178. --
  179. 2.20.1