Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #ifndef BASE_PORT_H_ |
michael@0 | 6 | #define BASE_PORT_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include <stdarg.h> |
michael@0 | 9 | #include "build/build_config.h" |
michael@0 | 10 | |
michael@0 | 11 | #ifdef COMPILER_MSVC |
michael@0 | 12 | #define GG_LONGLONG(x) x##I64 |
michael@0 | 13 | #define GG_ULONGLONG(x) x##UI64 |
michael@0 | 14 | #else |
michael@0 | 15 | #define GG_LONGLONG(x) x##LL |
michael@0 | 16 | #define GG_ULONGLONG(x) x##ULL |
michael@0 | 17 | #endif |
michael@0 | 18 | |
michael@0 | 19 | // Per C99 7.8.14, define __STDC_CONSTANT_MACROS before including <stdint.h> |
michael@0 | 20 | // to get the INTn_C and UINTn_C macros for integer constants. It's difficult |
michael@0 | 21 | // to guarantee any specific ordering of header includes, so it's difficult to |
michael@0 | 22 | // guarantee that the INTn_C macros can be defined by including <stdint.h> at |
michael@0 | 23 | // any specific point. Provide GG_INTn_C macros instead. |
michael@0 | 24 | |
michael@0 | 25 | #define GG_INT8_C(x) (x) |
michael@0 | 26 | #define GG_INT16_C(x) (x) |
michael@0 | 27 | #define GG_INT32_C(x) (x) |
michael@0 | 28 | #define GG_INT64_C(x) GG_LONGLONG(x) |
michael@0 | 29 | |
michael@0 | 30 | #define GG_UINT8_C(x) (x ## U) |
michael@0 | 31 | #define GG_UINT16_C(x) (x ## U) |
michael@0 | 32 | #define GG_UINT32_C(x) (x ## U) |
michael@0 | 33 | #define GG_UINT64_C(x) GG_ULONGLONG(x) |
michael@0 | 34 | |
michael@0 | 35 | // It's possible for functions that use a va_list, such as StringPrintf, to |
michael@0 | 36 | // invalidate the data in it upon use. The fix is to make a copy of the |
michael@0 | 37 | // structure before using it and use that copy instead. va_copy is provided |
michael@0 | 38 | // for this purpose. MSVC does not provide va_copy, so define an |
michael@0 | 39 | // implementation here. It is not guaranteed that assignment is a copy, so the |
michael@0 | 40 | // StringUtil.VariableArgsFunc unit test tests this capability. |
michael@0 | 41 | #if defined(COMPILER_GCC) |
michael@0 | 42 | #define GG_VA_COPY(a, b) (va_copy(a, b)) |
michael@0 | 43 | #elif defined(COMPILER_MSVC) |
michael@0 | 44 | #define GG_VA_COPY(a, b) (a = b) |
michael@0 | 45 | #endif |
michael@0 | 46 | |
michael@0 | 47 | // Define an OS-neutral wrapper for shared library entry points |
michael@0 | 48 | #if defined(OS_WIN) |
michael@0 | 49 | #define API_CALL __stdcall |
michael@0 | 50 | #else |
michael@0 | 51 | #define API_CALL |
michael@0 | 52 | #endif |
michael@0 | 53 | |
michael@0 | 54 | #endif // BASE_PORT_H_ |