Commit c7c7850b authored by Robert Edmonds's avatar Robert Edmonds

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.
parent 516f7228
...@@ -32,7 +32,8 @@ ...@@ -32,7 +32,8 @@
// Based on original Protocol Buffers design by // Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others. // 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 // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
...@@ -69,6 +70,8 @@ ...@@ -69,6 +70,8 @@
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.pb.h>
#include "protobuf-c.h"
namespace google { namespace google {
namespace protobuf { namespace protobuf {
namespace compiler { namespace compiler {
...@@ -131,25 +134,21 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { ...@@ -131,25 +134,21 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
"filename", file_->name(), "filename", file_->name(),
"filename_identifier", filename_identifier); "filename_identifier", filename_identifier);
#if 0 // Verify the protobuf-c library header version is compatible with the
// Verify the protobuf library header version is compatible with the protoc // protoc-c version before going any further.
// version before going any further.
printer->Print( printer->Print(
"#if GOOGLE_PROTOBUF_VERSION < $min_header_version$\n" "#if PROTOBUF_C_VERSION_NUMBER < $min_header_version$\n"
"#error This file was generated by a newer version of protoc which is\n" "# error This file was generated by a newer version of protoc-c which is "
"#error incompatible with your Protocol Buffer headers. Please update\n" "incompatible with your libprotobuf-c headers. Please update your headers.\n"
"#error your headers.\n" "#elif $protoc_version$ < PROTOBUF_C_VERSION_NUMBER\n"
"#endif\n" "# error This file was generated by an older version of protoc-c which is "
"#if $protoc_version$ < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION\n" "incompatible with your libprotobuf-c headers. Please regenerate this file "
"#error This file was generated by an older version of protoc which is\n" "with a newer version of protoc-c.\n"
"#error incompatible with your Protocol Buffer headers. Please\n"
"#error regenerate this file with a newer version of protoc.\n"
"#endif\n" "#endif\n"
"\n", "\n",
"min_header_version", "min_header_version",
SimpleItoa(protobuf::internal::kMinHeaderVersionForProtoc), SimpleItoa(PROTOBUF_C_VERSION_NUMBER),
"protoc_version", SimpleItoa(GOOGLE_PROTOBUF_VERSION)); "protoc_version", SimpleItoa(PROTOBUF_C_VERSION_NUMBER));
#endif
for (int i = 0; i < file_->dependency_count(); i++) { for (int i = 0; i < file_->dependency_count(); i++) {
printer->Print( printer->Print(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment