Repository navigation
GH-44464: [C++] Added rvalue-reference-qualified overload for arrow::Result::status() returning value instead of reference - #44477
Merged
mapleFU merged 1 commit intoNov 6, 2024
Conversation
|
|
pitrou
approved these changes
Oct 21, 2024
mapleFU
approved these changes
Oct 21, 2024
mapleFU
left a comment
Member
There was a problem hiding this comment.
This LGTM since seems that abseil do the same. Also paper like https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2718r0.html might prevent from this behavior...
bkietz
requested changes
Oct 21, 2024
…rrow::Result::status() returning value instead of reference
igor-anferov
force-pushed
the
GH-44464-arrow-result-status-on-rvalue-object
branch
from
November 3, 2024 21:24
2449343 to
5b5e898
Compare
bkietz
approved these changes
Nov 4, 2024
Contributor
Author
Member
|
Will merge this if no negative comment tonight |
Member
|
Thanks all, merged |
|
After merging your PR, Conbench analyzed the 3 benchmarking runs that have been run so far on merge-commit 6decf1c. There were no benchmark performance regressions. 🎉 The full Conbench report has more details. It also includes information about 29 possible false positives for unstable benchmarks that are known to sometimes produce them. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
In the current implementation,
arrow::Result::status()always returns the internalstatus_field by a const lvalue reference, regardless of the value category ofResult. This can lead to potential bugs. For example, consider the following code:In this case, the call to
status.ok()results in undefined behavior becausestatusis a dangling const lvalue reference that points to an object returned byfunctionReturningArrowResult(), which is destroyed after the semicolon.If
arrow::Resulthad two overloads of thestatus()method for different reference qualifiers:This would prevent such bugs and potentially allow for better optimization, as the
Statuscould be moved from an expiringResultobject.What changes are included in this PR?
This PR adds the proposed overload for the
arrow::Result::status()method and makes other rvalue-qualifiedarrow::Resultmethods preserve object ref-category during tailstatus()calls.Unfortunately, we can't move the
status_field in the rvalue-qualifiedstatus()method, as the state ofstatus_must be preserved until the destructor is called. This is because thestorage_field is either destructed or considered empty based on the state ofstatus_.Are these changes tested?
Since this change is trivial (the new overload doesn't modify the
Resultobject and returnsStatusby value), there's nothing significant to test, so no new tests were added.Are there any user-facing changes?
No existing code will be broken by this change. In all cases where
status()is called on an lvalueResult, the same reference-returning overload will be called. Meanwhile, code callingstatus()on an rvalueResultwill invoke the new overload, returningStatusby value instead.