]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Compat: Shuffle semi-duplicate min/max alternatives all into libcompat
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 6 Mar 2009 13:26:57 +0000 (02:26 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 6 Mar 2009 13:26:57 +0000 (02:26 +1300)
14 files changed:
compat/compat_shared.h
include/Range.h
include/util.h
src/BodyPipe.cc
src/ChunkedCodingParser.cc
src/adaptation/icap/ModXact.cc
src/client_side.cc
src/comm.cc
src/fd.cc
src/ip/IpAddress.cc
src/ipcache.cc
src/stmem.cc
src/store_client.cc
src/tests/stub_comm.cc

index a2bc9a4e9bb052eaf52502ec31bd3522c51abf48..63aa8ac38e9b49103796ecb7ed78157bc5d69f40 100644 (file)
@@ -94,10 +94,8 @@ struct rusage
 #endif /* !HAVE_STRUCT_RUSAGE */
 
 
-/* templates require C++ */
-#ifdef __cplusplus
-
 #ifndef min
+#ifdef __cplusplus
 /**
  * min() comparison may not always be provided.
  * Squid bundles this template for when its needed.
@@ -111,10 +109,14 @@ min(A const & lhs, A const & rhs)
         return rhs;
     return lhs;
 }
-#endif
-#define XMIN(x,y) (min (x,y))
+#else /* !__cplusplus */
+/* for non-C++ we are stuck with the < and ? operator */
+#define min(a,b) ((a) < (b) ? (a) : (b))
+#endif /* __cplusplus */
+#endif /* min */
 
 #ifndef max
+#ifdef __cplusplus
 /**
  * max() comparison may not always be provided.
  * Squid bundles this template for when its needed.
@@ -128,10 +130,11 @@ max(A const & lhs, A const & rhs)
         return rhs;
     return lhs;
 }
-#endif
-#define XMAX(a,b) (max (a,b))
-
+#else /* !__cplusplus */
+/* for non-C++ we are stuck with the < and ? operator */
+#define max(a,b) ((a) < (b) ? (b) : (a))
 #endif /* __cplusplus */
+#endif /* max */
 
 /**
  * tempnam() not provided by all systems
index e32b99d78294b3150e46fe21b3849650e3444d63..e23c947d685221e6589fdd3b9298a4937a200ba4 100644 (file)
@@ -70,7 +70,7 @@ template<class C>
 Range<C>
 Range<C>::intersection (Range const &rhs) const
 {
-    Range<C> result (XMAX(start, rhs.start), XMIN(end, rhs.end));
+    Range<C> result (max(start, rhs.start), min(end, rhs.end));
     return result;
 }
 
index b93947fb38212900478b56e07164f997d6a206e4..093225d7837e276290d93ae26df755f3c85dc99c 100644 (file)
@@ -146,13 +146,6 @@ SQUIDCEXTERN const char *xint64toa(int64_t num);
 SQUIDCEXTERN double drand48(void);
 #endif
 
-#ifndef xmax
-#define xmax(a,b) ((a) < (b) ? (b) : (a))
-#endif
-#ifndef xmin
-#define xmin(a,b) ((a) < (b) ? (a) : (b))
-#endif
-
 typedef struct {
     size_t count;
     size_t bytes;
index 66e0563e2cd328d62cacb02454912ffe9d0a0a51..0cae9446c1436359dda6bbc1121e6f2f4d6e30d1 100644 (file)
@@ -204,10 +204,10 @@ size_t
 BodyPipe::putMoreData(const char *buf, size_t size)
 {
     if (bodySizeKnown())
-        size = XMIN((uint64_t)size, unproducedSize());
+        size = min((uint64_t)size, unproducedSize());
 
     const size_t spaceSize = static_cast<size_t>(theBuf.potentialSpaceSize());
-    if ((size = XMIN(size, spaceSize))) {
+    if ((size = min(size, spaceSize))) {
         theBuf.append(buf, size);
         postAppend(size);
         return size;
@@ -269,7 +269,7 @@ BodyPipe::getMoreData(MemBuf &buf)
 
     if (buf.isNull())
         buf.init();
-    const size_t size = XMIN(theBuf.contentSize(), buf.potentialSpaceSize());
+    const size_t size = min(theBuf.contentSize(), buf.potentialSpaceSize());
     buf.append(theBuf.content(), size);
     theBuf.consume(size);
     postConsume(size);
index a3ef03f2dc9af167f723a345267168157bbafbd6..ebd2bd781fee7d8d0003213595e6c0e092a922a6 100644 (file)
@@ -91,8 +91,8 @@ void ChunkedCodingParser::parseChunkBody()
 {
     Must(theLeftBodySize > 0); // Should, really
 
-    const size_t availSize = XMIN(theLeftBodySize, (uint64_t)theIn->contentSize());
-    const size_t safeSize = XMIN(availSize, (size_t)theOut->potentialSpaceSize());
+    const size_t availSize = min(theLeftBodySize, (uint64_t)theIn->contentSize());
+    const size_t safeSize = min(availSize, (size_t)theOut->potentialSpaceSize());
 
     doNeedMoreData = availSize < theLeftBodySize;
     // and we may also need more space
index 7038f7c3d72856be76afc4dea310ef28fd92a6d5..4cb1622ea0b2d21a790d80368005d06f08434ab7 100644 (file)
@@ -208,7 +208,7 @@ void Adaptation::Icap::ModXact::writePreviewBody()
     Must(virgin.body_pipe != NULL);
 
     const size_t sizeMax = (size_t)virgin.body_pipe->buf().contentSize();
-    const size_t size = XMIN(preview.debt(), sizeMax);
+    const size_t size = min(preview.debt(), sizeMax);
     writeSomeBody("preview body", size);
 
     // change state once preview is written
@@ -249,7 +249,7 @@ void Adaptation::Icap::ModXact::writeSomeBody(const char *label, size_t size)
     writeBuf.init(); // note: we assume that last-chunk will fit
 
     const size_t writableSize = virginContentSize(virginBodyWriting);
-    const size_t chunkSize = XMIN(writableSize, size);
+    const size_t chunkSize = min(writableSize, size);
 
     if (chunkSize) {
         debugs(93, 7, HERE << "will write " << chunkSize <<
@@ -368,10 +368,10 @@ void Adaptation::Icap::ModXact::virginConsume()
            " from " << virgin.body_pipe->status());
 
     if (virginBodyWriting.active())
-        offset = XMIN(virginBodyWriting.offset(), offset);
+        offset = min(virginBodyWriting.offset(), offset);
 
     if (virginBodySending.active())
-        offset = XMIN(virginBodySending.offset(), offset);
+        offset = min(virginBodySending.offset(), offset);
 
     Must(virginConsumed <= offset && offset <= end);
 
@@ -1201,13 +1201,13 @@ void Adaptation::Icap::ModXact::decideOnPreview()
     Must(wantedSize >= 0);
 
     // cannot preview more than we can backup
-    size_t ad = XMIN(wantedSize, TheBackupLimit);
+    size_t ad = min(wantedSize, TheBackupLimit);
 
     if (!virginBody.expected())
         ad = 0;
     else
         if (virginBody.knownSize())
-            ad = XMIN(static_cast<uint64_t>(ad), virginBody.size()); // not more than we have
+            ad = min(static_cast<uint64_t>(ad), virginBody.size()); // not more than we have
 
     debugs(93, 5, HERE << "should offer " << ad << "-byte preview " <<
            "(service wanted " << wantedSize << ")");
index 4934d55126ae227d1084ca3d925d39f66b9067ca..74b68fcadbcfabf18045bc4b904067c8e886268d 100644 (file)
@@ -789,7 +789,7 @@ ClientSocketContext::lengthToSend(Range<int64_t> const &available)
     if (available.start < http->range_iter.currentSpec()->offset)
         return 0;
 
-    return XMIN(http->range_iter.debt(), (int64_t)maximum);
+    return min(http->range_iter.debt(), (int64_t)maximum);
 }
 
 void
index 10e9ee70a44fd37f7571585e0b1988e84be47ba3..a42c642958c94532abc069bd5e1ff96ada857c38 100644 (file)
@@ -1909,7 +1909,7 @@ comm_init(void) {
     /* Keep a few file descriptors free so that we don't run out of FD's
      * after accepting a client but before it opens a socket or a file.
      * Since Squid_MaxFD can be as high as several thousand, don't waste them */
-    RESERVED_FD = XMIN(100, Squid_MaxFD / 4);
+    RESERVED_FD = min(100, Squid_MaxFD / 4);
 
     conn_close_pool = memPoolCreate("close_handler", sizeof(close_handler));
 
index 2438e8fbd55227152b50028f4f7b32c0d49d8efe..144d36b720d86bfe94e985a0bdcf3d7669efb0b4 100644 (file)
--- a/src/fd.cc
+++ b/src/fd.cc
@@ -310,12 +310,12 @@ fdAdjustReserved(void)
     /*
      * Calculate a new reserve, based on current usage and a small extra
      */
-    newReserve = Squid_MaxFD - Number_FD + XMIN(25, Squid_MaxFD / 16);
+    newReserve = Squid_MaxFD - Number_FD + min(25, Squid_MaxFD / 16);
 
     if (newReserve <= RESERVED_FD)
         return;
 
-    x = Squid_MaxFD - 20 - XMIN(25, Squid_MaxFD / 16);
+    x = Squid_MaxFD - 20 - min(25, Squid_MaxFD / 16);
 
     if (newReserve > x) {
         /* perhaps this should be fatal()? -DW */
@@ -323,7 +323,7 @@ fdAdjustReserved(void)
         newReserve = x;
     }
 
-    if (Squid_MaxFD - newReserve < XMIN(256, Squid_MaxFD / 2))
+    if (Squid_MaxFD - newReserve < min(256, Squid_MaxFD / 2))
         fatalf("Too few filedescriptors available in the system (%d usable of %d).\n", Squid_MaxFD - newReserve, Squid_MaxFD);
 
     debugs(51, 0, "Reserved FD adjusted from " << RESERVED_FD << " to " << newReserve << " due to failures");
index df001986e56c0c0386c5372cae762c2149c6d5b4..ee7dcd4a8e1d178db59152f8ca2176a67092d242 100644 (file)
@@ -978,9 +978,9 @@ char* IpAddress::NtoA(char* buf, const unsigned int blen, int force) const
     /* thats okay, our default is known */
     if ( IsAnyAddr() ) {
 #if USE_IPV6
-        memcpy(buf,"::\0", xmin(3,blen));
+        memcpy(buf,"::\0", min((const unsigned int)3,blen));
 #else
-        memcpy(buf,"0.0.0.0\0", xmin(8,blen));
+        memcpy(buf,"0.0.0.0\0", min((const unsigned int)8,blen));
 #endif
         return buf;
     }
@@ -991,7 +991,7 @@ char* IpAddress::NtoA(char* buf, const unsigned int blen, int force) const
     /* However IPv4 CAN. */
     if ( force == AF_INET && !IsIPv4() ) {
         if ( IsIPv6() ) {
-            memcpy(buf, "{!IPv4}\0", xmin(8,blen));
+            memcpy(buf, "{!IPv4}\0", min((const unsigned int)8,blen));
         }
         return buf;
     }
@@ -1015,7 +1015,7 @@ char* IpAddress::NtoA(char* buf, const unsigned int blen, int force) const
                force << "). accepted={" << AF_UNSPEC << "," << AF_INET << "," << AF_INET6 << "}");
         fprintf(stderr,"WARNING: Corrupt IP Address details OR required to display in unknown format (%d). accepted={%d,%d,%d} ",
                 force, AF_UNSPEC, AF_INET, AF_INET6);
-        memcpy(buf,"dead:beef::\0", xmin(13,blen));
+        memcpy(buf,"dead:beef::\0", min((const unsigned int)13,blen));
         assert(false);
     }
 
index 5834fbae2e74a24155323e16721c54d469dbb170..a82cbda3c04245b15c13d8857aa5b1621a411d1a 100644 (file)
@@ -1333,7 +1333,7 @@ ipcacheMarkBadAddr(const char *name, IpAddress &addr)
     if (!ia->bad_mask[k]) {
         ia->bad_mask[k] = TRUE;
         ia->badcount++;
-        i->expires = XMIN(squid_curtime + XMAX((time_t)60, Config.negativeDnsTtl), i->expires);
+        i->expires = min(squid_curtime + max((time_t)60, Config.negativeDnsTtl), i->expires);
         debugs(14, 2, "ipcacheMarkBadAddr: " << name << " " << addr );
     }
 
index e8dfe64663d26e14cecba46297d942a2018e10ad..b264138f69565c596c9daa97c4a41bf1e08bfdda 100644 (file)
@@ -140,7 +140,7 @@ mem_hdr::writeAvailable(mem_node *aNode, int64_t location, size_t amount, char c
 
     /* these two can go I think */
     assert (location - aNode->nodeBuffer.offset == (int64_t)aNode->nodeBuffer.length);
-    size_t copyLen = XMIN (amount, aNode->space());
+    size_t copyLen = min(amount, aNode->space());
 
     xmemcpy(aNode->nodeBuffer.data + aNode->nodeBuffer.length, source, copyLen);
 
@@ -216,7 +216,7 @@ mem_hdr::copyAvailable(mem_node *aNode, int64_t location, size_t amount, char *t
 
     size_t copyOffset = location - aNode->nodeBuffer.offset;
 
-    size_t copyLen = XMIN (amount, aNode->nodeBuffer.length - copyOffset);
+    size_t copyLen = min(amount, aNode->nodeBuffer.length - copyOffset);
 
     xmemcpy(target, aNode->nodeBuffer.data + copyOffset, copyLen);
 
index 077d8681b8e5809045b6afa48be6863ab8a23dc6..c6ead68240dbde5853b276b1333d72121f2262f0 100644 (file)
@@ -585,7 +585,7 @@ store_client::readHeader(char const *buf, ssize_t len)
         /*
          * we have (part of) what they want
          */
-        size_t copy_sz = XMIN(copyInto.length, body_sz);
+        size_t copy_sz = min(copyInto.length, body_sz);
         debugs(90, 3, "storeClientReadHeader: copying " << copy_sz << " bytes of body");
         xmemmove(copyInto.data, copyInto.data + mem->swap_hdr_sz, copy_sz);
 
index 83b96c5c5ad25c5f47e6657704a9c92f95d9f215..56a57ad7113a12bf818615729fb9ed02a40a6b02 100644 (file)
@@ -147,7 +147,7 @@ comm_init(void)
     /* Keep a few file descriptors free so that we don't run out of FD's
      * after accepting a client but before it opens a socket or a file.
      * Since Squid_MaxFD can be as high as several thousand, don't waste them */
-    RESERVED_FD = XMIN(100, Squid_MaxFD / 4);
+    RESERVED_FD = min(100, Squid_MaxFD / 4);
 }
 
 /* MinGW needs also a stub of _comm_close() */