Skip to content

Commit b2e39c1

Browse files
Adam Cozzettecopybara-github
authored andcommitted
Cherry-pick recent changes from the upb repo (#13908)
I merged a handful of PRs on the upb repo after upb moved into the protobuf repo. This PR cherry-picks them here so that they will not be lost. ``` commit 7afb426 Author: Keith Smiley <keithbsmiley@gmail.com> Date: Thu Sep 7 11:36:01 2023 -0700 [bazel] Fix disallowing dylibs on darwin (#1180) Since this bazel commit bazelbuild/bazel@ec55533 building dylibs like the ones in this rule on darwin platforms has been unsupported. This feature is a default C++ toolchain feature to indicate this. In bazel 7.x these dylibs will fail to link if they are still built. As far as I can tell in the tests even if they are built they are never used on macOS. Co-authored-by: Adam Cozzette <acozzette@google.com> commit 72decab Author: Keith Smiley <keithbsmiley@gmail.com> Date: Thu Sep 7 09:42:20 2023 -0700 Add missing darwin_x86_64 CPU (#1181) This CPU is often used when cross compiling from M1 machines. I'm also hoping we can remove the legacy 'darwin' CPU. commit ccadaf3 Author: messense <messense@icloud.com> Date: Fri Sep 8 00:28:54 2023 +0800 Fix `PyUpb_Message_MergeInternal` segfault (#1338) when `PyUpb_Message_MergeFromString` returns `NULL`, currently `PyUpb_Message_MergeInternal` will call `Py_DECREF` on `NULL` which results in a segmentation fault. This patch switches to `Py_XDECREF` to fix the segfault. commit 2a5724d Author: Kevin Greene <kgreenek@gmail.com> Date: Wed Sep 6 16:46:35 2023 -0700 Fix lambda capture compiler error with c++20 (#1502) When compiling with C++20, the following error is produced: ``` upb/mini_table.hpp:63:22: note: add explicit 'this' or '*this' capture upb/mini_table.hpp: In lambda function: upb/mini_table.hpp:71:22: error: implicit capture of 'this' via '[=]' is deprecated in C++20 [-Werror=deprecated] 71 | return appender_([=](char* buf) { ``` In C++20, it is no longer allowed to implicitly capture 'this' in a lambda using [=]. This commit explicitly captures required values in the appropriate lambdas and removes all uses of [=] with lambdas. ``` Closes #13908 COPYBARA_INTEGRATE_REVIEW=#13908 from acozzette:upb 7afb426 PiperOrigin-RevId: 563784513
1 parent 420f92a commit b2e39c1

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

upb/bazel/upb_proto_library.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def _cc_library_func(ctx, name, hdrs, srcs, copts, includes, dep_ccinfos):
153153
cc_toolchain = toolchain,
154154
compilation_outputs = compilation_outputs,
155155
linking_contexts = linking_contexts,
156-
disallow_dynamic_library = cc_common.is_enabled(feature_configuration = feature_configuration, feature_name = "targets_windows"),
156+
disallow_dynamic_library = cc_common.is_enabled(feature_configuration = feature_configuration, feature_name = "targets_windows") or not cc_common.is_enabled(feature_configuration = feature_configuration, feature_name = "supports_dynamic_linker"),
157157
)
158158

159159
return CcInfo(

upb/python/dist/dist.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def _get_suffix(limited_api, python_version, cpu):
2222
python_version += "m"
2323
abis = {
2424
"darwin_arm64": "darwin",
25+
"darwin_x86_64": "darwin",
2526
"darwin": "darwin",
2627
"osx-x86_64": "darwin",
2728
"osx-aarch_64": "darwin",

upb/python/message.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ static PyObject* PyUpb_Message_MergeInternal(PyObject* self, PyObject* arg,
12161216
if (!serialized) return NULL;
12171217
PyObject* ret = PyUpb_Message_MergeFromString(self, serialized);
12181218
Py_DECREF(serialized);
1219-
Py_DECREF(ret);
1219+
Py_XDECREF(ret);
12201220
Py_RETURN_NONE;
12211221
}
12221222

upb/upb/mini_descriptor/internal/encode.hpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,64 +43,66 @@ class MtDataEncoder {
4343
MtDataEncoder() : appender_(&encoder_) {}
4444

4545
bool StartMessage(uint64_t msg_mod) {
46-
return appender_([=](char* buf) {
46+
return appender_([this, msg_mod](char* buf) {
4747
return upb_MtDataEncoder_StartMessage(&encoder_, buf, msg_mod);
4848
});
4949
}
5050

5151
bool PutField(upb_FieldType type, uint32_t field_num, uint64_t field_mod) {
52-
return appender_([=](char* buf) {
52+
return appender_([this, type, field_num, field_mod](char* buf) {
5353
return upb_MtDataEncoder_PutField(&encoder_, buf, type, field_num,
5454
field_mod);
5555
});
5656
}
5757

5858
bool StartOneof() {
59-
return appender_([=](char* buf) {
59+
return appender_([this](char* buf) {
6060
return upb_MtDataEncoder_StartOneof(&encoder_, buf);
6161
});
6262
}
6363

6464
bool PutOneofField(uint32_t field_num) {
65-
return appender_([=](char* buf) {
65+
return appender_([this, field_num](char* buf) {
6666
return upb_MtDataEncoder_PutOneofField(&encoder_, buf, field_num);
6767
});
6868
}
6969

7070
bool StartEnum() {
71-
return appender_(
72-
[=](char* buf) { return upb_MtDataEncoder_StartEnum(&encoder_, buf); });
71+
return appender_([this](char* buf) {
72+
return upb_MtDataEncoder_StartEnum(&encoder_, buf);
73+
});
7374
}
7475

7576
bool PutEnumValue(uint32_t enum_value) {
76-
return appender_([=](char* buf) {
77+
return appender_([this, enum_value](char* buf) {
7778
return upb_MtDataEncoder_PutEnumValue(&encoder_, buf, enum_value);
7879
});
7980
}
8081

8182
bool EndEnum() {
82-
return appender_(
83-
[=](char* buf) { return upb_MtDataEncoder_EndEnum(&encoder_, buf); });
83+
return appender_([this](char* buf) {
84+
return upb_MtDataEncoder_EndEnum(&encoder_, buf);
85+
});
8486
}
8587

8688
bool EncodeExtension(upb_FieldType type, uint32_t field_num,
8789
uint64_t field_mod) {
88-
return appender_([=](char* buf) {
90+
return appender_([this, type, field_num, field_mod](char* buf) {
8991
return upb_MtDataEncoder_EncodeExtension(&encoder_, buf, type, field_num,
9092
field_mod);
9193
});
9294
}
9395

9496
bool EncodeMap(upb_FieldType key_type, upb_FieldType val_type,
9597
uint64_t key_mod, uint64_t val_mod) {
96-
return appender_([=](char* buf) {
98+
return appender_([this, key_type, val_type, key_mod, val_mod](char* buf) {
9799
return upb_MtDataEncoder_EncodeMap(&encoder_, buf, key_type, val_type,
98100
key_mod, val_mod);
99101
});
100102
}
101103

102104
bool EncodeMessageSet() {
103-
return appender_([=](char* buf) {
105+
return appender_([this](char* buf) {
104106
return upb_MtDataEncoder_EncodeMessageSet(&encoder_, buf);
105107
});
106108
}

0 commit comments

Comments
 (0)