1370b324cSopenharmony_ci// Common.h 2370b324cSopenharmony_ci 3370b324cSopenharmony_ci#if defined(_MSC_VER) && _MSC_VER >= 1800 4370b324cSopenharmony_ci#pragma warning(disable : 4464) // relative include path contains '..' 5370b324cSopenharmony_ci#endif 6370b324cSopenharmony_ci 7370b324cSopenharmony_ci#ifndef ZIP7_INC_COMMON_H 8370b324cSopenharmony_ci#define ZIP7_INC_COMMON_H 9370b324cSopenharmony_ci 10370b324cSopenharmony_ci#include "../../C/Compiler.h" 11370b324cSopenharmony_ci 12370b324cSopenharmony_ci/* 13370b324cSopenharmony_ciThis file is included to all cpp files in 7-Zip. 14370b324cSopenharmony_ciEach folder contains StdAfx.h file that includes "Common.h". 15370b324cSopenharmony_ciSo 7-Zip includes "Common.h" in both modes: 16370b324cSopenharmony_ci with precompiled StdAfx.h 17370b324cSopenharmony_ciand 18370b324cSopenharmony_ci without precompiled StdAfx.h 19370b324cSopenharmony_ci 20370b324cSopenharmony_ciIf you use 7-Zip code, you must include "Common.h" before other h files of 7-zip. 21370b324cSopenharmony_ciIf you don't need some things that are used in 7-Zip, 22370b324cSopenharmony_ciyou can change this h file or h files included in this file. 23370b324cSopenharmony_ci*/ 24370b324cSopenharmony_ci 25370b324cSopenharmony_ci#ifdef _MSC_VER 26370b324cSopenharmony_ci #pragma warning(disable : 4710) // function not inlined 27370b324cSopenharmony_ci // 'CUncopyable::CUncopyable': 28370b324cSopenharmony_ci #pragma warning(disable : 4514) // unreferenced inline function has been removed 29370b324cSopenharmony_ci #if _MSC_VER < 1300 30370b324cSopenharmony_ci #pragma warning(disable : 4702) // unreachable code 31370b324cSopenharmony_ci #pragma warning(disable : 4714) // function marked as __forceinline not inlined 32370b324cSopenharmony_ci #pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information 33370b324cSopenharmony_ci #endif 34370b324cSopenharmony_ci #if _MSC_VER < 1400 35370b324cSopenharmony_ci #pragma warning(disable : 4511) // copy constructor could not be generated // #pragma warning(disable : 4512) // assignment operator could not be generated 36370b324cSopenharmony_ci #pragma warning(disable : 4512) // assignment operator could not be generated 37370b324cSopenharmony_ci #endif 38370b324cSopenharmony_ci #if _MSC_VER > 1400 && _MSC_VER <= 1900 39370b324cSopenharmony_ci // #pragma warning(disable : 4996) 40370b324cSopenharmony_ci // strcat: This function or variable may be unsafe 41370b324cSopenharmony_ci // GetVersion was declared deprecated 42370b324cSopenharmony_ci #endif 43370b324cSopenharmony_ci 44370b324cSopenharmony_ci#if _MSC_VER > 1200 45370b324cSopenharmony_ci// -Wall warnings 46370b324cSopenharmony_ci 47370b324cSopenharmony_ci#if _MSC_VER <= 1600 48370b324cSopenharmony_ci#pragma warning(disable : 4917) // 'OLE_HANDLE' : a GUID can only be associated with a class, interface or namespace 49370b324cSopenharmony_ci#endif 50370b324cSopenharmony_ci 51370b324cSopenharmony_ci// #pragma warning(disable : 4061) // enumerator '' in switch of enum '' is not explicitly handled by a case label 52370b324cSopenharmony_ci// #pragma warning(disable : 4266) // no override available for virtual member function from base ''; function is hidden 53370b324cSopenharmony_ci#pragma warning(disable : 4625) // copy constructor was implicitly defined as deleted 54370b324cSopenharmony_ci#pragma warning(disable : 4626) // assignment operator was implicitly defined as deleted 55370b324cSopenharmony_ci#if _MSC_VER >= 1600 && _MSC_VER < 1920 56370b324cSopenharmony_ci#pragma warning(disable : 4571) // Informational: catch(...) semantics changed since Visual C++ 7.1; structured exceptions (SEH) are no longer caught 57370b324cSopenharmony_ci#endif 58370b324cSopenharmony_ci#if _MSC_VER >= 1600 59370b324cSopenharmony_ci#pragma warning(disable : 4365) // 'initializing' : conversion from 'int' to 'unsigned int', signed / unsigned mismatch 60370b324cSopenharmony_ci#endif 61370b324cSopenharmony_ci#if _MSC_VER < 1800 62370b324cSopenharmony_ci// we disable the warning, if we don't use 'final' in class 63370b324cSopenharmony_ci#pragma warning(disable : 4265) // class has virtual functions, but destructor is not virtual 64370b324cSopenharmony_ci#endif 65370b324cSopenharmony_ci 66370b324cSopenharmony_ci#if _MSC_VER >= 1900 67370b324cSopenharmony_ci#pragma warning(disable : 5026) // move constructor was implicitly defined as deleted 68370b324cSopenharmony_ci#pragma warning(disable : 5027) // move assignment operator was implicitly defined as deleted 69370b324cSopenharmony_ci#endif 70370b324cSopenharmony_ci#if _MSC_VER >= 1912 71370b324cSopenharmony_ci#pragma warning(disable : 5039) // pointer or reference to potentially throwing function passed to 'extern "C"' function under - EHc.Undefined behavior may occur if this function throws an exception. 72370b324cSopenharmony_ci#endif 73370b324cSopenharmony_ci#if _MSC_VER >= 1925 74370b324cSopenharmony_ci// #pragma warning(disable : 5204) // 'ISequentialInStream' : class has virtual functions, but its trivial destructor is not virtual; instances of objects derived from this class may not be destructed correctly 75370b324cSopenharmony_ci#endif 76370b324cSopenharmony_ci#if _MSC_VER >= 1934 77370b324cSopenharmony_ci// #pragma warning(disable : 5264) // const variable is not used 78370b324cSopenharmony_ci#endif 79370b324cSopenharmony_ci 80370b324cSopenharmony_ci#endif // _MSC_VER > 1200 81370b324cSopenharmony_ci#endif // _MSC_VER 82370b324cSopenharmony_ci 83370b324cSopenharmony_ci 84370b324cSopenharmony_ci#if defined(_MSC_VER) // && !defined(__clang__) 85370b324cSopenharmony_ci#define Z7_DECLSPEC_NOTHROW __declspec(nothrow) 86370b324cSopenharmony_ci#elif defined(__clang__) || defined(__GNUC__) 87370b324cSopenharmony_ci#define Z7_DECLSPEC_NOTHROW __attribute__((nothrow)) 88370b324cSopenharmony_ci#else 89370b324cSopenharmony_ci#define Z7_DECLSPEC_NOTHROW 90370b324cSopenharmony_ci#endif 91370b324cSopenharmony_ci 92370b324cSopenharmony_ci/* 93370b324cSopenharmony_ci#if defined (_MSC_VER) && _MSC_VER >= 1900 \ 94370b324cSopenharmony_ci || defined(__clang__) && __clang_major__ >= 6 \ 95370b324cSopenharmony_ci || defined(__GNUC__) && __GNUC__ >= 6 96370b324cSopenharmony_ci #define Z7_noexcept noexcept 97370b324cSopenharmony_ci#else 98370b324cSopenharmony_ci #define Z7_noexcept throw() 99370b324cSopenharmony_ci#endif 100370b324cSopenharmony_ci*/ 101370b324cSopenharmony_ci 102370b324cSopenharmony_ci 103370b324cSopenharmony_ci#if defined(__clang__) 104370b324cSopenharmony_ci 105370b324cSopenharmony_ci// noexcept, final, = delete 106370b324cSopenharmony_ci#pragma GCC diagnostic ignored "-Wc++98-compat" 107370b324cSopenharmony_ci#if __clang_major__ >= 4 108370b324cSopenharmony_ci// throw() dynamic exception specifications are deprecated 109370b324cSopenharmony_ci#pragma GCC diagnostic ignored "-Wdeprecated-dynamic-exception-spec" 110370b324cSopenharmony_ci#endif 111370b324cSopenharmony_ci#pragma GCC diagnostic ignored "-Wold-style-cast" 112370b324cSopenharmony_ci#pragma GCC diagnostic ignored "-Wglobal-constructors" 113370b324cSopenharmony_ci#pragma GCC diagnostic ignored "-Wexit-time-destructors" 114370b324cSopenharmony_ci 115370b324cSopenharmony_ci// #pragma GCC diagnostic ignored "-Wunused-private-field" 116370b324cSopenharmony_ci// #pragma GCC diagnostic ignored "-Wnonportable-system-include-path" 117370b324cSopenharmony_ci// #pragma GCC diagnostic ignored "-Wsuggest-override" 118370b324cSopenharmony_ci// #pragma GCC diagnostic ignored "-Wsign-conversion" 119370b324cSopenharmony_ci// #pragma GCC diagnostic ignored "-Winconsistent-missing-override" 120370b324cSopenharmony_ci// #pragma GCC diagnostic ignored "-Wsuggest-destructor-override" 121370b324cSopenharmony_ci// #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" 122370b324cSopenharmony_ci// #pragma GCC diagnostic ignored "-Wdeprecated-copy-with-user-provided-dtor" 123370b324cSopenharmony_ci// #pragma GCC diagnostic ignored "-Wdeprecated-copy-dtor" 124370b324cSopenharmony_ci// #ifndef _WIN32 125370b324cSopenharmony_ci// #pragma GCC diagnostic ignored "-Wweak-vtables" 126370b324cSopenharmony_ci// #endif 127370b324cSopenharmony_ci/* 128370b324cSopenharmony_ci#if defined(Z7_GCC_VERSION) && (Z7_GCC_VERSION >= 40400) \ 129370b324cSopenharmony_ci || defined(Z7_CLANG_VERSION) && (Z7_CLANG_VERSION >= 30000) 130370b324cSopenharmony_ci// enumeration values not explicitly handled in switch 131370b324cSopenharmony_ci#pragma GCC diagnostic ignored "-Wswitch-enum" 132370b324cSopenharmony_ci#endif 133370b324cSopenharmony_ci*/ 134370b324cSopenharmony_ci#endif // __clang__ 135370b324cSopenharmony_ci 136370b324cSopenharmony_ci 137370b324cSopenharmony_ci#ifdef __GNUC__ 138370b324cSopenharmony_ci// #pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor" 139370b324cSopenharmony_ci#endif 140370b324cSopenharmony_ci 141370b324cSopenharmony_ci 142370b324cSopenharmony_ci/* There is BUG in MSVC 6.0 compiler for operator new[]: 143370b324cSopenharmony_ci It doesn't check overflow, when it calculates size in bytes for allocated array. 144370b324cSopenharmony_ci So we can use Z7_ARRAY_NEW macro instead of new[] operator. */ 145370b324cSopenharmony_ci 146370b324cSopenharmony_ci#if defined(_MSC_VER) && (_MSC_VER == 1200) && !defined(_WIN64) 147370b324cSopenharmony_ci #define Z7_ARRAY_NEW(p, T, size) p = new T[((size) > (unsigned)0xFFFFFFFF / sizeof(T)) ? (unsigned)0xFFFFFFFF / sizeof(T) : (size)]; 148370b324cSopenharmony_ci#else 149370b324cSopenharmony_ci #define Z7_ARRAY_NEW(p, T, size) p = new T[size]; 150370b324cSopenharmony_ci#endif 151370b324cSopenharmony_ci 152370b324cSopenharmony_ci#if (defined(__GNUC__) && (__GNUC__ >= 8)) 153370b324cSopenharmony_ci #define Z7_ATTR_NORETURN __attribute__((noreturn)) 154370b324cSopenharmony_ci#elif (defined(__clang__) && (__clang_major__ >= 3)) 155370b324cSopenharmony_ci #if __has_feature(cxx_attributes) 156370b324cSopenharmony_ci #define Z7_ATTR_NORETURN [[noreturn]] 157370b324cSopenharmony_ci #else 158370b324cSopenharmony_ci #define Z7_ATTR_NORETURN __attribute__((noreturn)) 159370b324cSopenharmony_ci #endif 160370b324cSopenharmony_ci#elif (defined(_MSC_VER) && (_MSC_VER >= 1900)) 161370b324cSopenharmony_ci #define Z7_ATTR_NORETURN [[noreturn]] 162370b324cSopenharmony_ci#else 163370b324cSopenharmony_ci #define Z7_ATTR_NORETURN 164370b324cSopenharmony_ci#endif 165370b324cSopenharmony_ci 166370b324cSopenharmony_ci 167370b324cSopenharmony_ci// final in "GCC 4.7.0" 168370b324cSopenharmony_ci// In C++98 and C++03 code the alternative spelling __final can be used instead (this is a GCC extension.) 169370b324cSopenharmony_ci 170370b324cSopenharmony_ci#if defined (__cplusplus) && __cplusplus >= 201103L \ 171370b324cSopenharmony_ci || defined(_MSC_VER) && _MSC_VER >= 1800 \ 172370b324cSopenharmony_ci || defined(__clang__) && __clang_major__ >= 4 \ 173370b324cSopenharmony_ci /* || defined(__GNUC__) && __GNUC__ >= 9 */ 174370b324cSopenharmony_ci #define Z7_final final 175370b324cSopenharmony_ci #if defined(__clang__) && __cplusplus < 201103L 176370b324cSopenharmony_ci #pragma GCC diagnostic ignored "-Wc++11-extensions" 177370b324cSopenharmony_ci #endif 178370b324cSopenharmony_ci#elif defined (__cplusplus) && __cplusplus >= 199711L \ 179370b324cSopenharmony_ci && defined(__GNUC__) && __GNUC__ >= 4 && !defined(__clang__) 180370b324cSopenharmony_ci #define Z7_final __final 181370b324cSopenharmony_ci#else 182370b324cSopenharmony_ci #define Z7_final 183370b324cSopenharmony_ci #if defined(__clang__) && __clang_major__ >= 4 \ 184370b324cSopenharmony_ci || defined(__GNUC__) && __GNUC__ >= 4 185370b324cSopenharmony_ci #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" 186370b324cSopenharmony_ci #pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor" 187370b324cSopenharmony_ci #endif 188370b324cSopenharmony_ci#endif 189370b324cSopenharmony_ci 190370b324cSopenharmony_ci#define Z7_class_final(c) class c Z7_final 191370b324cSopenharmony_ci 192370b324cSopenharmony_ci 193370b324cSopenharmony_ci#if defined (__cplusplus) && __cplusplus >= 201103L \ 194370b324cSopenharmony_ci || (defined(_MSC_VER) && _MSC_VER >= 1800) 195370b324cSopenharmony_ci #define Z7_CPP_IS_SUPPORTED_default 196370b324cSopenharmony_ci #define Z7_eq_delete = delete 197370b324cSopenharmony_ci // #define Z7_DECL_DEFAULT_COPY_CONSTRUCTOR_IF_SUPPORTED(c) c(const c& k) = default; 198370b324cSopenharmony_ci#else 199370b324cSopenharmony_ci #define Z7_eq_delete 200370b324cSopenharmony_ci // #define Z7_DECL_DEFAULT_COPY_CONSTRUCTOR_IF_SUPPORTED(c) 201370b324cSopenharmony_ci#endif 202370b324cSopenharmony_ci 203370b324cSopenharmony_ci 204370b324cSopenharmony_ci#if defined(__cplusplus) && (__cplusplus >= 201103L) \ 205370b324cSopenharmony_ci || defined(_MSC_VER) && (_MSC_VER >= 1400) /* && (_MSC_VER != 1600) */ \ 206370b324cSopenharmony_ci || defined(__clang__) && __clang_major__ >= 4 207370b324cSopenharmony_ci #if defined(_MSC_VER) && (_MSC_VER == 1600) /* && (_MSC_VER != 1600) */ 208370b324cSopenharmony_ci #pragma warning(disable : 4481) // nonstandard extension used: override specifier 'override' 209370b324cSopenharmony_ci #define Z7_DESTRUCTOR_override 210370b324cSopenharmony_ci #else 211370b324cSopenharmony_ci #define Z7_DESTRUCTOR_override override 212370b324cSopenharmony_ci #endif 213370b324cSopenharmony_ci #define Z7_override override 214370b324cSopenharmony_ci#else 215370b324cSopenharmony_ci #define Z7_override 216370b324cSopenharmony_ci #define Z7_DESTRUCTOR_override 217370b324cSopenharmony_ci#endif 218370b324cSopenharmony_ci 219370b324cSopenharmony_ci 220370b324cSopenharmony_ci 221370b324cSopenharmony_ci#define Z7_CLASS_NO_COPY(cls) \ 222370b324cSopenharmony_ci private: \ 223370b324cSopenharmony_ci cls(const cls &) Z7_eq_delete; \ 224370b324cSopenharmony_ci cls &operator=(const cls &) Z7_eq_delete; 225370b324cSopenharmony_ci 226370b324cSopenharmony_ciclass CUncopyable 227370b324cSopenharmony_ci{ 228370b324cSopenharmony_ciprotected: 229370b324cSopenharmony_ci CUncopyable() {} // allow constructor 230370b324cSopenharmony_ci // ~CUncopyable() {} 231370b324cSopenharmony_ci Z7_CLASS_NO_COPY(CUncopyable) 232370b324cSopenharmony_ci}; 233370b324cSopenharmony_ci 234370b324cSopenharmony_ci#define MY_UNCOPYABLE :private CUncopyable 235370b324cSopenharmony_ci// #define MY_UNCOPYABLE 236370b324cSopenharmony_ci 237370b324cSopenharmony_ci 238370b324cSopenharmony_citypedef void (*Z7_void_Function)(void); 239370b324cSopenharmony_ci 240370b324cSopenharmony_ci#if defined(__clang__) || defined(__GNUC__) 241370b324cSopenharmony_ci#define Z7_CAST_FUNC(t, e) reinterpret_cast<t>(reinterpret_cast<Z7_void_Function>(e)) 242370b324cSopenharmony_ci#else 243370b324cSopenharmony_ci#define Z7_CAST_FUNC(t, e) reinterpret_cast<t>(reinterpret_cast<void*>(e)) 244370b324cSopenharmony_ci// #define Z7_CAST_FUNC(t, e) reinterpret_cast<t>(e) 245370b324cSopenharmony_ci#endif 246370b324cSopenharmony_ci 247370b324cSopenharmony_ci#define Z7_GET_PROC_ADDRESS(func_type, hmodule, func_name) \ 248370b324cSopenharmony_ci Z7_CAST_FUNC(func_type, GetProcAddress(hmodule, func_name)) 249370b324cSopenharmony_ci 250370b324cSopenharmony_ci// || defined(__clang__) 251370b324cSopenharmony_ci// || defined(__GNUC__) 252370b324cSopenharmony_ci 253370b324cSopenharmony_ci#if defined(_MSC_VER) && (_MSC_VER >= 1400) 254370b324cSopenharmony_ci#define Z7_DECLSPEC_NOVTABLE __declspec(novtable) 255370b324cSopenharmony_ci#else 256370b324cSopenharmony_ci#define Z7_DECLSPEC_NOVTABLE 257370b324cSopenharmony_ci#endif 258370b324cSopenharmony_ci 259370b324cSopenharmony_ci#ifdef __clang__ 260370b324cSopenharmony_ci#define Z7_PURE_INTERFACES_BEGIN \ 261370b324cSopenharmony_ci_Pragma("GCC diagnostic push") \ 262370b324cSopenharmony_ci_Pragma("GCC diagnostic ignored \"-Wnon-virtual-dtor\"") 263370b324cSopenharmony_ci_Pragma("GCC diagnostic ignored \"-Wweak-vtables\"") 264370b324cSopenharmony_ci#define Z7_PURE_INTERFACES_END \ 265370b324cSopenharmony_ci_Pragma("GCC diagnostic pop") 266370b324cSopenharmony_ci#else 267370b324cSopenharmony_ci#define Z7_PURE_INTERFACES_BEGIN 268370b324cSopenharmony_ci#define Z7_PURE_INTERFACES_END 269370b324cSopenharmony_ci#endif 270370b324cSopenharmony_ci 271370b324cSopenharmony_ci// NewHandler.h and NewHandler.cpp redefine operator new() to throw exceptions, if compiled with old MSVC compilers 272370b324cSopenharmony_ci#include "NewHandler.h" 273370b324cSopenharmony_ci 274370b324cSopenharmony_ci/* 275370b324cSopenharmony_ci// #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) 276370b324cSopenharmony_ci#ifndef ARRAY_SIZE 277370b324cSopenharmony_ci#define ARRAY_SIZE(a) Z7_ARRAY_SIZE(a) 278370b324cSopenharmony_ci#endif 279370b324cSopenharmony_ci*/ 280370b324cSopenharmony_ci 281370b324cSopenharmony_ci#endif // ZIP7_INC_COMMON_H 282370b324cSopenharmony_ci 283370b324cSopenharmony_ci 284370b324cSopenharmony_ci 285370b324cSopenharmony_ci// #define Z7_REDEFINE_NULL 286370b324cSopenharmony_ci 287370b324cSopenharmony_ci#if defined(Z7_REDEFINE_NULL) /* && (!defined(__clang__) || defined(_MSC_VER)) */ 288370b324cSopenharmony_ci 289370b324cSopenharmony_ci// NULL is defined in <stddef.h> 290370b324cSopenharmony_ci#include <stddef.h> 291370b324cSopenharmony_ci#undef NULL 292370b324cSopenharmony_ci 293370b324cSopenharmony_ci#ifdef __cplusplus 294370b324cSopenharmony_ci #if defined (__cplusplus) && __cplusplus >= 201103L \ 295370b324cSopenharmony_ci || (defined(_MSC_VER) && _MSC_VER >= 1800) 296370b324cSopenharmony_ci #define NULL nullptr 297370b324cSopenharmony_ci #else 298370b324cSopenharmony_ci #define NULL 0 299370b324cSopenharmony_ci #endif 300370b324cSopenharmony_ci#else 301370b324cSopenharmony_ci #define NULL ((void *)0) 302370b324cSopenharmony_ci#endif 303370b324cSopenharmony_ci 304370b324cSopenharmony_ci#else // Z7_REDEFINE_NULL 305370b324cSopenharmony_ci 306370b324cSopenharmony_ci#if defined(__clang__) && __clang_major__ >= 5 307370b324cSopenharmony_ci#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" 308370b324cSopenharmony_ci#endif 309370b324cSopenharmony_ci 310370b324cSopenharmony_ci#endif // Z7_REDEFINE_NULL 311370b324cSopenharmony_ci 312370b324cSopenharmony_ci// for precompiler: 313370b324cSopenharmony_ci#include "MyWindows.h" 314