toolkit/crashreporter/google-breakpad/src/common/mac/GTMGarbageCollection.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/GTMGarbageCollection.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,72 @@
     1.4 +//
     1.5 +//  GTMGarbageCollection.h
     1.6 +//
     1.7 +//  Copyright 2007-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 +#import <Foundation/Foundation.h>
    1.23 +
    1.24 +#import "GTMDefines.h"
    1.25 +
    1.26 +// This allows us to easily move our code from GC to non GC.
    1.27 +// They are no-ops unless we are require Leopard or above.
    1.28 +// See 
    1.29 +// http://developer.apple.com/documentation/Cocoa/Conceptual/GarbageCollection/index.html
    1.30 +// and
    1.31 +// http://developer.apple.com/documentation/Cocoa/Conceptual/GarbageCollection/Articles/gcCoreFoundation.html#//apple_ref/doc/uid/TP40006687-SW1
    1.32 +// for details.
    1.33 +
    1.34 +#if (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) && !GTM_IPHONE_SDK
    1.35 +// General use would be to call this through GTMCFAutorelease
    1.36 +// but there may be a reason the you want to make something collectable
    1.37 +// but not autoreleased, especially in pure GC code where you don't
    1.38 +// want to bother with the nop autorelease. Done as a define instead of an 
    1.39 +// inline so that tools like Clang's scan-build don't report code as leaking.
    1.40 +#define GTMNSMakeCollectable(cf) ((id)NSMakeCollectable(cf))
    1.41 +
    1.42 +// GTMNSMakeUncollectable is for global maps, etc. that we don't
    1.43 +// want released ever. You should still retain these in non-gc code.
    1.44 +GTM_INLINE void GTMNSMakeUncollectable(id object) {
    1.45 +  [[NSGarbageCollector defaultCollector] disableCollectorForPointer:object];
    1.46 +}
    1.47 +
    1.48 +// Hopefully no code really needs this, but GTMIsGarbageCollectionEnabled is
    1.49 +// a common way to check at runtime if GC is on.
    1.50 +// There are some places where GC doesn't work w/ things w/in Apple's
    1.51 +// frameworks, so this is here so GTM unittests and detect it, and not run
    1.52 +// individual tests to work around bugs in Apple's frameworks.
    1.53 +GTM_INLINE BOOL GTMIsGarbageCollectionEnabled(void) {
    1.54 +  return ([NSGarbageCollector defaultCollector] != nil);
    1.55 +}
    1.56 +
    1.57 +#else
    1.58 +
    1.59 +#define GTMNSMakeCollectable(cf) ((id)(cf))
    1.60 +
    1.61 +GTM_INLINE void GTMNSMakeUncollectable(id object) {
    1.62 +}
    1.63 +
    1.64 +GTM_INLINE BOOL GTMIsGarbageCollectionEnabled(void) {
    1.65 +  return NO;
    1.66 +}
    1.67 +
    1.68 +#endif
    1.69 +
    1.70 +// GTMCFAutorelease makes a CF object collectable in GC mode, or adds it 
    1.71 +// to the autorelease pool in non-GC mode. Either way it is taken care
    1.72 +// of. Done as a define instead of an inline so that tools like Clang's
    1.73 +// scan-build don't report code as leaking.
    1.74 +#define GTMCFAutorelease(cf) ([GTMNSMakeCollectable(cf) autorelease])
    1.75 +

mercurial