tightly couple protoc-c output with the protobuf-c headers

this adds a version guard like the protobuf C++ implementation. it
ensures that protoc-c and <protobuf-c.h> are from the exact same version
of protobuf-c.
This commit is contained in:
Robert Edmonds 2014-04-03 18:19:00 -04:00
parent 516f72286a
commit c7c7850b51

View File

@ -32,7 +32,8 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
// Copyright (c) 2008-2013, Dave Benson. All rights reserved.
// Copyright (c) 2008-2014, Dave Benson and the protobuf-c authors.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
@ -69,6 +70,8 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/descriptor.pb.h>
#include "protobuf-c.h"
namespace google {
namespace protobuf {
namespace compiler {
@ -131,25 +134,21 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
"filename", file_->name(),
"filename_identifier", filename_identifier);
#if 0
// Verify the protobuf library header version is compatible with the protoc
// version before going any further.
// Verify the protobuf-c library header version is compatible with the
// protoc-c version before going any further.
printer->Print(
"#if GOOGLE_PROTOBUF_VERSION < $min_header_version$\n"
"#error This file was generated by a newer version of protoc which is\n"
"#error incompatible with your Protocol Buffer headers. Please update\n"
"#error your headers.\n"
"#endif\n"
"#if $protoc_version$ < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION\n"
"#error This file was generated by an older version of protoc which is\n"
"#error incompatible with your Protocol Buffer headers. Please\n"
"#error regenerate this file with a newer version of protoc.\n"
"#if PROTOBUF_C_VERSION_NUMBER < $min_header_version$\n"
"# error This file was generated by a newer version of protoc-c which is "
"incompatible with your libprotobuf-c headers. Please update your headers.\n"
"#elif $protoc_version$ < PROTOBUF_C_VERSION_NUMBER\n"
"# error This file was generated by an older version of protoc-c which is "
"incompatible with your libprotobuf-c headers. Please regenerate this file "
"with a newer version of protoc-c.\n"
"#endif\n"
"\n",
"min_header_version",
SimpleItoa(protobuf::internal::kMinHeaderVersionForProtoc),
"protoc_version", SimpleItoa(GOOGLE_PROTOBUF_VERSION));
#endif
SimpleItoa(PROTOBUF_C_VERSION_NUMBER),
"protoc_version", SimpleItoa(PROTOBUF_C_VERSION_NUMBER));
for (int i = 0; i < file_->dependency_count(); i++) {
printer->Print(