diff options
Diffstat (limited to 'third_party/cld/base')
-rw-r--r-- | third_party/cld/base/basictypes.h | 348 | ||||
-rw-r--r-- | third_party/cld/base/build_config.h | 112 | ||||
-rw-r--r-- | third_party/cld/base/casts.h | 2 | ||||
-rw-r--r-- | third_party/cld/base/commandlineflags.h | 4 | ||||
-rw-r--r-- | third_party/cld/base/log_severity.h | 2 | ||||
-rw-r--r-- | third_party/cld/base/logging.h | 18 | ||||
-rw-r--r-- | third_party/cld/base/macros.h | 31 | ||||
-rw-r--r-- | third_party/cld/base/port.h | 54 | ||||
-rw-r--r-- | third_party/cld/base/string_util.h | 23 | ||||
-rw-r--r-- | third_party/cld/base/type_traits.h | 2 | ||||
-rw-r--r-- | third_party/cld/base/vlog_is_on.h | 8 |
11 files changed, 567 insertions, 37 deletions
diff --git a/third_party/cld/base/basictypes.h b/third_party/cld/base/basictypes.h new file mode 100644 index 0000000..617b669 --- /dev/null +++ b/third_party/cld/base/basictypes.h @@ -0,0 +1,348 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_BASICTYPES_H_ +#define BASE_BASICTYPES_H_ + +#include <limits.h> // So we can set the bounds of our types +#include <stddef.h> // For size_t +#include <string.h> // for memcpy + +#include "base/port.h" // Types that only need exist on certain systems + +#ifndef COMPILER_MSVC +// stdint.h is part of C99 but MSVC doesn't have it. +#include <stdint.h> // For intptr_t. +#endif + +typedef signed char schar; +typedef signed char int8; +typedef short int16; +// TODO(mbelshe) Remove these type guards. These are +// temporary to avoid conflicts with npapi.h. +#ifndef _INT32 +#define _INT32 +typedef int int32; +#endif + +// The NSPR system headers define 64-bit as |long| when possible. In order to +// not have typedef mismatches, we do the same on LP64. +#if __LP64__ +typedef long int64; +#else +typedef long long int64; +#endif + +// NOTE: unsigned types are DANGEROUS in loops and other arithmetical +// places. Use the signed types unless your variable represents a bit +// pattern (eg a hash value) or you really need the extra bit. Do NOT +// use 'unsigned' to express "this value should always be positive"; +// use assertions for this. + +typedef unsigned char uint8; +typedef unsigned short uint16; +// TODO(mbelshe) Remove these type guards. These are +// temporary to avoid conflicts with npapi.h. +#ifndef _UINT32 +#define _UINT32 +typedef unsigned int uint32; +#endif + +// See the comment above about NSPR and 64-bit. +#if __LP64__ +typedef unsigned long uint64; +#else +typedef unsigned long long uint64; +#endif + +// A type to represent a Unicode code-point value. As of Unicode 4.0, +// such values require up to 21 bits. +// (For type-checking on pointers, make this explicitly signed, +// and it should always be the signed version of whatever int32 is.) +typedef signed int char32; + +const uint8 kuint8max = (( uint8) 0xFF); +const uint16 kuint16max = ((uint16) 0xFFFF); +const uint32 kuint32max = ((uint32) 0xFFFFFFFF); +const uint64 kuint64max = ((uint64) GG_LONGLONG(0xFFFFFFFFFFFFFFFF)); +const int8 kint8min = (( int8) 0x80); +const int8 kint8max = (( int8) 0x7F); +const int16 kint16min = (( int16) 0x8000); +const int16 kint16max = (( int16) 0x7FFF); +const int32 kint32min = (( int32) 0x80000000); +const int32 kint32max = (( int32) 0x7FFFFFFF); +const int64 kint64min = (( int64) GG_LONGLONG(0x8000000000000000)); +const int64 kint64max = (( int64) GG_LONGLONG(0x7FFFFFFFFFFFFFFF)); + +// A macro to disallow the copy constructor and operator= functions +// This should be used in the private: declarations for a class +#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ + TypeName(const TypeName&); \ + void operator=(const TypeName&) + +// An older, deprecated, politically incorrect name for the above. +#define DISALLOW_EVIL_CONSTRUCTORS(TypeName) DISALLOW_COPY_AND_ASSIGN(TypeName) + +// A macro to disallow all the implicit constructors, namely the +// default constructor, copy constructor and operator= functions. +// +// This should be used in the private: declarations for a class +// that wants to prevent anyone from instantiating it. This is +// especially useful for classes containing only static methods. +#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ + TypeName(); \ + DISALLOW_COPY_AND_ASSIGN(TypeName) + +// The arraysize(arr) macro returns the # of elements in an array arr. +// The expression is a compile-time constant, and therefore can be +// used in defining new arrays, for example. If you use arraysize on +// a pointer by mistake, you will get a compile-time error. +// +// One caveat is that arraysize() doesn't accept any array of an +// anonymous type or a type defined inside a function. In these rare +// cases, you have to use the unsafe ARRAYSIZE_UNSAFE() macro below. This is +// due to a limitation in C++'s template system. The limitation might +// eventually be removed, but it hasn't happened yet. + +// This template function declaration is used in defining arraysize. +// Note that the function doesn't need an implementation, as we only +// use its type. +template <typename T, size_t N> +char (&ArraySizeHelper(T (&array)[N]))[N]; + +// That gcc wants both of these prototypes seems mysterious. VC, for +// its part, can't decide which to use (another mystery). Matching of +// template overloads: the final frontier. +#ifndef _MSC_VER +template <typename T, size_t N> +char (&ArraySizeHelper(const T (&array)[N]))[N]; +#endif + +#define arraysize(array) (sizeof(ArraySizeHelper(array))) + +// ARRAYSIZE_UNSAFE performs essentially the same calculation as arraysize, +// but can be used on anonymous types or types defined inside +// functions. It's less safe than arraysize as it accepts some +// (although not all) pointers. Therefore, you should use arraysize +// whenever possible. +// +// The expression ARRAYSIZE_UNSAFE(a) is a compile-time constant of type +// size_t. +// +// ARRAYSIZE_UNSAFE catches a few type errors. If you see a compiler error +// +// "warning: division by zero in ..." +// +// when using ARRAYSIZE_UNSAFE, you are (wrongfully) giving it a pointer. +// You should only use ARRAYSIZE_UNSAFE on statically allocated arrays. +// +// The following comments are on the implementation details, and can +// be ignored by the users. +// +// ARRAYSIZE_UNSAFE(arr) works by inspecting sizeof(arr) (the # of bytes in +// the array) and sizeof(*(arr)) (the # of bytes in one array +// element). If the former is divisible by the latter, perhaps arr is +// indeed an array, in which case the division result is the # of +// elements in the array. Otherwise, arr cannot possibly be an array, +// and we generate a compiler error to prevent the code from +// compiling. +// +// Since the size of bool is implementation-defined, we need to cast +// !(sizeof(a) & sizeof(*(a))) to size_t in order to ensure the final +// result has type size_t. +// +// This macro is not perfect as it wrongfully accepts certain +// pointers, namely where the pointer size is divisible by the pointee +// size. Since all our code has to go through a 32-bit compiler, +// where a pointer is 4 bytes, this means all pointers to a type whose +// size is 3 or greater than 4 will be (righteously) rejected. + +#define ARRAYSIZE_UNSAFE(a) \ + ((sizeof(a) / sizeof(*(a))) / \ + static_cast<size_t>(!(sizeof(a) % sizeof(*(a))))) + + +// Use implicit_cast as a safe version of static_cast or const_cast +// for upcasting in the type hierarchy (i.e. casting a pointer to Foo +// to a pointer to SuperclassOfFoo or casting a pointer to Foo to +// a const pointer to Foo). +// When you use implicit_cast, the compiler checks that the cast is safe. +// Such explicit implicit_casts are necessary in surprisingly many +// situations where C++ demands an exact type match instead of an +// argument type convertable to a target type. +// +// The From type can be inferred, so the preferred syntax for using +// implicit_cast is the same as for static_cast etc.: +// +// implicit_cast<ToType>(expr) +// +// implicit_cast would have been part of the C++ standard library, +// but the proposal was submitted too late. It will probably make +// its way into the language in the future. +template<typename To, typename From> +inline To implicit_cast(From const &f) { + return f; +} + +// The COMPILE_ASSERT macro can be used to verify that a compile time +// expression is true. For example, you could use it to verify the +// size of a static array: +// +// COMPILE_ASSERT(ARRAYSIZE_UNSAFE(content_type_names) == CONTENT_NUM_TYPES, +// content_type_names_incorrect_size); +// +// or to make sure a struct is smaller than a certain size: +// +// COMPILE_ASSERT(sizeof(foo) < 128, foo_too_large); +// +// The second argument to the macro is the name of the variable. If +// the expression is false, most compilers will issue a warning/error +// containing the name of the variable. + +template <bool> +struct CompileAssert { +}; + +#undef COMPILE_ASSERT +#define COMPILE_ASSERT(expr, msg) \ + typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] + +// Implementation details of COMPILE_ASSERT: +// +// - COMPILE_ASSERT works by defining an array type that has -1 +// elements (and thus is invalid) when the expression is false. +// +// - The simpler definition +// +// #define COMPILE_ASSERT(expr, msg) typedef char msg[(expr) ? 1 : -1] +// +// does not work, as gcc supports variable-length arrays whose sizes +// are determined at run-time (this is gcc's extension and not part +// of the C++ standard). As a result, gcc fails to reject the +// following code with the simple definition: +// +// int foo; +// COMPILE_ASSERT(foo, msg); // not supposed to compile as foo is +// // not a compile-time constant. +// +// - By using the type CompileAssert<(bool(expr))>, we ensures that +// expr is a compile-time constant. (Template arguments must be +// determined at compile-time.) +// +// - The outter parentheses in CompileAssert<(bool(expr))> are necessary +// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written +// +// CompileAssert<bool(expr)> +// +// instead, these compilers will refuse to compile +// +// COMPILE_ASSERT(5 > 0, some_message); +// +// (They seem to think the ">" in "5 > 0" marks the end of the +// template argument list.) +// +// - The array size is (bool(expr) ? 1 : -1), instead of simply +// +// ((expr) ? 1 : -1). +// +// This is to avoid running into a bug in MS VC 7.1, which +// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1. + + +// MetatagId refers to metatag-id that we assign to +// each metatag <name, value> pair.. +typedef uint32 MetatagId; + +// Argument type used in interfaces that can optionally take ownership +// of a passed in argument. If TAKE_OWNERSHIP is passed, the called +// object takes ownership of the argument. Otherwise it does not. +enum Ownership { + DO_NOT_TAKE_OWNERSHIP, + TAKE_OWNERSHIP +}; + +// bit_cast<Dest,Source> is a template function that implements the +// equivalent of "*reinterpret_cast<Dest*>(&source)". We need this in +// very low-level functions like the protobuf library and fast math +// support. +// +// float f = 3.14159265358979; +// int i = bit_cast<int32>(f); +// // i = 0x40490fdb +// +// The classical address-casting method is: +// +// // WRONG +// float f = 3.14159265358979; // WRONG +// int i = * reinterpret_cast<int*>(&f); // WRONG +// +// The address-casting method actually produces undefined behavior +// according to ISO C++ specification section 3.10 -15 -. Roughly, this +// section says: if an object in memory has one type, and a program +// accesses it with a different type, then the result is undefined +// behavior for most values of "different type". +// +// This is true for any cast syntax, either *(int*)&f or +// *reinterpret_cast<int*>(&f). And it is particularly true for +// conversions betweeen integral lvalues and floating-point lvalues. +// +// The purpose of 3.10 -15- is to allow optimizing compilers to assume +// that expressions with different types refer to different memory. gcc +// 4.0.1 has an optimizer that takes advantage of this. So a +// non-conforming program quietly produces wildly incorrect output. +// +// The problem is not the use of reinterpret_cast. The problem is type +// punning: holding an object in memory of one type and reading its bits +// back using a different type. +// +// The C++ standard is more subtle and complex than this, but that +// is the basic idea. +// +// Anyways ... +// +// bit_cast<> calls memcpy() which is blessed by the standard, +// especially by the example in section 3.9 . Also, of course, +// bit_cast<> wraps up the nasty logic in one place. +// +// Fortunately memcpy() is very fast. In optimized mode, with a +// constant size, gcc 2.95.3, gcc 4.0.1, and msvc 7.1 produce inline +// code with the minimal amount of data movement. On a 32-bit system, +// memcpy(d,s,4) compiles to one load and one store, and memcpy(d,s,8) +// compiles to two loads and two stores. +// +// I tested this code with gcc 2.95.3, gcc 4.0.1, icc 8.1, and msvc 7.1. +// +// WARNING: if Dest or Source is a non-POD type, the result of the memcpy +// is likely to surprise you. + +template <class Dest, class Source> +inline Dest bit_cast(const Source& source) { + // Compile time assertion: sizeof(Dest) == sizeof(Source) + // A compile error here means your Dest and Source have different sizes. + typedef char VerifySizesAreEqual [sizeof(Dest) == sizeof(Source) ? 1 : -1]; + + Dest dest; + memcpy(&dest, &source, sizeof(dest)); + return dest; +} + +// The following enum should be used only as a constructor argument to indicate +// that the variable has static storage class, and that the constructor should +// do nothing to its state. It indicates to the reader that it is legal to +// declare a static instance of the class, provided the constructor is given +// the base::LINKER_INITIALIZED argument. Normally, it is unsafe to declare a +// static variable that has a constructor or a destructor because invocation +// order is undefined. However, IF the type can be initialized by filling with +// zeroes (which the loader does for static variables), AND the destructor also +// does nothing to the storage, AND there are no virtual methods, then a +// constructor declared as +// explicit MyClass(base::LinkerInitialized x) {} +// and invoked as +// static MyClass my_variable_name(base::LINKER_INITIALIZED); +namespace base { +enum LinkerInitialized { LINKER_INITIALIZED }; +} // base + + +#endif // BASE_BASICTYPES_H_ diff --git a/third_party/cld/base/build_config.h b/third_party/cld/base/build_config.h new file mode 100644 index 0000000..da7a37f --- /dev/null +++ b/third_party/cld/base/build_config.h @@ -0,0 +1,112 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file adds defines about the platform we're currently building on. +// Operating System: +// OS_WIN / OS_MACOSX / OS_LINUX / OS_POSIX (MACOSX or LINUX) +// Compiler: +// COMPILER_MSVC / COMPILER_GCC +// Processor: +// ARCH_CPU_X86 / ARCH_CPU_X86_64 / ARCH_CPU_X86_FAMILY (X86 or X86_64) +// ARCH_CPU_32_BITS / ARCH_CPU_64_BITS + +#ifndef BUILD_BUILD_CONFIG_H_ +#define BUILD_BUILD_CONFIG_H_ + +// A set of macros to use for platform detection. +#if defined(__APPLE__) +#define OS_MACOSX 1 +#elif defined(__linux__) +#define OS_LINUX 1 +// Use TOOLKIT_GTK on linux if TOOLKIT_VIEWS isn't defined. +#if !defined(TOOLKIT_VIEWS) +#define TOOLKIT_GTK +#endif +#elif defined(_WIN32) +#define OS_WIN 1 +#define TOOLKIT_VIEWS 1 +#elif defined(__FreeBSD__) +#define OS_FREEBSD 1 +#define TOOLKIT_GTK +#elif defined(__OpenBSD__) +#define OS_OPENBSD 1 +#define TOOLKIT_GTK +#else +#error Please add support for your platform in build/build_config.h +#endif + +// A flag derived from the above flags, used to cover GTK code in +// both TOOLKIT_GTK and TOOLKIT_VIEWS. +#if defined(TOOLKIT_GTK) || (defined(TOOLKIT_VIEWS) && !defined(OS_WIN)) +#define TOOLKIT_USES_GTK 1 +#endif + +#if defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_OPENBSD) +#define USE_NSS 1 // Use NSS for crypto. +#define USE_X11 1 // Use X for graphics. +#endif + +// For access to standard POSIXish features, use OS_POSIX instead of a +// more specific macro. +#if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_OPENBSD) +#define OS_POSIX 1 +// Use base::DataPack for name/value pairs. +#define USE_BASE_DATA_PACK 1 +#endif + +// Use tcmalloc +#if defined(OS_WIN) && ! defined(NO_TCMALLOC) +#define USE_TCMALLOC 1 +#endif + +// Compiler detection. +#if defined(__GNUC__) +#define COMPILER_GCC 1 +#elif defined(_MSC_VER) +#define COMPILER_MSVC 1 +#else +#error Please add support for your compiler in build/build_config.h +#endif + +// Processor architecture detection. For more info on what's defined, see: +// http://msdn.microsoft.com/en-us/library/b0084kay.aspx +// http://www.agner.org/optimize/calling_conventions.pdf +// or with gcc, run: "echo | gcc -E -dM -" +#if defined(_M_X64) || defined(__x86_64__) +#define ARCH_CPU_X86_FAMILY 1 +#define ARCH_CPU_X86_64 1 +#define ARCH_CPU_64_BITS 1 +#elif defined(_M_IX86) || defined(__i386__) +#define ARCH_CPU_X86_FAMILY 1 +#define ARCH_CPU_X86 1 +#define ARCH_CPU_32_BITS 1 +#elif defined(__ARMEL__) +#define ARCH_CPU_ARM_FAMILY 1 +#define ARCH_CPU_ARMEL 1 +#define ARCH_CPU_32_BITS 1 +#define WCHAR_T_IS_UNSIGNED 1 +#else +#error Please add support for your architecture in build/build_config.h +#endif + +// Type detection for wchar_t. +#if defined(OS_WIN) +#define WCHAR_T_IS_UTF16 +#elif defined(OS_POSIX) && defined(COMPILER_GCC) && \ + defined(__WCHAR_MAX__) && \ + (__WCHAR_MAX__ == 0x7fffffff || __WCHAR_MAX__ == 0xffffffff) +#define WCHAR_T_IS_UTF32 +#elif defined(OS_POSIX) && defined(COMPILER_GCC) && \ + defined(__WCHAR_MAX__) && \ + (__WCHAR_MAX__ == 0x7fff || __WCHAR_MAX__ == 0xffff) +// On Posix, we'll detect short wchar_t, but projects aren't guaranteed to +// compile in this mode (in particular, Chrome doesn't). This is intended for +// other projects using base who manage their own dependencies and make sure +// short wchar works for them. +#define WCHAR_T_IS_UTF16 +#else +#error Please add support for your compiler in build/build_config.h +#endif + +#endif // BUILD_BUILD_CONFIG_H_ diff --git a/third_party/cld/base/casts.h b/third_party/cld/base/casts.h index 1ceb061..68f39d6 100644 --- a/third_party/cld/base/casts.h +++ b/third_party/cld/base/casts.h @@ -8,7 +8,7 @@ #include <assert.h> // for use with down_cast<> #include <string.h> // for memcpy -#include "third_party/cld/base/macros.h" +#include "base/macros.h" // Use implicit_cast as a safe version of static_cast or const_cast diff --git a/third_party/cld/base/commandlineflags.h b/third_party/cld/base/commandlineflags.h index 90598a7..a492f0b 100644 --- a/third_party/cld/base/commandlineflags.h +++ b/third_party/cld/base/commandlineflags.h @@ -27,8 +27,8 @@ #include <vector> #include "base/basictypes.h" #include "base/port.h" -#include "third_party/cld/base/stl_decl_msvc.h" -#include "third_party/cld/base/global_strip_options.h" +#include "base/stl_decl_msvc.h" +#include "base/global_strip_options.h" // -------------------------------------------------------------------- // To actually define a flag in a file, use DEFINE_bool, diff --git a/third_party/cld/base/log_severity.h b/third_party/cld/base/log_severity.h index 05e6f18..ecb01d9 100644 --- a/third_party/cld/base/log_severity.h +++ b/third_party/cld/base/log_severity.h @@ -6,7 +6,7 @@ #define BASE_LOG_SEVERITY_H_ #include "base/port.h" -#include "third_party/cld/base/commandlineflags.h" +#include "base/commandlineflags.h" // Variables of type LogSeverity are widely taken to lie in the range // [0, NUM_SEVERITIES-1]. Be careful to preserve this assumption if diff --git a/third_party/cld/base/logging.h b/third_party/cld/base/logging.h index 52c0eb4..d03e1dc 100644 --- a/third_party/cld/base/logging.h +++ b/third_party/cld/base/logging.h @@ -18,15 +18,15 @@ #include "base/port.h" #include "base/basictypes.h" -#include "third_party/cld/base/commandlineflags.h" -#include "third_party/cld/base/crash.h" -#include "third_party/cld/base/dynamic_annotations.h" -#include "third_party/cld/base/macros.h" -#include "third_party/cld/base/scoped_ptr.h" -#include "third_party/cld/base/stl_decl_msvc.h" -#include "third_party/cld/base/log_severity.h" -#include "third_party/cld/base/vlog_is_on.h" -#include "third_party/cld/base/global_strip_options.h" +#include "base/commandlineflags.h" +#include "base/crash.h" +#include "base/dynamic_annotations.h" +#include "base/macros.h" +#include "base/scoped_ptr.h" +#include "base/stl_decl_msvc.h" +#include "base/log_severity.h" +#include "base/vlog_is_on.h" +#include "global_strip_options.h" // Make a bunch of macros for logging. The way to log things is to stream // things to LOG(<a particular severity level>). E.g., diff --git a/third_party/cld/base/macros.h b/third_party/cld/base/macros.h index 7d0730d..0aab0c4 100644 --- a/third_party/cld/base/macros.h +++ b/third_party/cld/base/macros.h @@ -1,7 +1,7 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. - +// // Various Google-specific macros. // // This code is compiled directly on many platforms, including client @@ -14,10 +14,7 @@ #include <stddef.h> // For size_t -// We use our own local version of type traits while we're waiting -// for TR1 type traits to be standardized. Define some macros so that -// most google3 code doesn't have to work with type traits directly. -#include "third_party/cld/base/type_traits.h" +#include "base/type_traits.h" // The COMPILE_ASSERT macro can be used to verify that a compile time @@ -34,14 +31,10 @@ // The second argument to the macro is the name of the variable. If // the expression is false, most compilers will issue a warning/error // containing the name of the variable. -/* -template <bool> -struct CompileAssert { -}; #define COMPILE_ASSERT(expr, msg) \ typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] -*/ + // Implementation details of COMPILE_ASSERT: // // - COMPILE_ASSERT works by defining an array type that has -1 @@ -86,6 +79,13 @@ struct CompileAssert { // A macro to disallow the copy constructor and operator= functions // This should be used in the private: declarations for a class +// +// For disallowing only assign or copy, write the code directly, but declare +// the intend in a comment, for example: +// void operator=(const TypeName&); // DISALLOW_ASSIGN +// Note, that most uses of DISALLOW_ASSIGN and DISALLOW_COPY are broken +// semantically, one should either use disallow both or neither. Try to +// avoid these in new code. #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ TypeName(const TypeName&); \ void operator=(const TypeName&) @@ -173,14 +173,12 @@ char (&ArraySizeHelper(const T (&array)[N]))[N]; // - wan 2005-11-16 // // Starting with Visual C++ 2005, WinNT.h includes ARRAYSIZE. - #if !defined(COMPILER_MSVC) || (defined(_MSC_VER) && _MSC_VER < 1400) #define ARRAYSIZE(a) \ ((sizeof(a) / sizeof(*(a))) / \ static_cast<size_t>(!(sizeof(a) % sizeof(*(a))))) #endif - // A macro to turn a symbol into a string #define AS_STRING(x) AS_STRING_INTERNAL(x) #define AS_STRING_INTERNAL(x) #x @@ -196,13 +194,6 @@ char (&ArraySizeHelper(const T (&array)[N]))[N]; // Implementation note: the typedef at the end is just to make it legal // to put a semicolon after DECLARE_POD(foo). // -// The only reason this matters is that a few parts of the google3 -// code base either require their template arguments to be PODs -// (e.g. compact_vector) or are able to use a more efficient code path -// when their template arguments are PODs (e.g. sparse_hash_map). You -// should use DECLARE_POD if you have written a class that you intend -// to use with one of those components, and if you know that your -// class satisfies all of the conditions to be a POD type. // // So what's a POD? The C++ standard (clause 9 paragraph 4) gives a // full definition, but a good rule of thumb is that a struct is a POD diff --git a/third_party/cld/base/port.h b/third_party/cld/base/port.h new file mode 100644 index 0000000..3f363ed --- /dev/null +++ b/third_party/cld/base/port.h @@ -0,0 +1,54 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_PORT_H_ +#define BASE_PORT_H_ + +#include <stdarg.h> +#include "base/build_config.h" + +#ifdef COMPILER_MSVC +#define GG_LONGLONG(x) x##I64 +#define GG_ULONGLONG(x) x##UI64 +#else +#define GG_LONGLONG(x) x##LL +#define GG_ULONGLONG(x) x##ULL +#endif + +// Per C99 7.8.14, define __STDC_CONSTANT_MACROS before including <stdint.h> +// to get the INTn_C and UINTn_C macros for integer constants. It's difficult +// to guarantee any specific ordering of header includes, so it's difficult to +// guarantee that the INTn_C macros can be defined by including <stdint.h> at +// any specific point. Provide GG_INTn_C macros instead. + +#define GG_INT8_C(x) (x) +#define GG_INT16_C(x) (x) +#define GG_INT32_C(x) (x) +#define GG_INT64_C(x) GG_LONGLONG(x) + +#define GG_UINT8_C(x) (x ## U) +#define GG_UINT16_C(x) (x ## U) +#define GG_UINT32_C(x) (x ## U) +#define GG_UINT64_C(x) GG_ULONGLONG(x) + +// It's possible for functions that use a va_list, such as StringPrintf, to +// invalidate the data in it upon use. The fix is to make a copy of the +// structure before using it and use that copy instead. va_copy is provided +// for this purpose. MSVC does not provide va_copy, so define an +// implementation here. It is not guaranteed that assignment is a copy, so the +// StringUtil.VariableArgsFunc unit test tests this capability. +#if defined(COMPILER_GCC) +#define GG_VA_COPY(a, b) (va_copy(a, b)) +#elif defined(COMPILER_MSVC) +#define GG_VA_COPY(a, b) (a = b) +#endif + +// Define an OS-neutral wrapper for shared library entry points +#if defined(OS_WIN) +#define API_CALL __stdcall +#else +#define API_CALL +#endif + +#endif // BASE_PORT_H_ diff --git a/third_party/cld/base/string_util.h b/third_party/cld/base/string_util.h new file mode 100644 index 0000000..365d1bf --- /dev/null +++ b/third_party/cld/base/string_util.h @@ -0,0 +1,23 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// This file defines utility functions for working with strings.
+
+#ifndef BASE_STRING_UTIL_H_
+#define BASE_STRING_UTIL_H_
+
+#include <string.h>
+
+namespace base {
+
+// Compare the two strings s1 and s2 without regard to case using
+// the current locale; returns 0 if they are equal, 1 if s1 > s2, and -1 if
+// s2 > s1 according to a lexicographic comparison.
+inline int strcasecmp(const char* s1, const char* s2) {
+ return _stricmp(s1, s2);
+}
+
+}
+
+#endif // BASE_STRING_UTIL_H_
diff --git a/third_party/cld/base/type_traits.h b/third_party/cld/base/type_traits.h index f423140..154f304 100644 --- a/third_party/cld/base/type_traits.h +++ b/third_party/cld/base/type_traits.h @@ -28,7 +28,7 @@ #ifndef BASE_TYPE_TRAITS_H_ #define BASE_TYPE_TRAITS_H_ -#include "third_party/cld/base/template_util.h" // For true_type and false_type +#include "base/template_util.h" // For true_type and false_type #include <utility> // For pair namespace base { diff --git a/third_party/cld/base/vlog_is_on.h b/third_party/cld/base/vlog_is_on.h index 57c11ff..5b8273d 100644 --- a/third_party/cld/base/vlog_is_on.h +++ b/third_party/cld/base/vlog_is_on.h @@ -40,8 +40,8 @@ #include "base/atomicops.h" #include "base/basictypes.h" #include "base/port.h" -#include "third_party/cld/base/commandlineflags.h" -#include "third_party/cld/base/log_severity.h" +#include "base/commandlineflags.h" +#include "base/log_severity.h" DECLARE_int32(v); // in vlog_is_on.cc DECLARE_bool(silent_init); // in google.cc @@ -101,7 +101,9 @@ const Atomic32 kDefaultSite = kUseFlag << 16; // The global epoch is the least significant half of an Atomic32, and // may only be accessed through atomic operations. -inline Atomic32 GlobalEpoch() { return Acquire_Load(&vlog_epoch) & 0x0000FFFF; } +inline Atomic32 GlobalEpoch() { + return Acquire_Load(&vlog_epoch) & 0x0000FFFF; +} // The least significant half of a site is the epoch. inline int SiteEpoch(Atomic32 site) { return site & 0x0000FFFF; } |