forked from msys2/MINGW-packages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0018-Provide-a-working-strtok_r-for-MinGW.patch
213 lines (194 loc) · 6.61 KB
/
0018-Provide-a-working-strtok_r-for-MinGW.patch
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
208
209
210
211
212
From 6ba0bec0545343c9b12c1468839014166a69ddc7 Mon Sep 17 00:00:00 2001
From: Jon TURNEY <[email protected]>
Date: Wed, 9 Apr 2014 23:49:03 +0100
Subject: [PATCH 18/24] Provide a working strtok_r for MinGW
Emulating it using strtok will not work as re-entrancy is required
Signed-off-by: Jon TURNEY <[email protected]>
---
Makefile.am | 2 +-
compat/strtok_r.c | 85 +++++++++++++++++++++++++++++
configure.ac | 3 +
src/config.h.in | 3 +
src/processor/basic_source_line_resolver.cc | 4 ++
src/processor/cfi_frame_info.cc | 6 +-
src/processor/tokenize.cc | 6 +-
7 files changed, 106 insertions(+), 3 deletions(-)
create mode 100644 compat/strtok_r.c
diff --git a/Makefile.am b/Makefile.am
index f1f29f3..aa333ae 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1183,7 +1183,7 @@ src_processor_minidump_stackwalk_LDADD = \
src/processor/stackwalker_x86.o \
src/processor/tokenize.o \
src/third_party/libdisasm/libdisasm.a \
- $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) $(SOCKET_LIBS)
+ $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) $(SOCKET_LIBS) @LIBOBJS@
endif !DISABLE_PROCESSOR
diff --git a/compat/strtok_r.c b/compat/strtok_r.c
new file mode 100644
index 0000000..ec7b637
--- /dev/null
+++ b/compat/strtok_r.c
@@ -0,0 +1,85 @@
+/*-
+ * Copyright (c) 1998 Softweyr LLC. All rights reserved.
+ *
+ * strtok_r, from Berkeley strtok
+ * Oct 13, 1998 by Wes Peters <[email protected]>
+ *
+ * Copyright (c) 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notices, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notices, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Softweyr LLC, the
+ * University of California, Berkeley, and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTWEYR LLC, THE
+ * REGENTS, OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+char *
+strtok_r(char *s, const char *delim, char **last)
+{
+ char *spanp, *tok;
+ int c, sc;
+
+ if (s == NULL && (s = *last) == NULL)
+ return (NULL);
+
+ /*
+ * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
+ */
+cont:
+ c = *s++;
+ for (spanp = (char *)delim; (sc = *spanp++) != 0;) {
+ if (c == sc)
+ goto cont;
+ }
+
+ if (c == 0) { /* no non-delimiter characters */
+ *last = NULL;
+ return (NULL);
+ }
+ tok = s - 1;
+
+ /*
+ * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
+ * Note that delim must have one NUL; we stop if we see that, too.
+ */
+ for (;;) {
+ c = *s++;
+ spanp = (char *)delim;
+ do {
+ if ((sc = *spanp++) == c) {
+ if (c == 0)
+ s = NULL;
+ else
+ s[-1] = '\0';
+ *last = s;
+ return (tok);
+ }
+ } while (sc != 0);
+ }
+ /* NOTREACHED */
+}
diff --git a/configure.ac b/configure.ac
index b2d8e33..88cbf36 100644
--- a/configure.ac
+++ b/configure.ac
@@ -76,6 +76,9 @@ m4_include(m4/ax_pthread.m4)
AX_PTHREAD
AC_CHECK_HEADERS([a.out.h])
+AC_CONFIG_LIBOBJ_DIR([compat])
+AC_REPLACE_FUNCS([strtok_r])
+
# Only build Linux client libs when compiling for Linux
case $host in
*-*-linux* | *-android* )
diff --git a/src/config.h.in b/src/config.h.in
index 1db0159..cd76ccb 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -24,6 +24,9 @@
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
+/* Define to 1 if you have the `strtok_r' function. */
+#undef HAVE_STRTOK_R
+
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
diff --git a/src/processor/basic_source_line_resolver.cc b/src/processor/basic_source_line_resolver.cc
index 1d4d0e9..6bbbf13 100644
--- a/src/processor/basic_source_line_resolver.cc
+++ b/src/processor/basic_source_line_resolver.cc
@@ -49,6 +49,10 @@
#include "processor/tokenize.h"
+#ifndef HAVE_STRTOK_R
+extern "C" char *strtok_r(char *, const char *, char **);
+#endif
+
using std::map;
using std::vector;
using std::make_pair;
diff --git a/src/processor/cfi_frame_info.cc b/src/processor/cfi_frame_info.cc
index 0c4af7b..dd2b438 100644
--- a/src/processor/cfi_frame_info.cc
+++ b/src/processor/cfi_frame_info.cc
@@ -41,12 +41,16 @@
#include "common/scoped_ptr.h"
#include "processor/postfix_evaluator-inl.h"
-namespace google_breakpad {
+#ifndef HAVE_STRTOK_R
+extern "C" char *strtok_r(char *, const char *, char **);
+#endif
#ifdef _MSC_VER
#define strtok_r strtok_s
#endif
+namespace google_breakpad {
+
template<typename V>
bool CFIFrameInfo::FindCallerRegs(const RegisterValueMap<V> ®isters,
const MemoryRegion &memory,
diff --git a/src/processor/tokenize.cc b/src/processor/tokenize.cc
index 8fce87a..e6213ac 100644
--- a/src/processor/tokenize.cc
+++ b/src/processor/tokenize.cc
@@ -34,12 +34,16 @@
#include "common/using_std_string.h"
-namespace google_breakpad {
+#ifndef HAVE_STRTOK_R
+extern "C" char *strtok_r(char *, const char *, char **);
+#endif
#ifdef _MSC_VER
#define strtok_r strtok_s
#endif
+namespace google_breakpad {
+
using std::vector;
bool Tokenize(char *line,
--
2.1.1