-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
### Rationale for this change It'd be convenient to construct placeholder error Status cheaply. ### What changes are included in this PR? A constant error Status can now be constructed wrapped in a function like ```c++ Status UninitializedResult() { static StatusConstant uninitialized_result{StatusCode::UnknownError, "Uninitialized Result<T>"}; return uninitialized_result; } ``` Copying the constant status is relatively cheap (no heap interaction), so it's suitable for use as a placeholder error status. Added `bool Status::State::is_constant` which causes copies to be shallow and skips destruction. Also `Status::state_` is a const pointer now; this helps to ensure that it is obvious when we mutate state_ (as in AddContextLine). ### Are these changes tested? Minimal unit test added. The main consideration is probably benchmarks to make sure hot paths don't get much slower. ### Are there any user-facing changes? This API is not currently public; no user-facing changes. * GitHub Issue: #44491 Lead-authored-by: Benjamin Kietzman <[email protected]> Co-authored-by: Antoine Pitrou <[email protected]> Signed-off-by: Antoine Pitrou <[email protected]>
- Loading branch information
Showing
7 changed files
with
114 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
#pragma once | ||
|
||
#include "arrow/status.h" | ||
#include "arrow/util/logging.h" | ||
|
||
namespace arrow::internal { | ||
|
||
class StatusConstant { | ||
public: | ||
StatusConstant(StatusCode code, std::string msg, | ||
std::shared_ptr<StatusDetail> detail = nullptr) | ||
: state_{code, /*is_constant=*/true, std::move(msg), std::move(detail)} { | ||
ARROW_CHECK_NE(code, StatusCode::OK) | ||
<< "StatusConstant is not intended for use with OK status codes"; | ||
} | ||
|
||
operator Status() { // NOLINT(runtime/explicit) | ||
Status st; | ||
st.state_ = &state_; | ||
return st; | ||
} | ||
|
||
private: | ||
Status::State state_; | ||
}; | ||
|
||
} // namespace arrow::internal |
This file contains 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