From: Francesco Chemolli Date: Fri, 4 Oct 2013 13:55:21 +0000 (+0200) Subject: Removed copyright statements from SBuf code, pending project policy X-Git-Tag: SQUID_3_5_0_1~612^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5082718;p=thirdparty%2Fsquid.git Removed copyright statements from SBuf code, pending project policy Made SBuf::size_type unsigned and adjusted tests accordingly Add documentation for SBuf::spaceSize --- diff --git a/src/MemBlob.cc b/src/MemBlob.cc index 4acdb569a8..c57d9c5750 100644 --- a/src/MemBlob.cc +++ b/src/MemBlob.cc @@ -1,6 +1,4 @@ /* - * MemBlob.cc (C) 2009 Francesco Chemolli - * * SQUID Web Proxy Cache http://www.squid-cache.org/ * ---------------------------------------------------------- * diff --git a/src/MemBlob.h b/src/MemBlob.h index 0dcca19523..804e0a6442 100644 --- a/src/MemBlob.h +++ b/src/MemBlob.h @@ -1,6 +1,4 @@ /* - * MemBlob.h (C) 2009 Francesco Chemolli - * * SQUID Web Proxy Cache http://www.squid-cache.org/ * ---------------------------------------------------------- * @@ -68,7 +66,7 @@ class MemBlob: public RefCountable { public: typedef RefCount Pointer; - typedef int32_t size_type; + typedef uint32_t size_type; MEMPROXY_CLASS(MemBlob); diff --git a/src/SBuf.cc b/src/SBuf.cc index a23b5a57ca..650042040a 100644 --- a/src/SBuf.cc +++ b/src/SBuf.cc @@ -1,6 +1,4 @@ /* - * SBuf.cc (C) 2008 Francesco Chemolli - * * SQUID Web Proxy Cache http://www.squid-cache.org/ * ---------------------------------------------------------- * @@ -183,7 +181,6 @@ SBuf::assign(const char *S, size_type n) void SBuf::reserveCapacity(size_type minCapacity) { - Must(0 <= minCapacity); Must(minCapacity <= maxSize); cow(minCapacity); } @@ -191,7 +188,6 @@ SBuf::reserveCapacity(size_type minCapacity) char * SBuf::rawSpace(size_type minSpace) { - Must(0 <= minSpace); Must(length() <= maxSize - minSpace); debugs(24, 7, "reserving " << minSpace << " for " << id); ++stats.rawAccess; @@ -236,8 +232,6 @@ SBuf::append(const SBuf &S) SBuf & SBuf::append(const char * S, size_type Ssize) { - Must (Ssize == npos || Ssize >= 0); - if (S == NULL) return *this; if (Ssize == npos) @@ -388,7 +382,6 @@ memcasecmp(const char *b1, const char *b2, SBuf::size_type len) int SBuf::compare(const SBuf &S, SBufCaseSensitive isCaseSensitive, size_type n) const { - Must(n == npos || n >= 0); if (n != npos) return substr(0,n).compare(S.substr(0,n),isCaseSensitive); @@ -451,7 +444,6 @@ SBuf::operator !=(const SBuf & S) const SBuf SBuf::consume(size_type n) { - Must (n == npos || n >= 0); if (n == npos) n = length(); else @@ -470,8 +462,6 @@ SBufStats& SBuf::GetStats() SBuf::size_type SBuf::copy(char *dest, size_type n) const { - Must(n >= 0); - size_type toexport = min(n,length()); memcpy(dest, buf(), toexport); ++stats.copyOut; @@ -511,10 +501,6 @@ SBuf::c_str() SBuf& SBuf::chop(size_type pos, size_type n) { - if (pos != npos && pos < 0) - pos = 0; - if (n != npos && n < 0) - n = npos; if (pos == npos || pos > length() || n == 0) { clear(); return *this; diff --git a/src/SBuf.h b/src/SBuf.h index dc030b64cb..15c80cf684 100644 --- a/src/SBuf.h +++ b/src/SBuf.h @@ -1,6 +1,4 @@ /* - * SBuf.h (C) 2008 Francesco Chemolli - * * SQUID Web Proxy Cache http://www.squid-cache.org/ * ---------------------------------------------------------- * @@ -112,7 +110,7 @@ class SBuf { public: typedef MemBlob::size_type size_type; - static const size_type npos = -1; + static const size_type npos = 0xffffffff; // max(uint32_t) /// Maximum size of a SBuf. By design it MUST be < MAX(size_type)/2. Currently 256Mb. static const size_type maxSize = 0xfffffff; @@ -129,7 +127,7 @@ public: * \param n how many bytes to import into the SBuf. If it is npos * or unspecified, imports to end-of-cstring * \note it is the caller's responsibility not to go out of bounds - * \note bounds is 0 <= pos < length() + * \note bounds is 0 <= pos < length(); caller must pay attention to signedness */ explicit SBuf(const char *S, size_type n = npos); @@ -239,7 +237,7 @@ public: /** random-access read to any char within the SBuf. * * \throw OutOfBoundsException when access is out of bounds - * \note bounds is 0 <= pos < length() + * \note bounds is 0 <= pos < length(); caller must pay attention to signedness */ const char at(size_type pos) const {checkAccessBounds(pos); return operator[](pos);} @@ -248,7 +246,7 @@ public: * \param pos the position to be overwritten * \param toset the value to be written * \throw OutOfBoundsException when pos is of bounds - * \note bounds is 0 <= pos < length() + * \note bounds is 0 <= pos < length(); caller must pay attention to signedness * \note performs a copy-on-write if needed. */ void setAt(size_type pos, char toset); @@ -355,8 +353,10 @@ public: */ char *rawSpace(size_type minSize); - /** + /** Obtain how much free space is available in the backing store. * + * \note: unless the client just cow()ed, it is not guaranteed that + * the free space can be used. */ size_type spaceSize() const { return store_->spaceSize(); } @@ -439,11 +439,10 @@ public: * It is an in-place-modifying version of substr. * \param pos start sub-stringing from this byte. If it is * npos or it is greater than the SBuf length, the SBuf is cleared and - * an empty SBuf is returned. If it is <0, it is ignored + * an empty SBuf is returned. * \param n maximum number of bytes of the resulting SBuf. * npos means "to end of SBuf". * if it is 0, the SBuf is cleared and an empty SBuf is returned. - * if it is < 0, it is ignored (same as supplying npos) * if it overflows the end of the SBuf, it is capped to the end of SBuf * \see substr, trim */ @@ -482,7 +481,6 @@ public: * sequence contained in the str argument. * \param startPos if specified, ignore any occurrences before that position * if startPos is npos or greater than length() npos is always returned - * if startPos is < 0, it is ignored * \return npos if the SBuf was not found */ size_type find(const SBuf & str, size_type startPos = 0) const; @@ -493,7 +491,6 @@ public: * \return npos if the char was not found * \param endPos if specified, ignore any occurrences after that position. * if npos or greater than length(), the whole SBuf is considered - * if < 0, npos is always returned */ size_type rfind(char c, size_type endPos = npos) const; @@ -504,7 +501,6 @@ public: * \return npos if the sequence was not found * \param endPos if specified, ignore any occurrences after that position * if npos or greater than length(), the whole SBuf is considered - * if < 0, npos is always returned */ size_type rfind(const SBuf &str, size_type endPos = npos) const; @@ -515,7 +511,6 @@ public: * \return npos if no character in the set could be found * \param startPos if specified, ignore any occurrences before that position * if npos, then npos is always returned - * if <0, it is ignored. */ size_type find_first_of(const SBuf &set, size_type startPos = 0) const; diff --git a/src/SBufExceptions.cc b/src/SBufExceptions.cc index 01106c4d01..b682d12207 100644 --- a/src/SBufExceptions.cc +++ b/src/SBufExceptions.cc @@ -1,6 +1,4 @@ /* - * SBufExceptions.cc (C) 2008 Francesco Chemolli - * * SQUID Web Proxy Cache http://www.squid-cache.org/ * ---------------------------------------------------------- * diff --git a/src/SBufExceptions.h b/src/SBufExceptions.h index 70ec2a76a6..451f8ec077 100644 --- a/src/SBufExceptions.h +++ b/src/SBufExceptions.h @@ -1,6 +1,4 @@ /* - * SBufExceptions.h (C) 2008 Francesco Chemolli - * * SQUID Web Proxy Cache http://www.squid-cache.org/ * ---------------------------------------------------------- * diff --git a/src/SquidString.h b/src/SquidString.h index 41d060eaa4..7be3f7170d 100644 --- a/src/SquidString.h +++ b/src/SquidString.h @@ -43,40 +43,6 @@ #define SQUIDSTRINGPRINT(s) (s).psize(),(s).rawBuf() #endif /* SQUIDSTRINGPH */ -#define DEBUGSTRINGS 0 -#if DEBUGSTRINGS -#include "splay.h" - -class String; - -class StringRegistry -{ - -public: - static StringRegistry &Instance(); - - void add(String const *); - - StringRegistry(); - - void remove(String const *); - -private: - static OBJH Stat; - - static StringRegistry Instance_; - - static SplayNode::SPLAYWALKEE Stater; - - Splay entries; - - bool registered; - -}; - -class StoreEntry; -#endif - class String { @@ -150,10 +116,6 @@ public: _SQUID_INLINE_ void cut(size_type newLength); -#if DEBUGSTRINGS - void stat(StoreEntry *) const; -#endif - private: void allocAndFill(const char *str, int len); void allocBuffer(size_type sz); diff --git a/src/icmp/Makefile.am b/src/icmp/Makefile.am index bbc76b59e8..cb022bd0bd 100644 --- a/src/icmp/Makefile.am +++ b/src/icmp/Makefile.am @@ -22,6 +22,25 @@ libexec_PROGRAMS = $(PINGER) noinst_LTLIBRARIES = libicmp-core.la libicmp.la +SBUF_SOURCE= \ + $(top_srcdir)/src/SBuf.h \ + $(top_srcdir)/src/SBuf.cc \ + $(top_srcdir)/src/MemBlob.h \ + $(top_srcdir)/src/MemBlob.cc \ + $(top_srcdir)/src/OutOfBoundsException.h \ + $(top_srcdir)/src/SBufExceptions.h \ + $(top_srcdir)/src/SBufExceptions.cc \ + $(top_srcdir)/src/SBufTokenizer.h \ + $(top_srcdir)/src/SBufTokenizer.cc \ + $(top_srcdir)/src/SBufList.h \ + $(top_srcdir)/src/SBufList.cc \ + $(top_srcdir)/src/SBufUtil.h \ + $(top_srcdir)/src/SBufUtil.cc \ + $(top_srcdir)/src/String.cc \ + $(top_srcdir)/src/SquidString.h \ + $(top_srcdir)/src/base/TextException.h \ + $(top_srcdir)/src/base/TextException.cc + # ICMP API definition ... libicmp_core_la_SOURCES = \ Icmp.h \ diff --git a/src/tests/SBufFindTest.cc b/src/tests/SBufFindTest.cc index cd3d2079fc..d07f5b0e35 100644 --- a/src/tests/SBufFindTest.cc +++ b/src/tests/SBufFindTest.cc @@ -31,11 +31,11 @@ SBufFindTest::run() { srandom(randomSeed); - for (SBuf::size_type hayLen = 0; hayLen <= maxHayLength; nextLen(hayLen, maxHayLength)) { + for (SBuf::size_type hayLen = 0U; hayLen <= maxHayLength; nextLen(hayLen, maxHayLength)) { const SBuf cleanHay = RandomSBuf(hayLen); const SBuf::size_type maxNeedleLen = hayLen + 10; - for (SBuf::size_type needleLen = 0; needleLen <= maxNeedleLen; nextLen(needleLen, maxNeedleLen)) { + for (SBuf::size_type needleLen = 0U; needleLen <= maxNeedleLen; nextLen(needleLen, maxNeedleLen)) { theSBufNeedle = RandomSBuf(needleLen); for (int i = 0; i < placeEof; i++) { @@ -386,7 +386,7 @@ SBufFindTest::RandomSBuf(const int length) /// increments len to quickly cover [0, max] range, slowing down in risky areas /// jumps to max+1 if caseLimit is reached void -SBufFindTest::nextLen(int &len, const int max) +SBufFindTest::nextLen(SBuf::size_type &len, const SBuf::size_type max) { assert(len <= max); diff --git a/src/tests/SBufFindTest.h b/src/tests/SBufFindTest.h index c4202e8e91..7756ee4557 100644 --- a/src/tests/SBufFindTest.h +++ b/src/tests/SBufFindTest.h @@ -33,7 +33,7 @@ public: protected: static SBuf RandomSBuf(const int length); - void nextLen(int &len, const int max); + void nextLen(SBuf::size_type &len, const SBuf::size_type max); void placeNeedle(const SBuf &cleanHay); void testAllMethods(); diff --git a/src/tests/testSBuf.cc b/src/tests/testSBuf.cc index 2a796c7891..c971fdb2c5 100644 --- a/src/tests/testSBuf.cc +++ b/src/tests/testSBuf.cc @@ -48,7 +48,7 @@ testSBuf::testSBufConstructDestruct() // test accessors on empty SBuf. { SBuf s1; - CPPUNIT_ASSERT_EQUAL(0,s1.length()); + CPPUNIT_ASSERT_EQUAL(0U,s1.length()); CPPUNIT_ASSERT_EQUAL(SBuf(""),s1); CPPUNIT_ASSERT_EQUAL(empty_sbuf,s1); CPPUNIT_ASSERT_EQUAL(0,strcmp("",s1.c_str())); @@ -57,7 +57,7 @@ testSBuf::testSBufConstructDestruct() // TEST: copy-construct NULL string (implicit destructor non-crash test) { SBuf s1(NULL); - CPPUNIT_ASSERT_EQUAL(0,s1.length()); + CPPUNIT_ASSERT_EQUAL(0U,s1.length()); CPPUNIT_ASSERT_EQUAL(SBuf(""),s1); CPPUNIT_ASSERT_EQUAL(empty_sbuf,s1); CPPUNIT_ASSERT_EQUAL(0,strcmp("",s1.c_str())); @@ -66,7 +66,7 @@ testSBuf::testSBufConstructDestruct() // TEST: copy-construct empty string (implicit destructor non-crash test) { SBuf s1(""); - CPPUNIT_ASSERT_EQUAL(0,s1.length()); + CPPUNIT_ASSERT_EQUAL(0U,s1.length()); CPPUNIT_ASSERT_EQUAL(SBuf(""),s1); CPPUNIT_ASSERT_EQUAL(empty_sbuf,s1); CPPUNIT_ASSERT_EQUAL(0,strcmp("",s1.c_str())); @@ -75,7 +75,7 @@ testSBuf::testSBufConstructDestruct() // TEST: copy-construct from a SBuf { SBuf s1(empty_sbuf); - CPPUNIT_ASSERT_EQUAL(0,s1.length()); + CPPUNIT_ASSERT_EQUAL(0U,s1.length()); CPPUNIT_ASSERT_EQUAL(SBuf(""),s1); CPPUNIT_ASSERT_EQUAL(empty_sbuf,s1); CPPUNIT_ASSERT_EQUAL(0,strcmp("",s1.c_str())); @@ -441,7 +441,7 @@ testSBuf::testFindChar() // FORWARD SEARCH // needle in haystack idx=s1.find('d'); - CPPUNIT_ASSERT_EQUAL(3,idx); + CPPUNIT_ASSERT_EQUAL(3U,idx); CPPUNIT_ASSERT_EQUAL('d',s1[idx]); // needle not present in haystack @@ -449,21 +449,17 @@ testSBuf::testFindChar() CPPUNIT_ASSERT_EQUAL(nposResult,idx); // search in portion - idx=s1.find('e',3); - CPPUNIT_ASSERT_EQUAL(4,idx); + idx=s1.find('e',3U); + CPPUNIT_ASSERT_EQUAL(4U,idx); // char not in searched portion - idx=s1.find('e',5); + idx=s1.find('e',5U); CPPUNIT_ASSERT_EQUAL(nposResult,idx); // invalid start position idx=s1.find('d',SBuf::npos); CPPUNIT_ASSERT_EQUAL(nposResult,idx); - // invalid start position - idx=s1.find('d', -5); - CPPUNIT_ASSERT_EQUAL(3, idx); - // search outside of haystack idx=s1.find('d',s1.length()+1); CPPUNIT_ASSERT_EQUAL(nposResult,idx); @@ -471,7 +467,7 @@ testSBuf::testFindChar() // REVERSE SEARCH // needle in haystack idx=s1.rfind('d'); - CPPUNIT_ASSERT_EQUAL(3, idx); + CPPUNIT_ASSERT_EQUAL(3U, idx); CPPUNIT_ASSERT_EQUAL('d', s1[idx]); // needle not present in haystack @@ -480,19 +476,15 @@ testSBuf::testFindChar() // search in portion idx=s1.rfind('e',5); - CPPUNIT_ASSERT_EQUAL(4,idx); + CPPUNIT_ASSERT_EQUAL(4U,idx); // char not in searched portion idx=s1.rfind('e',3); CPPUNIT_ASSERT_EQUAL(nposResult,idx); - // invalid start position - idx=s1.rfind('d', -5); - CPPUNIT_ASSERT_EQUAL(nposResult,idx); - // overlong haystack specification idx=s1.rfind('d',s1.length()+1); - CPPUNIT_ASSERT_EQUAL(3,idx); + CPPUNIT_ASSERT_EQUAL(3U,idx); } void @@ -506,10 +498,10 @@ testSBuf::testFindSBuf() // FORWARD search // needle in haystack idx = haystack.find(SBuf("def")); - CPPUNIT_ASSERT_EQUAL(3,idx); + CPPUNIT_ASSERT_EQUAL(3U,idx); idx = haystack.find(SBuf("xyz")); - CPPUNIT_ASSERT_EQUAL(23,idx); + CPPUNIT_ASSERT_EQUAL(23U,idx); // needle not in haystack, no initial char match idx = haystack.find(SBuf(" eq")); @@ -535,10 +527,6 @@ testSBuf::testFindSBuf() idx = haystack.find(SBuf("def"),SBuf::npos); CPPUNIT_ASSERT_EQUAL(nposResult, idx); - // invalid start position: negative - idx = haystack.find(SBuf("def"),-5); - CPPUNIT_ASSERT_EQUAL(3, idx); - // needle bigger than haystack idx = SBuf("def").find(haystack); CPPUNIT_ASSERT_EQUAL(nposResult, idx); @@ -549,19 +537,19 @@ testSBuf::testFindSBuf() h2.append(haystack); idx = h2.find(SBuf("def")); - CPPUNIT_ASSERT_EQUAL(3,idx); + CPPUNIT_ASSERT_EQUAL(3U,idx); idx = h2.find(SBuf("xyzab")); - CPPUNIT_ASSERT_EQUAL(23,idx); + CPPUNIT_ASSERT_EQUAL(23U,idx); } // REVERSE search // needle in haystack idx = haystack.rfind(SBuf("def")); - CPPUNIT_ASSERT_EQUAL(3,idx); + CPPUNIT_ASSERT_EQUAL(3U,idx); idx = haystack.rfind(SBuf("xyz")); - CPPUNIT_ASSERT_EQUAL(23,idx); + CPPUNIT_ASSERT_EQUAL(23U,idx); // needle not in haystack, no initial char match idx = haystack.rfind(SBuf(" eq")); @@ -577,7 +565,7 @@ testSBuf::testFindSBuf() // search in portion: needle in searched part idx = haystack.rfind(SBuf("def"),7); - CPPUNIT_ASSERT_EQUAL(3, idx); + CPPUNIT_ASSERT_EQUAL(3U, idx); // search in portion: needle not in searched part idx = haystack.rfind(SBuf("mno"),3); @@ -585,15 +573,11 @@ testSBuf::testFindSBuf() // search in portion: overhang idx = haystack.rfind(SBuf("def"),4); - CPPUNIT_ASSERT_EQUAL(3, idx); + CPPUNIT_ASSERT_EQUAL(3U, idx); // npos start position idx = haystack.rfind(SBuf("def"),SBuf::npos); - CPPUNIT_ASSERT_EQUAL(3, idx); - - // invalid start position: negative - idx = haystack.rfind(SBuf("def"),-5); - CPPUNIT_ASSERT_EQUAL(nposResult, idx); + CPPUNIT_ASSERT_EQUAL(3U, idx); // needle bigger than haystack idx = SBuf("def").rfind(haystack); @@ -605,10 +589,10 @@ testSBuf::testFindSBuf() h2.append(haystack); idx = h2.rfind(SBuf("def")); - CPPUNIT_ASSERT_EQUAL(29,idx); + CPPUNIT_ASSERT_EQUAL(29U,idx); idx = h2.find(SBuf("xyzab")); - CPPUNIT_ASSERT_EQUAL(23,idx); + CPPUNIT_ASSERT_EQUAL(23U,idx); } } @@ -618,7 +602,7 @@ testSBuf::testRFindChar() SBuf s1(literal); SBuf::size_type idx; idx=s1.rfind(' '); - CPPUNIT_ASSERT_EQUAL(40,idx); + CPPUNIT_ASSERT_EQUAL(40U,idx); CPPUNIT_ASSERT_EQUAL(' ',s1[idx]); } @@ -638,7 +622,7 @@ testSBuf::testRFindSBuf() CPPUNIT_ASSERT_EQUAL(SBuf::npos,idx); idx=haystack.rfind(SBuf("fox")); - CPPUNIT_ASSERT_EQUAL(16,idx); + CPPUNIT_ASSERT_EQUAL(16U,idx); // needle not found, no match for first char idx=goobar.rfind(SBuf("foo")); @@ -650,15 +634,15 @@ testSBuf::testRFindSBuf() SBuf g("g"); //match at the last char idx=haystack.rfind(g); - CPPUNIT_ASSERT_EQUAL(43,idx); + CPPUNIT_ASSERT_EQUAL(43U,idx); CPPUNIT_ASSERT_EQUAL('g',haystack[idx]); idx=haystack.rfind(SBuf("The")); - CPPUNIT_ASSERT_EQUAL(0,idx); + CPPUNIT_ASSERT_EQUAL(0U,idx); haystack.append("The"); idx=haystack.rfind(SBuf("The")); - CPPUNIT_ASSERT_EQUAL(44,idx); + CPPUNIT_ASSERT_EQUAL(44U,idx); //partial match haystack="The quick brown fox"; @@ -697,7 +681,7 @@ void testSBuf::testCopy() CPPUNIT_ASSERT_EQUAL(s.length(),s.copy(buf,40)); CPPUNIT_ASSERT_EQUAL(0,strncmp(s.rawContent(),buf,s.length())); s=literal; - CPPUNIT_ASSERT_EQUAL(40,s.copy(buf,40)); + CPPUNIT_ASSERT_EQUAL(40U,s.copy(buf,40)); s2.assign(buf,40); s.chop(0,40); CPPUNIT_ASSERT_EQUAL(s2,s); @@ -774,7 +758,7 @@ void testSBuf::testFindFirstOf() // found at beginning idx=haystack.find_first_of(SBuf("THANDF")); - CPPUNIT_ASSERT_EQUAL(0,idx); + CPPUNIT_ASSERT_EQUAL(0U,idx); //found at end of haystack idx=haystack.find_first_of(SBuf("QWERYVg")); @@ -782,7 +766,7 @@ void testSBuf::testFindFirstOf() //found in the middle of haystack idx=haystack.find_first_of(SBuf("QWERqYV")); - CPPUNIT_ASSERT_EQUAL(4,idx); + CPPUNIT_ASSERT_EQUAL(4U,idx); } void testSBuf::testAutoFind()