toolkit/crashreporter/google-breakpad/src/common/mac/GTMDefines.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/google-breakpad/src/common/mac/GTMDefines.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,444 @@
     1.4 +//
     1.5 +// GTMDefines.h
     1.6 +//
     1.7 +//  Copyright 2008 Google Inc.
     1.8 +//
     1.9 +//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
    1.10 +//  use this file except in compliance with the License.  You may obtain a copy
    1.11 +//  of the License at
    1.12 +//
    1.13 +//  http://www.apache.org/licenses/LICENSE-2.0
    1.14 +//
    1.15 +//  Unless required by applicable law or agreed to in writing, software
    1.16 +//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    1.17 +//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
    1.18 +//  License for the specific language governing permissions and limitations under
    1.19 +//  the License.
    1.20 +//
    1.21 +
    1.22 +// ============================================================================
    1.23 +
    1.24 +#include <AvailabilityMacros.h>
    1.25 +#include <TargetConditionals.h>
    1.26 +
    1.27 +#ifdef __OBJC__
    1.28 +#include <Foundation/NSObjCRuntime.h>
    1.29 +#endif  // __OBJC__
    1.30 +
    1.31 +#if TARGET_OS_IPHONE
    1.32 +#include <Availability.h>
    1.33 +#endif  // TARGET_OS_IPHONE
    1.34 +
    1.35 +// Not all MAC_OS_X_VERSION_10_X macros defined in past SDKs
    1.36 +#ifndef MAC_OS_X_VERSION_10_5
    1.37 +  #define MAC_OS_X_VERSION_10_5 1050
    1.38 +#endif
    1.39 +#ifndef MAC_OS_X_VERSION_10_6
    1.40 +  #define MAC_OS_X_VERSION_10_6 1060
    1.41 +#endif
    1.42 +#ifndef MAC_OS_X_VERSION_10_7
    1.43 +  #define MAC_OS_X_VERSION_10_7 1070
    1.44 +#endif
    1.45 +
    1.46 +// Not all __IPHONE_X macros defined in past SDKs
    1.47 +#ifndef __IPHONE_3_0
    1.48 +  #define __IPHONE_3_0 30000
    1.49 +#endif
    1.50 +#ifndef __IPHONE_3_1
    1.51 +  #define __IPHONE_3_1 30100
    1.52 +#endif
    1.53 +#ifndef __IPHONE_3_2
    1.54 +  #define __IPHONE_3_2 30200
    1.55 +#endif
    1.56 +#ifndef __IPHONE_4_0
    1.57 +  #define __IPHONE_4_0 40000
    1.58 +#endif
    1.59 +#ifndef __IPHONE_4_3
    1.60 +  #define __IPHONE_4_3 40300
    1.61 +#endif
    1.62 +#ifndef __IPHONE_5_0
    1.63 +  #define __IPHONE_5_0 50000
    1.64 +#endif
    1.65 +
    1.66 +// ----------------------------------------------------------------------------
    1.67 +// CPP symbols that can be overridden in a prefix to control how the toolbox
    1.68 +// is compiled.
    1.69 +// ----------------------------------------------------------------------------
    1.70 +
    1.71 +
    1.72 +// By setting the GTM_CONTAINERS_VALIDATION_FAILED_LOG and
    1.73 +// GTM_CONTAINERS_VALIDATION_FAILED_ASSERT macros you can control what happens
    1.74 +// when a validation fails. If you implement your own validators, you may want
    1.75 +// to control their internals using the same macros for consistency.
    1.76 +#ifndef GTM_CONTAINERS_VALIDATION_FAILED_ASSERT
    1.77 +  #define GTM_CONTAINERS_VALIDATION_FAILED_ASSERT 0
    1.78 +#endif
    1.79 +
    1.80 +// Give ourselves a consistent way to do inlines.  Apple's macros even use
    1.81 +// a few different actual definitions, so we're based off of the foundation
    1.82 +// one.
    1.83 +#if !defined(GTM_INLINE)
    1.84 +  #if (defined (__GNUC__) && (__GNUC__ == 4)) || defined (__clang__)
    1.85 +    #define GTM_INLINE static __inline__ __attribute__((always_inline))
    1.86 +  #else
    1.87 +    #define GTM_INLINE static __inline__
    1.88 +  #endif
    1.89 +#endif
    1.90 +
    1.91 +// Give ourselves a consistent way of doing externs that links up nicely
    1.92 +// when mixing objc and objc++
    1.93 +#if !defined (GTM_EXTERN)
    1.94 +  #if defined __cplusplus
    1.95 +    #define GTM_EXTERN extern "C"
    1.96 +    #define GTM_EXTERN_C_BEGIN extern "C" {
    1.97 +    #define GTM_EXTERN_C_END }
    1.98 +  #else
    1.99 +    #define GTM_EXTERN extern
   1.100 +    #define GTM_EXTERN_C_BEGIN
   1.101 +    #define GTM_EXTERN_C_END
   1.102 +  #endif
   1.103 +#endif
   1.104 +
   1.105 +// Give ourselves a consistent way of exporting things if we have visibility
   1.106 +// set to hidden.
   1.107 +#if !defined (GTM_EXPORT)
   1.108 +  #define GTM_EXPORT __attribute__((visibility("default")))
   1.109 +#endif
   1.110 +
   1.111 +// Give ourselves a consistent way of declaring something as unused. This
   1.112 +// doesn't use __unused because that is only supported in gcc 4.2 and greater.
   1.113 +#if !defined (GTM_UNUSED)
   1.114 +#define GTM_UNUSED(x) ((void)(x))
   1.115 +#endif
   1.116 +
   1.117 +// _GTMDevLog & _GTMDevAssert
   1.118 +//
   1.119 +// _GTMDevLog & _GTMDevAssert are meant to be a very lightweight shell for
   1.120 +// developer level errors.  This implementation simply macros to NSLog/NSAssert.
   1.121 +// It is not intended to be a general logging/reporting system.
   1.122 +//
   1.123 +// Please see http://code.google.com/p/google-toolbox-for-mac/wiki/DevLogNAssert
   1.124 +// for a little more background on the usage of these macros.
   1.125 +//
   1.126 +//    _GTMDevLog           log some error/problem in debug builds
   1.127 +//    _GTMDevAssert        assert if conditon isn't met w/in a method/function
   1.128 +//                           in all builds.
   1.129 +//
   1.130 +// To replace this system, just provide different macro definitions in your
   1.131 +// prefix header.  Remember, any implementation you provide *must* be thread
   1.132 +// safe since this could be called by anything in what ever situtation it has
   1.133 +// been placed in.
   1.134 +//
   1.135 +
   1.136 +// We only define the simple macros if nothing else has defined this.
   1.137 +#ifndef _GTMDevLog
   1.138 +
   1.139 +#ifdef DEBUG
   1.140 +  #define _GTMDevLog(...) NSLog(__VA_ARGS__)
   1.141 +#else
   1.142 +  #define _GTMDevLog(...) do { } while (0)
   1.143 +#endif
   1.144 +
   1.145 +#endif // _GTMDevLog
   1.146 +
   1.147 +#ifndef _GTMDevAssert
   1.148 +// we directly invoke the NSAssert handler so we can pass on the varargs
   1.149 +// (NSAssert doesn't have a macro we can use that takes varargs)
   1.150 +#if !defined(NS_BLOCK_ASSERTIONS)
   1.151 +  #define _GTMDevAssert(condition, ...)                                       \
   1.152 +    do {                                                                      \
   1.153 +      if (!(condition)) {                                                     \
   1.154 +        [[NSAssertionHandler currentHandler]                                  \
   1.155 +            handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] \
   1.156 +                               file:[NSString stringWithUTF8String:__FILE__]  \
   1.157 +                         lineNumber:__LINE__                                  \
   1.158 +                        description:__VA_ARGS__];                             \
   1.159 +      }                                                                       \
   1.160 +    } while(0)
   1.161 +#else // !defined(NS_BLOCK_ASSERTIONS)
   1.162 +  #define _GTMDevAssert(condition, ...) do { } while (0)
   1.163 +#endif // !defined(NS_BLOCK_ASSERTIONS)
   1.164 +
   1.165 +#endif // _GTMDevAssert
   1.166 +
   1.167 +// _GTMCompileAssert
   1.168 +// _GTMCompileAssert is an assert that is meant to fire at compile time if you
   1.169 +// want to check things at compile instead of runtime. For example if you
   1.170 +// want to check that a wchar is 4 bytes instead of 2 you would use
   1.171 +// _GTMCompileAssert(sizeof(wchar_t) == 4, wchar_t_is_4_bytes_on_OS_X)
   1.172 +// Note that the second "arg" is not in quotes, and must be a valid processor
   1.173 +// symbol in it's own right (no spaces, punctuation etc).
   1.174 +
   1.175 +// Wrapping this in an #ifndef allows external groups to define their own
   1.176 +// compile time assert scheme.
   1.177 +#ifndef _GTMCompileAssert
   1.178 +  // We got this technique from here:
   1.179 +  // http://unixjunkie.blogspot.com/2007/10/better-compile-time-asserts_29.html
   1.180 +
   1.181 +  #define _GTMCompileAssertSymbolInner(line, msg) _GTMCOMPILEASSERT ## line ## __ ## msg
   1.182 +  #define _GTMCompileAssertSymbol(line, msg) _GTMCompileAssertSymbolInner(line, msg)
   1.183 +  #define _GTMCompileAssert(test, msg) \
   1.184 +    typedef char _GTMCompileAssertSymbol(__LINE__, msg) [ ((test) ? 1 : -1) ]
   1.185 +#endif // _GTMCompileAssert
   1.186 +
   1.187 +// ----------------------------------------------------------------------------
   1.188 +// CPP symbols defined based on the project settings so the GTM code has
   1.189 +// simple things to test against w/o scattering the knowledge of project
   1.190 +// setting through all the code.
   1.191 +// ----------------------------------------------------------------------------
   1.192 +
   1.193 +// Provide a single constant CPP symbol that all of GTM uses for ifdefing
   1.194 +// iPhone code.
   1.195 +#if TARGET_OS_IPHONE // iPhone SDK
   1.196 +  // For iPhone specific stuff
   1.197 +  #define GTM_IPHONE_SDK 1
   1.198 +  #if TARGET_IPHONE_SIMULATOR
   1.199 +    #define GTM_IPHONE_SIMULATOR 1
   1.200 +  #else
   1.201 +    #define GTM_IPHONE_DEVICE 1
   1.202 +  #endif  // TARGET_IPHONE_SIMULATOR
   1.203 +  // By default, GTM has provided it's own unittesting support, define this
   1.204 +  // to use the support provided by Xcode, especially for the Xcode4 support
   1.205 +  // for unittesting.
   1.206 +  #ifndef GTM_IPHONE_USE_SENTEST
   1.207 +    #define GTM_IPHONE_USE_SENTEST 0
   1.208 +  #endif
   1.209 +#else
   1.210 +  // For MacOS specific stuff
   1.211 +  #define GTM_MACOS_SDK 1
   1.212 +#endif
   1.213 +
   1.214 +// Some of our own availability macros
   1.215 +#if GTM_MACOS_SDK
   1.216 +#define GTM_AVAILABLE_ONLY_ON_IPHONE UNAVAILABLE_ATTRIBUTE
   1.217 +#define GTM_AVAILABLE_ONLY_ON_MACOS
   1.218 +#else
   1.219 +#define GTM_AVAILABLE_ONLY_ON_IPHONE
   1.220 +#define GTM_AVAILABLE_ONLY_ON_MACOS UNAVAILABLE_ATTRIBUTE
   1.221 +#endif
   1.222 +
   1.223 +// Provide a symbol to include/exclude extra code for GC support.  (This mainly
   1.224 +// just controls the inclusion of finalize methods).
   1.225 +#ifndef GTM_SUPPORT_GC
   1.226 +  #if GTM_IPHONE_SDK
   1.227 +    // iPhone never needs GC
   1.228 +    #define GTM_SUPPORT_GC 0
   1.229 +  #else
   1.230 +    // We can't find a symbol to tell if GC is supported/required, so best we
   1.231 +    // do on Mac targets is include it if we're on 10.5 or later.
   1.232 +    #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
   1.233 +      #define GTM_SUPPORT_GC 0
   1.234 +    #else
   1.235 +      #define GTM_SUPPORT_GC 1
   1.236 +    #endif
   1.237 +  #endif
   1.238 +#endif
   1.239 +
   1.240 +// To simplify support for 64bit (and Leopard in general), we provide the type
   1.241 +// defines for non Leopard SDKs
   1.242 +#if !(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
   1.243 + // NSInteger/NSUInteger and Max/Mins
   1.244 +  #ifndef NSINTEGER_DEFINED
   1.245 +    #if __LP64__ || NS_BUILD_32_LIKE_64
   1.246 +      typedef long NSInteger;
   1.247 +      typedef unsigned long NSUInteger;
   1.248 +    #else
   1.249 +      typedef int NSInteger;
   1.250 +      typedef unsigned int NSUInteger;
   1.251 +    #endif
   1.252 +    #define NSIntegerMax    LONG_MAX
   1.253 +    #define NSIntegerMin    LONG_MIN
   1.254 +    #define NSUIntegerMax   ULONG_MAX
   1.255 +    #define NSINTEGER_DEFINED 1
   1.256 +  #endif  // NSINTEGER_DEFINED
   1.257 +  // CGFloat
   1.258 +  #ifndef CGFLOAT_DEFINED
   1.259 +    #if defined(__LP64__) && __LP64__
   1.260 +      // This really is an untested path (64bit on Tiger?)
   1.261 +      typedef double CGFloat;
   1.262 +      #define CGFLOAT_MIN DBL_MIN
   1.263 +      #define CGFLOAT_MAX DBL_MAX
   1.264 +      #define CGFLOAT_IS_DOUBLE 1
   1.265 +    #else /* !defined(__LP64__) || !__LP64__ */
   1.266 +      typedef float CGFloat;
   1.267 +      #define CGFLOAT_MIN FLT_MIN
   1.268 +      #define CGFLOAT_MAX FLT_MAX
   1.269 +      #define CGFLOAT_IS_DOUBLE 0
   1.270 +    #endif /* !defined(__LP64__) || !__LP64__ */
   1.271 +    #define CGFLOAT_DEFINED 1
   1.272 +  #endif // CGFLOAT_DEFINED
   1.273 +#endif  // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
   1.274 +
   1.275 +// Some support for advanced clang static analysis functionality
   1.276 +// See http://clang-analyzer.llvm.org/annotations.html
   1.277 +#ifndef __has_feature      // Optional.
   1.278 +  #define __has_feature(x) 0 // Compatibility with non-clang compilers.
   1.279 +#endif
   1.280 +
   1.281 +#ifndef NS_RETURNS_RETAINED
   1.282 +  #if __has_feature(attribute_ns_returns_retained)
   1.283 +    #define NS_RETURNS_RETAINED __attribute__((ns_returns_retained))
   1.284 +  #else
   1.285 +    #define NS_RETURNS_RETAINED
   1.286 +  #endif
   1.287 +#endif
   1.288 +
   1.289 +#ifndef NS_RETURNS_NOT_RETAINED
   1.290 +  #if __has_feature(attribute_ns_returns_not_retained)
   1.291 +    #define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained))
   1.292 +  #else
   1.293 +    #define NS_RETURNS_NOT_RETAINED
   1.294 +  #endif
   1.295 +#endif
   1.296 +
   1.297 +#ifndef CF_RETURNS_RETAINED
   1.298 +  #if __has_feature(attribute_cf_returns_retained)
   1.299 +    #define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
   1.300 +  #else
   1.301 +    #define CF_RETURNS_RETAINED
   1.302 +  #endif
   1.303 +#endif
   1.304 +
   1.305 +#ifndef CF_RETURNS_NOT_RETAINED
   1.306 +  #if __has_feature(attribute_cf_returns_not_retained)
   1.307 +    #define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained))
   1.308 +  #else
   1.309 +    #define CF_RETURNS_NOT_RETAINED
   1.310 +  #endif
   1.311 +#endif
   1.312 +
   1.313 +#ifndef NS_CONSUMED
   1.314 +  #if __has_feature(attribute_ns_consumed)
   1.315 +    #define NS_CONSUMED __attribute__((ns_consumed))
   1.316 +  #else
   1.317 +    #define NS_CONSUMED
   1.318 +  #endif
   1.319 +#endif
   1.320 +
   1.321 +#ifndef CF_CONSUMED
   1.322 +  #if __has_feature(attribute_cf_consumed)
   1.323 +    #define CF_CONSUMED __attribute__((cf_consumed))
   1.324 +  #else
   1.325 +    #define CF_CONSUMED
   1.326 +  #endif
   1.327 +#endif
   1.328 +
   1.329 +#ifndef NS_CONSUMES_SELF
   1.330 +  #if __has_feature(attribute_ns_consumes_self)
   1.331 +    #define NS_CONSUMES_SELF __attribute__((ns_consumes_self))
   1.332 +  #else
   1.333 +    #define NS_CONSUMES_SELF
   1.334 +  #endif
   1.335 +#endif
   1.336 +
   1.337 +// Defined on 10.6 and above.
   1.338 +#ifndef NS_FORMAT_ARGUMENT
   1.339 +  #define NS_FORMAT_ARGUMENT(A)
   1.340 +#endif
   1.341 +
   1.342 +// Defined on 10.6 and above.
   1.343 +#ifndef NS_FORMAT_FUNCTION
   1.344 +  #define NS_FORMAT_FUNCTION(F,A)
   1.345 +#endif
   1.346 +
   1.347 +// Defined on 10.6 and above.
   1.348 +#ifndef CF_FORMAT_ARGUMENT
   1.349 +  #define CF_FORMAT_ARGUMENT(A)
   1.350 +#endif
   1.351 +
   1.352 +// Defined on 10.6 and above.
   1.353 +#ifndef CF_FORMAT_FUNCTION
   1.354 +  #define CF_FORMAT_FUNCTION(F,A)
   1.355 +#endif
   1.356 +
   1.357 +#ifndef GTM_NONNULL
   1.358 +  #define GTM_NONNULL(x) __attribute__((nonnull(x)))
   1.359 +#endif
   1.360 +
   1.361 +// Invalidates the initializer from which it's called.
   1.362 +#ifndef GTMInvalidateInitializer
   1.363 +  #if __has_feature(objc_arc)
   1.364 +    #define GTMInvalidateInitializer() \
   1.365 +      do { \
   1.366 +        [self class]; /* Avoid warning of dead store to |self|. */ \
   1.367 +        _GTMDevAssert(NO, @"Invalid initializer."); \
   1.368 +        return nil; \
   1.369 +      } while (0)
   1.370 +  #else
   1.371 +    #define GTMInvalidateInitializer() \
   1.372 +      do { \
   1.373 +        [self release]; \
   1.374 +        _GTMDevAssert(NO, @"Invalid initializer."); \
   1.375 +        return nil; \
   1.376 +      } while (0)
   1.377 +  #endif
   1.378 +#endif
   1.379 +
   1.380 +#ifdef __OBJC__
   1.381 +
   1.382 +// Declared here so that it can easily be used for logging tracking if
   1.383 +// necessary. See GTMUnitTestDevLog.h for details.
   1.384 +@class NSString;
   1.385 +GTM_EXTERN void _GTMUnitTestDevLog(NSString *format, ...) NS_FORMAT_FUNCTION(1, 2);
   1.386 +
   1.387 +// Macro to allow you to create NSStrings out of other macros.
   1.388 +// #define FOO foo
   1.389 +// NSString *fooString = GTM_NSSTRINGIFY(FOO);
   1.390 +#if !defined (GTM_NSSTRINGIFY)
   1.391 +  #define GTM_NSSTRINGIFY_INNER(x) @#x
   1.392 +  #define GTM_NSSTRINGIFY(x) GTM_NSSTRINGIFY_INNER(x)
   1.393 +#endif
   1.394 +
   1.395 +// Macro to allow fast enumeration when building for 10.5 or later, and
   1.396 +// reliance on NSEnumerator for 10.4.  Remember, NSDictionary w/ FastEnumeration
   1.397 +// does keys, so pick the right thing, nothing is done on the FastEnumeration
   1.398 +// side to be sure you're getting what you wanted.
   1.399 +#ifndef GTM_FOREACH_OBJECT
   1.400 +  #if TARGET_OS_IPHONE || !(MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5)
   1.401 +    #define GTM_FOREACH_ENUMEREE(element, enumeration) \
   1.402 +      for (element in enumeration)
   1.403 +    #define GTM_FOREACH_OBJECT(element, collection) \
   1.404 +      for (element in collection)
   1.405 +    #define GTM_FOREACH_KEY(element, collection) \
   1.406 +      for (element in collection)
   1.407 +  #else
   1.408 +    #define GTM_FOREACH_ENUMEREE(element, enumeration) \
   1.409 +      for (NSEnumerator *_ ## element ## _enum = enumeration; \
   1.410 +           (element = [_ ## element ## _enum nextObject]) != nil; )
   1.411 +    #define GTM_FOREACH_OBJECT(element, collection) \
   1.412 +      GTM_FOREACH_ENUMEREE(element, [collection objectEnumerator])
   1.413 +    #define GTM_FOREACH_KEY(element, collection) \
   1.414 +      GTM_FOREACH_ENUMEREE(element, [collection keyEnumerator])
   1.415 +  #endif
   1.416 +#endif
   1.417 +
   1.418 +// ============================================================================
   1.419 +
   1.420 +// To simplify support for both Leopard and Snow Leopard we declare
   1.421 +// the Snow Leopard protocols that we need here.
   1.422 +#if !defined(GTM_10_6_PROTOCOLS_DEFINED) && !(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
   1.423 +#define GTM_10_6_PROTOCOLS_DEFINED 1
   1.424 +@protocol NSConnectionDelegate
   1.425 +@end
   1.426 +@protocol NSAnimationDelegate
   1.427 +@end
   1.428 +@protocol NSImageDelegate
   1.429 +@end
   1.430 +@protocol NSTabViewDelegate
   1.431 +@end
   1.432 +#endif  // !defined(GTM_10_6_PROTOCOLS_DEFINED) && !(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
   1.433 +
   1.434 +// GTM_SEL_STRING is for specifying selector (usually property) names to KVC
   1.435 +// or KVO methods.
   1.436 +// In debug it will generate warnings for undeclared selectors if
   1.437 +// -Wunknown-selector is turned on.
   1.438 +// In release it will have no runtime overhead.
   1.439 +#ifndef GTM_SEL_STRING
   1.440 +  #ifdef DEBUG
   1.441 +    #define GTM_SEL_STRING(selName) NSStringFromSelector(@selector(selName))
   1.442 +  #else
   1.443 +    #define GTM_SEL_STRING(selName) @#selName
   1.444 +  #endif  // DEBUG
   1.445 +#endif  // GTM_SEL_STRING
   1.446 +
   1.447 +#endif  // __OBJC__

mercurial