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