Address clang warnings.
* Split off AIThreadSafeBitsPOD, because offsetof may only be used on POD types. * Added ASSERT_ONLY and ASSERT_ONLY_COMMA * Removed a few unused class members * Fixed a bug in AIHTTPReceivedHeaders::equal that more or less only compared the length of the headers before :/
This commit is contained in:
@@ -111,10 +111,10 @@ template<typename T> struct AIAccess;
|
||||
template<typename T> struct AISTAccessConst;
|
||||
template<typename T> struct AISTAccess;
|
||||
|
||||
// This helper class is needed because offsetof is only allowed on POD types.
|
||||
template<typename T>
|
||||
class AIThreadSafeBits
|
||||
struct AIThreadSafeBitsPOD
|
||||
{
|
||||
private:
|
||||
// AIThreadSafe is a wrapper around an instance of T.
|
||||
// Because T might not have a default constructor, it is constructed
|
||||
// 'in place', with placement new, in the memory reserved here.
|
||||
@@ -122,7 +122,11 @@ private:
|
||||
// Make sure that the memory that T will be placed in is properly
|
||||
// aligned by using an array of long's.
|
||||
long mMemory[(sizeof(T) + sizeof(long) - 1) / sizeof(long)];
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class AIThreadSafeBits : private AIThreadSafeBitsPOD<T>
|
||||
{
|
||||
public:
|
||||
// The wrapped objects are constructed in-place with placement new *outside*
|
||||
// of this object (by AITHREADSAFE macro(s) or derived classes).
|
||||
@@ -130,20 +134,20 @@ public:
|
||||
~AIThreadSafeBits() { ptr()->~T(); }
|
||||
|
||||
// Only for use by AITHREADSAFE, see below.
|
||||
void* memory() const { return const_cast<long*>(&mMemory[0]); }
|
||||
void* memory() const { return const_cast<long*>(&AIThreadSafeBitsPOD<T>::mMemory[0]); }
|
||||
|
||||
// Cast a T* back to AIThreadSafeBits<T>. This is the inverse of memory().
|
||||
template<typename T2>
|
||||
static AIThreadSafeBits<T2>* wrapper_cast(T2* ptr)
|
||||
{ return reinterpret_cast<AIThreadSafeBits<T2>*>(reinterpret_cast<char*>(ptr) - offsetof(AIThreadSafeBits<T2>, mMemory[0])); }
|
||||
{ return static_cast<AIThreadSafeBits<T2>*>(reinterpret_cast<AIThreadSafeBitsPOD<T2>*>(reinterpret_cast<char*>(ptr) - offsetof(AIThreadSafeBitsPOD<T2>, mMemory[0]))); }
|
||||
template<typename T2>
|
||||
static AIThreadSafeBits<T2> const* wrapper_cast(T2 const* ptr)
|
||||
{ return reinterpret_cast<AIThreadSafeBits<T2> const*>(reinterpret_cast<char const*>(ptr) - offsetof(AIThreadSafeBits<T2>, mMemory[0])); }
|
||||
{ return static_cast<AIThreadSafeBits<T2> const*>(reinterpret_cast<AIThreadSafeBitsPOD<T2> const*>(reinterpret_cast<char const*>(ptr) - offsetof(AIThreadSafeBitsPOD<T2>, mMemory[0]))); }
|
||||
|
||||
protected:
|
||||
// Accessors.
|
||||
T const* ptr() const { return reinterpret_cast<T const*>(mMemory); }
|
||||
T* ptr() { return reinterpret_cast<T*>(mMemory); }
|
||||
T const* ptr() const { return reinterpret_cast<T const*>(AIThreadSafeBitsPOD<T>::mMemory); }
|
||||
T* ptr() { return reinterpret_cast<T*>(AIThreadSafeBitsPOD<T>::mMemory); }
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -124,6 +124,25 @@ const int LL_ERR_PRICE_MISMATCH = -23018;
|
||||
#define llverify(func) do {if (func) {}} while(0)
|
||||
#endif
|
||||
|
||||
// This can be used for function parameters that are only used by llassert.
|
||||
// The ellipsis is needed in case the parameter contains comma's (ie, as part of the type,
|
||||
// or trailing comma). The first version can be used as first (or only) parameter of a function,
|
||||
// or as parameter in the middle when adding a trailing comma, while the second version can be
|
||||
// used as last parameter.
|
||||
//
|
||||
// Example usage:
|
||||
//
|
||||
// void foo(ASSERT_ONLY(int x));
|
||||
// void foo(x, ASSERT_ONLY(int y,) int z);
|
||||
// void foo(x/*,*/ ASSERT_ONLY_COMMA(int y)); // The optional /*,*/ makes it just a bit better readable.
|
||||
#ifdef SHOW_ASSERT
|
||||
#define ASSERT_ONLY(type_param,...) type_param,##__VA_ARGS__
|
||||
#define ASSERT_ONLY_COMMA(type_param,...) , type_param,##__VA_ARGS__
|
||||
#else
|
||||
#define ASSERT_ONLY(type_param,...)
|
||||
#define ASSERT_ONLY_COMMA(type_param,...)
|
||||
#endif
|
||||
|
||||
// handy compile-time assert - enforce those template parameters!
|
||||
#define cassert(expn) typedef char __C_ASSERT__[(expn)?1:-1] /* Flawfinder: ignore */
|
||||
//XXX: used in two places in llcommon/llskipmap.h
|
||||
|
||||
@@ -290,7 +290,7 @@ enum refresh_t {
|
||||
class CurlSocketInfo
|
||||
{
|
||||
public:
|
||||
CurlSocketInfo(MultiHandle& multi_handle, CURL* easy, curl_socket_t s, int action, ThreadSafeBufferedCurlEasyRequest* lockobj);
|
||||
CurlSocketInfo(MultiHandle& multi_handle, ASSERT_ONLY(CURL* easy,) curl_socket_t s, int action, ThreadSafeBufferedCurlEasyRequest* lockobj);
|
||||
~CurlSocketInfo();
|
||||
|
||||
void set_action(int action);
|
||||
@@ -300,7 +300,6 @@ class CurlSocketInfo
|
||||
|
||||
private:
|
||||
MultiHandle& mMultiHandle;
|
||||
CURL const* mEasy;
|
||||
curl_socket_t mSocketFd;
|
||||
int mAction;
|
||||
bool mDead;
|
||||
@@ -669,12 +668,10 @@ class MergeIterator
|
||||
private:
|
||||
PollSet* mReadPollSet;
|
||||
PollSet* mWritePollSet;
|
||||
int readIndx;
|
||||
int writeIndx;
|
||||
};
|
||||
|
||||
MergeIterator::MergeIterator(PollSet* readPollSet, PollSet* writePollSet) :
|
||||
mReadPollSet(readPollSet), mWritePollSet(writePollSet), readIndx(0), writeIndx(0)
|
||||
mReadPollSet(readPollSet), mWritePollSet(writePollSet)
|
||||
{
|
||||
mReadPollSet->reset();
|
||||
mWritePollSet->reset();
|
||||
@@ -766,8 +763,8 @@ std::ostream& operator<<(std::ostream& os, DebugFdSet const& s)
|
||||
}
|
||||
#endif
|
||||
|
||||
CurlSocketInfo::CurlSocketInfo(MultiHandle& multi_handle, CURL* easy, curl_socket_t s, int action, ThreadSafeBufferedCurlEasyRequest* lockobj) :
|
||||
mMultiHandle(multi_handle), mEasy(easy), mSocketFd(s), mAction(CURL_POLL_NONE), mDead(false), mEasyRequest(lockobj)
|
||||
CurlSocketInfo::CurlSocketInfo(MultiHandle& multi_handle, ASSERT_ONLY(CURL* easy,) curl_socket_t s, int action, ThreadSafeBufferedCurlEasyRequest* lockobj) :
|
||||
mMultiHandle(multi_handle), mSocketFd(s), mAction(CURL_POLL_NONE), mDead(false), mEasyRequest(lockobj)
|
||||
{
|
||||
llassert(*AICurlEasyRequest_wat(*mEasyRequest) == easy);
|
||||
mMultiHandle.assign(s, this);
|
||||
|
||||
@@ -174,7 +174,7 @@ bool AIHTTPReceivedHeaders::equal(std::string const& key1, std::string const& ke
|
||||
}
|
||||
for (std::string::const_iterator i1 = key1.begin(), i2 = key2.begin(); i1 != key1.end(); ++i1, ++i2)
|
||||
{
|
||||
if ((*i1 ^ *i2) & 0xdf != 0)
|
||||
if (((*i1 ^ *i2) & 0xdf) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user