Add util::ResultPtr class #26022

pull ryanofsky wants to merge 8 commits into bitcoin:master from ryanofsky:pr/bresult-ptr changing 14 files +769 −176
  1. ryanofsky commented at 3:57 pm on September 6, 2022: contributor

    This is based on #25665. The non-base commits are:


    The util::ResultPtr class is a wrapper for util::Result providing syntax sugar to make it less awkward to use with returned pointers. Instead of needing to be deferenced twice with **result or (*result)->member, it only needs to be dereferenced once with *result or result->member. Also when it is used in a boolean context, instead of evaluating to true when there is no error and the pointer is null, it evaluates to false so it is straightforward to determine whether the result points to something.

    This PR is only partial a solution to #26004 because while it makes it easier to check for null pointer values, it does not make it impossible to return a null pointer value inside a successful result. It would be possible to enforce that successful results always contain non-null pointers by using a not_null type (https://github.com/bitcoin/bitcoin/issues/24423) in combination with ResultPtr, though.

  2. ryanofsky commented at 3:57 pm on September 6, 2022: contributor
    In draft state because it’s a partial solution to #26004 and could be discussed more
  3. DrahtBot commented at 11:11 pm on September 6, 2022: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #30364 (logging: Replace LogError and LogWarning with LogAlert by ryanofsky)
    • #30344 (kernel: remove mempool_persist by theuni)
    • #30342 (kernel, logging: Pass Logger instances to kernel objects by ryanofsky)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  4. DrahtBot added the label Needs rebase on Sep 19, 2022
  5. ryanofsky force-pushed on Sep 20, 2022
  6. ryanofsky commented at 6:28 pm on September 20, 2022: contributor
    Rebased 4b8ee99dea4d990ac21dd6074a15511bc7842a8e -> 123788cf6dd74510e2a5b4ea3c566dc512a871ef (pr/bresult-ptr.1 -> pr/bresult-ptr.2, compare) due to conflict with #26005
  7. DrahtBot removed the label Needs rebase on Sep 20, 2022
  8. DrahtBot added the label CI failed on May 30, 2023
  9. DrahtBot removed the label CI failed on May 31, 2023
  10. DrahtBot added the label Needs rebase on Oct 24, 2023
  11. ryanofsky force-pushed on Oct 26, 2023
  12. DrahtBot removed the label Needs rebase on Oct 26, 2023
  13. DrahtBot added the label CI failed on Jan 14, 2024
  14. ryanofsky force-pushed on Feb 21, 2024
  15. ryanofsky commented at 11:29 pm on February 21, 2024: contributor

    Rebased a1dddc5a2a86908d9ea677875ad67a79d2c71d14 -> 8ecac0885ef5b6fc2313cd2f8dfb48c10a05db27 (pr/bresult-ptr.3 -> pr/bresult-ptr.4, compare) on top of #25665.

    I also rewrote the commit and PR description. I think this is in a good state to review, despite being based on another PR.

  16. DrahtBot removed the label CI failed on Feb 22, 2024
  17. DrahtBot added the label Needs rebase on Apr 30, 2024
  18. ryanofsky force-pushed on May 1, 2024
  19. ryanofsky commented at 5:56 pm on May 1, 2024: contributor
    Rebased 8ecac0885ef5b6fc2313cd2f8dfb48c10a05db27 -> 9f58eb795ec5592c59f9af3269f004e589a2368f (pr/bresult-ptr.4 -> pr/bresult-ptr.5, compare) on top of latest #25665 (no other changes)
  20. DrahtBot removed the label Needs rebase on May 1, 2024
  21. DrahtBot added the label Needs rebase on May 20, 2024
  22. refactor: Add util::Result failure values
    Add util::Result support for returning more error information. For better error
    handling, adds the ability to return a value on failure, not just a value on
    success. This is a key missing feature that made the result class not useful
    for functions like LoadChainstate() which produce different errors that need to
    be handled differently.
    
    This change also makes some more minor improvements:
    
    - Smaller type size. util::Result<int> is 16 bytes, and util::Result<void> is 8
      bytes. Previously util::Result<int> and util::Result<void> were 72 bytes.
    
    - More documentation and tests.
    41f6b999d0
  23. refactor: Add util::Result::Update() method
    Add util::Result Update method to make it possible to change the value of an
    existing Result object. This will be useful for functions that can return
    multiple error and warning messages, and want to be able to change the result
    value while keeping existing messages.
    6fff420672
  24. refactor: Use util::Result class in LoadChainstate and VerifyLoadedChainstate 79a970d4f1
  25. refactor: Add util::Result multiple error and warning messages
    Add util::Result support for returning warning messages and multiple errors,
    not just a single error string. This provides a way for functions to report
    errors and warnings in a standard way, and simplifies interfaces.
    
    The functionality is unit tested here, and put to use in followup PR
    https://github.com/bitcoin/bitcoin/pull/25722
    ba959dbed3
  26. test: add static test for util::Result memory usage
    Suggested by Martin Leitner-Ankerl <martin.ankerl@gmail.com>
    https://github.com/bitcoin/bitcoin/pull/25722#discussion_r1174298529
    
    Co-authored-by: Martin Leitner-Ankerl <martin.ankerl@gmail.com>
    b08548336e
  27. Merge remote-tracking branch 'origin/pull/25665/head' 256987e499
  28. Add util::ResultPtr class
    The util::ResultPtr class is a wrapper for util::Result providing syntax sugar
    to make it less awkward to use with returned pointers. Instead of needing to be
    deferenced twice with **result or (*result)->member, it only needs to be
    dereferenced once with *result or result->member. Also when it is used in a
    boolean context, instead of evaluating to true when there is no error and the
    pointer is null, it evaluates to false so it is straightforward to determine
    whether the result points to something.
    
    This PR is only partial a solution to #26004 because while it makes it easier
    to check for null pointer values, it does not make it impossible to return a
    null pointer value inside a successful result. It would be possible to enforce
    that successful results always contain non-null pointers by using a not_null
    type (https://github.com/bitcoin/bitcoin/issues/24423) in combination with
    ResultPtr, though.
    40d119fa42
  29. Use ResultPtr<unique_ptr> instead of Result<unique_ptr> 73ec37294e
  30. ryanofsky force-pushed on Jun 17, 2024
  31. DrahtBot removed the label Needs rebase on Jun 17, 2024
  32. DrahtBot added the label Needs rebase on Jul 2, 2024
  33. DrahtBot commented at 11:19 am on July 2, 2024: contributor

    🐙 This pull request conflicts with the target branch and needs rebase.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-07-03 10:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me