summaryrefslogtreecommitdiff
path: root/user/the_silver_searcher/no-common.patch
blob: 50f1fa6a94fdb1f38cd6b91a2eb62f90bfd568d2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
From 21eaa1c4160b868b0c5bbf59da17974429f30055 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Wed, 15 Apr 2020 20:23:52 +0300
Subject: [PATCH] Fix multiple global symbols definitions.

See the use of extern here:

* https://www.geeksforgeeks.org/understanding-extern-keyword-in-c/

* https://en.wikipedia.org/wiki/External_variable

*
https://stackoverflow.com/questions/496448/how-to-correctly-use-the-extern-keyword-in-c
---
 src/ignore.c  |  2 ++
 src/ignore.h  |  2 +-
 src/log.c     |  1 +
 src/log.h     |  2 +-
 src/options.c |  2 ++
 src/options.h |  2 +-
 src/search.c  | 13 +++++++++++++
 src/search.h  | 20 ++++++++++----------
 src/util.c    |  2 ++
 src/util.h    |  4 ++--
 10 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/src/ignore.c b/src/ignore.c
index 7ae83f3ee..88036eff4 100644
--- a/src/ignore.c
+++ b/src/ignore.c
@@ -20,6 +20,8 @@
 const int fnmatch_flags = FNM_PATHNAME;
 #endif
 
+ignores *root_ignores;
+
 /* TODO: build a huge-ass list of files we want to ignore by default (build cache stuff, pyc files, etc) */
 
 const char *evil_hardcoded_ignore_files[] = {
diff --git a/src/ignore.h b/src/ignore.h
index 20d5a6af8..8db0f3772 100644
--- a/src/ignore.h
+++ b/src/ignore.h
@@ -29,7 +29,7 @@ struct ignores {
 };
 typedef struct ignores ignores;
 
-ignores *root_ignores;
+extern ignores *root_ignores;
 
 extern const char *evil_hardcoded_ignore_files[];
 extern const char *ignore_pattern_files[];
diff --git a/src/log.c b/src/log.c
index 1481b6d02..f6f4e9a83 100644
--- a/src/log.c
+++ b/src/log.c
@@ -4,6 +4,7 @@
 #include "log.h"
 #include "util.h"
 
+pthread_mutex_t print_mtx = PTHREAD_MUTEX_INITIALIZER;
 static enum log_level log_threshold = LOG_LEVEL_ERR;
 
 void set_log_level(enum log_level threshold) {
diff --git a/src/log.h b/src/log.h
index 85847ee7b..318622c3c 100644
--- a/src/log.h
+++ b/src/log.h
@@ -9,7 +9,7 @@
 #include <pthread.h>
 #endif
 
-pthread_mutex_t print_mtx;
+extern pthread_mutex_t print_mtx;
 
 enum log_level {
     LOG_LEVEL_DEBUG = 10,
diff --git a/src/options.c b/src/options.c
index 4abf4dcd3..699530138 100644
--- a/src/options.c
+++ b/src/options.c
@@ -20,6 +20,8 @@ const char *color_line_number = "\033[1;33m"; /* bold yellow */
 const char *color_match = "\033[30;43m";      /* black with yellow background */
 const char *color_path = "\033[1;32m";        /* bold green */
 
+cli_options opts;
+
 /* TODO: try to obey out_fd? */
 void usage(void) {
     printf("\n");
diff --git a/src/options.h b/src/options.h
index aae930936..0d852167e 100644
--- a/src/options.h
+++ b/src/options.h
@@ -91,7 +91,7 @@ typedef struct {
 } cli_options;
 
 /* global options. parse_options gives it sane values, everything else reads from it */
-cli_options opts;
+extern cli_options opts;
 
 typedef struct option option_t;
 
diff --git a/src/search.c b/src/search.c
index 0f4ae2113..0dad3c072 100644
--- a/src/search.c
+++ b/src/search.c
@@ -2,6 +2,19 @@
 #include "print.h"
 #include "scandir.h"
 
+size_t alpha_skip_lookup[256];
+size_t *find_skip_lookup;
+uint8_t h_table[H_SIZE] __attribute__((aligned(64)));
+
+work_queue_t *work_queue = NULL;
+work_queue_t *work_queue_tail = NULL;
+int done_adding_files = 0;
+pthread_cond_t files_ready = PTHREAD_COND_INITIALIZER;
+pthread_mutex_t stats_mtx = PTHREAD_MUTEX_INITIALIZER;
+pthread_mutex_t work_queue_mtx = PTHREAD_MUTEX_INITIALIZER;
+
+symdir_t *symhash = NULL;
+
 void search_buf(const char *buf, const size_t buf_len,
                 const char *dir_full_path) {
     int binary = -1; /* 1 = yes, 0 = no, -1 = don't know */
diff --git a/src/search.h b/src/search.h
index 6bac42038..00aa018dd 100644
--- a/src/search.h
+++ b/src/search.h
@@ -31,9 +31,9 @@
 #include "uthash.h"
 #include "util.h"
 
-size_t alpha_skip_lookup[256];
-size_t *find_skip_lookup;
-uint8_t h_table[H_SIZE] __attribute__((aligned(64)));
+extern size_t alpha_skip_lookup[256];
+extern size_t *find_skip_lookup;
+extern uint8_t h_table[H_SIZE] __attribute__((aligned(64)));
 
 struct work_queue_t {
     char *path;
@@ -41,12 +41,12 @@ struct work_queue_t {
 };
 typedef struct work_queue_t work_queue_t;
 
-work_queue_t *work_queue;
-work_queue_t *work_queue_tail;
-int done_adding_files;
-pthread_cond_t files_ready;
-pthread_mutex_t stats_mtx;
-pthread_mutex_t work_queue_mtx;
+extern work_queue_t *work_queue;
+extern work_queue_t *work_queue_tail;
+extern int done_adding_files;
+extern pthread_cond_t files_ready;
+extern pthread_mutex_t stats_mtx;
+extern pthread_mutex_t work_queue_mtx;
 
 
 /* For symlink loop detection */
@@ -64,7 +64,7 @@ typedef struct {
     UT_hash_handle hh;
 } symdir_t;
 
-symdir_t *symhash;
+extern symdir_t *symhash;
 
 ssize_t search_buf(const char *buf, const size_t buf_len,
                    const char *dir_full_path);
diff --git a/src/util.c b/src/util.c
index 3949477b2..90ffb6f1d 100644
--- a/src/util.c
+++ b/src/util.c
@@ -21,6 +21,8 @@
     }                                     \
     return ptr;
 
+FILE *out_fd = NULL;
+ag_stats stats;
 void *ag_malloc(size_t size) {
     void *ptr = malloc(size);
     CHECK_AND_RETURN(ptr)
diff --git a/src/util.h b/src/util.h
index 0c9b9b112..338b05f45 100644
--- a/src/util.h
+++ b/src/util.h
@@ -12,7 +12,7 @@
 #include "log.h"
 #include "options.h"
 
-FILE *out_fd;
+extern FILE *out_fd;
 
 #ifndef TRUE
 #define TRUE 1
@@ -51,7 +51,7 @@ typedef struct {
 } ag_stats;
 
 
-ag_stats stats;
+extern ag_stats stats;
 
 /* Union to translate between chars and words without violating strict aliasing */
 typedef union {