67 lines
2.1 KiB
Diff
67 lines
2.1 KiB
Diff
From 1937ba946b0a7a62c0f534e60f4d4799d7e0daed Mon Sep 17 00:00:00 2001
|
|
From: Robert Edmonds <edmonds@users.noreply.github.com>
|
|
Date: Sun, 2 Jul 2023 22:57:57 -0400
|
|
Subject: [PATCH] protoc-c: Use FileDescriptorLegacy to obtain proto syntax
|
|
version on protobuf >= 23.0
|
|
|
|
Use the newer "legacy" way of determining whether a file descriptor is
|
|
using proto2 or proto3 syntax on protobuf >= 23.0.
|
|
|
|
Based on
|
|
https://github.com/protobuf-c/protobuf-c/pull/556/commits/66574f3fd85a205eb7c90b790477d5415364209e
|
|
but continues to support older versions of protobuf.
|
|
|
|
Unfortunately, since this is a "deprecated", "legacy" API it'll probably
|
|
disappear in about five seconds.
|
|
---
|
|
protoc-c/c_file.cc | 4 ++++
|
|
protoc-c/c_helpers.h | 8 ++++++++
|
|
2 files changed, 12 insertions(+)
|
|
|
|
diff --git a/protoc-c/c_file.cc b/protoc-c/c_file.cc
|
|
index 59c1824..d211a3d 100644
|
|
--- a/protoc-c/c_file.cc
|
|
+++ b/protoc-c/c_file.cc
|
|
@@ -119,7 +119,11 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
|
|
|
|
int min_header_version = 1000000;
|
|
#if defined(HAVE_PROTO3)
|
|
+# if GOOGLE_PROTOBUF_VERSION >= 4023000
|
|
+ if (FileDescriptorLegacy(file_).syntax() == FileDescriptorLegacy::SYNTAX_PROTO3) {
|
|
+# else
|
|
if (file_->syntax() == FileDescriptor::SYNTAX_PROTO3) {
|
|
+#endif
|
|
min_header_version = 1003000;
|
|
}
|
|
#endif
|
|
diff --git a/protoc-c/c_helpers.h b/protoc-c/c_helpers.h
|
|
index adc7ee2..055528b 100644
|
|
--- a/protoc-c/c_helpers.h
|
|
+++ b/protoc-c/c_helpers.h
|
|
@@ -70,6 +70,10 @@
|
|
#include <protobuf-c/protobuf-c.pb.h>
|
|
#include <google/protobuf/io/printer.h>
|
|
|
|
+#if GOOGLE_PROTOBUF_VERSION >= 4023000
|
|
+# include <google/protobuf/descriptor_legacy.h>
|
|
+#endif
|
|
+
|
|
namespace google {
|
|
namespace protobuf {
|
|
namespace compiler {
|
|
@@ -172,7 +176,11 @@ int compare_name_indices_by_name(const void*, const void*);
|
|
// This wrapper is needed to be able to compile against protobuf2.
|
|
inline int FieldSyntax(const FieldDescriptor* field) {
|
|
#ifdef HAVE_PROTO3
|
|
+# if GOOGLE_PROTOBUF_VERSION >= 4023000
|
|
+ return FileDescriptorLegacy(field->file()).syntax() == FileDescriptorLegacy::SYNTAX_PROTO3 ? 3 : 2;
|
|
+# else
|
|
return field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 ? 3 : 2;
|
|
+# endif
|
|
#else
|
|
return 2;
|
|
#endif
|
|
--
|
|
2.33.0
|
|
|