@ -51,10 +51,8 @@ namespace objectivec {
namespace {
namespace {
// This is also found in GPBBootstrap.h, and needs to be kept in sync. It
// This is also found in GPBBootstrap.h, and needs to be kept in sync.
// is the version check done to ensure generated code works with the current
const int32 GOOGLE_PROTOBUF_OBJC_VERSION = 30002 ;
// runtime being used.
const int32 GOOGLE_PROTOBUF_OBJC_GEN_VERSION = 30002 ;
const char * kHeaderExtension = " .pbobjc.h " ;
const char * kHeaderExtension = " .pbobjc.h " ;
@ -192,13 +190,19 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
// Add some verification that the generated code matches the source the
// Add some verification that the generated code matches the source the
// code is being compiled with.
// code is being compiled with.
// NOTE: This captures the raw numeric values at the time the generator was
// compiled, since that will be the versions for the ObjC runtime at that
// time. The constants in the generated code will then get their values at
// at compile time (so checking against the headers being used to compile).
printer - > Print (
printer - > Print (
" #if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != $protoc_gen_objc_version$ \n "
" #if GOOGLE_PROTOBUF_OBJC_VERSION < $google_protobuf_objc_version$ \n "
" #error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources. \n "
" #error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. \n "
" #endif \n "
" #if $google_protobuf_objc_version$ < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION \n "
" #error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources. \n "
" #endif \n "
" #endif \n "
" \n " ,
" \n " ,
" protoc_gen_objc_version " ,
" google_protobuf_objc_version " , SimpleItoa ( GOOGLE_PROTOBUF_OBJC_VERSION ) ) ;
SimpleItoa ( GOOGLE_PROTOBUF_OBJC_GEN_VERSION ) ) ;
// #import any headers for "public imports" in the proto file.
// #import any headers for "public imports" in the proto file.
{
{
@ -392,7 +396,7 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
" // about thread safety and initialization of registry. \n "
" // about thread safety and initialization of registry. \n "
" static GPBExtensionRegistry* registry = nil; \n "
" static GPBExtensionRegistry* registry = nil; \n "
" if (!registry) { \n "
" if (!registry) { \n "
" GPBDebugCheckRuntimeVersion (); \n "
" GPB_DEBUG_CHECK_RUNTIME_VERSIONS (); \n "
" registry = [[GPBExtensionRegistry alloc] init]; \n " ) ;
" registry = [[GPBExtensionRegistry alloc] init]; \n " ) ;
printer - > Indent ( ) ;
printer - > Indent ( ) ;
@ -487,7 +491,7 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
" // about thread safety of the singleton. \n "
" // about thread safety of the singleton. \n "
" static GPBFileDescriptor *descriptor = NULL; \n "
" static GPBFileDescriptor *descriptor = NULL; \n "
" if (!descriptor) { \n "
" if (!descriptor) { \n "
" GPBDebugCheckRuntimeVersion (); \n " ) ;
" GPB_DEBUG_CHECK_RUNTIME_VERSIONS (); \n " ) ;
if ( vars [ " objc_prefix " ] . size ( ) > 0 ) {
if ( vars [ " objc_prefix " ] . size ( ) > 0 ) {
printer - > Print (
printer - > Print (
vars ,
vars ,