]>
git.saurik.com Git - apple/libdispatch.git/blob - os/object.h
   2  * Copyright (c) 2011-2014 Apple Inc. All rights reserved. 
   4  * @APPLE_APACHE_LICENSE_HEADER_START@ 
   6  * Licensed under the Apache License, Version 2.0 (the "License"); 
   7  * you may not use this file except in compliance with the License. 
   8  * You may obtain a copy of the License at 
  10  *     http://www.apache.org/licenses/LICENSE-2.0 
  12  * Unless required by applicable law or agreed to in writing, software 
  13  * distributed under the License is distributed on an "AS IS" BASIS, 
  14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  15  * See the License for the specific language governing permissions and 
  16  * limitations under the License. 
  18  * @APPLE_APACHE_LICENSE_HEADER_END@ 
  25 #include <Availability.h> 
  33  * By default, libSystem objects such as GCD and XPC objects are declared as 
  34  * Objective-C types when building with an Objective-C compiler. This allows 
  35  * them to participate in ARC, in RR management by the Blocks runtime and in 
  36  * leaks checking by the static analyzer, and enables them to be added to Cocoa 
  39  * NOTE: this requires explicit cancellation of dispatch sources and xpc 
  40  *       connections whose handler blocks capture the source/connection object, 
  41  *       resp. ensuring that such captures do not form retain cycles (e.g. by 
  42  *       declaring the source as __weak). 
  44  * To opt-out of this default behavior, add -DOS_OBJECT_USE_OBJC=0 to your 
  47  * This mode requires a platform with the modern Objective-C runtime, the 
  48  * Objective-C GC compiler option to be disabled, and at least a Mac OS X 10.8 
  49  * or iOS 6.0 deployment target. 
  52 #ifndef OS_OBJECT_HAVE_OBJC_SUPPORT 
  53 #if defined(__OBJC__) && defined(__OBJC2__) && !defined(__OBJC_GC__) && ( \ 
  54                 __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_8 || \ 
  55                 __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_6_0) 
  56 #define OS_OBJECT_HAVE_OBJC_SUPPORT 1 
  58 #define OS_OBJECT_HAVE_OBJC_SUPPORT 0 
  62 #if OS_OBJECT_HAVE_OBJC_SUPPORT 
  63 #ifndef OS_OBJECT_USE_OBJC 
  64 #define OS_OBJECT_USE_OBJC 1 
  66 #elif defined(OS_OBJECT_USE_OBJC) && OS_OBJECT_USE_OBJC 
  67 /* Unsupported platform for OS_OBJECT_USE_OBJC=1 */ 
  68 #undef OS_OBJECT_USE_OBJC 
  69 #define OS_OBJECT_USE_OBJC 0 
  71 #define OS_OBJECT_USE_OBJC 0 
  74 #if OS_OBJECT_USE_OBJC 
  75 #import <objc/NSObject.h> 
  76 #define OS_OBJECT_CLASS(name) OS_##name 
  77 #define OS_OBJECT_DECL(name, ...) \ 
  78                 @protocol OS_OBJECT_CLASS(name) __VA_ARGS__ \ 
  80                 typedef NSObject<OS_OBJECT_CLASS(name)> *name##_t 
  81 #define OS_OBJECT_DECL_SUBCLASS(name, super) \ 
  82                 OS_OBJECT_DECL(name, <OS_OBJECT_CLASS(super)>) 
  83 #if defined(__has_attribute) 
  84 #if __has_attribute(ns_returns_retained) 
  85 #define OS_OBJECT_RETURNS_RETAINED __attribute__((__ns_returns_retained__)) 
  87 #define OS_OBJECT_RETURNS_RETAINED 
  89 #if __has_attribute(ns_consumed) 
  90 #define OS_OBJECT_CONSUMED __attribute__((__ns_consumed__)) 
  92 #define OS_OBJECT_CONSUMED 
  95 #define OS_OBJECT_RETURNS_RETAINED 
  96 #define OS_OBJECT_CONSUMED 
  98 #if defined(__has_feature) 
  99 #if __has_feature(objc_arc) 
 100 #define OS_OBJECT_BRIDGE __bridge 
 101 #define OS_WARN_RESULT_NEEDS_RELEASE 
 103 #define OS_OBJECT_BRIDGE 
 104 #define OS_WARN_RESULT_NEEDS_RELEASE OS_WARN_RESULT 
 107 #define OS_OBJECT_BRIDGE 
 108 #define OS_WARN_RESULT_NEEDS_RELEASE OS_WARN_RESULT 
 110 #ifndef OS_OBJECT_USE_OBJC_RETAIN_RELEASE 
 111 #if defined(__clang_analyzer__) 
 112 #define OS_OBJECT_USE_OBJC_RETAIN_RELEASE 1 
 113 #elif defined(__has_feature) 
 114 #if __has_feature(objc_arc) 
 115 #define OS_OBJECT_USE_OBJC_RETAIN_RELEASE 1 
 117 #define OS_OBJECT_USE_OBJC_RETAIN_RELEASE 0 
 120 #define OS_OBJECT_USE_OBJC_RETAIN_RELEASE 0 
 125 #define OS_OBJECT_RETURNS_RETAINED 
 127 #define OS_OBJECT_CONSUMED 
 129 #define OS_OBJECT_BRIDGE 
 131 #define OS_WARN_RESULT_NEEDS_RELEASE OS_WARN_RESULT 
 132 #define OS_OBJECT_USE_OBJC_RETAIN_RELEASE 0 
 135 #define OS_OBJECT_GLOBAL_OBJECT(type, object) ((OS_OBJECT_BRIDGE type)&(object)) 
 140  * @function os_retain 
 143  * Increment the reference count of an os_object. 
 146  * On a platform with the modern Objective-C runtime this is exactly equivalent 
 147  * to sending the object the -[retain] message. 
 150  * The object to retain. 
 153  * The retained object. 
 155 __OSX_AVAILABLE_STARTING(__MAC_10_10
,__IPHONE_8_0
) 
 158 os_retain(void *object
); 
 159 #if OS_OBJECT_USE_OBJC 
 161 #define os_retain(object) [object retain] 
 165  * @function os_release 
 168  * Decrement the reference count of a os_object. 
 171  * On a platform with the modern Objective-C runtime this is exactly equivalent 
 172  * to sending the object the -[release] message. 
 175  * The object to release. 
 177 __OSX_AVAILABLE_STARTING(__MAC_10_10
,__IPHONE_8_0
) 
 180 os_release(void *object
); 
 181 #if OS_OBJECT_USE_OBJC 
 183 #define os_release(object) [object release]