GPBBootstrap.h 4.5 KB

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