aboutsummaryrefslogtreecommitdiff
path: root/objectivec/GPBUtilities.m
diff options
context:
space:
mode:
authorThomas Van Lenten <thomasvl@google.com>2016-09-15 13:27:17 -0400
committerThomas Van Lenten <thomasvl@google.com>2016-09-15 17:22:51 -0400
commit1aa65000568422f0187d2eb4fef00bcdca0cc125 (patch)
tree0e7a0728d64ef3cdec39ab42c6113ee714eab388 /objectivec/GPBUtilities.m
parent86fcd879b38505446799b2f2a2929415ddad620a (diff)
downloadprotobuf-1aa65000568422f0187d2eb4fef00bcdca0cc125.tar.gz
protobuf-1aa65000568422f0187d2eb4fef00bcdca0cc125.tar.bz2
protobuf-1aa65000568422f0187d2eb4fef00bcdca0cc125.zip
Update the ObjC version checks to support a min and current version.
- Capture the version used to generated. - Check at compile time and runtime that generated code isn't from a newer version, also check that the min version required is also supported. - Keep the old constants/macros/functions to special case the last version that was working so those generated sources still work until we decide otherwise.
Diffstat (limited to 'objectivec/GPBUtilities.m')
-rw-r--r--objectivec/GPBUtilities.m44
1 files changed, 43 insertions, 1 deletions
diff --git a/objectivec/GPBUtilities.m b/objectivec/GPBUtilities.m
index 80b85d07..d4538598 100644
--- a/objectivec/GPBUtilities.m
+++ b/objectivec/GPBUtilities.m
@@ -58,8 +58,50 @@ NSData *GPBEmptyNSData(void) {
return defaultNSData;
}
+// -- About Version Checks --
+// There's actually 3 places these checks all come into play:
+// 1. When the generated source is compile into .o files, the header check
+// happens. This is checking the protoc used matches the library being used
+// when making the .o.
+// 2. Every place a generated proto header is included in a developer's code,
+// the header check comes into play again. But this time it is checking that
+// the current library headers being used still support/match the ones for
+// the generated code.
+// 3. At runtime the final check here (GPBCheckRuntimeVersionsInternal), is
+// called from the generated code passing in values captured when the
+// generated code's .o was made. This checks that at runtime the generated
+// code and runtime library match.
+
+void GPBCheckRuntimeVersionSupport(int32_t objcRuntimeVersion) {
+ // NOTE: This is passing the value captured in the compiled code to check
+ // against the values captured when the runtime support was compiled. This
+ // ensures the library code isn't in a different framework/library that
+ // was generated with a non matching version.
+ if (GOOGLE_PROTOBUF_OBJC_VERSION < objcRuntimeVersion) {
+ // Library is too old for headers.
+ [NSException raise:NSInternalInconsistencyException
+ format:@"Linked to ProtocolBuffer runtime version %d,"
+ @" but code compiled needing atleast %d!",
+ GOOGLE_PROTOBUF_OBJC_VERSION, objcRuntimeVersion];
+ }
+ if (objcRuntimeVersion < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION) {
+ // Headers are too old for library.
+ [NSException raise:NSInternalInconsistencyException
+ format:@"Proto generation source compiled against runtime"
+ @" version %d, but this version of the runtime only"
+ @" supports back to %d!",
+ objcRuntimeVersion,
+ GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION];
+ }
+}
+
+// This api is no longer used for version checks. 30001 is the last version
+// using this old versioning model. When that support is removed, this function
+// can be removed (along with the declaration in GPBUtilities_PackagePrivate.h).
void GPBCheckRuntimeVersionInternal(int32_t version) {
- if (version != GOOGLE_PROTOBUF_OBJC_GEN_VERSION) {
+ GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION == 30001,
+ time_to_remove_this_old_version_shim);
+ if (version != GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION) {
[NSException raise:NSInternalInconsistencyException
format:@"Linked to ProtocolBuffer runtime version %d,"
@" but code compiled with version %d!",