From: <ag...@us...> - 2012-01-26 04:16:39
|
Revision: 2685 http://zoolib.svn.sourceforge.net/zoolib/?rev=2685&view=rev Author: agreen Date: 2012-01-26 04:16:33 +0000 (Thu, 26 Jan 2012) Log Message: ----------- Changes suggested by clang static analysis. Migrate some stuff into zconfigl.h so it's less clumsy to use. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZDCPixmapBlitPriv.h trunk/zoolib/source/cxx/zoolib/ZDList.h trunk/zoolib/source/cxx/zoolib/ZDebug.cpp trunk/zoolib/source/cxx/zoolib/ZDebug.h trunk/zoolib/source/cxx/zoolib/ZFile_POSIX.cpp trunk/zoolib/source/cxx/zoolib/ZMACRO_typeof.h trunk/zoolib/source/cxx/zoolib/ZQ.h trunk/zoolib/source/cxx/zoolib/ZRGBA.h trunk/zoolib/source/cxx/zoolib/ZSet_T.h trunk/zoolib/source/cxx/zoolib/ZStrim.h trunk/zoolib/source/cxx/zoolib/ZString.h trunk/zoolib/source/cxx/zoolib/ZThread.h trunk/zoolib/source/cxx/zoolib/ZWinCOM.h trunk/zoolib/source/cxx/zoolib/zconfigd.h trunk/zoolib/source/cxx/zoolib/zconfigl.h Modified: trunk/zoolib/source/cxx/zoolib/ZDCPixmapBlitPriv.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZDCPixmapBlitPriv.h 2012-01-26 04:15:29 UTC (rev 2684) +++ trunk/zoolib/source/cxx/zoolib/ZDCPixmapBlitPriv.h 2012-01-26 04:16:33 UTC (rev 2685) @@ -1540,7 +1540,6 @@ iDestB.left, iDestPD); - ZRGBA_POD theColor = iColor; for (;;) { int destCountH = destWidth + 1; @@ -1617,7 +1616,6 @@ iDestB.left, iDestPD); - ZRGBA_POD theColor = iColor; for (;;) { int destCountH = destWidth + 1; @@ -1674,6 +1672,7 @@ { switch (iOp) { + default: case eOp_Copy: { sTile_SD_T(iSource, iSourceRD, iSourceB, iSourcePD, @@ -1711,6 +1710,7 @@ { switch (iOp) { + default: case eOp_Copy: { sCopy_SD_T(iSource, iSourceRD, iSourcePD, @@ -1749,6 +1749,7 @@ { switch (iOp) { + default: case eOp_Copy: { sTile_SMD_T(iSource, iSourceRD, iSourceB, iSourcePD, @@ -1796,6 +1797,7 @@ { switch (iOp) { + default: case eOp_Copy: { sTileSource_SMD_T(iSource, iSourceRD, iSourceB, iSourcePD, @@ -1843,6 +1845,7 @@ { switch (iOp) { + default: case eOp_Copy: { sTileMatte_SMD_T(iSource, iSourceRD, iSourcePD, @@ -1890,6 +1893,7 @@ { switch (iOp) { + default: case eOp_Copy: { sCopy_SMD_T(iSource, iSourceRD, iSourcePD, @@ -1934,6 +1938,7 @@ { switch (iOp) { + default: case eOp_Copy: { sFillPixval(oDest, iDestRD, iDestB, iDestPD.AsPixval(iColor)); @@ -1967,6 +1972,7 @@ { switch (iOp) { + default: case eOp_Copy: { sColor_MD_T(iMatte, iMatteRD, iMattePD, @@ -2007,6 +2013,7 @@ { switch (iOp) { + default: case eOp_Copy: { sColorTile_MD_T(iMatte, iMatteRD, iMatteB, iMattePD, Modified: trunk/zoolib/source/cxx/zoolib/ZDList.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZDList.h 2012-01-26 04:15:29 UTC (rev 2684) +++ trunk/zoolib/source/cxx/zoolib/ZDList.h 2012-01-26 04:16:33 UTC (rev 2685) @@ -58,7 +58,7 @@ size_t Size() const { return fSize; } - bool Empty() const + bool IsEmpty() const { ZAssertStop(L::kDebug, (!fSize && !fHeadL) || (fSize && fHeadL)); return !fHeadL; Modified: trunk/zoolib/source/cxx/zoolib/ZDebug.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZDebug.cpp 2012-01-26 04:15:29 UTC (rev 2684) +++ trunk/zoolib/source/cxx/zoolib/ZDebug.cpp 2012-01-26 04:16:33 UTC (rev 2685) @@ -22,7 +22,6 @@ #include "zoolib/ZDebug.h" #include "zoolib/ZFunctionChain.h" #include "zoolib/ZCONFIG_SPI.h" -#include "zoolib/ZTypes.h" #include <stdio.h> #include <string.h> @@ -209,9 +208,9 @@ mov eax, 0x18 mov eax, es:[eax] sub eax, 0x10 -#ifdef xor -#undef xor -#endif + #ifdef xor + #undef xor + #endif xor eax, [threadID] mov [obfuscator], eax } @@ -278,3 +277,16 @@ } // namespace ZDebug } // namespace ZooLib + +// ================================================================================================= +// MARK: - ZUnimplemented + +namespace ZooLib { + +// I'd like to formalize ZUnimplemented a little more sometime. +// Perhaps it should throw an exception in production code. + +void ZUnimplemented() + { ZDebugStopf(0, ("Unimplemented routine")); } + +} // namespace ZooLib Modified: trunk/zoolib/source/cxx/zoolib/ZDebug.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZDebug.h 2012-01-26 04:15:29 UTC (rev 2684) +++ trunk/zoolib/source/cxx/zoolib/ZDebug.h 2012-01-26 04:16:33 UTC (rev 2685) @@ -25,12 +25,12 @@ #include <cstdarg> // For std::va_list #include <cstddef> // For std::size_t +// ================================================================================================= +// MARK: - ZDebug + namespace ZooLib { namespace ZDebug { -// ================================================================================================= -// MARK: - ZDebug - struct Params_t { int fLevel; @@ -96,14 +96,21 @@ #define ZAssertCompile(a) typedef ZooLib::ZDebug::AssertCompile<(a)>::IsValid ZAssertCompileValid -// I'd like to formalize ZUnimplemented a little more sometime. Perhaps it should -// throw an exception in production code. -#define ZUnimplemented() ZDebugStopf(0, ("Unimplemented routine")) - // There are still quite a lot of places where plain old ZAssert is used. -#define ZAssert(a) ZAssertStop(0, a) +#ifndef ZAssert + #define ZAssert(a) ZAssertStop(0, a) +#endif } // namespace ZDebug } // namespace ZooLib +// ================================================================================================= +// MARK: - ZUnimplemented + +namespace ZooLib { + +void ZUnimplemented() ZMACRO_Attribute_NoReturn; + +} // namespace ZooLib + #endif // __ZDebug_h__ Modified: trunk/zoolib/source/cxx/zoolib/ZFile_POSIX.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZFile_POSIX.cpp 2012-01-26 04:15:29 UTC (rev 2684) +++ trunk/zoolib/source/cxx/zoolib/ZFile_POSIX.cpp 2012-01-26 04:16:33 UTC (rev 2685) @@ -536,9 +536,7 @@ } } -#if ZCONFIG(Compiler,GCC) -__attribute__((unused)) -#endif +ZMACRO_Attribute_Unused static void spSplit(char iSep, bool iIncludeEmpties, const string& iPath, vector<string>& oComps) { if (size_t length = iPath.length()) Modified: trunk/zoolib/source/cxx/zoolib/ZMACRO_typeof.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZMACRO_typeof.h 2012-01-26 04:15:29 UTC (rev 2684) +++ trunk/zoolib/source/cxx/zoolib/ZMACRO_typeof.h 2012-01-26 04:16:33 UTC (rev 2685) @@ -21,10 +21,8 @@ #ifndef __ZMACRO_typeof_h__ #define __ZMACRO_typeof_h__ 1 -#if defined(_MSC_VER) +#if not defined(_MSC_VER) -#if 0 - #elif _MSC_VER >= 1600 // Visual C++ 2010 @@ -58,6 +56,9 @@ // 2) var_type_id(expersssion) // 3) type_of(expression) +namespace ZooLib { +namespace MACRO_auto { + // IMPLEMENTATION template<int ID> class CTypeRegRoot @@ -104,9 +105,9 @@ // type_id #define type_id(type) \ (CProvideCounterValue< \ - /*register TYPE--ID*/ typename CTypeReg<type, CCountOf<type >::count>::Dummy, \ - /*increment compile-time Counter*/ CCounter<CCountOf<type >::count>, \ - /*pass value of Counter*/CCountOf<type >::count \ + typename CTypeReg<type, CCountOf<type >::count>::Dummy, \ + CCounter<CCountOf<type >::count>, \ + CCountOf<type >::count \ >::value) // Lets type_id() be > than 0 @@ -139,6 +140,5 @@ #define ZMACRO_auto_(name,expr) ZMACRO_typeof(expr) name = (expr) #endif // _MSV_VER -#endif // defined(_MSC_VER) #endif // __ZMACRO_typeof_h__ Modified: trunk/zoolib/source/cxx/zoolib/ZQ.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZQ.h 2012-01-26 04:15:29 UTC (rev 2684) +++ trunk/zoolib/source/cxx/zoolib/ZQ.h 2012-01-26 04:16:33 UTC (rev 2685) @@ -296,12 +296,7 @@ } private: - #if ZCONFIG(Compiler,GCC) - char fBytes[sizeof(T)] __attribute__((aligned)); - #else - char fBytes[sizeof(T)]; - #endif - + char fBytes[sizeof(T)] ZMACRO_Attribute_Aligned; bool fHasValue; }; Modified: trunk/zoolib/source/cxx/zoolib/ZRGBA.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZRGBA.h 2012-01-26 04:15:29 UTC (rev 2684) +++ trunk/zoolib/source/cxx/zoolib/ZRGBA.h 2012-01-26 04:16:33 UTC (rev 2685) @@ -211,9 +211,9 @@ bool operator<(const ZRGBA_POD& other) const { - return red < other.red || - red == other.red && green < other.green || - red == other.red && green == other.green && blue < other.blue; + return (red < other.red) + || (red == other.red && green < other.green) + || (red == other.red && green == other.green && blue < other.blue); } }; Modified: trunk/zoolib/source/cxx/zoolib/ZSet_T.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZSet_T.h 2012-01-26 04:15:29 UTC (rev 2684) +++ trunk/zoolib/source/cxx/zoolib/ZSet_T.h 2012-01-26 04:16:33 UTC (rev 2685) @@ -82,7 +82,7 @@ ZSet_T& Insert(const T& iElem); ZSet_T& Erase(const T& iElem); - bool Empty() const; + bool IsEmpty() const; const Base_t& GetElems() const; @@ -290,7 +290,7 @@ } template <class T, class Comparator> -bool ZSet_T<T,Comparator>::Empty() const +bool ZSet_T<T,Comparator>::IsEmpty() const { return this->empty(); } template <class T, class Comparator> Modified: trunk/zoolib/source/cxx/zoolib/ZStrim.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZStrim.h 2012-01-26 04:15:29 UTC (rev 2684) +++ trunk/zoolib/source/cxx/zoolib/ZStrim.h 2012-01-26 04:16:33 UTC (rev 2685) @@ -27,14 +27,6 @@ #include <stdarg.h> // For va_list #include <stdexcept> // For range_error -#ifndef ZMACRO_Attribute_Format_Printf - #if ZCONFIG(Compiler,GCC) - #define ZMACRO_Attribute_Format_Printf(m,n) __attribute__((format(printf,m,n))) - #else - #define ZMACRO_Attribute_Format_Printf(m,n) - #endif -#endif - namespace ZooLib { class ZStrimW; Modified: trunk/zoolib/source/cxx/zoolib/ZString.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZString.h 2012-01-26 04:15:29 UTC (rev 2684) +++ trunk/zoolib/source/cxx/zoolib/ZString.h 2012-01-26 04:16:33 UTC (rev 2685) @@ -25,20 +25,11 @@ #include <cstdarg> #include <string> -#ifndef ZMACRO_Attribute_Format_printf - #if ZCONFIG(Compiler,GCC) - #define ZMACRO_Attribute_Format_printf(m,n) __attribute__((format(printf,m,n))) - #else - #define ZMACRO_Attribute_Format_printf(m,n) - #endif -#endif +// ================================================================================================= -// ================================================== - namespace ZooLib { -std::string ZStringf(const char* iString, ...) - ZMACRO_Attribute_Format_printf(1,2); +std::string ZStringf(const char* iString, ...) ZMACRO_Attribute_Format_Printf(1,2); std::string ZStringf(const char* iString, std::va_list iArgs); Modified: trunk/zoolib/source/cxx/zoolib/ZThread.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThread.h 2012-01-26 04:15:29 UTC (rev 2684) +++ trunk/zoolib/source/cxx/zoolib/ZThread.h 2012-01-26 04:16:33 UTC (rev 2685) @@ -140,11 +140,7 @@ { // Useful when debugging under GDB, which (on MacOS) doesn't always // tell us what pthread_id corresponds to a thread. - #if ZCONFIG(Compiler,GCC) - const ZThread::ID theThreadID __attribute__((unused)) = ZThread::sID(); - #else - const ZThread::ID theThreadID = ZThread::sID(); - #endif + const ZThread::ID theThreadID ZMACRO_Attribute_Unused = ZThread::sID(); sStarted(); Modified: trunk/zoolib/source/cxx/zoolib/ZWinCOM.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZWinCOM.h 2012-01-26 04:15:29 UTC (rev 2684) +++ trunk/zoolib/source/cxx/zoolib/ZWinCOM.h 2012-01-26 04:16:33 UTC (rev 2685) @@ -125,14 +125,9 @@ { return fHRESULT; } private: - #if ZCONFIG(Compiler,GCC) - mutable char fBytes[sizeof(T)] __attribute__((aligned)); - #else - mutable char fBytes[sizeof(T)]; - #endif - - mutable bool fHasValue; + mutable char fBytes[sizeof(T)] ZMACRO_Attribute_Aligned; const HRESULT fHRESULT; + mutable bool fHasValue; }; // ================================================================================================= Modified: trunk/zoolib/source/cxx/zoolib/zconfigd.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/zconfigd.h 2012-01-26 04:15:29 UTC (rev 2684) +++ trunk/zoolib/source/cxx/zoolib/zconfigd.h 2012-01-26 04:16:33 UTC (rev 2685) @@ -18,8 +18,8 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------------------------- */ -#ifndef __zconfigd__ -#define __zconfigd__ 1 +#ifndef __zconfigd_h__ +#define __zconfigd_h__ 1 // Which compiler -- ZCONFIG_Compiler #define ZCONFIG_Compiler_CodeWarrior 1 @@ -47,4 +47,4 @@ // on CW, DEBUG defined on gcc). You should therefore define ZCONFIG_DebugLevel in your zconfig.h // file if it needs to be different from the default value of 1. -#endif // __zconfigd__ +#endif // __zconfigd_h__ Modified: trunk/zoolib/source/cxx/zoolib/zconfigl.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/zconfigl.h 2012-01-26 04:15:29 UTC (rev 2684) +++ trunk/zoolib/source/cxx/zoolib/zconfigl.h 2012-01-26 04:16:33 UTC (rev 2685) @@ -18,8 +18,8 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------------------------- */ -#ifndef __zconfigl__ -#define __zconfigl__ 1 +#ifndef __zconfigl_h__ +#define __zconfigl_h__ 1 // Ensure our definitions have been set up #include "zoolib/zconfigd.h" @@ -92,17 +92,17 @@ #ifndef ZCONFIG_Endian # if 0 -# elif (ZCONFIG_Processor == ZCONFIG_Processor_PPC) +# elif ZCONFIG(Processor, PPC) # define ZCONFIG_Endian ZCONFIG_Endian_Big -# elif (ZCONFIG_Processor == ZCONFIG_Processor_PPC_64) +# elif ZCONFIG(Processor, PPC_64) # define ZCONFIG_Endian ZCONFIG_Endian_Big -# elif (ZCONFIG_Processor == ZCONFIG_Processor_68K) +# elif ZCONFIG(Processor, 68K) # define ZCONFIG_Endian ZCONFIG_Endian_Big -# elif (ZCONFIG_Processor == ZCONFIG_Processor_x86) +# elif ZCONFIG(Processor, x86) # define ZCONFIG_Endian ZCONFIG_Endian_Little -# elif (ZCONFIG_Processor == ZCONFIG_Processor_x86_64) +# elif ZCONFIG(Processor, x86_64) # define ZCONFIG_Endian ZCONFIG_Endian_Little -# elif (ZCONFIG_Processor == ZCONFIG_Processor_ARM) +# elif ZCONFIG(Processor, ARM) # define ZCONFIG_Endian ZCONFIG_Endian_Little # endif #endif @@ -116,9 +116,9 @@ #ifndef ZCONFIG_Is64Bit # if 0 -# elif (ZCONFIG_Processor == ZCONFIG_Processor_PPC_64) +# elif ZCONFIG(Processor, PPC_64) # define ZCONFIG_Is64Bit 1 -# elif (ZCONFIG_Processor == ZCONFIG_Processor_x86_64) +# elif ZCONFIG(Processor, x86_64) # define ZCONFIG_Is64Bit 1 # endif #endif @@ -148,6 +148,12 @@ // With XCode we could base debug off !__OPTIMIZE__ #ifndef ZCONFIG_Debug # if 0 +# elif defined(__MACH__) +# if not defined(__OPTIMIZE__) +# define ZCONFIG_Debug ZCONFIG_DebugLevel +# else +# define ZCONFIG_Debug 0 +# endif # elif defined(__MWERKS__) # if __option(sym) # define ZCONFIG_Debug ZCONFIG_DebugLevel @@ -155,7 +161,7 @@ # define ZCONFIG_Debug 0 # endif # elif defined(_MSC_VER) -# if defined(_DEBUG) +# if defined(DEBUG) || defined(_DEBUG) # define ZCONFIG_Debug ZCONFIG_DebugLevel # else # define ZCONFIG_Debug 0 @@ -254,6 +260,7 @@ // inherits 'XXX' via dominance # pragma warning(disable:4250) + #else typedef wchar_t __wchar_t; @@ -265,27 +272,34 @@ // Objective C we're switching to use the soon-to-be standardized nullptr. #ifdef __cplusplus - #ifdef __MWERKS__ + + #if 0 + #elif defined(_MSC_VER) && _MSC_VER >= 1600 + + // nullptr is naturally available + + #elif defined(__MWERKS__) + class nullptr_t { + void operator&() const; public: template <class T> operator T*() const { return 0; } - private: - void operator&() const; }; #define nullptr nullptr_t() - #elif _MSC_VER >= 1600 - // nullptr is naturally available + #else + const class nullptr_t { + void operator&() const; public: template <class T> operator T*() const { return 0; } template <class C, class T> operator T C::*() const { return 0; } - private: - void operator&() const; } nullptr = {}; + #endif + #elif not defined(nullptr) #define nullptr 0 #endif @@ -296,14 +310,14 @@ #ifdef __cplusplus const class notnull_t {} notnull = {}; - const class null_t + const struct null_t { - public: const notnull_t operator!() const { return notnull; } } null = {}; #endif // ================================================================================================= + #if __MACH__ #define ZMACINCLUDE2(a,b) <a/b> #if __MWERKS__ @@ -316,9 +330,13 @@ #define ZMACINCLUDE3(a,b,c) <c> #endif +// ================================================================================================= + #define ZMACRO_Concat_(x, y) x ## y #define ZMACRO_Concat(x, y) ZMACRO_Concat_(x,y) +// ================================================================================================= + #ifdef __cplusplus #define ZMACRO_ExternC_Begin extern "C" { #define ZMACRO_ExternC_End } // extern "C" @@ -327,8 +345,12 @@ #define ZMACRO_ExternC_End #endif +// ================================================================================================= + #define ZMACRO_Stringify(a) #a +// ================================================================================================= + #if defined(_MSC_VER) #include "zoolib/ZMACRO_typeof.h" #else @@ -339,5 +361,38 @@ #define ZMACRO_auto_(name,expr) ZMACRO_typeof(expr) name = (expr) #endif +// ================================================================================================= -#endif // __zconfigl__ +#ifndef ZMACRO_Attribute_Format_Printf + #if ZCONFIG(Compiler,GCC) + #define ZMACRO_Attribute_Format_Printf(m,n) __attribute__((format(printf,m,n))) + #else + #define ZMACRO_Attribute_Format_Printf(m,n) + #endif +#endif + +#ifndef ZMACRO_Attribute_Aligned + #if ZCONFIG(Compiler,GCC) + #define ZMACRO_Attribute_Aligned __attribute__((aligned)) + #else + #define ZMACRO_Attribute_Aligned + #endif +#endif + +#ifndef ZMACRO_Attribute_NoReturn + #if ZCONFIG(Compiler,GCC) + #define ZMACRO_Attribute_NoReturn __attribute__((noreturn)) + #else + #define ZMACRO_Attribute_NoReturn + #endif +#endif + +#ifndef ZMACRO_Attribute_Unused + #if ZCONFIG(Compiler,GCC) + #define ZMACRO_Attribute_Unused __attribute__((unused)) + #else + #define ZMACRO_Attribute_Unused + #endif +#endif + +#endif // __zconfigl_h__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |