]>
Commit | Line | Data |
---|---|---|
6edc270a MF |
1 | ------------------------------------------------------------ |
2 | revno: 14173 | |
3 | revision-id: squid3@treenet.co.nz-20170621201248-ezpvykg0b307ix61 | |
4 | parent: squid3@treenet.co.nz-20170621195439-l63xfsad58ghhhfu | |
5 | fixes bug: http://bugs.squid-cache.org/show_bug.cgi?id=4671 | |
6 | author: Alex Rousskov <rousskov@measurement-factory.com> | |
7 | committer: Amos Jeffries <squid3@treenet.co.nz> | |
8 | branch nick: 3.5 | |
9 | timestamp: Thu 2017-06-22 08:12:48 +1200 | |
10 | message: | |
11 | Replace new/delete operators using modern C++ rules. | |
12 | ||
13 | This change was motivated by "Mismatched free()/delete/delete[]" errors | |
14 | reported by valgrind and mused about in Squid source code. | |
15 | ||
16 | I speculate that the old new/delete replacement code was the result of | |
17 | slow accumulation of working hacks to accomodate various environments, | |
18 | as compiler support for the feature evolved. The cumulative result does | |
19 | not actually work well (see the above paragraph), and the replacement | |
20 | functions had the following visible coding problems according to [1,2]: | |
21 | ||
22 | a) Declared with non-standard profiles that included throw specifiers. | |
23 | b) Declared inline. C++ says that the results of inline declarations | |
24 | have unspecified effects. In Squid, they probably necessitated | |
25 | complex compiler-specific "extern inline" workarounds. | |
26 | c) Defined in the header file. C++ says that defining replacements "in | |
27 | any source file" is enough and that multiple replacements per | |
28 | program (which is what a header file definition produces) result in | |
29 | "undefined behavior". | |
30 | d) Declared inconsistently (only 2 out of 4 flavors). Declaring one base | |
31 | flavor should be sufficient, but if we declare more, we should | |
32 | declare all of them. | |
33 | ||
34 | [1] http://en.cppreference.com/w/cpp/memory/new/operator_new | |
35 | [2] http://en.cppreference.com/w/cpp/memory/new/operator_delete | |
36 | ||
37 | The replacements were not provided to clang (trunk r13219), but there | |
38 | was no explanation why. This patch does not change that exclusion. | |
39 | ||
40 | I have no idea whether any of the old hacks are still necessary in some | |
41 | cases. However, I suspect that either we do not care much if the | |
42 | replacements are not enabled on some poorly supported platforms OR we | |
43 | can disable them (or make them work) using much simpler hacks for the | |
44 | platforms we do care about. | |
45 | ------------------------------------------------------------ | |
46 | # Bazaar merge directive format 2 (Bazaar 0.90) | |
47 | # revision_id: squid3@treenet.co.nz-20170621201248-ezpvykg0b307ix61 | |
48 | # target_branch: http://bzr.squid-cache.org/bzr/squid3/3.5 | |
49 | # testament_sha1: 4f15c23326e4e4fe2ca2a6c7a13333e01677a0b0 | |
50 | # timestamp: 2017-06-21 20:51:02 +0000 | |
51 | # source_branch: http://bzr.squid-cache.org/bzr/squid3/3.5 | |
52 | # base_revision_id: squid3@treenet.co.nz-20170621195439-\ | |
53 | # l63xfsad58ghhhfu | |
54 | # | |
55 | # Begin patch | |
56 | === modified file 'compat/os/macosx.h' | |
57 | --- compat/os/macosx.h 2017-01-01 00:16:45 +0000 | |
58 | +++ compat/os/macosx.h 2017-06-21 20:12:48 +0000 | |
59 | @@ -28,11 +28,6 @@ | |
60 | ||
61 | #include "compat/cmsg.h" | |
62 | ||
63 | -// MacOS GCC 4.0.1 and 4.2.1 supply __GNUC_GNU_INLINE__ but do not actually define __attribute__((gnu_inline)) | |
64 | -#if defined(__cplusplus) && !defined(_SQUID_EXTERNNEW_) | |
65 | -#define _SQUID_EXTERNNEW_ extern inline | |
66 | -#endif | |
67 | - | |
68 | #endif /* _SQUID_APPLE_ */ | |
69 | #endif /* SQUID_OS_MACOSX_H */ | |
70 | ||
71 | ||
72 | === modified file 'compat/os/sgi.h' | |
73 | --- compat/os/sgi.h 2017-01-01 00:16:45 +0000 | |
74 | +++ compat/os/sgi.h 2017-06-21 20:12:48 +0000 | |
75 | @@ -25,15 +25,6 @@ | |
76 | #define _ABI_SOURCE | |
77 | #endif /* USE_ASYNC_IO */ | |
78 | ||
79 | -#if defined(__cplusplus) && !defined(_SQUID_EXTERNNEW_) && !defined(_GNUC_) | |
80 | -/* | |
81 | - * The gcc compiler treats extern inline functions as being extern, | |
82 | - * while the SGI MIPSpro compilers treat them as inline. To get equivalent | |
83 | - * behavior, remove the inline keyword. | |
84 | - */ | |
85 | -#define _SQUID_EXTERNNEW_ extern | |
86 | -#endif | |
87 | - | |
88 | #endif /* _SQUID_SGI_ */ | |
89 | #endif /* SQUID_OS_SGI_H */ | |
90 | ||
91 | ||
92 | === modified file 'compat/os/solaris.h' | |
93 | --- compat/os/solaris.h 2017-01-01 00:16:45 +0000 | |
94 | +++ compat/os/solaris.h 2017-06-21 20:12:48 +0000 | |
95 | @@ -59,13 +59,6 @@ | |
96 | #endif | |
97 | ||
98 | /* | |
99 | - * SunPro CC handles extern inline as inline, PLUS extern symbols. | |
100 | - */ | |
101 | -#if !defined(_SQUID_EXTERNNEW_) && defined(__SUNPRO_CC) | |
102 | -#define _SQUID_EXTERNNEW_ extern | |
103 | -#endif | |
104 | - | |
105 | -/* | |
106 | * SunStudio CC does not define C++ portability API __FUNCTION__ | |
107 | */ | |
108 | #if defined(__SUNPRO_CC) && !defined(__FUNCTION__) | |
109 | ||
110 | === removed file 'include/SquidNew.h' | |
111 | --- include/SquidNew.h 2017-01-01 00:16:45 +0000 | |
112 | +++ include/SquidNew.h 1970-01-01 00:00:00 +0000 | |
113 | @@ -1,41 +0,0 @@ | |
114 | -/* | |
115 | - * Copyright (C) 1996-2017 The Squid Software Foundation and contributors | |
116 | - * | |
117 | - * Squid software is distributed under GPLv2+ license and includes | |
118 | - * contributions from numerous individuals and organizations. | |
119 | - * Please see the COPYING and CONTRIBUTORS files for details. | |
120 | - */ | |
121 | - | |
122 | -#ifndef SQUID_NEW_H | |
123 | -#define SQUID_NEW_H | |
124 | - | |
125 | -#if !defined(__SUNPRO_CC) && !defined(__clang__) | |
126 | -/* Any code using libstdc++ must have externally resolvable overloads | |
127 | - * for void * operator new - which means in the .o for the binary, | |
128 | - * or in a shared library. static libs don't propogate the symbol | |
129 | - * so, look in the translation unit containing main() in squid | |
130 | - * for the extern version in squid | |
131 | - */ | |
132 | -#include <new> | |
133 | - | |
134 | -_SQUID_EXTERNNEW_ void *operator new(size_t size) throw (std::bad_alloc) | |
135 | -{ | |
136 | - return xmalloc(size); | |
137 | -} | |
138 | -_SQUID_EXTERNNEW_ void operator delete (void *address) throw() | |
139 | -{ | |
140 | - xfree(address); | |
141 | -} | |
142 | -_SQUID_EXTERNNEW_ void *operator new[] (size_t size) throw (std::bad_alloc) | |
143 | -{ | |
144 | - return xmalloc(size); | |
145 | -} | |
146 | -_SQUID_EXTERNNEW_ void operator delete[] (void *address) throw() | |
147 | -{ | |
148 | - xfree(address); | |
149 | -} | |
150 | - | |
151 | -#endif /* !__SUNPRO_CC && !__clang__*/ | |
152 | - | |
153 | -#endif /* SQUID_NEW_H */ | |
154 | - | |
155 | ||
156 | === modified file 'include/util.h' | |
157 | --- include/util.h 2017-01-01 00:16:45 +0000 | |
158 | +++ include/util.h 2017-06-21 20:12:48 +0000 | |
159 | @@ -19,23 +19,6 @@ | |
160 | SQUIDCEXTERN int tvSubUsec(struct timeval, struct timeval); | |
161 | SQUIDCEXTERN double tvSubDsec(struct timeval, struct timeval); | |
162 | SQUIDCEXTERN void Tolower(char *); | |
163 | -#if defined(__cplusplus) | |
164 | -/* | |
165 | - * Any code using libstdc++ must have externally resolvable overloads | |
166 | - * for void * operator new - which means in the .o for the binary, | |
167 | - * or in a shared library. static libs don't propogate the symbol | |
168 | - * so, look in the translation unit containing main() in squid | |
169 | - * for the extern version in squid | |
170 | - */ | |
171 | -#if !defined(_SQUID_EXTERNNEW_) | |
172 | -#if defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__) | |
173 | -#define _SQUID_EXTERNNEW_ extern inline __attribute__((gnu_inline)) | |
174 | -#else | |
175 | -#define _SQUID_EXTERNNEW_ extern inline | |
176 | -#endif | |
177 | -#endif | |
178 | -#include "SquidNew.h" | |
179 | -#endif | |
180 | ||
181 | SQUIDCEXTERN time_t parse_iso3307_time(const char *buf); | |
182 | ||
183 | ||
184 | === modified file 'src/SquidNew.cc' | |
185 | --- src/SquidNew.cc 2017-01-01 00:16:45 +0000 | |
186 | +++ src/SquidNew.cc 2017-06-21 20:12:48 +0000 | |
187 | @@ -8,29 +8,45 @@ | |
188 | ||
189 | /* DEBUG: none Memory Allocation */ | |
190 | ||
191 | -#define _SQUID_EXTERNNEW_ | |
192 | - | |
193 | #include "squid.h" | |
194 | ||
195 | -#ifdef __SUNPRO_CC | |
196 | +#if !defined(__clang__) | |
197 | ||
198 | #include <new> | |
199 | -void *operator new(size_t size) throw (std::bad_alloc) | |
200 | -{ | |
201 | - return xmalloc(size); | |
202 | -} | |
203 | -void operator delete (void *address) throw() | |
204 | -{ | |
205 | - xfree (address); | |
206 | -} | |
207 | -void *operator new[] (size_t size) throw (std::bad_alloc) | |
208 | -{ | |
209 | - return xmalloc(size); | |
210 | -} | |
211 | -void operator delete[] (void *address) throw() | |
212 | -{ | |
213 | - xfree (address); | |
214 | -} | |
215 | - | |
216 | -#endif /* __SUNPRO_CC */ | |
217 | + | |
218 | +void *operator new(size_t size) | |
219 | +{ | |
220 | + return xmalloc(size); | |
221 | +} | |
222 | +void operator delete(void *address) | |
223 | +{ | |
224 | + xfree(address); | |
225 | +} | |
226 | +void *operator new[](size_t size) | |
227 | +{ | |
228 | + return xmalloc(size); | |
229 | +} | |
230 | +void operator delete[](void *address) | |
231 | +{ | |
232 | + xfree(address); | |
233 | +} | |
234 | + | |
235 | +void *operator new(size_t size, const std::nothrow_t &tag) | |
236 | +{ | |
237 | + return xmalloc(size); | |
238 | +} | |
239 | +void operator delete(void *address, const std::nothrow_t &tag) | |
240 | +{ | |
241 | + xfree(address); | |
242 | +} | |
243 | +void *operator new[](size_t size, const std::nothrow_t &tag) | |
244 | +{ | |
245 | + return xmalloc(size); | |
246 | +} | |
247 | +void operator delete[](void *address, const std::nothrow_t &tag) | |
248 | +{ | |
249 | + xfree(address); | |
250 | +} | |
251 | + | |
252 | +#endif /* !defined(__clang__) */ | |
253 | ||
254 |