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

Side by Side Diff: content/browser/mac/closure_blocks_leopard_compat.h

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

Powered by Google App Engine
This is Rietveld 408576698