mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Reading exported data from shared objects on windows is broken. It requires __declspec(dllimport). However, this is problematic, as we use the same static libraries both from a shared and static context. So we can't just blindly apply dllimport. The linker should have caught this, as data members are exported in a different way. However, due to a bug in native-utils, data member symbols were exposed directly. However, interacting with those data member was completely broken. The only way we can really solve this is to just not use static data members. We're pretty good about this in WPILib itself. However, protobuf is absolutely terrible at this. There are a ton of inline functions that access global data. For the protobuf library itself, we can solve this easily enough. However, for the generated protobuf code, this is much more problematic. The member needed to bypass the global data is private. This means using just the stock protobuf code, this problem is not solvable. But, protobuf generated code has insertion points. Those insertion points let us add our own code into the generated code via a protoc plugin. And it just so happens that an insertion point exists to add extra public methodsto the generated protobuf header. There is also an insertion point to let us add to the cpp file. The methods we need are the getters, for unpacking protobufs. For any protobuf that has a message as a member, we generate a new wpi_x() getter (the existing one is just x(), where x is the field name). We then implement this in the cpp file. A trick we can use is in the cpp file, we can safely call the x() function, as the cpp file is in the same library as the global. Thus we can call that inline method, and not actually need to directly access any internal private state of the protobuf object. TL;DR, all protobuf classes that have messages as fields now have a wpi_x() accessor that must be used instead of x() if you want the code to work on windows. After wpilibsuite/native-utils#212, the bad code will fail to link, rather then just fail at runtime.
96 lines
3.1 KiB
Diff
96 lines
3.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Peter Johnson <johnson.peter@gmail.com>
|
|
Date: Wed, 14 Jun 2023 00:02:26 -0700
|
|
Subject: [PATCH 10/13] Disable pedantic warning
|
|
|
|
---
|
|
src/google/protobuf/descriptor.h | 8 ++++++++
|
|
src/google/protobuf/generated_message_reflection.cc | 2 ++
|
|
src/google/protobuf/parse_context.h | 8 ++++++++
|
|
src/google/protobuf/stubs/common.cc | 4 ++--
|
|
4 files changed, 20 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h
|
|
index 6e536e5705f8df4f7c13638d50c114cbfb92fb4a..bee3e32b9f1d5ba47b83d1e388716a3c3b6e82c6 100644
|
|
--- a/src/google/protobuf/descriptor.h
|
|
+++ b/src/google/protobuf/descriptor.h
|
|
@@ -80,6 +80,10 @@
|
|
#define PROTOBUF_EXPORT
|
|
#endif
|
|
|
|
+#ifdef __GNUC__
|
|
+#pragma GCC diagnostic push
|
|
+#pragma GCC diagnostic ignored "-Wpedantic"
|
|
+#endif
|
|
|
|
namespace google {
|
|
namespace protobuf {
|
|
@@ -2434,6 +2438,10 @@ inline FileDescriptor::Syntax FileDescriptor::syntax() const {
|
|
} // namespace protobuf
|
|
} // namespace google
|
|
|
|
+#ifdef __GNUC__
|
|
+#pragma GCC diagnostic pop
|
|
+#endif
|
|
+
|
|
#undef PROTOBUF_INTERNAL_CHECK_CLASS_SIZE
|
|
#include <google/protobuf/port_undef.inc>
|
|
|
|
diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc
|
|
index 599dde80b671085d87ff1812929cafe8d2aecf75..aaed21920908b329e22c2e0d92f69397996a9f93 100644
|
|
--- a/src/google/protobuf/generated_message_reflection.cc
|
|
+++ b/src/google/protobuf/generated_message_reflection.cc
|
|
@@ -77,6 +77,8 @@ using google::protobuf::internal::WrappedMutex;
|
|
|
|
#ifdef _MSC_VER
|
|
#pragma warning(disable : 4065)
|
|
+#elif defined(__GNUC__)
|
|
+#pragma GCC diagnostic ignored "-Wpedantic"
|
|
#endif
|
|
|
|
namespace google {
|
|
diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h
|
|
index 7aea50cdc385f0ed01b3989e12276494bf574939..97daae09cbff11fd3b4b99cee935aeb542c42eb4 100644
|
|
--- a/src/google/protobuf/parse_context.h
|
|
+++ b/src/google/protobuf/parse_context.h
|
|
@@ -52,6 +52,10 @@
|
|
// Must be included last.
|
|
#include <google/protobuf/port_def.inc>
|
|
|
|
+#ifdef __GNUC__
|
|
+#pragma GCC diagnostic push
|
|
+#pragma GCC diagnostic ignored "-Wpedantic"
|
|
+#endif
|
|
|
|
namespace google {
|
|
namespace protobuf {
|
|
@@ -1020,6 +1024,10 @@ PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* UnknownFieldParse(
|
|
} // namespace protobuf
|
|
} // namespace google
|
|
|
|
+#ifdef __GNUC__
|
|
+#pragma GCC diagnostic pop
|
|
+#endif
|
|
+
|
|
#include <google/protobuf/port_undef.inc>
|
|
|
|
#endif // GOOGLE_PROTOBUF_PARSE_CONTEXT_H__
|
|
diff --git a/src/google/protobuf/stubs/common.cc b/src/google/protobuf/stubs/common.cc
|
|
index e0a807ffbbc94d07176e20db230204384170607b..1423021b846966eb02d36c10df488f8aa0082a64 100644
|
|
--- a/src/google/protobuf/stubs/common.cc
|
|
+++ b/src/google/protobuf/stubs/common.cc
|
|
@@ -277,11 +277,11 @@ LogHandler* SetLogHandler(LogHandler* new_func) {
|
|
|
|
LogSilencer::LogSilencer() {
|
|
++internal::log_silencer_count_;
|
|
-};
|
|
+}
|
|
|
|
LogSilencer::~LogSilencer() {
|
|
--internal::log_silencer_count_;
|
|
-};
|
|
+}
|
|
|
|
// ===================================================================
|
|
// emulates google3/base/callback.cc
|