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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 //
michael@0 2 // GTMDefines.h
michael@0 3 //
michael@0 4 // Copyright 2008 Google Inc.
michael@0 5 //
michael@0 6 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
michael@0 7 // use this file except in compliance with the License. You may obtain a copy
michael@0 8 // of the License at
michael@0 9 //
michael@0 10 // http://www.apache.org/licenses/LICENSE-2.0
michael@0 11 //
michael@0 12 // Unless required by applicable law or agreed to in writing, software
michael@0 13 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
michael@0 14 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
michael@0 15 // License for the specific language governing permissions and limitations under
michael@0 16 // the License.
michael@0 17 //
michael@0 18
michael@0 19 // ============================================================================
michael@0 20
michael@0 21 #include <AvailabilityMacros.h>
michael@0 22 #include <TargetConditionals.h>
michael@0 23
michael@0 24 #ifdef __OBJC__
michael@0 25 #include <Foundation/NSObjCRuntime.h>
michael@0 26 #endif // __OBJC__
michael@0 27
michael@0 28 #if TARGET_OS_IPHONE
michael@0 29 #include <Availability.h>
michael@0 30 #endif // TARGET_OS_IPHONE
michael@0 31
michael@0 32 // Not all MAC_OS_X_VERSION_10_X macros defined in past SDKs
michael@0 33 #ifndef MAC_OS_X_VERSION_10_5
michael@0 34 #define MAC_OS_X_VERSION_10_5 1050
michael@0 35 #endif
michael@0 36 #ifndef MAC_OS_X_VERSION_10_6
michael@0 37 #define MAC_OS_X_VERSION_10_6 1060
michael@0 38 #endif
michael@0 39 #ifndef MAC_OS_X_VERSION_10_7
michael@0 40 #define MAC_OS_X_VERSION_10_7 1070
michael@0 41 #endif
michael@0 42
michael@0 43 // Not all __IPHONE_X macros defined in past SDKs
michael@0 44 #ifndef __IPHONE_3_0
michael@0 45 #define __IPHONE_3_0 30000
michael@0 46 #endif
michael@0 47 #ifndef __IPHONE_3_1
michael@0 48 #define __IPHONE_3_1 30100
michael@0 49 #endif
michael@0 50 #ifndef __IPHONE_3_2
michael@0 51 #define __IPHONE_3_2 30200
michael@0 52 #endif
michael@0 53 #ifndef __IPHONE_4_0
michael@0 54 #define __IPHONE_4_0 40000
michael@0 55 #endif
michael@0 56 #ifndef __IPHONE_4_3
michael@0 57 #define __IPHONE_4_3 40300
michael@0 58 #endif
michael@0 59 #ifndef __IPHONE_5_0
michael@0 60 #define __IPHONE_5_0 50000
michael@0 61 #endif
michael@0 62
michael@0 63 // ----------------------------------------------------------------------------
michael@0 64 // CPP symbols that can be overridden in a prefix to control how the toolbox
michael@0 65 // is compiled.
michael@0 66 // ----------------------------------------------------------------------------
michael@0 67
michael@0 68
michael@0 69 // By setting the GTM_CONTAINERS_VALIDATION_FAILED_LOG and
michael@0 70 // GTM_CONTAINERS_VALIDATION_FAILED_ASSERT macros you can control what happens
michael@0 71 // when a validation fails. If you implement your own validators, you may want
michael@0 72 // to control their internals using the same macros for consistency.
michael@0 73 #ifndef GTM_CONTAINERS_VALIDATION_FAILED_ASSERT
michael@0 74 #define GTM_CONTAINERS_VALIDATION_FAILED_ASSERT 0
michael@0 75 #endif
michael@0 76
michael@0 77 // Give ourselves a consistent way to do inlines. Apple's macros even use
michael@0 78 // a few different actual definitions, so we're based off of the foundation
michael@0 79 // one.
michael@0 80 #if !defined(GTM_INLINE)
michael@0 81 #if (defined (__GNUC__) && (__GNUC__ == 4)) || defined (__clang__)
michael@0 82 #define GTM_INLINE static __inline__ __attribute__((always_inline))
michael@0 83 #else
michael@0 84 #define GTM_INLINE static __inline__
michael@0 85 #endif
michael@0 86 #endif
michael@0 87
michael@0 88 // Give ourselves a consistent way of doing externs that links up nicely
michael@0 89 // when mixing objc and objc++
michael@0 90 #if !defined (GTM_EXTERN)
michael@0 91 #if defined __cplusplus
michael@0 92 #define GTM_EXTERN extern "C"
michael@0 93 #define GTM_EXTERN_C_BEGIN extern "C" {
michael@0 94 #define GTM_EXTERN_C_END }
michael@0 95 #else
michael@0 96 #define GTM_EXTERN extern
michael@0 97 #define GTM_EXTERN_C_BEGIN
michael@0 98 #define GTM_EXTERN_C_END
michael@0 99 #endif
michael@0 100 #endif
michael@0 101
michael@0 102 // Give ourselves a consistent way of exporting things if we have visibility
michael@0 103 // set to hidden.
michael@0 104 #if !defined (GTM_EXPORT)
michael@0 105 #define GTM_EXPORT __attribute__((visibility("default")))
michael@0 106 #endif
michael@0 107
michael@0 108 // Give ourselves a consistent way of declaring something as unused. This
michael@0 109 // doesn't use __unused because that is only supported in gcc 4.2 and greater.
michael@0 110 #if !defined (GTM_UNUSED)
michael@0 111 #define GTM_UNUSED(x) ((void)(x))
michael@0 112 #endif
michael@0 113
michael@0 114 // _GTMDevLog & _GTMDevAssert
michael@0 115 //
michael@0 116 // _GTMDevLog & _GTMDevAssert are meant to be a very lightweight shell for
michael@0 117 // developer level errors. This implementation simply macros to NSLog/NSAssert.
michael@0 118 // It is not intended to be a general logging/reporting system.
michael@0 119 //
michael@0 120 // Please see http://code.google.com/p/google-toolbox-for-mac/wiki/DevLogNAssert
michael@0 121 // for a little more background on the usage of these macros.
michael@0 122 //
michael@0 123 // _GTMDevLog log some error/problem in debug builds
michael@0 124 // _GTMDevAssert assert if conditon isn't met w/in a method/function
michael@0 125 // in all builds.
michael@0 126 //
michael@0 127 // To replace this system, just provide different macro definitions in your
michael@0 128 // prefix header. Remember, any implementation you provide *must* be thread
michael@0 129 // safe since this could be called by anything in what ever situtation it has
michael@0 130 // been placed in.
michael@0 131 //
michael@0 132
michael@0 133 // We only define the simple macros if nothing else has defined this.
michael@0 134 #ifndef _GTMDevLog
michael@0 135
michael@0 136 #ifdef DEBUG
michael@0 137 #define _GTMDevLog(...) NSLog(__VA_ARGS__)
michael@0 138 #else
michael@0 139 #define _GTMDevLog(...) do { } while (0)
michael@0 140 #endif
michael@0 141
michael@0 142 #endif // _GTMDevLog
michael@0 143
michael@0 144 #ifndef _GTMDevAssert
michael@0 145 // we directly invoke the NSAssert handler so we can pass on the varargs
michael@0 146 // (NSAssert doesn't have a macro we can use that takes varargs)
michael@0 147 #if !defined(NS_BLOCK_ASSERTIONS)
michael@0 148 #define _GTMDevAssert(condition, ...) \
michael@0 149 do { \
michael@0 150 if (!(condition)) { \
michael@0 151 [[NSAssertionHandler currentHandler] \
michael@0 152 handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] \
michael@0 153 file:[NSString stringWithUTF8String:__FILE__] \
michael@0 154 lineNumber:__LINE__ \
michael@0 155 description:__VA_ARGS__]; \
michael@0 156 } \
michael@0 157 } while(0)
michael@0 158 #else // !defined(NS_BLOCK_ASSERTIONS)
michael@0 159 #define _GTMDevAssert(condition, ...) do { } while (0)
michael@0 160 #endif // !defined(NS_BLOCK_ASSERTIONS)
michael@0 161
michael@0 162 #endif // _GTMDevAssert
michael@0 163
michael@0 164 // _GTMCompileAssert
michael@0 165 // _GTMCompileAssert is an assert that is meant to fire at compile time if you
michael@0 166 // want to check things at compile instead of runtime. For example if you
michael@0 167 // want to check that a wchar is 4 bytes instead of 2 you would use
michael@0 168 // _GTMCompileAssert(sizeof(wchar_t) == 4, wchar_t_is_4_bytes_on_OS_X)
michael@0 169 // Note that the second "arg" is not in quotes, and must be a valid processor
michael@0 170 // symbol in it's own right (no spaces, punctuation etc).
michael@0 171
michael@0 172 // Wrapping this in an #ifndef allows external groups to define their own
michael@0 173 // compile time assert scheme.
michael@0 174 #ifndef _GTMCompileAssert
michael@0 175 // We got this technique from here:
michael@0 176 // http://unixjunkie.blogspot.com/2007/10/better-compile-time-asserts_29.html
michael@0 177
michael@0 178 #define _GTMCompileAssertSymbolInner(line, msg) _GTMCOMPILEASSERT ## line ## __ ## msg
michael@0 179 #define _GTMCompileAssertSymbol(line, msg) _GTMCompileAssertSymbolInner(line, msg)
michael@0 180 #define _GTMCompileAssert(test, msg) \
michael@0 181 typedef char _GTMCompileAssertSymbol(__LINE__, msg) [ ((test) ? 1 : -1) ]
michael@0 182 #endif // _GTMCompileAssert
michael@0 183
michael@0 184 // ----------------------------------------------------------------------------
michael@0 185 // CPP symbols defined based on the project settings so the GTM code has
michael@0 186 // simple things to test against w/o scattering the knowledge of project
michael@0 187 // setting through all the code.
michael@0 188 // ----------------------------------------------------------------------------
michael@0 189
michael@0 190 // Provide a single constant CPP symbol that all of GTM uses for ifdefing
michael@0 191 // iPhone code.
michael@0 192 #if TARGET_OS_IPHONE // iPhone SDK
michael@0 193 // For iPhone specific stuff
michael@0 194 #define GTM_IPHONE_SDK 1
michael@0 195 #if TARGET_IPHONE_SIMULATOR
michael@0 196 #define GTM_IPHONE_SIMULATOR 1
michael@0 197 #else
michael@0 198 #define GTM_IPHONE_DEVICE 1
michael@0 199 #endif // TARGET_IPHONE_SIMULATOR
michael@0 200 // By default, GTM has provided it's own unittesting support, define this
michael@0 201 // to use the support provided by Xcode, especially for the Xcode4 support
michael@0 202 // for unittesting.
michael@0 203 #ifndef GTM_IPHONE_USE_SENTEST
michael@0 204 #define GTM_IPHONE_USE_SENTEST 0
michael@0 205 #endif
michael@0 206 #else
michael@0 207 // For MacOS specific stuff
michael@0 208 #define GTM_MACOS_SDK 1
michael@0 209 #endif
michael@0 210
michael@0 211 // Some of our own availability macros
michael@0 212 #if GTM_MACOS_SDK
michael@0 213 #define GTM_AVAILABLE_ONLY_ON_IPHONE UNAVAILABLE_ATTRIBUTE
michael@0 214 #define GTM_AVAILABLE_ONLY_ON_MACOS
michael@0 215 #else
michael@0 216 #define GTM_AVAILABLE_ONLY_ON_IPHONE
michael@0 217 #define GTM_AVAILABLE_ONLY_ON_MACOS UNAVAILABLE_ATTRIBUTE
michael@0 218 #endif
michael@0 219
michael@0 220 // Provide a symbol to include/exclude extra code for GC support. (This mainly
michael@0 221 // just controls the inclusion of finalize methods).
michael@0 222 #ifndef GTM_SUPPORT_GC
michael@0 223 #if GTM_IPHONE_SDK
michael@0 224 // iPhone never needs GC
michael@0 225 #define GTM_SUPPORT_GC 0
michael@0 226 #else
michael@0 227 // We can't find a symbol to tell if GC is supported/required, so best we
michael@0 228 // do on Mac targets is include it if we're on 10.5 or later.
michael@0 229 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
michael@0 230 #define GTM_SUPPORT_GC 0
michael@0 231 #else
michael@0 232 #define GTM_SUPPORT_GC 1
michael@0 233 #endif
michael@0 234 #endif
michael@0 235 #endif
michael@0 236
michael@0 237 // To simplify support for 64bit (and Leopard in general), we provide the type
michael@0 238 // defines for non Leopard SDKs
michael@0 239 #if !(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
michael@0 240 // NSInteger/NSUInteger and Max/Mins
michael@0 241 #ifndef NSINTEGER_DEFINED
michael@0 242 #if __LP64__ || NS_BUILD_32_LIKE_64
michael@0 243 typedef long NSInteger;
michael@0 244 typedef unsigned long NSUInteger;
michael@0 245 #else
michael@0 246 typedef int NSInteger;
michael@0 247 typedef unsigned int NSUInteger;
michael@0 248 #endif
michael@0 249 #define NSIntegerMax LONG_MAX
michael@0 250 #define NSIntegerMin LONG_MIN
michael@0 251 #define NSUIntegerMax ULONG_MAX
michael@0 252 #define NSINTEGER_DEFINED 1
michael@0 253 #endif // NSINTEGER_DEFINED
michael@0 254 // CGFloat
michael@0 255 #ifndef CGFLOAT_DEFINED
michael@0 256 #if defined(__LP64__) && __LP64__
michael@0 257 // This really is an untested path (64bit on Tiger?)
michael@0 258 typedef double CGFloat;
michael@0 259 #define CGFLOAT_MIN DBL_MIN
michael@0 260 #define CGFLOAT_MAX DBL_MAX
michael@0 261 #define CGFLOAT_IS_DOUBLE 1
michael@0 262 #else /* !defined(__LP64__) || !__LP64__ */
michael@0 263 typedef float CGFloat;
michael@0 264 #define CGFLOAT_MIN FLT_MIN
michael@0 265 #define CGFLOAT_MAX FLT_MAX
michael@0 266 #define CGFLOAT_IS_DOUBLE 0
michael@0 267 #endif /* !defined(__LP64__) || !__LP64__ */
michael@0 268 #define CGFLOAT_DEFINED 1
michael@0 269 #endif // CGFLOAT_DEFINED
michael@0 270 #endif // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
michael@0 271
michael@0 272 // Some support for advanced clang static analysis functionality
michael@0 273 // See http://clang-analyzer.llvm.org/annotations.html
michael@0 274 #ifndef __has_feature // Optional.
michael@0 275 #define __has_feature(x) 0 // Compatibility with non-clang compilers.
michael@0 276 #endif
michael@0 277
michael@0 278 #ifndef NS_RETURNS_RETAINED
michael@0 279 #if __has_feature(attribute_ns_returns_retained)
michael@0 280 #define NS_RETURNS_RETAINED __attribute__((ns_returns_retained))
michael@0 281 #else
michael@0 282 #define NS_RETURNS_RETAINED
michael@0 283 #endif
michael@0 284 #endif
michael@0 285
michael@0 286 #ifndef NS_RETURNS_NOT_RETAINED
michael@0 287 #if __has_feature(attribute_ns_returns_not_retained)
michael@0 288 #define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained))
michael@0 289 #else
michael@0 290 #define NS_RETURNS_NOT_RETAINED
michael@0 291 #endif
michael@0 292 #endif
michael@0 293
michael@0 294 #ifndef CF_RETURNS_RETAINED
michael@0 295 #if __has_feature(attribute_cf_returns_retained)
michael@0 296 #define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
michael@0 297 #else
michael@0 298 #define CF_RETURNS_RETAINED
michael@0 299 #endif
michael@0 300 #endif
michael@0 301
michael@0 302 #ifndef CF_RETURNS_NOT_RETAINED
michael@0 303 #if __has_feature(attribute_cf_returns_not_retained)
michael@0 304 #define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained))
michael@0 305 #else
michael@0 306 #define CF_RETURNS_NOT_RETAINED
michael@0 307 #endif
michael@0 308 #endif
michael@0 309
michael@0 310 #ifndef NS_CONSUMED
michael@0 311 #if __has_feature(attribute_ns_consumed)
michael@0 312 #define NS_CONSUMED __attribute__((ns_consumed))
michael@0 313 #else
michael@0 314 #define NS_CONSUMED
michael@0 315 #endif
michael@0 316 #endif
michael@0 317
michael@0 318 #ifndef CF_CONSUMED
michael@0 319 #if __has_feature(attribute_cf_consumed)
michael@0 320 #define CF_CONSUMED __attribute__((cf_consumed))
michael@0 321 #else
michael@0 322 #define CF_CONSUMED
michael@0 323 #endif
michael@0 324 #endif
michael@0 325
michael@0 326 #ifndef NS_CONSUMES_SELF
michael@0 327 #if __has_feature(attribute_ns_consumes_self)
michael@0 328 #define NS_CONSUMES_SELF __attribute__((ns_consumes_self))
michael@0 329 #else
michael@0 330 #define NS_CONSUMES_SELF
michael@0 331 #endif
michael@0 332 #endif
michael@0 333
michael@0 334 // Defined on 10.6 and above.
michael@0 335 #ifndef NS_FORMAT_ARGUMENT
michael@0 336 #define NS_FORMAT_ARGUMENT(A)
michael@0 337 #endif
michael@0 338
michael@0 339 // Defined on 10.6 and above.
michael@0 340 #ifndef NS_FORMAT_FUNCTION
michael@0 341 #define NS_FORMAT_FUNCTION(F,A)
michael@0 342 #endif
michael@0 343
michael@0 344 // Defined on 10.6 and above.
michael@0 345 #ifndef CF_FORMAT_ARGUMENT
michael@0 346 #define CF_FORMAT_ARGUMENT(A)
michael@0 347 #endif
michael@0 348
michael@0 349 // Defined on 10.6 and above.
michael@0 350 #ifndef CF_FORMAT_FUNCTION
michael@0 351 #define CF_FORMAT_FUNCTION(F,A)
michael@0 352 #endif
michael@0 353
michael@0 354 #ifndef GTM_NONNULL
michael@0 355 #define GTM_NONNULL(x) __attribute__((nonnull(x)))
michael@0 356 #endif
michael@0 357
michael@0 358 // Invalidates the initializer from which it's called.
michael@0 359 #ifndef GTMInvalidateInitializer
michael@0 360 #if __has_feature(objc_arc)
michael@0 361 #define GTMInvalidateInitializer() \
michael@0 362 do { \
michael@0 363 [self class]; /* Avoid warning of dead store to |self|. */ \
michael@0 364 _GTMDevAssert(NO, @"Invalid initializer."); \
michael@0 365 return nil; \
michael@0 366 } while (0)
michael@0 367 #else
michael@0 368 #define GTMInvalidateInitializer() \
michael@0 369 do { \
michael@0 370 [self release]; \
michael@0 371 _GTMDevAssert(NO, @"Invalid initializer."); \
michael@0 372 return nil; \
michael@0 373 } while (0)
michael@0 374 #endif
michael@0 375 #endif
michael@0 376
michael@0 377 #ifdef __OBJC__
michael@0 378
michael@0 379 // Declared here so that it can easily be used for logging tracking if
michael@0 380 // necessary. See GTMUnitTestDevLog.h for details.
michael@0 381 @class NSString;
michael@0 382 GTM_EXTERN void _GTMUnitTestDevLog(NSString *format, ...) NS_FORMAT_FUNCTION(1, 2);
michael@0 383
michael@0 384 // Macro to allow you to create NSStrings out of other macros.
michael@0 385 // #define FOO foo
michael@0 386 // NSString *fooString = GTM_NSSTRINGIFY(FOO);
michael@0 387 #if !defined (GTM_NSSTRINGIFY)
michael@0 388 #define GTM_NSSTRINGIFY_INNER(x) @#x
michael@0 389 #define GTM_NSSTRINGIFY(x) GTM_NSSTRINGIFY_INNER(x)
michael@0 390 #endif
michael@0 391
michael@0 392 // Macro to allow fast enumeration when building for 10.5 or later, and
michael@0 393 // reliance on NSEnumerator for 10.4. Remember, NSDictionary w/ FastEnumeration
michael@0 394 // does keys, so pick the right thing, nothing is done on the FastEnumeration
michael@0 395 // side to be sure you're getting what you wanted.
michael@0 396 #ifndef GTM_FOREACH_OBJECT
michael@0 397 #if TARGET_OS_IPHONE || !(MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5)
michael@0 398 #define GTM_FOREACH_ENUMEREE(element, enumeration) \
michael@0 399 for (element in enumeration)
michael@0 400 #define GTM_FOREACH_OBJECT(element, collection) \
michael@0 401 for (element in collection)
michael@0 402 #define GTM_FOREACH_KEY(element, collection) \
michael@0 403 for (element in collection)
michael@0 404 #else
michael@0 405 #define GTM_FOREACH_ENUMEREE(element, enumeration) \
michael@0 406 for (NSEnumerator *_ ## element ## _enum = enumeration; \
michael@0 407 (element = [_ ## element ## _enum nextObject]) != nil; )
michael@0 408 #define GTM_FOREACH_OBJECT(element, collection) \
michael@0 409 GTM_FOREACH_ENUMEREE(element, [collection objectEnumerator])
michael@0 410 #define GTM_FOREACH_KEY(element, collection) \
michael@0 411 GTM_FOREACH_ENUMEREE(element, [collection keyEnumerator])
michael@0 412 #endif
michael@0 413 #endif
michael@0 414
michael@0 415 // ============================================================================
michael@0 416
michael@0 417 // To simplify support for both Leopard and Snow Leopard we declare
michael@0 418 // the Snow Leopard protocols that we need here.
michael@0 419 #if !defined(GTM_10_6_PROTOCOLS_DEFINED) && !(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
michael@0 420 #define GTM_10_6_PROTOCOLS_DEFINED 1
michael@0 421 @protocol NSConnectionDelegate
michael@0 422 @end
michael@0 423 @protocol NSAnimationDelegate
michael@0 424 @end
michael@0 425 @protocol NSImageDelegate
michael@0 426 @end
michael@0 427 @protocol NSTabViewDelegate
michael@0 428 @end
michael@0 429 #endif // !defined(GTM_10_6_PROTOCOLS_DEFINED) && !(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
michael@0 430
michael@0 431 // GTM_SEL_STRING is for specifying selector (usually property) names to KVC
michael@0 432 // or KVO methods.
michael@0 433 // In debug it will generate warnings for undeclared selectors if
michael@0 434 // -Wunknown-selector is turned on.
michael@0 435 // In release it will have no runtime overhead.
michael@0 436 #ifndef GTM_SEL_STRING
michael@0 437 #ifdef DEBUG
michael@0 438 #define GTM_SEL_STRING(selName) NSStringFromSelector(@selector(selName))
michael@0 439 #else
michael@0 440 #define GTM_SEL_STRING(selName) @#selName
michael@0 441 #endif // DEBUG
michael@0 442 #endif // GTM_SEL_STRING
michael@0 443
michael@0 444 #endif // __OBJC__

mercurial