Skip to content

Commit

Permalink
Work on predef.h
Browse files Browse the repository at this point in the history
 * Some comments
 * Remove min and max shims (parenthesize calls to std::min/max to
   avoid macro)
 * Remove ABSOLUTE and RELATIVE shims (Mordor no longer uses ABSOLUTE
   and RELATIVE)
 * Fix ERROR shim to put it in the global namespace, not just #undef
   it

 * Don't name a variable interface - it's #defined to struct, and
   can't be #undef'ed

Change-Id: I3eebf65e5f378ec65d685e67cb4daf1868e65f6d
Reviewed-on: https://gerrit.dechocorp.com/14623
Reviewed-by: Hudson
Reviewed-by: Russ Simons <russs@mozy.com>
  • Loading branch information
ccutrer committed Dec 22, 2010
1 parent 3985b18 commit 9ab1f65
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 94 deletions.
5 changes: 3 additions & 2 deletions mordor/http/client.cpp
Expand Up @@ -336,7 +336,7 @@ ClientConnection::scheduleAllWaitingResponses()
// MORDOR_ASSERT(m_mutex.locked());
MORDOR_LOG_TRACE(g_log) << m_connectionNumber << " scheduling all responses";
unsigned long long firstResponseToSchedule =
std::min(m_priorResponseFailed, m_priorResponseClosed);
(std::min)(m_priorResponseFailed, m_priorResponseClosed);

std::list<ClientRequest *>::iterator end = m_currentRequest;
if (end != m_pendingRequests.end())
Expand Down Expand Up @@ -1142,7 +1142,8 @@ ClientRequest::ensureResponse()
} catch (...) {
boost::mutex::scoped_lock lock(m_conn->m_mutex);
m_conn->invariant();
m_conn->m_priorResponseFailed = std::min(m_requestNumber, m_conn->m_priorResponseFailed);
m_conn->m_priorResponseFailed = (std::min)(m_requestNumber,
m_conn->m_priorResponseFailed);
m_responseState = ERROR;
if (!m_conn->m_pendingRequests.empty() &&
m_conn->m_pendingRequests.front() == this) {
Expand Down
2 changes: 1 addition & 1 deletion mordor/http/http_parser.rl
Expand Up @@ -721,7 +721,7 @@ Parser::earliestPointer() const
{
const char *parent = RagelParser::earliestPointer();
if (mark2 && parent)
return std::min(mark2, parent);
return (std::min)(mark2, parent);
if (mark2)
return mark2;
return parent;
Expand Down
2 changes: 1 addition & 1 deletion mordor/http/multipart.cpp
Expand Up @@ -134,7 +134,7 @@ class BodyPartStream : public MutatingFilterStream
{
ptrdiff_t boundary = parent()->find(m_boundary, len, false);
if (boundary >= 0)
len = std::min((size_t)boundary, len);
len = (std::min)((size_t)boundary, len);
return parent()->read(b, len);
}

Expand Down
10 changes: 5 additions & 5 deletions mordor/http/server.cpp
Expand Up @@ -186,7 +186,7 @@ ServerConnection::scheduleAllWaitingResponses()
// MORDOR_ASSERT(m_mutex.locked());
MORDOR_LOG_TRACE(g_log) << this << " scheduling all responses";

unsigned long long firstFailedRequest = std::min(m_priorRequestFailed,
unsigned long long firstFailedRequest = (std::min)(m_priorRequestFailed,
m_priorResponseClosed);
for (std::list<ServerRequest *>::iterator it(m_pendingRequests.begin());
it != m_pendingRequests.end();
Expand Down Expand Up @@ -392,7 +392,7 @@ ServerRequest::cancel()
m_responseState = ERROR;
m_conn->m_stream->cancelRead();
m_conn->m_stream->cancelWrite();
m_conn->m_priorRequestFailed = std::min(m_conn->m_priorRequestFailed,
m_conn->m_priorRequestFailed = (std::min)(m_conn->m_priorRequestFailed,
m_requestNumber);
std::list<ServerRequest *>::iterator it =
std::find(m_conn->m_pendingRequests.begin(),
Expand Down Expand Up @@ -783,7 +783,7 @@ ServerRequest::commit()
} catch(...) {
boost::mutex::scoped_lock lock(m_conn->m_mutex);
m_conn->invariant();
m_conn->m_priorRequestFailed = std::min(m_conn->m_priorRequestFailed,
m_conn->m_priorRequestFailed = (std::min)(m_conn->m_priorRequestFailed,
m_requestNumber);
m_conn->scheduleAllWaitingResponses();
throw;
Expand Down Expand Up @@ -986,7 +986,7 @@ respondStream(ServerRequest::ptr request, Stream::ptr response)
cr.first = size - it->second;
} else {
cr.first = it->first;
cr.last = std::min(it->second, size - 1);
cr.last = (std::min)(it->second, size - 1);
}
if (response->supportsSeek())
response->seek(cr.first);
Expand Down Expand Up @@ -1035,7 +1035,7 @@ respondStream(ServerRequest::ptr request, Stream::ptr response)
cr->last = size - 1;
} else {
cr->first = range.front().first;
cr->last = std::min(range.front().second, size - 1);
cr->last = (std::min)(range.front().second, size - 1);
}
request->response().entity.contentLength = cr->last - cr->first + 1;
}
Expand Down
27 changes: 13 additions & 14 deletions mordor/predef.h
Expand Up @@ -4,13 +4,19 @@
#include "version.h"

#ifdef WINDOWS
// Get Vista+ APIs
#define _WIN32_WINNT 0x0600
// Don't include tons of crap from windows.h
#define WIN32_LEAN_AND_MEAN
// Define this so security.h works
#define SECURITY_WIN32
// Shut up, CRT
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_NONSTDC_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS

// Use more common names for functions
// (cross-platform 64-bit, strip the underscores)
#define strtoll _strtoi64
#define strtoull _strtoui64
#define strnicmp _strnicmp
Expand All @@ -22,27 +28,20 @@
#include <windows.h>
#include <ws2tcpip.h>

#ifdef min
#undef min
#endif
#ifdef max
#undef max
#endif
#ifdef ABSOLUTE
#undef ABSOLUTE
#endif
#ifdef RELATIVE
#undef RELATIVE
#endif
// Take things out of the preprocessor, and put into the global namespace
// From WinGDI.h: #define ERROR 0
#ifdef ERROR
#undef ERROR
enum {
ERROR = 0
};
#endif

// Take things out of the preprocessor, and put into the global namespace
// From WinNT.h: #define DELETE (0x00010000L)
#ifdef DELETE
#undef DELETE
enum {
DELETE = (0x00010000L)
DELETE = (0x00010000L)
};
#endif

Expand Down
16 changes: 8 additions & 8 deletions mordor/socket.cpp
Expand Up @@ -1398,7 +1398,7 @@ Address::getInterfaceAddresses(int family)
if (error)
MORDOR_THROW_EXCEPTION_FROM_ERROR_API(error, "PIP_ADAPTER_INFO");
for (; addresses2; addresses2 = addresses2->Next) {
std::string interface(addresses2->AdapterName);
std::string iface(addresses2->AdapterName);
if (family != AF_INET && family != AF_UNSPEC)
continue;
IP_ADDR_STRING *address = &addresses2->IpAddressList;
Expand All @@ -1408,7 +1408,7 @@ Address::getInterfaceAddresses(int family)
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr(address->IpAddress.String);
unsigned int mask = inet_addr(address->IpMask.String);
result.insert(std::make_pair(interface, std::make_pair(
result.insert(std::make_pair(iface, std::make_pair(
Address::create((sockaddr *)&addr,
sizeof(sockaddr_in)), countBits(mask))));
}
Expand All @@ -1418,7 +1418,7 @@ Address::getInterfaceAddresses(int family)
}

for (; addresses; addresses = addresses->Next) {
std::string interface(addresses->AdapterName);
std::string iface(addresses->AdapterName);
IP_ADAPTER_UNICAST_ADDRESS *address = addresses->FirstUnicastAddress;
for (; address; address = address->Next) {
if (family != AF_UNSPEC &&
Expand All @@ -1435,7 +1435,7 @@ Address::getInterfaceAddresses(int family)
prefixLength = address->OnLinkPrefixLength;
}

result.insert(std::make_pair(interface,
result.insert(std::make_pair(iface,
std::make_pair(addr, prefixLength)));
}
}
Expand Down Expand Up @@ -1485,17 +1485,17 @@ Address::getInterfaceAddresses(int family)
}

std::vector<std::pair<Address::ptr, unsigned int> >
Address::getInterfaceAddresses(const std::string &interface, int family)
Address::getInterfaceAddresses(const std::string &iface, int family)
{
typedef std::multimap<std::string, std::pair<Address::ptr, unsigned int> >
AddressesMap;
std::vector<std::pair<Address::ptr, unsigned int> > result;
AddressesMap interfaces = getInterfaceAddresses(family);
std::pair<AddressesMap::iterator, AddressesMap::iterator> its;
if (interface.empty() || interface == "*")
if (iface.empty() || iface == "*")
its = std::make_pair(interfaces.begin(), interfaces.end());
else
its = interfaces.equal_range(interface);
its = interfaces.equal_range(iface);
for (; its.first != its.second; ++its.first)
result.push_back(its.first->second);
return result;
Expand Down Expand Up @@ -1553,7 +1553,7 @@ Address::insert(std::ostream &os) const
bool
Address::operator<(const Address &rhs) const
{
socklen_t minimum = std::min(nameLen(), rhs.nameLen());
socklen_t minimum = (std::min)(nameLen(), rhs.nameLen());
int result = memcmp(name(), rhs.name(), minimum);
if (result < 0)
return true;
Expand Down
4 changes: 2 additions & 2 deletions mordor/socket.h
Expand Up @@ -211,9 +211,9 @@ struct Address
/// @returns interface => (address, prefixLength)
static std::multimap<std::string, std::pair<ptr, unsigned int> >
getInterfaceAddresses(int family = AF_UNSPEC);
// @param interface Interface name, or "*" to indicate all interfaces
// @param iface Interface name, or "*" to indicate all interfaces
static std::vector<std::pair<ptr, unsigned int> >
getInterfaceAddresses(const std::string &interface,
getInterfaceAddresses(const std::string &iface,
int family = AF_UNSPEC);
static ptr create(const sockaddr *name, socklen_t nameLen);

Expand Down
48 changes: 24 additions & 24 deletions mordor/statistics.h
Expand Up @@ -78,23 +78,23 @@ struct MinStatistic : Statistic

MinStatistic(const char *units = NULL)
: Statistic(units),
min(std::numeric_limits<T>::max())
minimum((std::numeric_limits<T>::max)())
{}

volatile value_type min;
volatile value_type minimum;

void reset() { min = std::numeric_limits<T>::max(); }
void reset() { minimum = (std::numeric_limits<T>::max)(); }

std::ostream &serialize(std::ostream &os) const
{ return os << min; }
{ return os << minimum; }

void update(value_type value)
{
value_type oldval = min;
value_type oldval = minimum;
do {
if (oldval < value)
break;
} while (value != (oldval = atomicCompareAndSwap(min, value, oldval)));
} while (value != (oldval = atomicCompareAndSwap(minimum, value, oldval)));
}
};

Expand All @@ -106,22 +106,22 @@ struct MaxStatistic : Statistic

MaxStatistic(const char *units = NULL)
: Statistic(units),
max(std::numeric_limits<T>::min())
maximum((std::numeric_limits<T>::min)())
{}
volatile value_type max;
volatile value_type maximum;

void reset() { max = std::numeric_limits<T>::min(); }
void reset() { maximum = (std::numeric_limits<T>::min)(); }

std::ostream &serialize(std::ostream &os) const
{ return os << max; }
{ return os << maximum; }

void update(value_type value)
{
value_type oldval = max;
value_type oldval = maximum;
do {
if (oldval > value)
break;
} while (value != (oldval = atomicCompareAndSwap(max, value, oldval)));
} while (value != (oldval = atomicCompareAndSwap(maximum, value, oldval)));
}
};

Expand Down Expand Up @@ -178,33 +178,33 @@ struct AverageMinMaxStatistic : AverageStatistic<T>
{
AverageMinMaxStatistic(const char *sumunits = NULL, const char *countunits = NULL)
: AverageStatistic<T>(sumunits, countunits),
min(sumunits),
max(sumunits)
minimum(sumunits),
maximum(sumunits)
{}

MinStatistic<T> min;
MaxStatistic<T> max;
MinStatistic<T> minimum;
MaxStatistic<T> maximum;

void reset()
{
AverageStatistic<T>::reset();
min.reset();
max.reset();
minimum.reset();
maximum.reset();
}

void update(T value)
{
AverageStatistic<T>::update(value);
min.update(value);
max.update(value);
minimum.update(value);
maximum.update(value);
}

const Statistic *begin() const { return &min; }
const Statistic *begin() const { return &minimum; }
const Statistic *next(const Statistic *previous) const
{
if (previous == &min)
return &max;
else if (previous == &max)
if (previous == &minimum)
return &maximum;
else if (previous == &maximum)
return AverageStatistic<T>::begin();
else
return AverageStatistic<T>::next(previous);
Expand Down

0 comments on commit 9ab1f65

Please sign in to comment.