Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions .github/workflows/test_upb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
config:
- { name: "Fastbuild" }
- { name: "Optimized", flags: "-c opt", continuous-only: true }
- { name: "GCC Optimized", flags: "-c opt --force_pic --java_runtime_version=remotejdk_11 --copt=\"-Wno-error=maybe-uninitialized\"", image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:8.0.1-12.2-12e21b8dda91028bc14212a3ab582c7c4d149fac" }
- { name: "GCC Static", flags: "-c opt --dynamic_mode=off --java_runtime_version=remotejdk_11 --copt=\"-Wno-error=maybe-uninitialized\"", image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:8.0.1-12.2-12e21b8dda91028bc14212a3ab582c7c4d149fac", continuous-only: true }
- { name: "ASAN", flags: "--config=asan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/...", runner: ubuntu-22-4core }
- { name: "UBSAN", flags: "--config=ubsan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/... -//lua/...", continuous-only: true }
- { name: "32-bit", flags: "--copt=-m32 --linkopt=-m32", exclude-targets: "-//benchmarks:benchmark -//python/..." }
Expand All @@ -49,33 +51,12 @@ jobs:
if: ${{ !matrix.config.continuous-only || inputs.continuous-run }}
uses: protocolbuffers/protobuf-ci/bazel-docker@v5
with:
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/sanitize:${{ matrix.config.bazel_version || '8.0.1' }}-12e21b8dda91028bc14212a3ab582c7c4d149fac
image: ${{ matrix.config.image || 'us-docker.pkg.dev/protobuf-build/containers/test/linux/sanitize:8.0.1-12e21b8dda91028bc14212a3ab582c7c4d149fac' }}
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: upb-bazel
bazel: test //bazel/... //benchmarks/... //lua/... //python/... //upb/... //upb_generator/... ${{ matrix.config.flags }}
exclude-targets: ${{ matrix.config.exclude-targets }}

linux-gcc:
strategy:
fail-fast: false # Don't cancel all jobs if one fails.
name: GCC Optimized
runs-on: ubuntu-latest
steps:
- name: Checkout pending changes
uses: protocolbuffers/protobuf-ci/checkout@v5
with:
ref: ${{ inputs.safe-checkout }}
- name: Run tests
uses: protocolbuffers/protobuf-ci/bazel-docker@v5
with:
image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:8.0.1-12.2-12e21b8dda91028bc14212a3ab582c7c4d149fac"
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: "upb-bazel-gcc"
bazel: >-
test -c opt
--copt="-Wno-error=maybe-uninitialized" --java_runtime_version=remotejdk_11
//bazel/... //benchmarks/... //lua/... //python/... //upb/... //upb_generator/...

windows:
strategy:
fail-fast: false # Don't cancel all jobs if one fails.
Expand Down
2 changes: 2 additions & 0 deletions cmake/installed_include_golden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,14 @@ upb/message/value.h
upb/mini_descriptor/build_enum.h
upb/mini_descriptor/decode.h
upb/mini_descriptor/link.h
upb/mini_table/compat.h
upb/mini_table/debug_string.h
upb/mini_table/enum.h
upb/mini_table/extension.h
upb/mini_table/extension_registry.h
upb/mini_table/field.h
upb/mini_table/file.h
upb/mini_table/generated_registry.h
upb/mini_table/message.h
upb/mini_table/sub.h
upb/port/atomic.h
Expand Down
1 change: 1 addition & 0 deletions pkg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ cc_dist_library(
"//upb/json",
"//upb/message:compare",
"//upb/message:copy",
"//upb/mini_table:compat",
"//upb/mini_table:debug_string",
"//upb/text",
"//upb/text:debug",
Expand Down
5 changes: 5 additions & 0 deletions upb/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ cc_library(
"//upb/message:internal",
"//upb/mini_descriptor",
"//upb/mini_table",
"//upb/mini_table:internal",
"//upb/wire",
] + select({
":fasttable_enabled_setting": [
Expand Down Expand Up @@ -308,9 +309,13 @@ filegroup(
filegroup(
name = "test_srcs",
srcs = [
"//upb/hash:test_srcs",
"//upb/json:test_srcs",
"//upb/lex:test_srcs",
"//upb/mem:test_srcs",
"//upb/message:test_srcs",
"//upb/mini_descriptor:test_srcs",
"//upb/mini_table:test_srcs",
"//upb/test:test_srcs",
"//upb/util:test_srcs",
"//upb/wire:test_srcs",
Expand Down
1 change: 1 addition & 0 deletions upb/generated_code_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "upb/mini_table/extension_registry.h"
#include "upb/mini_table/field.h"
#include "upb/mini_table/file.h"
#include "upb/mini_table/internal/generated_registry.h"
#include "upb/mini_table/message.h"
#include "upb/mini_table/sub.h"
#include "upb/wire/decode.h"
Expand Down
2 changes: 1 addition & 1 deletion upb/hash/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ filegroup(
"**/*test.cc",
],
),
visibility = ["//pkg:__pkg__"],
visibility = ["//upb:__pkg__"],
)
2 changes: 1 addition & 1 deletion upb/lex/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ filegroup(
"**/*test.cc",
],
),
visibility = ["//pkg:__pkg__"],
visibility = ["//upb:__pkg__"],
)
2 changes: 1 addition & 1 deletion upb/mini_descriptor/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ filegroup(
"**/*test.cc",
],
),
visibility = ["//pkg:__pkg__"],
visibility = ["//upb:__pkg__"],
)
19 changes: 18 additions & 1 deletion upb/mini_table/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ cc_library(
name = "mini_table",
srcs = [
"extension_registry.c",
"generated_registry.c",
"message.c",
],
hdrs = [
Expand All @@ -36,6 +37,7 @@ cc_library(
"extension_registry.h",
"field.h",
"file.h",
"generated_registry.h",
"message.h",
"sub.h",
],
Expand Down Expand Up @@ -84,6 +86,7 @@ cc_library(
"internal/extension.h",
"internal/field.h",
"internal/file.h",
"internal/generated_registry.h",
"internal/message.h",
"internal/size_log2.h",
"internal/sub.h",
Expand All @@ -92,7 +95,6 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
"//upb/base",
"//upb/hash",
"//upb/mem",
"//upb/message:types",
"//upb/port",
Expand Down Expand Up @@ -131,6 +133,21 @@ cc_test(
],
)

cc_test(
name = "generated_registry_test",
srcs = ["generated_registry_test.cc"],
deps = [
":mini_table",
"//src/google/protobuf:descriptor_upb_minitable_proto",
"//upb/test:custom_options_upb_minitable_proto",
"//upb/test:editions_test_upb_minitable_proto",
"//upb/test:test_multiple_files_upb_minitable_proto",
"@abseil-cpp//absl/synchronization",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
)

proto_library(
name = "message_benchmark_proto",
testonly = 1,
Expand Down
43 changes: 33 additions & 10 deletions upb/mini_table/extension_registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "upb/hash/str_table.h"
#include "upb/mem/arena.h"
#include "upb/mini_table/extension.h"
#include "upb/mini_table/generated_registry.h"
#include "upb/mini_table/internal/generated_registry.h"
#include "upb/mini_table/message.h"

// Must be last.
Expand Down Expand Up @@ -89,25 +91,46 @@ upb_ExtensionRegistryStatus upb_ExtensionRegistry_AddArray(
return status;
}

#ifdef UPB_LINKARR_DECLARE

UPB_LINKARR_DECLARE(upb_AllExts, const upb_MiniTableExtension);
const UPB_PRIVATE(upb_GeneratedExtensionListEntry) *
UPB_PRIVATE(upb_generated_extension_list) = NULL;

bool upb_ExtensionRegistry_AddAllLinkedExtensions(upb_ExtensionRegistry* r) {
const upb_MiniTableExtension* start = UPB_LINKARR_START(upb_AllExts);
const upb_MiniTableExtension* stop = UPB_LINKARR_STOP(upb_AllExts);
for (const upb_MiniTableExtension* p = start; p < stop; p++) {
// Windows can introduce zero padding, so we have to skip zeroes.
if (upb_MiniTableExtension_Number(p) != 0) {
if (upb_ExtensionRegistry_Add(r, p) != kUpb_ExtensionRegistryStatus_Ok) {
const UPB_PRIVATE(upb_GeneratedExtensionListEntry)* entry =
UPB_PRIVATE(upb_generated_extension_list);
while (entry != NULL) {
// Comparing pointers to different objects is undefined behavior, so we
// convert them to uintptr_t and compare their values.
uintptr_t begin = (uintptr_t)entry->start;
uintptr_t end = (uintptr_t)entry->stop;
uintptr_t current = begin;
while (current < end) {
const upb_MiniTableExtension* ext =
(const upb_MiniTableExtension*)current;
// Sentinels and padding introduced by the linker can result in zeroed
// entries, so simply skip them.
if (upb_MiniTableExtension_Number(ext) == 0) {
// MSVC introduces padding that might not be sized exactly the same as
// upb_MiniTableExtension, so we can't iterate by sizeof. This is a
// valid thing for any linker to do, so it's safer to just always do it.
current += UPB_ALIGN_OF(upb_MiniTableExtension);
continue;
}

if (upb_ExtensionRegistry_Add(r, ext) !=
kUpb_ExtensionRegistryStatus_Ok) {
return false;
}
current += sizeof(upb_MiniTableExtension);
}
entry = entry->next;
}
return true;
}

#endif // UPB_LINKARR_DECLARE
const upb_ExtensionRegistry* upb_ExtensionRegistry_GetGenerated(
const upb_GeneratedRegistryRef* genreg) {
return genreg != NULL ? genreg->UPB_PRIVATE(registry) : NULL;
}

const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup(
const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num) {
Expand Down
12 changes: 9 additions & 3 deletions upb/mini_table/extension_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "upb/mem/arena.h"
#include "upb/mini_table/extension.h"
#include "upb/mini_table/generated_registry.h"
#include "upb/mini_table/message.h"

// Must be last.
Expand Down Expand Up @@ -79,8 +80,6 @@ UPB_API upb_ExtensionRegistryStatus upb_ExtensionRegistry_Add(
upb_ExtensionRegistryStatus upb_ExtensionRegistry_AddArray(
upb_ExtensionRegistry* r, const upb_MiniTableExtension** e, size_t count);

#ifdef UPB_LINKARR_DECLARE

// Adds all extensions linked into the binary into the registry. The set of
// linked extensions is assembled by the linker using linker arrays. This
// will likely not work properly if the extensions are split across multiple
Expand All @@ -94,7 +93,14 @@ upb_ExtensionRegistryStatus upb_ExtensionRegistry_AddArray(
UPB_API bool upb_ExtensionRegistry_AddAllLinkedExtensions(
upb_ExtensionRegistry* r);

#endif // UPB_LINKARR_DECLARE
// Returns the extension registry contained by a reference to the generated
// registry. The reference must be held for the lifetime of the registry.
//
// TODO This should actually be moved to generated_registry.h, but
// can't because of the current location of
// upb_ExtensionRegistry_AddAllLinkedExtensions.
UPB_API const upb_ExtensionRegistry* upb_ExtensionRegistry_GetGenerated(
const upb_GeneratedRegistryRef* genreg);

// Looks up the extension (if any) defined for message type |t| and field
// number |num|. Returns the extension if found, otherwise NULL.
Expand Down
Loading
Loading