From: Francesco Chemolli Date: Mon, 24 Aug 2015 17:49:50 +0000 (+0200) Subject: mempools-nozero part 3: debug X-Git-Tag: SQUID_4_0_1~112 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae72213d5ae7c19a165660b5eaf0dea6697775b9;p=thirdparty%2Fsquid.git mempools-nozero part 3: debug Make Debug::OutStream to be a MEMPROXY_CLASS user, rather than rolling own operator new and delete. --- diff --git a/src/Debug.h b/src/Debug.h index 668fd78f34..bb083a7b21 100644 --- a/src/Debug.h +++ b/src/Debug.h @@ -11,6 +11,9 @@ #ifndef SQUID_DEBUG_H #define SQUID_DEBUG_H +// XXX should be mem/forward.h once it removes dependencies on typedefs.h +#include "mem/AllocatorProxy.h" + #include #undef assert #include @@ -71,12 +74,10 @@ private: /// with the libc++6 std::ostringstream definitions class OutStream : public std::ostringstream { - // XXX: use MEMPROXY_CLASS() once that no longer pulls in typedefs.h and enums.h and globals.h + MEMPROXY_CLASS(OutStream); public: - void *operator new(size_t size) throw(std::bad_alloc) {return xmalloc(size);} - void operator delete(void *address) throw() {xfree(address);} - void *operator new[] (size_t size) throw(std::bad_alloc) ; //{return xmalloc(size);} - void operator delete[] (void *address) throw() ; // {xfree(address);} + void *operator new[] (size_t size) throw(std::bad_alloc) = delete; //{return xmalloc(size);} + void operator delete[] (void *address) throw() = delete; // {xfree(address);} }; static OutStream *CurrentDebug; diff --git a/src/Makefile.am b/src/Makefile.am index 976ce1bba5..97b26321a1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1142,6 +1142,7 @@ tests_testACLMaxUserIP_SOURCES= \ tests/stub_libcomm.cc \ tests/stub_libdiskio.cc \ tests/stub_libformat.cc \ + tests/stub_libmem.cc \ tests/stub_libsslsquid.cc \ tests/stub_MemObject.cc \ tests/stub_MemStore.cc \ @@ -1165,7 +1166,6 @@ tests_testACLMaxUserIP_SOURCES= \ tests/stub_time.cc \ url.cc \ URL.h \ - tests/stub_libmem.cc \ MemBuf.cc \ wordlist.h \ wordlist.cc @@ -1206,6 +1206,7 @@ tests_testBoilerplate_SOURCES = \ tests/testBoilerplate.cc \ tests/testBoilerplate.h \ tests/stub_debug.cc \ + tests/stub_libmem.cc \ tests/stub_time.cc nodist_tests_testBoilerplate_SOURCES = \ tests/stub_cbdata.cc \ @@ -1230,6 +1231,7 @@ nodist_tests_testCharacterSet_SOURCES = \ $(TESTSOURCES) \ tests/stub_cbdata.cc \ tests/stub_debug.cc \ + tests/stub_libmem.cc \ tests/stub_MemBuf.cc tests_testCharacterSet_LDFLAGS = $(LIBADD_DL) tests_testCharacterSet_LDADD= \ @@ -1665,6 +1667,7 @@ tests_testDns_SOURCES= \ tests/testRFC1035.h nodist_tests_testDns_SOURCES= \ tests/stub_debug.cc \ + tests/stub_libmem.cc \ tests/stub_SBuf.cc \ tests/stub_tools.cc tests_testDns_LDADD= \ @@ -2427,7 +2430,6 @@ tests_testHttp1Parser_SOURCES = \ MemBuf.cc \ MemBuf.h \ tests/stub_MemObject.cc \ - tests/stub_libmem.cc \ mime_header.cc \ mime_header.h \ String.cc \ @@ -2442,6 +2444,7 @@ tests_testHttp1Parser_SOURCES = \ tests/stub_debug.cc \ tests/stub_event.cc \ tests/stub_HelperChildConfig.cc \ + tests/stub_libmem.cc \ tests/stub_libsecurity.cc \ tests/stub_stmem.cc \ tests/stub_store.cc \ @@ -2720,6 +2723,7 @@ nodist_tests_testIcmp_SOURCES = \ icmp/Icmp.h \ SquidTime.h \ tests/stub_debug.cc \ + tests/stub_libmem.cc \ time.cc \ globals.cc tests_testIcmp_LDFLAGS = $(LIBADD_DL) @@ -2739,6 +2743,7 @@ tests_testIpAddress_SOURCES= \ nodist_tests_testIpAddress_SOURCES= \ ip/Address.h \ tests/stub_debug.cc \ + tests/stub_libmem.cc \ tests/stub_tools.cc tests_testIpAddress_LDADD= \ ip/libip.la \ @@ -2925,7 +2930,6 @@ tests_testStore_DEPENDENCIES = \ ## libsquid pulls in SquidConfig and children. stub them. tests_testString_SOURCES = \ ClientInfo.h \ - tests/stub_libmem.cc \ MemBuf.cc \ String.cc \ $(SBUF_SOURCE) \ @@ -2940,6 +2944,7 @@ tests_testString_SOURCES = \ tests/stub_cbdata.cc \ tests/stub_debug.cc \ tests/stub_HelperChildConfig.cc \ + tests/stub_libmem.cc \ tools.h \ tests/stub_tools.cc \ tests/stub_time.cc \ @@ -3158,6 +3163,7 @@ testRefCount_SOURCES= \ base/RefCount.h \ tests/stub_cbdata.cc \ tests/stub_debug.cc \ + tests/stub_libmem.cc \ tests/stub_MemBuf.cc \ tests/testRefCount.cc testRefCount_LDADD = \ @@ -3426,7 +3432,6 @@ tests_testURL_SOURCES = \ MasterXaction.h \ multicast.h \ multicast.cc \ - tests/stub_libmem.cc \ mem_node.cc \ MemBuf.cc \ MemObject.cc \ @@ -3499,6 +3504,7 @@ tests_testURL_SOURCES = \ tests/stub_libauth_acls.cc \ tests/stub_libauth.cc \ tests/stub_libdiskio.cc \ + tests/stub_libmem.cc \ tests/stub_libsecurity.cc \ tests/stub_main_cc.cc \ tests/stub_ipc_Forwarder.cc \ @@ -3658,7 +3664,6 @@ tests_testSBufList_DEPENDENCIES= $(SQUID_CPPUNIT_LA) tests_testConfigParser_SOURCES = \ ClientInfo.h \ - tests/stub_libmem.cc \ tests/stub_MemBuf.cc \ tests/stub_time.cc \ $(SBUF_SOURCE) \ @@ -3676,6 +3681,7 @@ tests_testConfigParser_SOURCES = \ tests/stub_cache_manager.cc \ tests/stub_cbdata.cc \ tests/stub_debug.cc \ + tests/stub_libmem.cc \ tests/stub_HelperChildConfig.cc \ tools.h \ tests/stub_tools.cc \ diff --git a/src/SBufAlgos.cc b/src/SBufAlgos.cc index 595094f44a..7619b06296 100644 --- a/src/SBufAlgos.cc +++ b/src/SBufAlgos.cc @@ -9,17 +9,30 @@ #include "squid.h" #include "SBufAlgos.h" -std::size_t std::hash::operator() (const SBuf & sbuf) const noexcept +static std::size_t +lowSBufHash (const SBuf & sbuf, bool caseInsensitive = false) noexcept { //ripped and adapted from hash_string const char *s = sbuf.rawContent(); size_t rv = 0; SBuf::size_type len=sbuf.length(); while (len != 0) { - rv ^= 271 * *s; + rv ^= 271 * (caseInsensitive? xtolower(*s) : *s); ++s; --len; } return rv ^ (sbuf.length() * 271); } +std::size_t +std::hash::operator() (const SBuf & sbuf) const noexcept +{ + return lowSBufHash(sbuf); +} + +std::size_t +CaseInsensitiveSBufHash::operator() (const SBuf & sbuf) const noexcept +{ + return lowSBufHash(sbuf, true); +} + diff --git a/src/SBufAlgos.h b/src/SBufAlgos.h index 6bd1f69408..e7dcb84f0a 100644 --- a/src/SBufAlgos.h +++ b/src/SBufAlgos.h @@ -90,5 +90,18 @@ struct hash }; } +/** hash functor for SBufs, meant so support case-insensitive std::unordered_map + * + * Typical use: + * \code + * auto m = std::unordered_map(); + * \endcode + */ +class CaseInsensitiveSBufHash +{ +public: + std::size_t operator()(const SBuf &) const noexcept; +}; + #endif /* SQUID_SBUFALGOS_H_ */ diff --git a/src/icmp/Makefile.am b/src/icmp/Makefile.am index 18bfe454a0..1979ef9d9e 100644 --- a/src/icmp/Makefile.am +++ b/src/icmp/Makefile.am @@ -44,6 +44,8 @@ COPIED_SOURCE= \ SquidConfig.cc \ SquidNew.cc \ stub_HelperChildConfig.cc \ + stub_libmem.cc \ + STUB.h \ time.cc # ICMP lookup helper @@ -83,19 +85,26 @@ CLEANFILES += $(COPIED_SOURCE) ## files we need to pull in from other locations ## copied like this to avoid subdir-objects collisions on 'make clean' debug.cc: $(top_srcdir)/src/debug.cc - cp $(top_srcdir)/src/debug.cc . + cp $< $@ globals.cc: $(top_srcdir)/src/globals.h cp $(top_builddir)/src/globals.cc . time.cc: $(top_srcdir)/src/time.cc - cp $(top_srcdir)/src/time.cc . + cp $< $@ SquidConfig.cc: $(top_srcdir)/src/SquidConfig.cc - cp $(top_srcdir)/src/SquidConfig.cc . + cp $< $@ SquidNew.cc: $(top_srcdir)/src/SquidNew.cc - cp $(top_srcdir)/src/SquidNew.cc . + cp $< $@ stub_HelperChildConfig.cc: $(top_srcdir)/src/tests/stub_HelperChildConfig.cc - cp $(top_srcdir)/src/tests/stub_HelperChildConfig.cc . + cp $< $@ + +stub_libmem.cc: $(top_srcdir)/src/tests/stub_libmem.cc STUB.h + cp $< $@ + +STUB.h: $(top_srcdir)/src/tests/STUB.h + cp $< $@ + \ No newline at end of file diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index fd4b760683..7f8ce9b57e 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -57,34 +57,49 @@ check_PROGRAMS += debug \ tcp_banger2_LDADD = $(top_builddir)/lib/libmiscutil.la -STUBS = stub_cbdata.cc stub_debug.cc stub_MemBuf.cc stub_SBuf.cc stub_tools.cc stub_fatal.cc +#do not include stub_libmem.cc here, as it would override libmem.la in +# several tests whose purpose is testing libmem itself. +STUBS = \ + stub_cbdata.cc \ + stub_debug.cc \ + stub_MemBuf.cc \ + stub_SBuf.cc \ + stub_tools.cc \ + stub_fatal.cc \ + STUB.h DEBUG_SOURCE = test_tools.cc $(STUBS) CLEANFILES += $(STUBS) stub_cbdata.cc: $(top_srcdir)/src/tests/stub_cbdata.cc - cp $(top_srcdir)/src/tests/stub_cbdata.cc . + cp $< $@ stub_debug.cc: $(top_srcdir)/src/tests/stub_debug.cc - cp $(top_srcdir)/src/tests/stub_debug.cc . + cp $< $@ stub_MemBuf.cc: $(top_srcdir)/src/tests/stub_MemBuf.cc - cp $(top_srcdir)/src/tests/stub_MemBuf.cc . + cp $< $@ stub_SBuf.cc: $(top_srcdir)/src/tests/stub_SBuf.cc - cp $(top_srcdir)/src/tests/stub_SBuf.cc . + cp $< $@ stub_tools.cc: $(top_srcdir)/src/tests/stub_tools.cc - cp $(top_srcdir)/src/tests/stub_tools.cc . + cp $< $@ stub_fatal.cc: $(top_srcdir)/src/tests/stub_fatal.cc - cp $(top_srcdir)/src/tests/stub_fatal.cc . + cp $< $@ + +stub_libmem.cc : $(top_srcdir)/src/tests/stub_libmem.cc STUB.h + cp $< $@ + +STUB.h : $(top_srcdir)/src/tests/STUB.h + cp $< $@ ## XXX: somewhat broken. Its meant to test our debugs() implementation. ## but it has never been linked to the actual src/debug.cc implementation !! ## all it tests are the stream operators and macro in src/Debug.h -debug_SOURCES = debug.cc $(DEBUG_SOURCE) +debug_SOURCES = debug.cc stub_libmem.cc $(DEBUG_SOURCE) -ESIExpressions_SOURCES = ESIExpressions.cc $(DEBUG_SOURCE) +ESIExpressions_SOURCES = ESIExpressions.cc stub_libmem.cc $(DEBUG_SOURCE) ESIExpressions_LDADD = $(top_builddir)/src/esi/Expression.o \ $(LDADD) @@ -102,12 +117,15 @@ mem_hdr_test_LDADD = \ $(LDADD) MemPoolTest_SOURCES = MemPoolTest.cc $(DEBUG_SOURCE) +MemPoolTest_LDADD = \ + $(top_builddir)/src/mem/libmem.la \ + $(LDADD) -splay_SOURCES = splay.cc $(DEBUG_SOURCE) +splay_SOURCES = splay.cc stub_libmem.cc $(DEBUG_SOURCE) -syntheticoperators_SOURCES = syntheticoperators.cc $(DEBUG_SOURCE) +syntheticoperators_SOURCES = syntheticoperators.cc stub_libmem.cc $(DEBUG_SOURCE) -VirtualDeleteOperator_SOURCES = VirtualDeleteOperator.cc $(DEBUG_SOURCE) +VirtualDeleteOperator_SOURCES = VirtualDeleteOperator.cc stub_libmem.cc $(DEBUG_SOURCE) ## membanger won't link today. Bitrot.. ##CC = gcc diff --git a/tools/Makefile.am b/tools/Makefile.am index a19811a92f..abf810d3db 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -29,25 +29,30 @@ include $(top_srcdir)/doc/manuals/Substitute.am ## Several files need to be shared but we cannot depend on the other ## directories to be built. test_tools.cc: $(top_srcdir)/test-suite/test_tools.cc - cp $(top_srcdir)/test-suite/test_tools.cc . + cp $< $@ stub_debug.cc: $(top_srcdir)/src/tests/stub_debug.cc - cp $(top_srcdir)/src/tests/stub_debug.cc . + cp $< $@ time.cc: $(top_srcdir)/src/time.cc - cp $(top_srcdir)/src/time.cc . + cp $< $@ + +stub_libmem.cc : $(top_srcdir)/src/tests/stub_libmem.cc STUB.h + cp $< $@ + +STUB.h : $(top_srcdir)/src/tests/STUB.h + cp $< $@ # stock tools for unit tests - library independent versions of dlink_list # etc. # globals.cc is needed by test_tools.cc. # Neither of these should be disted from here. TESTSOURCES= test_tools.cc -CLEANFILES += test_tools.cc stub_debug.cc time.cc +CLEANFILES += test_tools.cc stub_debug.cc time.cc stub_libmem.cc STUB.h ## Test Scripts EXTRA_DIST += helper-ok-dying.pl helper-ok.pl - ## ##### cachemgr.cgi ##### DEFAULT_CACHEMGR_CONFIG = $(sysconfdir)/cachemgr.conf @@ -56,7 +61,9 @@ libexec_PROGRAMS = cachemgr$(CGIEXT) cachemgr__CGIEXT__SOURCES = cachemgr.cc \ stub_debug.cc \ + stub_libmem.cc \ test_tools.cc \ + STUB.h \ time.cc cachemgr__CGIEXT__CXXFLAGS = -DDEFAULT_CACHEMGR_CONFIG=\"$(DEFAULT_CACHEMGR_CONFIG)\" $(AM_CXXFLAGS) @@ -68,8 +75,6 @@ man_MANS += cachemgr.cgi.8 cachemgr.cgi.8: $(srcdir)/cachemgr.cgi.8.in Makefile $(SUBSTITUTE) < $(srcdir)/cachemgr.cgi.8.in > $@ - - ## Shared install-data-local: diff --git a/tools/squidclient/Makefile.am b/tools/squidclient/Makefile.am index a509058c88..297d57aa30 100644 --- a/tools/squidclient/Makefile.am +++ b/tools/squidclient/Makefile.am @@ -27,20 +27,27 @@ include $(top_srcdir)/doc/manuals/Substitute.am ## Several files need to be shared but we cannot depend on the other ## directories to be built. test_tools.cc: $(top_srcdir)/test-suite/test_tools.cc - cp $(top_srcdir)/test-suite/test_tools.cc . + cp $< $@ stub_debug.cc: $(top_srcdir)/src/tests/stub_debug.cc - cp $(top_srcdir)/src/tests/stub_debug.cc . + cp $< $@ time.cc: $(top_srcdir)/src/time.cc - cp $(top_srcdir)/src/time.cc . + cp $< $@ + +stub_libmem.cc : $(top_srcdir)/src/tests/stub_libmem.cc STUB.h + cp $< $@ + +STUB.h : $(top_srcdir)/src/tests/STUB.h + cp $< $@ + # stock tools for unit tests - library independent versions of dlink_list # etc. # globals.cc is needed by test_tools.cc. # Neither of these should be disted from here. TESTSOURCES= test_tools.cc -CLEANFILES += test_tools.cc stub_debug.cc time.cc +CLEANFILES += test_tools.cc stub_debug.cc time.cc stub_libmem.cc STUB.h ## ##### squidclient ##### @@ -55,6 +62,8 @@ squidclient_SOURCES = \ squidclient.cc \ stub_debug.cc \ test_tools.cc \ + stub_libmem.cc \ + STUB.h \ time.cc \ Transport.cc \ Transport.h