-
Notifications
You must be signed in to change notification settings - Fork 658
build: Fix compilation errors when building with Protobuf 29.0+ #371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
build: Fix compilation errors when building with Protobuf 29.0+ #371
Conversation
|
Nice catch! Indeed, it cannot be used this way. Abseil's |
0600204
to
18da6a3
Compare
Force-pushed the branch to fix the problem discovered by @chriku. This fix uses direct |
This seems to be a bit much overkill for an error path that terminates the program anyway. if I'd gotten a ( |
@chriku Sure, you're absolutely right. This is an exceptional path, so indeed there's no need for extra typing to avoid a string copy. I'll post a fix a bit later. Thanks for the review! |
Starting from Protobuf 29.0, `protobuf::Message::GetTypeName()` can return either `std::string` or `absl::string_view`, depending on Abseil build options. For more details, see: protocolbuffers/protobuf@e13b8e9 Construct a temporary `std::string` to obtain a proper null-terminated buffer to use in `AssertMsg*`. Note that the lifetime of this instance will end just after the `AssertMsg2()` function call returns, hence this usage is safe (see https://eel.is/c++draft/class.temporary#4 for more details). Fixes: ValveSoftware#370 Signed-off-by: Pavel Solodovnikov <[email protected]>
18da6a3
to
f938f6f
Compare
Force-pushed the branch to implement the suggestion from @chriku to simplify the code. Also added a brief explanation about code safety with respect to the latest C++ standard draft. |
c++ lifetimes are always funny, eh? but the new code seems appropriate for the situation. PS: A small (hopefully helpful) hint: You (@ManManson) sound strangely AI like, be careful that you don't get misidentified and your PRs closed in fear of copyright uncertainties or worse |
Yep. That's the reason I've provided a thorough comment so that it doesn't make anyone looking at the code to raise an eyebrow. I think I've been writing like that long before AIs became manistream. I just happen to like explicit and verbose communication style when participating in public projects. 😄 |
Starting from Protobuf 29.0,
protobuf::Message::GetTypeName()
can return eitherstd::string
orabsl::string_view
, depending on Abseil build options.For more details, see:
Detect the return type of the method in compile-time and construct a supplementary
std::string
, from which we can obtain a proper null-terminated buffer and pass it to the internal assertion function, if needed.Fixes: #370