Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into fix_14509
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLunn committed Oct 27, 2023
2 parents 4ceb5f3 + 37cae2d commit a3f9d0b
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 198 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_upb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: "upb-bazel-windows"
bazel: test --cxxopt=/std:c++17 --host_cxxopt=/std:c++17 //upb/... //upb_generator/... //python/... //protos/... //protos_generator/...
exclude-targets: -//python:conformance_test -//upb:def_builder_test
exclude-targets: -//python:conformance_test -//upb/reflection:def_builder_test

macos:
strategy:
Expand Down
1 change: 1 addition & 0 deletions python/dist/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ pkg_files(
"//upb/mini_descriptor:source_files",
"//upb/mini_table:source_files",
"//upb/port:source_files",
"//upb/reflection:source_files",
"//upb/text:source_files",
"//upb/util:source_files",
"//upb/wire:source_files",
Expand Down
2 changes: 2 additions & 0 deletions python/google/protobuf/internal/api_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import sys
import warnings

_GOOGLE3_PYTHON_UPB_DEFAULT = False


def _ApiVersionToImplementationType(api_version):
if api_version == 2:
Expand Down
3 changes: 3 additions & 0 deletions src/google/protobuf/extension_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "google/protobuf/extension_set.h"

#include <atomic>
#include <string>
#include <tuple>
#include <type_traits>
Expand Down Expand Up @@ -1933,6 +1934,8 @@ LazyEagerVerifyFnType FindExtensionLazyEagerVerifyFn(
return nullptr;
}

std::atomic<ExtensionSet::LazyMessageExtension* (*)(Arena* arena)>
ExtensionSet::maybe_create_lazy_extension_;

} // namespace internal
} // namespace protobuf
Expand Down
16 changes: 11 additions & 5 deletions src/google/protobuf/extension_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define GOOGLE_PROTOBUF_EXTENSION_SET_H__

#include <algorithm>
#include <atomic>
#include <cassert>
#include <string>
#include <type_traits>
Expand Down Expand Up @@ -57,6 +58,7 @@ class FeatureSet;
namespace internal {
class FieldSkipper; // wire_format_lite.h
class WireFormat;
void InitializeLazyExtensionSet();
} // namespace internal
} // namespace protobuf
} // namespace google
Expand Down Expand Up @@ -508,6 +510,8 @@ class PROTOBUF_EXPORT ExtensionSet {
friend class google::protobuf::Reflection;
friend class google::protobuf::internal::WireFormat;

friend void internal::InitializeLazyExtensionSet();

const int32_t& GetRefInt32(int number, const int32_t& default_value) const;
const int64_t& GetRefInt64(int number, const int64_t& default_value) const;
const uint32_t& GetRefUInt32(int number, const uint32_t& default_value) const;
Expand Down Expand Up @@ -579,7 +583,13 @@ class PROTOBUF_EXPORT ExtensionSet {
virtual void UnusedKeyMethod(); // Dummy key method to avoid weak vtable.
};
// Give access to function defined below to see LazyMessageExtension.
friend LazyMessageExtension* MaybeCreateLazyExtension(Arena* arena);
static LazyMessageExtension* MaybeCreateLazyExtensionImpl(Arena* arena);
static LazyMessageExtension* MaybeCreateLazyExtension(Arena* arena) {
auto* f = maybe_create_lazy_extension_.load(std::memory_order_relaxed);
return f != nullptr ? f(arena) : nullptr;
}
static std::atomic<LazyMessageExtension* (*)(Arena* arena)>
maybe_create_lazy_extension_;
struct Extension {
// The order of these fields packs Extension into 24 bytes when using 8
// byte alignment. Consider this when adding or removing fields here.
Expand Down Expand Up @@ -1529,10 +1539,6 @@ class ExtensionIdentifier {
// Generated accessors


// Used to retrieve a lazy extension, may return nullptr in some environments.
extern PROTOBUF_ATTRIBUTE_WEAK ExtensionSet::LazyMessageExtension*
MaybeCreateLazyExtension(Arena* arena);

// Define a specialization of ExtensionIdentifier for bootstrapped extensions
// that we need to register lazily.
template <>
Expand Down
5 changes: 5 additions & 0 deletions src/google/protobuf/generated_message_reflection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <cstdint>
#include <cstring>
#include <string>
#include <type_traits>

#include "absl/base/call_once.h"
#include "absl/base/casts.h"
Expand Down Expand Up @@ -93,6 +94,9 @@ void InitializeFileDescriptorDefaultInstances() {
#endif // !defined(PROTOBUF_CONSTINIT_DEFAULT_INSTANCES)
}

void InitializeLazyExtensionSet() {
}

bool ParseNamedEnum(const EnumDescriptor* descriptor, absl::string_view name,
int* value) {
const EnumValueDescriptor* d = descriptor->FindValueByName(name);
Expand Down Expand Up @@ -3660,6 +3664,7 @@ void AddDescriptorsImpl(const DescriptorTable* table) {
// Reflection refers to the default fields so make sure they are initialized.
internal::InitProtobufDefaults();
internal::InitializeFileDescriptorDefaultInstances();
internal::InitializeLazyExtensionSet();

// Ensure all dependent descriptors are registered to the generated descriptor
// pool and message factory.
Expand Down
Loading

0 comments on commit a3f9d0b

Please sign in to comment.