Skip to content

Commit 71fca0c

Browse files
Merge pull request #12825 from protocolbuffers/fixes-23
Backport fixes for 23.x
2 parents b0e0c59 + 67ecdde commit 71fca0c

File tree

10 files changed

+112
-9
lines changed

10 files changed

+112
-9
lines changed

.github/workflows/test_cpp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ jobs:
234234
- name: Run tests
235235
uses: protocolbuffers/protobuf-ci/docker@v1
236236
with:
237-
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:13.1-5.4.0-307caa02808127e49720f3e77d6a9f3b3ef5a915
237+
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:12.2-5.4.0-307caa02808127e49720f3e77d6a9f3b3ef5a915
238238
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
239239
entrypoint: bash
240240
command: >-

csharp/src/Google.Protobuf/Reflection/DescriptorPool.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
using System;
3434
using System.Collections.Generic;
3535
using System.Text;
36-
using System.Text.RegularExpressions;
3736

3837
namespace Google.Protobuf.Reflection
3938
{
@@ -176,8 +175,6 @@ internal void AddSymbol(IDescriptor descriptor)
176175
descriptorsByName[fullName] = descriptor;
177176
}
178177

179-
private static readonly Regex ValidationRegex = new Regex("^[_A-Za-z][_A-Za-z0-9]*$", FrameworkPortability.CompiledRegexWhereAvailable);
180-
181178
/// <summary>
182179
/// Verifies that the descriptor's name is valid (i.e. it contains
183180
/// only letters, digits and underscores, and does not start with a digit).
@@ -189,11 +186,24 @@ private static void ValidateSymbolName(IDescriptor descriptor)
189186
{
190187
throw new DescriptorValidationException(descriptor, "Missing name.");
191188
}
192-
if (!ValidationRegex.IsMatch(descriptor.Name))
193-
{
194-
throw new DescriptorValidationException(descriptor,
195-
"\"" + descriptor.Name + "\" is not a valid identifier.");
189+
190+
// Symbol name must start with a letter or underscore, and it can contain letters,
191+
// numbers and underscores.
192+
string name = descriptor.Name;
193+
if (!IsAsciiLetter(name[0]) && name[0] != '_') {
194+
ThrowInvalidSymbolNameException(descriptor);
196195
}
196+
for (int i = 1; i < name.Length; i++) {
197+
if (!IsAsciiLetter(name[i]) && !IsAsciiDigit(name[i]) && name[i] != '_') {
198+
ThrowInvalidSymbolNameException(descriptor);
199+
}
200+
}
201+
202+
static bool IsAsciiLetter(char c) => (uint)((c | 0x20) - 'a') <= 'z' - 'a';
203+
static bool IsAsciiDigit(char c) => (uint)(c - '0') <= '9' - '0';
204+
static void ThrowInvalidSymbolNameException(IDescriptor descriptor) =>
205+
throw new DescriptorValidationException(
206+
descriptor, "\"" + descriptor.Name + "\" is not a valid identifier.");
197207
}
198208

199209
/// <summary>

objectivec/GPBAny.pbobjc.h

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/google/protobuf/compiler/cpp/message.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,9 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
11551155
" ::$proto_ns$::internal::WireFormatLite::$val_wire_type$> "
11561156
"SuperType;\n"
11571157
" $classname$();\n"
1158+
// Templatize constexpr constructor as a workaround for a bug in gcc 12
1159+
// (warning in gcc 13).
1160+
" template <typename = void>\n"
11581161
" explicit PROTOBUF_CONSTEXPR $classname$(\n"
11591162
" ::$proto_ns$::internal::ConstantInitialized);\n"
11601163
" explicit $classname$(::$proto_ns$::Arena* arena);\n"
@@ -1248,6 +1251,9 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
12481251
format("~$classname$() override;\n");
12491252
}
12501253
format(
1254+
// Templatize constexpr constructor as a workaround for a bug in gcc 12
1255+
// (warning in gcc 13).
1256+
"template<typename = void>\n"
12511257
"explicit PROTOBUF_CONSTEXPR "
12521258
"$classname$(::$proto_ns$::internal::ConstantInitialized);\n"
12531259
"\n"
@@ -2449,13 +2455,19 @@ void MessageGenerator::GenerateConstexprConstructor(io::Printer* p) {
24492455
Formatter format(p);
24502456

24512457
if (IsMapEntryMessage(descriptor_) || !HasImplData(descriptor_, options_)) {
2458+
// Templatize constexpr constructor as a workaround for a bug in gcc 12
2459+
// (warning in gcc 13).
24522460
format(
2461+
"template <typename>\n"
24532462
"PROTOBUF_CONSTEXPR $classname$::$classname$(\n"
24542463
" ::_pbi::ConstantInitialized) {}\n");
24552464
return;
24562465
}
24572466

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

src/google/protobuf/compiler/plugin.pb.cc

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/google/protobuf/compiler/plugin.pb.h

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/google/protobuf/descriptor.pb.cc

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)