protoc-gen-c/c_helpers.h: Move compat defines into new header file compat.h

This commit is contained in:
Robert Edmonds
2025-02-08 18:18:33 -05:00
parent 185beed28e
commit b28683f802
7 changed files with 51 additions and 10 deletions

View File

@@ -74,6 +74,7 @@
#include "c_message_field.h"
#include "c_primitive_field.h"
#include "c_string_field.h"
#include "compat.h"
namespace protobuf_c {

View File

@@ -73,6 +73,7 @@
#include <google/protobuf/stubs/common.h>
#include "c_helpers.h"
#include "compat.h"
namespace protobuf_c {

View File

@@ -186,16 +186,6 @@ inline int FieldSyntax(const google::protobuf::FieldDescriptor* field) {
return 2;
}
// Work around changes in protobuf >= 22.x without breaking compilation against
// older protobuf versions.
#if GOOGLE_PROTOBUF_VERSION >= 4022000
# define GOOGLE_ARRAYSIZE ABSL_ARRAYSIZE
# define GOOGLE_CHECK_EQ ABSL_CHECK_EQ
# define GOOGLE_CHECK_EQ ABSL_CHECK_EQ
# define GOOGLE_DCHECK_GE ABSL_DCHECK_GE
# define GOOGLE_LOG ABSL_LOG
#endif
} // namespace protobuf_c
#endif // PROTOBUF_C_PROTOC_GEN_C_C_HELPERS_H__

View File

@@ -78,6 +78,7 @@
#include "c_extension.h"
#include "c_helpers.h"
#include "c_message.h"
#include "compat.h"
namespace protobuf_c {

View File

@@ -67,6 +67,7 @@
#include "c_helpers.h"
#include "c_primitive_field.h"
#include "compat.h"
namespace protobuf_c {

46
protoc-gen-c/compat.h Normal file
View File

@@ -0,0 +1,46 @@
// Copyright (c) 2008-2025, 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
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef PROTOBUF_C_PROTOC_GEN_C_COMPAT_H__
#define PROTOBUF_C_PROTOC_GEN_C_COMPAT_H__
#if GOOGLE_PROTOBUF_VERSION >= 4022000
# define GOOGLE_ARRAYSIZE ABSL_ARRAYSIZE
# define GOOGLE_CHECK_EQ ABSL_CHECK_EQ
# define GOOGLE_DCHECK_GE ABSL_DCHECK_GE
# define GOOGLE_LOG ABSL_LOG
#endif
namespace protobuf_c {
namespace compat {
} // namespace compat
} // namespace protobuf_c
#endif // PROTOBUF_C_PROTOC_GEN_C_COMPAT_H__

View File

@@ -32,6 +32,7 @@
#include "c_generator.h"
#include "c_helpers.h"
#include "compat.h"
int main(int argc, char* argv[]) {
protobuf_c::CGenerator c_generator;