Skip to content

Commit

Permalink
Merge pull request #12825 from protocolbuffers/fixes-23
Browse files Browse the repository at this point in the history
Backport fixes for 23.x
  • Loading branch information
mkruskal-google committed May 16, 2023
2 parents b0e0c59 + 67ecdde commit 71fca0c
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ jobs:
- name: Run tests
uses: protocolbuffers/protobuf-ci/docker@v1
with:
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:13.1-5.4.0-307caa02808127e49720f3e77d6a9f3b3ef5a915
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:12.2-5.4.0-307caa02808127e49720f3e77d6a9f3b3ef5a915
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
entrypoint: bash
command: >-
Expand Down
24 changes: 17 additions & 7 deletions csharp/src/Google.Protobuf/Reflection/DescriptorPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace Google.Protobuf.Reflection
{
Expand Down Expand Up @@ -176,8 +175,6 @@ internal void AddSymbol(IDescriptor descriptor)
descriptorsByName[fullName] = descriptor;
}

private static readonly Regex ValidationRegex = new Regex("^[_A-Za-z][_A-Za-z0-9]*$", FrameworkPortability.CompiledRegexWhereAvailable);

/// <summary>
/// Verifies that the descriptor's name is valid (i.e. it contains
/// only letters, digits and underscores, and does not start with a digit).
Expand All @@ -189,11 +186,24 @@ private static void ValidateSymbolName(IDescriptor descriptor)
{
throw new DescriptorValidationException(descriptor, "Missing name.");
}
if (!ValidationRegex.IsMatch(descriptor.Name))
{
throw new DescriptorValidationException(descriptor,
"\"" + descriptor.Name + "\" is not a valid identifier.");

// Symbol name must start with a letter or underscore, and it can contain letters,
// numbers and underscores.
string name = descriptor.Name;
if (!IsAsciiLetter(name[0]) && name[0] != '_') {
ThrowInvalidSymbolNameException(descriptor);
}
for (int i = 1; i < name.Length; i++) {
if (!IsAsciiLetter(name[i]) && !IsAsciiDigit(name[i]) && name[i] != '_') {
ThrowInvalidSymbolNameException(descriptor);
}
}

static bool IsAsciiLetter(char c) => (uint)((c | 0x20) - 'a') <= 'z' - 'a';
static bool IsAsciiDigit(char c) => (uint)(c - '0') <= '9' - '0';
static void ThrowInvalidSymbolNameException(IDescriptor descriptor) =>
throw new DescriptorValidationException(
descriptor, "\"" + descriptor.Name + "\" is not a valid identifier.");
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion objectivec/GPBAny.pbobjc.h

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

12 changes: 12 additions & 0 deletions src/google/protobuf/compiler/cpp/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,9 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
" ::$proto_ns$::internal::WireFormatLite::$val_wire_type$> "
"SuperType;\n"
" $classname$();\n"
// Templatize constexpr constructor as a workaround for a bug in gcc 12
// (warning in gcc 13).
" template <typename = void>\n"
" explicit PROTOBUF_CONSTEXPR $classname$(\n"
" ::$proto_ns$::internal::ConstantInitialized);\n"
" explicit $classname$(::$proto_ns$::Arena* arena);\n"
Expand Down Expand Up @@ -1248,6 +1251,9 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
format("~$classname$() override;\n");
}
format(
// Templatize constexpr constructor as a workaround for a bug in gcc 12
// (warning in gcc 13).
"template<typename = void>\n"
"explicit PROTOBUF_CONSTEXPR "
"$classname$(::$proto_ns$::internal::ConstantInitialized);\n"
"\n"
Expand Down Expand Up @@ -2449,13 +2455,19 @@ void MessageGenerator::GenerateConstexprConstructor(io::Printer* p) {
Formatter format(p);

if (IsMapEntryMessage(descriptor_) || !HasImplData(descriptor_, options_)) {
// Templatize constexpr constructor as a workaround for a bug in gcc 12
// (warning in gcc 13).
format(
"template <typename>\n"
"PROTOBUF_CONSTEXPR $classname$::$classname$(\n"
" ::_pbi::ConstantInitialized) {}\n");
return;
}

// Templatize constexpr constructor as a workaround for a bug in gcc 12
// (warning in gcc 13).
format(
"template <typename>\n"
"PROTOBUF_CONSTEXPR $classname$::$classname$(\n"
" ::_pbi::ConstantInitialized)");

Expand Down
4 changes: 4 additions & 0 deletions src/google/protobuf/compiler/plugin.pb.cc

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

4 changes: 4 additions & 0 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.

28 changes: 28 additions & 0 deletions src/google/protobuf/descriptor.pb.cc

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

0 comments on commit 71fca0c

Please sign in to comment.