]> git.ipfire.org Git - thirdparty/squid.git/commit
Replace new/delete operators using modern C++ rules.
authorAlex Rousskov <rousskov@measurement-factory.com>
Fri, 27 May 2016 12:46:02 +0000 (00:46 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 27 May 2016 12:46:02 +0000 (00:46 +1200)
commit39cca4e121215f3f994c1e57f7201ad2a2a2d32a
tree99a8352955a66ddc79f072322fc8aadad4b397de
parent0792f48915b745311fe66aa6389f450861a1df8d
Replace new/delete operators using modern C++ rules.

This change was motivated by "Mismatched free()/delete/delete[]" errors
reported by valgrind and mused about in Squid source code.

I speculate that the old new/delete replacement code was the result of
slow accumulation of working hacks to accomodate various environments,
as compiler support for the feature evolved. The cumulative result does
not actually work well (see the above paragraph), and the replacement
functions had the following visible coding problems according to [1,2]:

a) Declared with non-standard profiles that included throw specifiers.
b) Declared inline. C++ says that the results of inline declarations
   have unspecified effects. In Squid, they probably necessitated
   complex compiler-specific "extern inline" workarounds.
c) Defined in the header file. C++ says that defining replacements "in
   any source file" is enough and that multiple replacements per
   program (which is what a header file definition produces) result in
   "undefined behavior".
d) Declared inconsistently (only 2 out of 4 flavors). Declaring one base
   flavor should be sufficient, but if we declare more, we should
   declare all of them.

[1] http://en.cppreference.com/w/cpp/memory/new/operator_new
[2] http://en.cppreference.com/w/cpp/memory/new/operator_delete

The replacements were not provided to clang (trunk r13219), but there
was no explanation why. This patch does not change that exclusion.

I have no idea whether any of the old hacks are still necessary in some
cases. However, I suspect that either we do not care much if the
replacements are not enabled on some poorly supported platforms OR we
can disable them (or make them work) using much simpler hacks for the
platforms we do care about.
compat/os/macosx.h
compat/os/sgi.h
compat/os/solaris.h
include/SquidNew.h [deleted file]
include/util.h
src/SquidNew.cc