GPBBootstrap.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  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.
  30. /**
  31. * 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. * 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. * full TextFormat can be useful for debugging.
  36. **/
  37. #ifndef GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
  38. #define GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS 0
  39. #endif
  40. // Used in the generated code to give sizes to enums. int32_t was chosen based
  41. // on the fact that Protocol Buffers enums are limited to this range.
  42. #if !__has_feature(objc_fixed_enum)
  43. #error All supported Xcode versions should support objc_fixed_enum.
  44. #endif
  45. // If the headers are imported into Objective-C++, we can run into an issue
  46. // where the definition of NS_ENUM (really CF_ENUM) changes based on the C++
  47. // standard that is in effect. If it isn't C++11 or higher, the definition
  48. // doesn't allow us to forward declare. We work around this one case by
  49. // providing a local definition. The default case has to use NS_ENUM for the
  50. // magic that is Swift bridging of enums.
  51. #if (defined(__cplusplus) && __cplusplus && __cplusplus < 201103L)
  52. #define GPB_ENUM(X) enum X : int32_t X; enum X : int32_t
  53. #else
  54. #define GPB_ENUM(X) NS_ENUM(int32_t, X)
  55. #endif
  56. /**
  57. * GPB_ENUM_FWD_DECLARE is used for forward declaring enums, for example:
  58. *
  59. * ```
  60. * GPB_ENUM_FWD_DECLARE(Foo_Enum)
  61. *
  62. * @interface BarClass : NSObject
  63. * @property (nonatomic) enum Foo_Enum value;
  64. * - (void)bazMethod:(enum Foo_Enum):value;
  65. * @end
  66. * ```
  67. **/
  68. #define GPB_ENUM_FWD_DECLARE(X) enum X : int32_t
  69. /**
  70. * Based upon CF_INLINE. Forces inlining in non DEBUG builds.
  71. **/
  72. #if !defined(DEBUG)
  73. #define GPB_INLINE static __inline__ __attribute__((always_inline))
  74. #else
  75. #define GPB_INLINE static __inline__
  76. #endif
  77. /**
  78. * For use in public headers that might need to deal with ARC.
  79. **/
  80. #ifndef GPB_UNSAFE_UNRETAINED
  81. #if __has_feature(objc_arc)
  82. #define GPB_UNSAFE_UNRETAINED __unsafe_unretained
  83. #else
  84. #define GPB_UNSAFE_UNRETAINED
  85. #endif
  86. #endif
  87. /**
  88. * Attribute used for Objective-C proto interface deprecations without messages.
  89. **/
  90. #ifndef GPB_DEPRECATED
  91. #define GPB_DEPRECATED __attribute__((deprecated))
  92. #endif
  93. /**
  94. * Attribute used for Objective-C proto interface deprecations with messages.
  95. **/
  96. #ifndef GPB_DEPRECATED_MSG
  97. #if __has_extension(attribute_deprecated_with_message)
  98. #define GPB_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
  99. #else
  100. #define GPB_DEPRECATED_MSG(msg) __attribute__((deprecated))
  101. #endif
  102. #endif
  103. // If property name starts with init we need to annotate it to get past ARC.
  104. // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227
  105. //
  106. // Meant to be used internally by generated code.
  107. #define GPB_METHOD_FAMILY_NONE __attribute__((objc_method_family(none)))
  108. // Prevent subclassing of generated proto classes.
  109. #ifndef GPB_FINAL
  110. #define GPB_FINAL __attribute__((objc_subclassing_restricted))
  111. #endif // GPB_FINAL
  112. // ----------------------------------------------------------------------------
  113. // These version numbers are all internal to the ObjC Protobuf runtime; they
  114. // are used to ensure compatibility between the generated sources and the
  115. // headers being compiled against and/or the version of sources being run
  116. // against.
  117. //
  118. // They are all #defines so the values are captured into every .o file they
  119. // are used in and to allow comparisons in the preprocessor.
  120. // Current library runtime version.
  121. // - Gets bumped when the runtime makes changes to the interfaces between the
  122. // generated code and runtime (things added/removed, etc).
  123. #define GOOGLE_PROTOBUF_OBJC_VERSION 30004
  124. // Minimum runtime version supported for compiling/running against.
  125. // - Gets changed when support for the older generated code is dropped.
  126. #define GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION 30001
  127. // This is a legacy constant now frozen in time for old generated code. If
  128. // GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION ever gets moved above 30001 then
  129. // this should also change to break code compiled with an old runtime that
  130. // can't be supported any more.
  131. #define GOOGLE_PROTOBUF_OBJC_GEN_VERSION 30001