]> git.saurik.com Git - apple/libdispatch.git/blame - os/object_private.h
libdispatch-703.50.37.tar.gz
[apple/libdispatch.git] / os / object_private.h
CommitLineData
c093abd6
A
1/*
2 * Copyright (c) 2011-2012 Apple Inc. All rights reserved.
3 *
4 * @APPLE_APACHE_LICENSE_HEADER_START@
5 *
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
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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.
17 *
18 * @APPLE_APACHE_LICENSE_HEADER_END@
19 */
20
21/*
22 * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
23 * which are subject to change in future releases of Mac OS X. Any applications
24 * relying on these interfaces WILL break.
25 */
26
27#ifndef __OS_OBJECT_PRIVATE__
28#define __OS_OBJECT_PRIVATE__
29
30#include <sys/cdefs.h>
31#include <stddef.h>
32#include <os/object.h>
33
34#ifndef __OSX_AVAILABLE_STARTING
35#define __OSX_AVAILABLE_STARTING(x, y)
36#endif
37
38#if __GNUC__
39#define OS_OBJECT_NOTHROW __attribute__((__nothrow__))
40#define OS_OBJECT_NONNULL __attribute__((__nonnull__))
41#define OS_OBJECT_WARN_RESULT __attribute__((__warn_unused_result__))
42#define OS_OBJECT_MALLOC __attribute__((__malloc__))
43#define OS_OBJECT_EXPORT extern __attribute__((visibility("default")))
44#else
45/*! @parseOnly */
46#define OS_OBJECT_NOTHROW
47/*! @parseOnly */
48#define OS_OBJECT_NONNULL
49/*! @parseOnly */
50#define OS_OBJECT_WARN_RESULT
51/*! @parseOnly */
52#define OS_OBJECT_MALLOC
53#define OS_OBJECT_EXPORT extern
54#endif
55
beb15981 56#if OS_OBJECT_USE_OBJC && __has_feature(objc_arc)
c093abd6
A
57#define _OS_OBJECT_OBJC_ARC 1
58#else
59#define _OS_OBJECT_OBJC_ARC 0
60#endif
61
62#define _OS_OBJECT_GLOBAL_REFCNT INT_MAX
63
64#define _OS_OBJECT_HEADER(isa, ref_cnt, xref_cnt) \
65 isa; /* must be pointer-sized */ \
66 int volatile ref_cnt; \
67 int volatile xref_cnt
68
69#if OS_OBJECT_HAVE_OBJC_SUPPORT
beb15981
A
70#define OS_OBJECT_CLASS_SYMBOL(name) OS_##name##_class
71#if TARGET_OS_MAC && !TARGET_OS_SIMULATOR && defined(__i386__)
72#define OS_OBJECT_HAVE_OBJC1 1
73#define OS_OBJECT_HAVE_OBJC2 0
74#define OS_OBJC_CLASS_RAW_SYMBOL_NAME(name) \
75 ".objc_class_name_" OS_STRINGIFY(name)
76#define _OS_OBJECT_CLASS_HEADER() \
77 const void *_os_obj_objc_isa
78#else
79#define OS_OBJECT_HAVE_OBJC1 0
80#define OS_OBJECT_HAVE_OBJC2 1
81#define OS_OBJC_CLASS_RAW_SYMBOL_NAME(name) "_OBJC_CLASS_$_" OS_STRINGIFY(name)
c093abd6
A
82// Must match size of compiler-generated OBJC_CLASS structure rdar://10640168
83#define _OS_OBJECT_CLASS_HEADER() \
84 void *_os_obj_objc_class_t[5]
beb15981
A
85#endif
86#define OS_OBJECT_OBJC_CLASS_DECL(name) \
87 extern void *OS_OBJECT_CLASS_SYMBOL(name) \
88 asm(OS_OBJC_CLASS_RAW_SYMBOL_NAME(OS_OBJECT_CLASS(name)))
c093abd6 89#else
beb15981
A
90#define OS_OBJECT_HAVE_OBJC1 0
91#define OS_OBJECT_HAVE_OBJC2 0
c093abd6
A
92#define _OS_OBJECT_CLASS_HEADER() \
93 void (*_os_obj_xref_dispose)(_os_object_t); \
94 void (*_os_obj_dispose)(_os_object_t)
95#endif
96
97#define OS_OBJECT_CLASS(name) OS_##name
98
beb15981
A
99#if OS_OBJECT_USE_OBJC && OS_OBJECT_SWIFT3
100@interface OS_OBJECT_CLASS(object) (OSObjectPrivate)
101- (void)_xref_dispose;
102- (void)_dispose;
103@end
104OS_OBJECT_DECL_PROTOCOL(object, <NSObject>);
105typedef OS_OBJECT_CLASS(object) *_os_object_t;
106#define _OS_OBJECT_DECL_SUBCLASS_INTERFACE(name, super) \
107 @interface OS_OBJECT_CLASS(name) : OS_OBJECT_CLASS(super) \
108 <OS_OBJECT_CLASS(name)> \
109 @end
110#define _OS_OBJECT_DECL_PROTOCOL(name, super) \
111 OS_OBJECT_DECL_PROTOCOL(name, <OS_OBJECT_CLASS(super)>)
112#define _OS_OBJECT_CLASS_IMPLEMENTS_PROTOCOL(name, super) \
113 OS_OBJECT_CLASS_IMPLEMENTS_PROTOCOL(name, super)
114#elif OS_OBJECT_USE_OBJC
c093abd6
A
115__OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_6_0)
116OS_OBJECT_EXPORT
117@interface OS_OBJECT_CLASS(object) : NSObject
118- (void)_xref_dispose;
119- (void)_dispose;
120@end
121typedef OS_OBJECT_CLASS(object) *_os_object_t;
122#define _OS_OBJECT_DECL_SUBCLASS_INTERFACE(name, super) \
123 @interface OS_OBJECT_CLASS(name) : OS_OBJECT_CLASS(super) \
124 <OS_OBJECT_CLASS(name)> \
125 @end
126#else
beb15981
A
127#define _OS_OBJECT_DECL_SUBCLASS_INTERFACE(name, super)
128#define _OS_OBJECT_DECL_PROTOCOL(name, super)
129#define _OS_OBJECT_CLASS_IMPLEMENTS_PROTOCOL(name, super)
c093abd6
A
130typedef struct _os_object_s *_os_object_t;
131#endif
132
beb15981
A
133OS_ASSUME_NONNULL_BEGIN
134
c093abd6
A
135__BEGIN_DECLS
136
137#if !_OS_OBJECT_OBJC_ARC
138
139__OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_6_0)
140OS_OBJECT_EXPORT OS_OBJECT_MALLOC OS_OBJECT_WARN_RESULT OS_OBJECT_NOTHROW
beb15981 141OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
c093abd6
A
142_os_object_t
143_os_object_alloc(const void *cls, size_t size);
144
517da941
A
145__OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
146OS_OBJECT_EXPORT OS_OBJECT_MALLOC OS_OBJECT_WARN_RESULT OS_OBJECT_NOTHROW
beb15981 147OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
517da941
A
148_os_object_t
149_os_object_alloc_realized(const void *cls, size_t size);
150
c093abd6
A
151__OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_6_0)
152OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
beb15981 153OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
c093abd6
A
154void _os_object_dealloc(_os_object_t object);
155
156__OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_6_0)
157OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
beb15981 158OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
c093abd6
A
159_os_object_t
160_os_object_retain(_os_object_t object);
161
45201a42
A
162__OSX_AVAILABLE_STARTING(__MAC_10_11,__IPHONE_9_0)
163OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
beb15981 164OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
45201a42
A
165_os_object_t
166_os_object_retain_with_resurrect(_os_object_t obj);
167
c093abd6
A
168__OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_6_0)
169OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
beb15981 170OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
c093abd6
A
171void
172_os_object_release(_os_object_t object);
173
174__OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_6_0)
175OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
beb15981 176OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
c093abd6
A
177_os_object_t
178_os_object_retain_internal(_os_object_t object);
179
180__OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_6_0)
181OS_OBJECT_EXPORT OS_OBJECT_NONNULL OS_OBJECT_NOTHROW
beb15981 182OS_SWIFT_UNAVAILABLE("Unavailable in Swift")
c093abd6
A
183void
184_os_object_release_internal(_os_object_t object);
185
186#endif // !_OS_OBJECT_OBJC_ARC
187
188__END_DECLS
189
beb15981
A
190OS_ASSUME_NONNULL_END
191
c093abd6 192#endif