1 // VirtualDub - Video processing and capture application
2 // System library component
3 // Copyright (C) 1998-2007 Avery Lee, All Rights Reserved.
5 // Beginning with 1.6.0, the VirtualDub system library is licensed
6 // differently than the remainder of VirtualDub. This particular file is
7 // thus licensed as follows (the "zlib" license):
9 // This software is provided 'as-is', without any express or implied
10 // warranty. In no event will the authors be held liable for any
11 // damages arising from the use of this software.
13 // Permission is granted to anyone to use this software for any purpose,
14 // including commercial applications, and to alter it and redistribute it
15 // freely, subject to the following restrictions:
17 // 1. The origin of this software must not be misrepresented; you must
18 // not claim that you wrote the original software. If you use this
19 // software in a product, an acknowledgment in the product
20 // documentation would be appreciated but is not required.
21 // 2. Altered source versions must be plainly marked as such, and must
22 // not be misrepresented as being the original software.
23 // 3. This notice may not be removed or altered from any source
26 #ifndef f_VD2_SYSTEM_VDTYPES_H
27 #define f_VD2_SYSTEM_VDTYPES_H
42 ///////////////////////////////////////////////////////////////////////////
46 ///////////////////////////////////////////////////////////////////////////
48 #ifndef VD_COMPILER_DETECTED
49 #define VD_COMPILER_DETECTED
52 #define VD_COMPILER_MSVC _MSC_VER
55 #define VD_COMPILER_MSVC_VC8 1
56 #define VD_COMPILER_MSVC_VC8_OR_LATER 1
58 #if _MSC_FULL_VER == 140040310
59 #define VD_COMPILER_MSVC_VC8_PSDK 1
60 #elif _MSC_FULL_VER == 14002207
61 #define VD_COMPILER_MSVC_VC8_DDK 1
64 #elif _MSC_VER >= 1310
65 #define VD_COMPILER_MSVC_VC71 1
66 #elif _MSC_VER >= 1300
67 #define VD_COMPILER_MSVC_VC7 1
68 #elif _MSC_VER >= 1200
69 #define VD_COMPILER_MSVC_VC6 1
71 #elif defined(__GNUC__)
72 #define VD_COMPILER_GCC
73 #if defined(__MINGW32__) || defined(__MINGW64__)
74 #define VD_COMPILER_GCC_MINGW
79 #ifndef VD_CPU_DETECTED
80 #define VD_CPU_DETECTED
83 #define VD_CPU_AMD64 1
84 #elif defined(_M_IX86) || defined(__i386__)
91 ///////////////////////////////////////////////////////////////////////////
95 ///////////////////////////////////////////////////////////////////////////
97 #ifndef VD_STANDARD_TYPES_DECLARED
99 typedef signed __int64 sint64
;
100 typedef unsigned __int64 uint64
;
101 #elif defined(__GNUC__)
102 typedef signed long long sint64
;
103 typedef unsigned long long uint64
;
105 typedef signed int sint32
;
106 typedef unsigned int uint32
;
107 typedef signed short sint16
;
108 typedef unsigned short uint16
;
109 typedef signed char sint8
;
110 typedef unsigned char uint8
;
112 typedef sint64 int64
;
113 typedef sint32 int32
;
114 typedef sint16 int16
;
118 typedef sint64 sintptr
;
119 typedef uint64 uintptr
;
122 typedef __w64 sint32 sintptr
;
123 typedef __w64 uint32 uintptr
;
125 typedef sint32 sintptr
;
126 typedef uint32 uintptr
;
131 #if defined(_MSC_VER)
132 #define VD64(x) x##i64
133 #elif defined(__GNUC__)
134 #define VD64(x) x##ll
136 #error Please add an entry for your compiler for 64-bit constant literals.
140 #define VDAPIENTRY __cdecl
142 typedef int64 VDTime
;
143 typedef int64 VDPosition
;
144 typedef struct __VDGUIHandle
*VDGUIHandle
;
146 // enforce wchar_t under Visual C++
148 #if defined(_MSC_VER) && !defined(_WCHAR_T_DEFINED)
152 ///////////////////////////////////////////////////////////////////////////
156 ///////////////////////////////////////////////////////////////////////////
158 #if defined(VD_COMPILER_MSVC) && (VD_COMPILER_MSVC < 1300 || (defined(VD_COMPILER_MSVC_VC8_PSDK) || defined(VD_COMPILER_MSVC_VC8_DDK)))
159 #define new_nothrow new
161 #define new_nothrow new(std::nothrow)
164 ///////////////////////////////////////////////////////////////////////////
168 ///////////////////////////////////////////////////////////////////////////
170 #if defined(VD_COMPILER_MSVC_VC6) || defined(VD_COMPILER_MSVC_VC8_DDK) || defined(VD_COMPILER_MSVC_VC8_PSDK)
171 // The VC6 STL was deliberately borked to avoid conflicting with
172 // Windows min/max macros. We work around this bogosity here. Note
173 // that NOMINMAX must be defined for these to compile properly. Also,
174 // there is a bug in the VC6 compiler that sometimes causes long
175 // lvalues to "promote" to int, causing ambiguous override errors.
176 // To avoid this, always explicitly declare which type you are using,
177 // i.e. min<int>(x,0). None of this is a problem with VC7 or later.
180 inline const T
& min(const T
& x
, const T
& y
) {
181 return _cpp_min(x
, y
);
185 inline const T
& max(const T
& x
, const T
& y
) {
186 return _cpp_max(x
, y
);
191 ///////////////////////////////////////////////////////////////////////////
195 ///////////////////////////////////////////////////////////////////////////
197 #if defined(VD_COMPILER_MSVC) && (VD_COMPILER_MSVC < 1400 || (defined(VD_COMPILER_MSVC_VC8_PSDK) || defined(VD_COMPILER_MSVC_VC8_DDK)))
198 inline int vswprintf(wchar_t *dst
, size_t bufsize
, const wchar_t *format
, va_list val
) {
199 return _vsnwprintf(dst
, bufsize
, format
, val
);
202 inline int swprintf(wchar_t *dst
, size_t bufsize
, const wchar_t *format
, ...) {
205 va_start(val
, format
);
206 int r
= vswprintf(dst
, bufsize
, format
, val
);
212 #define _strdup strdup
213 #define _stricmp stricmp
214 #define _strnicmp strnicmp
215 #define _wcsdup wcsdup
216 #define _wcsicmp wcsicmp
217 #define _wcsnicmp wcsnicmp
220 #if defined(VD_COMPILER_MSVC) && VD_COMPILER_MSVC < 1400
221 #define vdfor if(0);else for
226 ///////////////////////////////////////////////////////////////////////////
230 ///////////////////////////////////////////////////////////////////////////
232 #if defined(VD_COMPILER_MSVC)
233 #define VDINTERFACE __declspec(novtable)
234 #define VDNORETURN __declspec(noreturn)
237 #if VD_COMPILER_MSVC >= 1400
238 #define VDRESTRICT __restrict
243 #define VDNOINLINE __declspec(noinline)
244 #define VDFORCEINLINE __forceinline
245 #define VDALIGN(alignment) __declspec(align(alignment))
246 #elif defined(VD_COMPILER_GCC)
248 #define VDNORETURN __attribute__((noreturn))
249 #define VDPUREFUNC __attribute__((pure))
250 #define VDRESTRICT __restrict
251 #define VDNOINLINE __attribute__((noinline))
252 #define VDFORCEINLINE inline __attribute__((always_inline))
253 #define VDALIGN(alignment) __attribute__((aligned(alignment)))
259 #define VDFORCEINLINE
260 #define VDALIGN(alignment)
263 ///////////////////////////////////////////////////////////////////////////
267 ///////////////////////////////////////////////////////////////////////////
269 enum VDAssertResult
{
275 extern VDAssertResult
VDAssert(const char *exp
, const char *file
, int line
);
276 extern VDAssertResult
VDAssertPtr(const char *exp
, const char *file
, int line
);
277 extern void VDDebugPrint(const char *format
, ...);
279 #if defined(_MSC_VER)
281 #define VDBREAK __debugbreak()
283 #define VDBREAK __asm { int 3 }
285 #elif defined(__GNUC__)
286 #define VDBREAK __asm__ volatile ("int3" : : )
288 #define VDBREAK *(volatile char *)0 = *(volatile char *)0
296 struct VDAssertHelper
{
297 VDAssertHelper(const char *exp
, const char *file
) {
298 if (!sbAssertDisabled
)
299 switch(VDAssert(exp
, file
, line
)) {
303 case kVDAssertIgnore
:
304 sbAssertDisabled
= true;
309 static bool sbAssertDisabled
;
313 bool VDAssertHelper
<lineno
>::sbAssertDisabled
;
316 struct VDAssertHelper2
{ static bool sDisabled
; };
319 bool VDAssertHelper2
<lineno
>::sDisabled
;
322 // MPC-HC custom code start
323 // We use the old code since the new templated code isn't compatible with MSVC "Edit and continue" feature
324 // because __LINE__ can't be known at compile time.
325 #if !defined(VD_COMPILER_MSVC) || defined(__INTEL_COMPILER)
326 #define VDASSERT(exp) if (!VDAssertHelper2<__LINE__>::sDisabled) if (exp); else switch(VDAssert (#exp, __FILE__, __LINE__)) { case kVDAssertBreak: VDBREAK; break; case kVDAssertIgnore: VDAssertHelper2<__LINE__>::sDisabled = true; } else ((void)0)
327 #define VDASSERTPTR(exp) if (!VDAssertHelper2<__LINE__>::sDisabled) if (exp); else switch(VDAssertPtr(#exp, __FILE__, __LINE__)) { case kVDAssertBreak: VDBREAK; break; case kVDAssertIgnore: VDAssertHelper2<__LINE__>::sDisabled = true; } else ((void)0)
328 #define VDVERIFY(exp) if (exp); else if (!VDAssertHelper2<__LINE__>::sDisabled) switch(VDAssert (#exp, __FILE__, __LINE__)) { case kVDAssertBreak: VDBREAK; break; case kVDAssertIgnore: VDAssertHelper2<__LINE__>::sDisabled = true; } else ((void)0)
329 #define VDVERIFYPTR(exp) if (exp); else if (!VDAssertHelper2<__LINE__>::sDisabled) switch(VDAssertPtr(#exp, __FILE__, __LINE__)) { case kVDAssertBreak: VDBREAK; break; case kVDAssertIgnore: VDAssertHelper2<__LINE__>::sDisabled = true; } else ((void)0)
331 #define VDASSERT(exp) if (static bool active = true) if (exp); else switch(VDAssert (#exp, __FILE__, __LINE__)) { case kVDAssertBreak: VDBREAK; break; case kVDAssertIgnore: active = false; } else ((void)0)
332 #define VDASSERTPTR(exp) if (static bool active = true) if (exp); else switch(VDAssertPtr(#exp, __FILE__, __LINE__)) { case kVDAssertBreak: VDBREAK; break; case kVDAssertIgnore: active = false; } else ((void)0)
333 #define VDVERIFY(exp) if (exp); else if (static bool active = true) switch(VDAssert (#exp, __FILE__, __LINE__)) { case kVDAssertBreak: VDBREAK; break; case kVDAssertIgnore: active = false; } else ((void)0)
334 #define VDVERIFYPTR(exp) if (exp); else if (static bool active = true) switch(VDAssertPtr(#exp, __FILE__, __LINE__)) { case kVDAssertBreak: VDBREAK; break; case kVDAssertIgnore: active = false; } else ((void)0)
336 // MPC-HC custom code end
337 #define VDASSERTCT(exp) (void)sizeof(int[(exp)?1:-1])
339 #define VDINLINEASSERT(exp) ((exp)||(VDAssertHelper<__LINE__>(#exp, __FILE__),false))
340 #define VDINLINEASSERTFALSE(exp) ((exp)&&(VDAssertHelper<__LINE__>("!("#exp")", __FILE__),true))
342 #define NEVER_HERE do { if (VDAssert( "[never here]", __FILE__, __LINE__ )) VDBREAK; __assume(false); } while(false)
343 #define VDNEVERHERE do { if (VDAssert( "[never here]", __FILE__, __LINE__ )) VDBREAK; __assume(false); } while(false)
345 #define VDDEBUG VDDebugPrint
349 #if defined(_MSC_VER)
351 #define VDASSERT(exp) __assume(!!(exp))
352 #define VDASSERTPTR(exp) __assume(!!(exp))
354 #define VDASSERT(exp) __noop(exp)
355 #define VDASSERTPTR(exp) __noop(exp)
357 #elif defined(__GNUC__)
358 #define VDASSERT(exp) __builtin_expect(0 != (exp), 1)
359 #define VDASSERTPTR(exp) __builtin_expect(0 != (exp), 1)
362 #define VDVERIFY(exp) (exp)
363 #define VDVERIFYPTR(exp) (exp)
364 #define VDASSERTCT(exp)
366 #define VDINLINEASSERT(exp) (exp)
367 #define VDINLINEASSERTFALSE(exp) (exp)
369 #if defined(VD_COMPILER_MSVC)
370 #define NEVER_HERE __assume(false)
371 #define VDNEVERHERE __assume(false)
373 #define NEVER_HERE VDASSERT(false)
374 #define VDNEVERHERE VDASSERT(false)
377 extern int VDDEBUG_Helper(const char *, ...);
378 #define VDDEBUG (void)sizeof VDDEBUG_Helper
382 #define VDDEBUG2 VDDebugPrint
386 // These produce a diagnostic during compilation that indicate a TODO for
389 // #pragma message(__TODO__ "Fix this.)
390 // #vdpragma_TODO("Fix this.")
392 #define vdpragma_TODO2(x) #x
393 #define vdpragma_TODO1(x) vdpragma_TODO2(x)
394 #define vdpragma_TODO0 __FILE__ "(" vdpragma_TODO1(__LINE__) ") : TODO: "
397 #define vdpragma_TODO(x) message(vdpragma_TODO0 x)
399 #define vdpragma_TODO(x)
404 // These tag code that is not meant to go into a final build.
406 #define vdpragma_BS2(x) #x
407 #define vdpragma_BS1(x) vdpragma_BS2(x)
408 #define vdpragma_BS0 __FILE__ "(" vdpragma_BS1(__LINE__) ") : BS: "
411 #define vdpragma_BS(x) message(vdpragma_BS0 x)
413 #define vdpragma_BS(x)
416 ///////////////////////////////////////////////////////////////////////////
418 // Object scope macros
420 // vdobjectscope() allows you to define a construct where an object is
421 // constructed and live only within the controlled statement. This is
422 // used for vdsynchronized (thread.h) and protected scopes below.
423 // It relies on a strange quirk of C++ regarding initialized objects
424 // in the condition of a selection statement and also horribly abuses
425 // the switch statement, generating rather good code in release builds.
426 // The catch is that the controlled object must implement a conversion to
427 // bool returning false and must only be initialized with one argument (C
430 // Unfortunately, handy as this macro is, it is also damned good at
431 // breaking compilers. For a start, declaring an object with a non-
432 // trivial destructor in a switch() kills both VC6 and VC7 with a C1001.
433 // The bug is fixed in VC8 (MSC 14.00).
435 // A somewhat safer alternative is the for() statement, along the lines
438 // switch(bool v=false) case 0: default: for(object_def; !v; v=true)
440 // This avoids the conversion operator but unfortunately usually generates
441 // an actual loop in the output.
443 #if defined(VD_COMPILER_MSVC) && (VD_COMPILER_MSVC < 1400 || defined(VD_COMPILER_MSVC_VC8_DDK))
444 #define vdobjectscope(object_def) if(object_def) VDNEVERHERE; else
446 #define vdobjectscope(object_def) switch(object_def) case 0: default: