Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(742)

Side by Side Diff: base/mac/closure_blocks_leopard_compat.h

Issue 10785047: Remove all the OS X 10.6 SDK forward declarations. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/base.gyp ('k') | base/mac/closure_blocks_leopard_compat.S » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BASE_MAC_CLOSURE_BLOCKS_LEOPARD_COMPAT_H_
6 #define BASE_MAC_CLOSURE_BLOCKS_LEOPARD_COMPAT_H_
7
8 // libclosure (blocks) compatibility for Mac OS X 10.5 (Leopard)
9 //
10 // Background material:
11 // http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Blocks
12 // http://opensource.apple.com/source/libclosure/libclosure-38/
13 //
14 // Leopard doesn't support blocks. Chrome supports Leopard. Chrome needs to use
15 // blocks.
16 //
17 // In any file where you use blocks (any time you type ^{...}), you must
18 // #include this file to ensure that the runtime symbols referenced by code
19 // emitted by the compiler are marked for weak-import. This means that if
20 // these symbols are not present at runtime, the program will still load, but
21 // their values will be NULL.
22 //
23 // In any target (in the GYP sense) where you use blocks, you must also depend
24 // on the closure_blocks_leopard_compat target to ensure that these symbols
25 // will be available at link time, even when the 10.5 SDK is in use. This
26 // allows the continued use of the 10.5 SDK, which does not contain these
27 // symbols.
28 //
29 // This does not relieve you of the responsibility to not use blocks on
30 // Leopard. Because runtime support for Blocks still isn't present on that
31 // operating system, the weak-imported symbols will have value 0 and attempts
32 // to do anything meaningful with them will fail or crash. You must take care
33 // not to enter any codepath that uses blocks on Leopard. The base::mac::IsOS*
34 // family may be helpful.
35 //
36 // Although this scheme allows the use of the 10.5 SDK and 10.5 runtime in an
37 // application that uses blocks, it is still necessary to use a compiler that
38 // supports blocks. GCC 4.2 as shipped with Xcode 3.2 for Mac OS X 10.6
39 // qualifies, as do sufficiently recent versions of clang. GCC 4.2 as shipped
40 // with Xcode 3.1 for Mac OS X 10.5 does not qualify.
41
42 // _NSConcreteGlobalBlock and _NSConcreteStackBlock are private implementation
43 // details of libclosure defined in libclosure/libclosure-38/Block_private.h,
44 // but they're exposed from libSystem as public symbols, and the block-enabled
45 // compiler will emit code that references these symbols. Because the symbols
46 // aren't present in 10.5's libSystem, they must be declared as weak imports
47 // in any file that uses blocks. Any block-using file must #include this
48 // header to guarantee that the symbols will show up in linked output as weak
49 // imports when compiling for a 10.5 deployment target. Because the symbols
50 // are always present in 10.6 and higher, they do not need to be a weak
51 // imports when the deployment target is at least 10.6.
52 //
53 // Both GCC and clang emit references to these symbols, providing implicit
54 // declarations as needed, but respecting any user declaration when present.
55 // See gcc-5666.3/gcc/c-parser.c build_block_struct_initlist,
56 // gcc-5666.3/gcc/cp/parser.c build_block_struct_initlist, and
57 // clang-2.9/lib/CodeGen/CodeGenModule.cpp
58 // CodeGenModule::getNSConcreteGlobalBlock() and
59 // CodeGenModule::getNSConcreteStackBlock().
60
61 #include <AvailabilityMacros.h>
62
63 #if defined(MAC_OS_X_VERSION_10_6) && \
64 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 // SDK >= 10.6
65 // Get the system's own declarations of these things if using an SDK where
66 // they are present.
67 #include <Block.h>
68 #endif // SDK >= 10.6
69
70 extern "C" {
71
72 #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_5 // DT <= 10.5
73 #define MAYBE_WEAK_IMPORT __attribute__((weak_import))
74 #else // DT > 10.5
75 #define MAYBE_WEAK_IMPORT
76 #endif // DT <= 10.5
77
78 MAYBE_WEAK_IMPORT extern void* _Block_copy(const void*);
79 MAYBE_WEAK_IMPORT extern void _Block_release(const void*);
80 MAYBE_WEAK_IMPORT extern void _Block_object_assign(void*,
81 const void*,
82 const int);
83 MAYBE_WEAK_IMPORT extern void _Block_object_dispose(const void*, const int);
84
85 MAYBE_WEAK_IMPORT extern void* _NSConcreteGlobalBlock[32];
86 MAYBE_WEAK_IMPORT extern void* _NSConcreteStackBlock[32];
87
88 #undef MAYBE_WEAK_IMPORT
89
90 } // extern "C"
91
92 // Macros from <Block.h>, in case <Block.h> is not present.
93
94 #ifndef Block_copy
95 #define Block_copy(...) \
96 ((__typeof(__VA_ARGS__))_Block_copy((const void *)(__VA_ARGS__)))
97 #endif
98
99 #ifndef Block_release
100 #define Block_release(...) _Block_release((const void *)(__VA_ARGS__))
101 #endif
102
103 #endif // BASE_MAC_CLOSURE_BLOCKS_LEOPARD_COMPAT_H_
OLDNEW
« no previous file with comments | « base/base.gyp ('k') | base/mac/closure_blocks_leopard_compat.S » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698