Rich-T-kid opened a new pull request, #10317:
URL: https://github.com/apache/arrow-rs/pull/10317
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases. You can
link an issue to this PR using the GitHub syntax.
-->
- works towards #9843.
- a follow PR will be made to wire up the fallible API into other portions
of the code base.
# Rationale for this change
see #9843.
`MutableBuffer` is a low-level building block used throughout the Arrow
implementation. Every growth operation, `reserve`, `resize`, `push`,
`extend_from_slice`, etc, can panic on arithmetic overflow or an invalid
allocation layout. In library code that needs to surface errors gracefully.
This PR adds methods to return errors instead of panicking.
I made new methods instead of adding conditional checks/wrappers for each
method because its easier to slowly roll these changes out to call sites
instead of swapping.
<!--
Why are you proposing this change? If this is already explained clearly in
the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your
changes and offer better suggestions for fixes.
-->
# What changes are included in this PR?
```
┌──────────────────────────┬──────────────────────┐
│ Fallible │ Infallible │
├──────────────────────────┼──────────────────────┤
│ try_reserve │ reserve │
├──────────────────────────┼──────────────────────┤
│ try_repeat_slice_n_times │ repeat_slice_n_times │
├──────────────────────────┼──────────────────────┤
│ try_reallocate (private) │ reallocate │
├──────────────────────────┼──────────────────────┤
│ try_resize │ resize │
├──────────────────────────┼──────────────────────┤
│ try_shrink_to_fit │ shrink_to_fit │
├──────────────────────────┼──────────────────────┤
│ try_extend_from_slice │ extend_from_slice │
├──────────────────────────┼──────────────────────┤
│ try_push │ push │
├──────────────────────────┼──────────────────────┤
│ try_extend_zeros │ extend_zeros │
└──────────────────────────┴──────────────────────┘
```
<!--
There is no need to duplicate the description in the issue here but it is
sometimes worth providing a summary of the individual changes in this PR.
-->
# Are these changes tested?
Currently these methods aren't wired up to anything in the code base so I
didn't include any test. Id be happy to include some. The implementations of
the fallible API's are 1-1 to their non-fallible counter parts so i'm not sure
if this would be needed.
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are
they covered by existing tests)?
If this PR claims a performance improvement, please include evidence such as
benchmark results.
-->
# Are there any user-facing changes?
yes, users can now work with errors instead of having their programs panic.
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
If there are any breaking changes to public APIs, please call them out.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]