GPBBootstrap.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. //
  4. // Use of this source code is governed by a BSD-style
  5. // license that can be found in the LICENSE file or at
  6. // https://developers.google.com/open-source/licenses/bsd
  7. /**
  8. * The Objective C runtime has complete enough info that most protos don’t end
  9. * up using this, so leaving it on is no cost or very little cost. If you
  10. * happen to see it causing bloat, this is the way to disable it. If you do
  11. * need to disable it, try only disabling it for Release builds as having
  12. * full TextFormat can be useful for debugging.
  13. **/
  14. #ifndef GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
  15. #define GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS 0
  16. #endif
  17. // Used in the generated code to give sizes to enums. int32_t was chosen based
  18. // on the fact that Protocol Buffers enums are limited to this range.
  19. #if !__has_feature(objc_fixed_enum)
  20. #error All supported Xcode versions should support objc_fixed_enum.
  21. #endif
  22. // If the headers are imported into Objective-C++, we can run into an issue
  23. // where the definition of NS_ENUM (really CF_ENUM) changes based on the C++
  24. // standard that is in effect. If it isn't C++11 or higher, the definition
  25. // doesn't allow us to forward declare. We work around this one case by
  26. // providing a local definition. The default case has to use NS_ENUM for the
  27. // magic that is Swift bridging of enums.
  28. #if (defined(__cplusplus) && __cplusplus && __cplusplus < 201103L)
  29. #define GPB_ENUM(X) \
  30. enum X : int32_t X; \
  31. enum X : int32_t
  32. #else
  33. #define GPB_ENUM(X) NS_ENUM(int32_t, X)
  34. #endif
  35. /**
  36. * GPB_ENUM_FWD_DECLARE is used for forward declaring enums, for example:
  37. *
  38. * ```
  39. * GPB_ENUM_FWD_DECLARE(Foo_Enum)
  40. *
  41. * @interface BarClass : NSObject
  42. * @property (nonatomic) enum Foo_Enum value;
  43. * - (void)bazMethod:(enum Foo_Enum)value;
  44. * @end
  45. * ```
  46. **/
  47. #define GPB_ENUM_FWD_DECLARE(X) enum X : int32_t
  48. /**
  49. * Based upon CF_INLINE. Forces inlining in non DEBUG builds.
  50. **/
  51. #if !defined(DEBUG)
  52. #define GPB_INLINE static __inline__ __attribute__((always_inline))
  53. #else
  54. #define GPB_INLINE static __inline__
  55. #endif
  56. /**
  57. * For use in public headers that might need to deal with ARC.
  58. **/
  59. #ifndef GPB_UNSAFE_UNRETAINED
  60. #if __has_feature(objc_arc)
  61. #define GPB_UNSAFE_UNRETAINED __unsafe_unretained
  62. #else
  63. #define GPB_UNSAFE_UNRETAINED
  64. #endif
  65. #endif
  66. /**
  67. * Attribute used for Objective-C proto interface deprecations without messages.
  68. **/
  69. #ifndef GPB_DEPRECATED
  70. #define GPB_DEPRECATED __attribute__((deprecated))
  71. #endif
  72. /**
  73. * Attribute used for Objective-C proto interface deprecations with messages.
  74. **/
  75. #ifndef GPB_DEPRECATED_MSG
  76. #if __has_extension(attribute_deprecated_with_message)
  77. #define GPB_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
  78. #else
  79. #define GPB_DEPRECATED_MSG(msg) __attribute__((deprecated))
  80. #endif
  81. #endif
  82. // If property name starts with init we need to annotate it to get past ARC.
  83. // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227
  84. //
  85. // Meant to be used internally by generated code.
  86. #define GPB_METHOD_FAMILY_NONE __attribute__((objc_method_family(none)))
  87. // Prevent subclassing of generated proto classes.
  88. #ifndef GPB_FINAL
  89. #define GPB_FINAL __attribute__((objc_subclassing_restricted))
  90. #endif // GPB_FINAL
  91. // ----------------------------------------------------------------------------
  92. // These version numbers are all internal to the ObjC Protobuf runtime; they
  93. // are used to ensure compatibility between the generated sources and the
  94. // headers being compiled against and/or the version of sources being run
  95. // against.
  96. //
  97. // They are all #defines so the values are captured into every .o file they
  98. // are used in and to allow comparisons in the preprocessor.
  99. // Current library runtime version.
  100. // - Gets bumped when the runtime makes changes to the interfaces between the
  101. // generated code and runtime (things added/removed, etc).
  102. #define GOOGLE_PROTOBUF_OBJC_VERSION 30007
  103. // Minimum runtime version supported for compiling/running against.
  104. // - Gets changed when support for the older generated code is dropped.
  105. #define GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION 30001
  106. // This is a legacy constant now frozen in time for old generated code. If
  107. // GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION ever gets moved above 30001 then
  108. // this should also change to break code compiled with an old runtime that
  109. // can't be supported any more.
  110. #define GOOGLE_PROTOBUF_OBJC_GEN_VERSION 30001