Skip to content

Commit

Permalink
Merge pull request #17331 from protocolbuffers/cp-cp
Browse files Browse the repository at this point in the history
Omit the `_raw_default_instance_` declaration when using DLL linkage.
  • Loading branch information
zhangskz authored Jul 9, 2024
2 parents c1ec82f + aec8a76 commit 861be78
Show file tree
Hide file tree
Showing 17 changed files with 22 additions and 141 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
config:
- { name: Optimized, flags: --config=opt }
- { name: Debug, flags: --config=dbg }
- { name: ASAN, flags: --config=asan, runner: ubuntu-20-large }
- { name: MSAN, flags: --config=docker-msan, runner: ubuntu-20-large }
- { name: TSAN, flags: --config=tsan, runner: ubuntu-20-large }
- { name: ASAN, flags: --config=asan, runner: ubuntu-20-4core }
- { name: MSAN, flags: --config=docker-msan, runner: ubuntu-20-4core }
- { name: TSAN, flags: --config=tsan, runner: ubuntu-20-4core }
- { name: UBSAN, flags: --config=ubsan }
- { name: No-RTTI, flags: --cxxopt=-fno-rtti }
include:
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
matrix:
arch: [x86_64, aarch64]
name: Linux Release ${{ matrix.arch}}
runs-on: ubuntu-latest
runs-on: ubuntu-20-4core
steps:
- name: Checkout pending changes
uses: protocolbuffers/protobuf-ci/checkout@v3
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test_upb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- { name: "Bazel 7", bazel_version: "7.1.1" }
- { name: "Fastbuild" }
- { name: "Optimized", flags: "-c opt" }
- { name: "ASAN", flags: "--config=asan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/...", runner: ubuntu-20-large }
- { name: "ASAN", flags: "--config=asan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/...", runner: ubuntu-20-4core }
- { name: "UBSAN", flags: "--config=ubsan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/... -//lua/..." }
- { name: "32-bit", flags: "--copt=-m32 --linkopt=-m32", exclude-targets: "-//benchmarks:benchmark -//python/..." }
# TODO: Add 32-bit ASAN test
Expand Down Expand Up @@ -172,13 +172,13 @@ jobs:
# supported Python versions and assume this gives us sufficient test
# coverage.
- { os: ubuntu-latest, python-version: "3.8", architecture: x64, type: 'binary' }
- { os: macos-11, python-version: "3.8", architecture: x64, type: 'binary' }
- { os: macos-12, python-version: "3.8", architecture: x64, type: 'binary' }
- { os: ubuntu-latest, python-version: "3.12", architecture: x64, type: 'binary' }
- { os: macos-12, python-version: "3.12", architecture: x64, type: 'binary' }
- { os: macos-13, python-version: "3.12", architecture: x64, type: 'binary' }
- { os: ubuntu-latest, python-version: "3.8", architecture: x64, type: 'source' }
- { os: macos-11, python-version: "3.8", architecture: x64, type: 'source' }
- { os: macos-12, python-version: "3.8", architecture: x64, type: 'source' }
- { os: ubuntu-latest, python-version: "3.12", architecture: x64, type: 'source' }
- { os: macos-12, python-version: "3.12", architecture: x64, type: 'source' }
- { os: macos-13, python-version: "3.12", architecture: x64, type: 'source' }

# Windows uses the full API up until Python 3.10.
- { os: windows-2019, python-version: "3.8", architecture: x86, type: 'binary' }
Expand Down
2 changes: 0 additions & 2 deletions src/google/protobuf/any.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions src/google/protobuf/api.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions src/google/protobuf/compiler/cpp/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,18 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
$pbi$::ParseContext* ctx);
)cc");
}},
{"raw_default_instance",
[&] {
// We can't make a constexpr pointer to the global if we have DLL
// linkage so skip this. The fallback in
// `MessageLite::GetStrongPointerForType` will do the right thing in
// those platforms.
if (!options_.dllexport_decl.empty()) return;
p->Emit(R"cc(
static constexpr const void* _raw_default_instance_ =
&_$classname$_default_instance_;
)cc");
}},
{"decl_impl", [&] { GenerateImplDefinition(p); }},
{"split_friend",
[&] {
Expand Down Expand Up @@ -2043,8 +2055,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
$decl_data$;
$post_loop_handler$;
static constexpr const void* _raw_default_instance_ =
&_$classname$_default_instance_;
$raw_default_instance$;
friend class ::$proto_ns$::MessageLite;
friend class ::$proto_ns$::Arena;
Expand Down
2 changes: 0 additions & 2 deletions src/google/protobuf/compiler/java/java_features.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions src/google/protobuf/compiler/plugin.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/google/protobuf/cpp_features.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 861be78

Please sign in to comment.