]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
mempools-nozero part 3: debug
authorFrancesco Chemolli <kinkie@squid-cache.org>
Mon, 24 Aug 2015 17:49:50 +0000 (19:49 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Mon, 24 Aug 2015 17:49:50 +0000 (19:49 +0200)
Make Debug::OutStream to be a MEMPROXY_CLASS user, rather than rolling own
operator new and delete.

src/Debug.h
src/Makefile.am
src/SBufAlgos.cc
src/SBufAlgos.h
src/icmp/Makefile.am
test-suite/Makefile.am
tools/Makefile.am
tools/squidclient/Makefile.am

index 668fd78f346415777e671b3e034d2445b424f1cc..bb083a7b21ee0dfdd2291148db1c55eb8c98513e 100644 (file)
@@ -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 <iostream>
 #undef assert
 #include <sstream>
@@ -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;
index 976ce1bba5cdb9b99cf34c65b14a09661b67ba95..97b26321a1f47119a3397debde58b581ef1389d4 100644 (file)
@@ -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 \
index 595094f44abc4bd1976cbf64360872ca0a08b595..7619b0629697eb0b8e6b84deea6c40cce9a011ac 100644 (file)
@@ -9,17 +9,30 @@
 #include "squid.h"
 #include "SBufAlgos.h"
 
-std::size_t std::hash<SBuf>::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<SBuf>::operator() (const SBuf & sbuf) const noexcept
+{
+    return lowSBufHash(sbuf);
+}
+
+std::size_t
+CaseInsensitiveSBufHash::operator() (const SBuf & sbuf) const noexcept
+{
+    return lowSBufHash(sbuf, true);
+}
+
index 6bd1f694080727cc0f6f30cdc8f7bdf0995c60d9..e7dcb84f0aba59880f0089154d1b3f6a4de583e5 100644 (file)
@@ -90,5 +90,18 @@ struct hash<SBuf>
 };
 }
 
+/** hash functor for SBufs, meant so support case-insensitive std::unordered_map
+ *
+ * Typical use:
+ * \code
+ * auto m = std::unordered_map<SBuf, ValueType, CaseInsensitiveSBufHash>();
+ * \endcode
+ */
+class CaseInsensitiveSBufHash
+{
+public:
+    std::size_t operator()(const SBuf &) const noexcept;
+};
+
 #endif /* SQUID_SBUFALGOS_H_ */
 
index 18bfe454a0c09137da5140c58118983533ab2e67..1979ef9d9ebef764c9917ea15cf582953a3a95ae 100644 (file)
@@ -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
index fd4b7606837e492b611f0da92a34f6aa5f879202..7f8ce9b57efd6b5b5a07aa177eea9408f68b436c 100644 (file)
@@ -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
index a19811a92f630928acc9c45fbb54c417c77e1e91..abf810d3db448caa8827bdd26d2e9b5b3c51ded0 100644 (file)
@@ -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:
index a509058c883b61472bdead84a84d0e9f6046df2e..297d57aa305a8849d714a4f733584a84685f8aa5 100644 (file)
@@ -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