1 ------------------------------------------------------------
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>
9 timestamp: Thu 2017-06-22 08:12:48 +1200
11 Replace new/delete operators using modern C++ rules.
13 This change was motivated by "Mismatched free()/delete/delete[]" errors
14 reported by valgrind and mused about in Squid source code.
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]:
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
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
34 [1] http://en.cppreference.com/w/cpp/memory/new/operator_new
35 [2] http://en.cppreference.com/w/cpp/memory/new/operator_delete
37 The replacements were not provided to clang (trunk r13219), but there
38 was no explanation why. This patch does not change that exclusion.
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-\
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
61 #include "compat/cmsg.h"
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
68 #endif /* _SQUID_APPLE_ */
69 #endif /* SQUID_OS_MACOSX_H */
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
77 #endif /* USE_ASYNC_IO */
79 -#if defined(__cplusplus) && !defined(_SQUID_EXTERNNEW_) && !defined(_GNUC_)
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.
85 -#define _SQUID_EXTERNNEW_ extern
88 #endif /* _SQUID_SGI_ */
89 #endif /* SQUID_OS_SGI_H */
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
99 - * SunPro CC handles extern inline as inline, PLUS extern symbols.
101 -#if !defined(_SQUID_EXTERNNEW_) && defined(__SUNPRO_CC)
102 -#define _SQUID_EXTERNNEW_ extern
106 * SunStudio CC does not define C++ portability API __FUNCTION__
108 #if defined(__SUNPRO_CC) && !defined(__FUNCTION__)
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
115 - * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
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.
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
134 -_SQUID_EXTERNNEW_ void *operator new(size_t size) throw (std::bad_alloc)
136 - return xmalloc(size);
138 -_SQUID_EXTERNNEW_ void operator delete (void *address) throw()
142 -_SQUID_EXTERNNEW_ void *operator new[] (size_t size) throw (std::bad_alloc)
144 - return xmalloc(size);
146 -_SQUID_EXTERNNEW_ void operator delete[] (void *address) throw()
151 -#endif /* !__SUNPRO_CC && !__clang__*/
153 -#endif /* SQUID_NEW_H */
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
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)
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
171 -#if !defined(_SQUID_EXTERNNEW_)
172 -#if defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__)
173 -#define _SQUID_EXTERNNEW_ extern inline __attribute__((gnu_inline))
175 -#define _SQUID_EXTERNNEW_ extern inline
178 -#include "SquidNew.h"
181 SQUIDCEXTERN time_t parse_iso3307_time(const char *buf);
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
189 /* DEBUG: none Memory Allocation */
191 -#define _SQUID_EXTERNNEW_
196 +#if !defined(__clang__)
199 -void *operator new(size_t size) throw (std::bad_alloc)
201 - return xmalloc(size);
203 -void operator delete (void *address) throw()
207 -void *operator new[] (size_t size) throw (std::bad_alloc)
209 - return xmalloc(size);
211 -void operator delete[] (void *address) throw()
216 -#endif /* __SUNPRO_CC */
218 +void *operator new(size_t size)
220 + return xmalloc(size);
222 +void operator delete(void *address)
226 +void *operator new[](size_t size)
228 + return xmalloc(size);
230 +void operator delete[](void *address)
235 +void *operator new(size_t size, const std::nothrow_t &tag)
237 + return xmalloc(size);
239 +void operator delete(void *address, const std::nothrow_t &tag)
243 +void *operator new[](size_t size, const std::nothrow_t &tag)
245 + return xmalloc(size);
247 +void operator delete[](void *address, const std::nothrow_t &tag)
252 +#endif /* !defined(__clang__) */