1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
diff --git a/src/google/protobuf/generated_message_util.cc b/src/google/protobuf/generated_message_util.cc
index cb0c341553925..88996754a9278 100644
--- a/src/google/protobuf/generated_message_util.cc
+++ b/src/google/protobuf/generated_message_util.cc
@@ -83,27 +83,17 @@ static void InitWeakDefaults() {
void InitWeakDefaults() {}
#endif
-PROTOBUF_CONSTINIT std::atomic<bool> init_protobuf_defaults_state{false};
-static bool InitProtobufDefaultsImpl() {
- if (auto* to_destroy = fixed_address_empty_string.Init()) {
- OnShutdownDestroyString(to_destroy);
- }
- InitWeakDefaults();
-
-
- init_protobuf_defaults_state.store(true, std::memory_order_release);
- return true;
-}
-
+PROTOBUF_CONSTINIT bool init_protobuf_defaults_state{false};
void InitProtobufDefaultsSlow() {
- static bool is_inited = InitProtobufDefaultsImpl();
- (void)is_inited;
+ fixed_address_empty_string.Init();
+ init_protobuf_defaults_state = true;
+ InitWeakDefaults();
}
// Force the initialization of the empty string.
// Normally, registration would do it, but we don't have any guarantee that
// there is any object with reflection.
PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 static std::true_type init_empty_string =
- (InitProtobufDefaultsSlow(), std::true_type{});
+ (InitProtobufDefaults(), std::true_type{});
const std::string& GetEmptyString() {
InitProtobufDefaults();
diff --git a/src/google/protobuf/generated_message_util.h b/src/google/protobuf/generated_message_util.h
index 989734e57f5d5..f7e29d6028ebc 100644
--- a/src/google/protobuf/generated_message_util.h
+++ b/src/google/protobuf/generated_message_util.h
@@ -67,11 +67,14 @@ namespace internal {
// This fastpath inlines a single branch instead of having to make the
// InitProtobufDefaults function call.
// It also generates less inlined code than a function-scope static initializer.
-PROTOBUF_EXPORT extern std::atomic<bool> init_protobuf_defaults_state;
+PROTOBUF_EXPORT extern bool init_protobuf_defaults_state;
PROTOBUF_EXPORT void InitProtobufDefaultsSlow();
PROTOBUF_EXPORT inline void InitProtobufDefaults() {
- if (ABSL_PREDICT_FALSE(
- !init_protobuf_defaults_state.load(std::memory_order_acquire))) {
+ // This is not thread-safe, but is called within a static initializer. As long
+ // as there are no calls to this function from off the main thread, before
+ // main() starts, this is safe. After main() starts,
+ // init_protobuf_defaults_state will always be true.
+ if (ABSL_PREDICT_FALSE(!init_protobuf_defaults_state)) {
InitProtobufDefaultsSlow();
}
}
diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc
index edd6d5122598e..22c87f21587aa 100644
--- a/src/google/protobuf/port_def.inc
+++ b/src/google/protobuf/port_def.inc
@@ -574,16 +574,6 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3),
#define PROTOBUF_FINAL final
#endif
-// Determines the platforms where descriptor weak messages can be used.
-#ifdef PROTOBUF_DESCRIPTOR_WEAK_MESSAGES_ALLOWED
-#error PROTOBUF_DESCRIPTOR_WEAK_MESSAGES_ALLOWED was previously defined
-#endif
-#if defined(__GNUC__) && defined(__clang__) && !defined(__APPLE__) && \
- !defined(_MSC_VER) && !defined(_WIN32)
-#define PROTOBUF_DESCRIPTOR_WEAK_MESSAGES_ALLOWED
-#endif
-
-
// TODO: Enable the feature by default and remove this flag.
#ifdef PROTOBUF_PREFETCH_PARSE_TABLE
#error PROTOBUF_PREFETCH_PARSE_TABLE was previously defined
|