1/* 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11#ifndef WEBRTC_BASE_BASICTYPES_H_ 12#define WEBRTC_BASE_BASICTYPES_H_ 13 14#include <stddef.h> // for NULL, size_t 15 16#if !(defined(_MSC_VER) && (_MSC_VER < 1600)) 17#include <stdint.h> // for uintptr_t 18#endif 19 20#ifdef HAVE_CONFIG_H 21#include "config.h" // NOLINT 22#endif 23 24#include "webrtc/base/constructormagic.h" 25 26#if !defined(INT_TYPES_DEFINED) 27#define INT_TYPES_DEFINED 28#ifdef COMPILER_MSVC 29typedef unsigned __int64 uint64; 30typedef __int64 int64; 31#ifndef INT64_C 32#define INT64_C(x) x ## I64 33#endif 34#ifndef UINT64_C 35#define UINT64_C(x) x ## UI64 36#endif 37#define INT64_F "I64" 38#else // COMPILER_MSVC 39// On Mac OS X, cssmconfig.h defines uint64 as uint64_t 40// TODO(fbarchard): Use long long for compatibility with chromium on BSD/OSX. 41#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) 42typedef uint64_t uint64; 43typedef int64_t int64; 44#ifndef INT64_C 45#define INT64_C(x) x ## LL 46#endif 47#ifndef UINT64_C 48#define UINT64_C(x) x ## ULL 49#endif 50#define INT64_F "l" 51#elif defined(__LP64__) 52typedef unsigned long uint64; // NOLINT 53typedef long int64; // NOLINT 54#ifndef INT64_C 55#define INT64_C(x) x ## L 56#endif 57#ifndef UINT64_C 58#define UINT64_C(x) x ## UL 59#endif 60#define INT64_F "l" 61#else // __LP64__ 62typedef unsigned long long uint64; // NOLINT 63typedef long long int64; // NOLINT 64#ifndef INT64_C 65#define INT64_C(x) x ## LL 66#endif 67#ifndef UINT64_C 68#define UINT64_C(x) x ## ULL 69#endif 70#define INT64_F "ll" 71#endif // __LP64__ 72#endif // COMPILER_MSVC 73typedef unsigned int uint32; 74typedef int int32; 75typedef unsigned short uint16; // NOLINT 76typedef short int16; // NOLINT 77typedef unsigned char uint8; 78typedef signed char int8; 79#endif // INT_TYPES_DEFINED 80 81// Detect compiler is for x86 or x64. 82#if defined(__x86_64__) || defined(_M_X64) || \ 83 defined(__i386__) || defined(_M_IX86) 84#define CPU_X86 1 85#endif 86// Detect compiler is for arm. 87#if defined(__arm__) || defined(_M_ARM) 88#define CPU_ARM 1 89#endif 90#if defined(CPU_X86) && defined(CPU_ARM) 91#error CPU_X86 and CPU_ARM both defined. 92#endif 93#if !defined(ARCH_CPU_BIG_ENDIAN) && !defined(ARCH_CPU_LITTLE_ENDIAN) 94// x86, arm or GCC provided __BYTE_ORDER__ macros 95#if CPU_X86 || CPU_ARM || \ 96 (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) 97#define ARCH_CPU_LITTLE_ENDIAN 98#elif defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 99#define ARCH_CPU_BIG_ENDIAN 100#else 101#error ARCH_CPU_BIG_ENDIAN or ARCH_CPU_LITTLE_ENDIAN should be defined. 102#endif 103#endif 104#if defined(ARCH_CPU_BIG_ENDIAN) && defined(ARCH_CPU_LITTLE_ENDIAN) 105#error ARCH_CPU_BIG_ENDIAN and ARCH_CPU_LITTLE_ENDIAN both defined. 106#endif 107 108#if defined(WEBRTC_WIN) 109typedef int socklen_t; 110#endif 111 112// The following only works for C++ 113#ifdef __cplusplus 114namespace rtc { 115 template<class T> inline T _min(T a, T b) { return (a > b) ? b : a; } 116 template<class T> inline T _max(T a, T b) { return (a < b) ? b : a; } 117 118 // For wait functions that take a number of milliseconds, kForever indicates 119 // unlimited time. 120 const int kForever = -1; 121} 122 123#define ALIGNP(p, t) \ 124 (reinterpret_cast<uint8*>(((reinterpret_cast<uintptr_t>(p) + \ 125 ((t) - 1)) & ~((t) - 1)))) 126#define RTC_IS_ALIGNED(p, a) (!((uintptr_t)(p) & ((a) - 1))) 127 128// Use these to declare and define a static local variable (static T;) so that 129// it is leaked so that its destructors are not called at exit. 130#define LIBJINGLE_DEFINE_STATIC_LOCAL(type, name, arguments) \ 131 static type& name = *new type arguments 132 133#endif // __cplusplus 134#endif // WEBRTC_BASE_BASICTYPES_H_ 135