OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 10 matching lines...) Expand all Loading... |
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | 30 |
31 /** | 31 // The Objective C runtime has complete enough info that most protos don’t end |
32 * The Objective C runtime has complete enough info that most protos don’t end | 32 // up using this, so leaving it on is no cost or very little cost. If you |
33 * up using this, so leaving it on is no cost or very little cost. If you | 33 // happen to see it causing bloat, this is the way to disable it. If you do |
34 * happen to see it causing bloat, this is the way to disable it. If you do | 34 // need to disable it, try only disabling it for Release builds as having |
35 * need to disable it, try only disabling it for Release builds as having | 35 // full TextFormat can be useful for debugging. |
36 * full TextFormat can be useful for debugging. | |
37 **/ | |
38 #ifndef GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS | 36 #ifndef GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS |
39 #define GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS 0 | 37 #define GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS 0 |
40 #endif | 38 #endif |
41 | 39 |
42 // Used in the generated code to give sizes to enums. int32_t was chosen based | 40 // Used in the generated code to give sizes to enums. int32_t was chosen based |
43 // on the fact that Protocol Buffers enums are limited to this range. | 41 // on the fact that Protocol Buffers enums are limited to this range. |
44 #if !__has_feature(objc_fixed_enum) | 42 #if !__has_feature(objc_fixed_enum) |
45 #error All supported Xcode versions should support objc_fixed_enum. | 43 #error All supported Xcode versions should support objc_fixed_enum. |
46 #endif | 44 #endif |
47 | |
48 // If the headers are imported into Objective-C++, we can run into an issue | 45 // If the headers are imported into Objective-C++, we can run into an issue |
49 // where the defintion of NS_ENUM (really CF_ENUM) changes based on the C++ | 46 // where the defintion of NS_ENUM (really CF_ENUM) changes based on the C++ |
50 // standard that is in effect. If it isn't C++11 or higher, the definition | 47 // standard that is in effect. If it isn't C++11 or higher, the definition |
51 // doesn't allow us to forward declare. We work around this one case by | 48 // doesn't allow us to forward declare. We work around this one case by |
52 // providing a local definition. The default case has to use NS_ENUM for the | 49 // providing a local definition. The default case has to use NS_ENUM for the |
53 // magic that is Swift bridging of enums. | 50 // magic that is Swift bridging of enums. |
54 #if (defined(__cplusplus) && __cplusplus && __cplusplus < 201103L) | 51 #if (__cplusplus && __cplusplus < 201103L) |
55 #define GPB_ENUM(X) enum X : int32_t X; enum X : int32_t | 52 #define GPB_ENUM(X) enum X : int32_t X; enum X : int32_t |
56 #else | 53 #else |
57 #define GPB_ENUM(X) NS_ENUM(int32_t, X) | 54 #define GPB_ENUM(X) NS_ENUM(int32_t, X) |
58 #endif | 55 #endif |
59 | 56 // GPB_ENUM_FWD_DECLARE is used for forward declaring enums, ex: |
60 /** | 57 // GPB_ENUM_FWD_DECLARE(Foo_Enum) |
61 * GPB_ENUM_FWD_DECLARE is used for forward declaring enums, for example: | 58 // @property (nonatomic) Foo_Enum value; |
62 * | |
63 * ``` | |
64 * GPB_ENUM_FWD_DECLARE(Foo_Enum) | |
65 * | |
66 * @interface BarClass : NSObject | |
67 * @property (nonatomic) enum Foo_Enum value; | |
68 * - (void)bazMethod:(enum Foo_Enum):value; | |
69 * @end | |
70 * ``` | |
71 **/ | |
72 #define GPB_ENUM_FWD_DECLARE(X) enum X : int32_t | 59 #define GPB_ENUM_FWD_DECLARE(X) enum X : int32_t |
73 | 60 |
74 /** | 61 // Based upon CF_INLINE. Forces inlining in release. |
75 * Based upon CF_INLINE. Forces inlining in non DEBUG builds. | |
76 **/ | |
77 #if !defined(DEBUG) | 62 #if !defined(DEBUG) |
78 #define GPB_INLINE static __inline__ __attribute__((always_inline)) | 63 #define GPB_INLINE static __inline__ __attribute__((always_inline)) |
79 #else | 64 #else |
80 #define GPB_INLINE static __inline__ | 65 #define GPB_INLINE static __inline__ |
81 #endif | 66 #endif |
82 | 67 |
83 /** | 68 // For use in public headers that might need to deal with ARC. |
84 * For use in public headers that might need to deal with ARC. | |
85 **/ | |
86 #ifndef GPB_UNSAFE_UNRETAINED | 69 #ifndef GPB_UNSAFE_UNRETAINED |
87 #if __has_feature(objc_arc) | 70 #if __has_feature(objc_arc) |
88 #define GPB_UNSAFE_UNRETAINED __unsafe_unretained | 71 #define GPB_UNSAFE_UNRETAINED __unsafe_unretained |
89 #else | 72 #else |
90 #define GPB_UNSAFE_UNRETAINED | 73 #define GPB_UNSAFE_UNRETAINED |
91 #endif | 74 #endif |
92 #endif | 75 #endif |
93 | 76 |
94 // If property name starts with init we need to annotate it to get past ARC. | 77 // If property name starts with init we need to annotate it to get past ARC. |
95 // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-
property-with-an-objc-method-family/18723227#18723227 | 78 // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-
property-with-an-objc-method-family/18723227#18723227 |
96 // | |
97 // Meant to be used internally by generated code. | |
98 #define GPB_METHOD_FAMILY_NONE __attribute__((objc_method_family(none))) | 79 #define GPB_METHOD_FAMILY_NONE __attribute__((objc_method_family(none))) |
99 | 80 |
100 // ---------------------------------------------------------------------------- | 81 // The protoc-gen-objc version which works with the current version of the |
101 // These version numbers are all internal to the ObjC Protobuf runtime; they | 82 // generated Objective C sources. In general we don't want to change the |
102 // are used to ensure compatibility between the generated sources and the | 83 // runtime interfaces (or this version) as it means everything has to be |
103 // headers being compiled against and/or the version of sources being run | 84 // regenerated. |
104 // against. | |
105 // | |
106 // They are all #defines so the values are captured into every .o file they | |
107 // are used in and to allow comparisons in the preprocessor. | |
108 | |
109 // Current library runtime version. | |
110 // - Gets bumped when the runtime makes changes to the interfaces between the | |
111 // generated code and runtime (things added/removed, etc). | |
112 #define GOOGLE_PROTOBUF_OBJC_VERSION 30002 | |
113 | |
114 // Minimum runtime version supported for compiling/running against. | |
115 // - Gets changed when support for the older generated code is dropped. | |
116 #define GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION 30001 | |
117 | |
118 | |
119 // This is a legacy constant now frozen in time for old generated code. If | |
120 // GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION ever gets moved above 30001 then | |
121 // this should also change to break code compiled with an old runtime that | |
122 // can't be supported any more. | |
123 #define GOOGLE_PROTOBUF_OBJC_GEN_VERSION 30001 | 85 #define GOOGLE_PROTOBUF_OBJC_GEN_VERSION 30001 |
OLD | NEW |