Skip to content
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

<vector>, etc.: avoid _RERAISE in favor of usual scope guards #2307

Open
AlexGuteniev opened this issue Oct 29, 2021 · 3 comments
Open

<vector>, etc.: avoid _RERAISE in favor of usual scope guards #2307

AlexGuteniev opened this issue Oct 29, 2021 · 3 comments
Labels
enhancement Something can be improved

Comments

@AlexGuteniev
Copy link
Contributor

_RERAISE; expands to throw;, that is it rethrowing an exception.

This is used for cleanups in exception case.

It is inconvenient for debugging, when the same exception shows up twice.
Change this construct to usual scope guards.

@StephanTLavavej StephanTLavavej added the enhancement Something can be improved label Oct 29, 2021
@StephanTLavavej
Copy link
Member

Agreed; the inconsistency exists because _RERAISE is the original pattern and scope guards are the modern pattern, but we hadn't overhauled all occurrences.

This can be done incrementally, e.g. file-by-file.

AlexGuteniev added a commit to AlexGuteniev/STL that referenced this issue Oct 30, 2021
@StephanTLavavej StephanTLavavej changed the title <vector>, <mutex>, etc: avoid _RERAISE in favor of usual scope guards <vector>, etc.: avoid _RERAISE in favor of usual scope guards Jan 12, 2023
@StephanTLavavej
Copy link
Member

After the above PRs (thanks!) we're currently down to the following occurrences:

  • 2 in <chrono>
  • 1 in <iterator>
  • 1 in <ostream>
  • 10 in <vector>
  • 1 in <xiosbase>
  • 1 in <xpolymorphic_allocator.h>
  • 1 in <xtree>

@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Apr 27, 2023

  • 2 in <chrono>
    • I guess scope guard is unsuitable since sometimes we need to change the exception.
  • 10 in <vector>
    • There're nested try-catch-rethrow in the current implementation (now in _Insert_counted_range) which can't be directly converted to scope guards. We may need to heavily restructure _Insert_counted_range.

      STL/stl/inc/vector

      Lines 1173 to 1192 in 0a2d59e

      _TRY_BEGIN
      _Uninitialized_copy_n(_STD move(_First), _Count, _Whereptr, _Al);
      _CATCH_ALL
      // glue the broken pieces back together
      _TRY_BEGIN
      _Uninitialized_move(_Whereptr + _Count, _Whereptr + 2 * _Count, _Whereptr, _Al);
      _CATCH_ALL
      // vaporize the detached piece
      _Orphan_range(_Whereptr, _Oldlast);
      _Destroy_range(_Whereptr + _Count, _Mylast, _Al);
      _Mylast = _Whereptr;
      _RERAISE;
      _CATCH_END
      _STD _Move_unchecked(_Whereptr + 2 * _Count, _Mylast, _Whereptr + _Count);
      _Destroy_range(_Oldlast, _Mylast, _Al);
      _Mylast = _Oldlast;
      _RERAISE;
      _CATCH_END

      STL/stl/inc/vector

      Lines 1198 to 1216 in 0a2d59e

      _TRY_BEGIN
      _Uninitialized_copy_n(_STD move(_First), _Count, _Whereptr, _Al);
      _CATCH_ALL
      // glue the broken pieces back together
      _TRY_BEGIN
      _Uninitialized_move(_Relocated, _Mylast, _Whereptr, _Al);
      _CATCH_ALL
      // vaporize the detached piece
      _Orphan_range(_Whereptr, _Oldlast);
      _Destroy_range(_Relocated, _Mylast, _Al);
      _Mylast = _Whereptr;
      _RERAISE;
      _CATCH_END
      _Destroy_range(_Relocated, _Mylast, _Al);
      _Mylast = _Oldlast;
      _RERAISE;
      _CATCH_END
  • 1 in <xiosbase>
    • I don't think this is doable because iostream classes are designed to be conditionally rethrowing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something can be improved
Projects
None yet
Development

No branches or pull requests

3 participants