Skip to content

Conversation

@maflcko
Copy link
Member

@maflcko maflcko commented Nov 6, 2021

This adds (currently unused) span std::byte helpers, so that they can be used in new code.

The refactors are also required for #23438, but they are split up because the other pull doesn't compile with msvc right now.

The third commit is not needed for the other pull, but still nice.

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 7, 2021

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #23438 (refactor: Use spans of std::byte in serialize by MarcoFalke)
  • #23413 (Replace MakeSpan helper with Span deduction guide by sipa)

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.

@laanwj
Copy link
Member

laanwj commented Nov 8, 2021

This adds (currently unused) span std::byte helpers, so that they can be used in new code.

Let's make sure they are at least all used in tests in some way (I haven't checked if this is the case).

Copy link
Contributor

@klementtan klementtan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review and tested ACK fae93c5

Tested by writing an Adhoc unit test klementtan@129b1e0 (feel free to copy the test into this PR)

MarcoFalke added 3 commits November 9, 2021 17:41
Also, simplify unit tests with the CDataStream::str method.
Also, add Span<std::byte> interface to strencondings.
@maflcko
Copy link
Member Author

maflcko commented Nov 9, 2021

Thanks for the tests. However, I think the line

   BOOST_CHECK_EQUAL(std::to_integer<int>(byte_span_char[6]), '\0');

is undefined behavior. The size of the span should be 6, so at most it is allowed to read [5].
Also, the uint32_t tests will fail on different endian hardware?

I've pushed a commit with my own tests for all newly added functions.

@klementtan
Copy link
Contributor

reACK faa3ec2. Verified that all the new std::byte helper functions are tested.

@MarcoFalke Yup you're right, [6] would lead UB (it would have thrown assertion error if I compiled with--enable-debug) and the uint32_t tests would only work on little-endian machine. My bad! 😅

char dummy;
while (len--)
s.read(&dummy, 1);
s.ignore(len);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the most tricky change to review I think; whether the behavior here stays the same in all cases, also in edge cases at the end of the stream.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only change should be in the error message and a missing call to memcpy.

-CDataStream::read(): end of data
+CDataStream::ignore(): end of data

The commit is unrelated and not needed for the changes here, so I am happy to remove. If it will be removed, I'd later on need to replace char dummy; with std::byte dummy;.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with keeping it. I personally think the change is correct, just mentioned it as a point of focus for reviewers.

@laanwj
Copy link
Member

laanwj commented Nov 16, 2021

Code review ACK faa3ec2

@maflcko maflcko merged commit 9394964 into bitcoin:master Nov 24, 2021
@maflcko maflcko deleted the 2111-refSpan branch November 24, 2021 10:20
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Nov 24, 2021
faa3ec2 span: Add std::byte helpers (MarcoFalke)
fa18038 refactor: Use ignore helper when unserializing an invalid pubkey (MarcoFalke)
fabe18d Use value_type in CDataStream where possible (MarcoFalke)

Pull request description:

  This adds (currently unused) span std::byte helpers, so that they can be used in new code.

  The refactors are also required for bitcoin#23438, but they are split up because the other pull doesn't compile with msvc right now.

  The third commit is not needed for the other pull, but still nice.

ACKs for top commit:
  klementtan:
    reACK  faa3ec2. Verified that all the new `std::byte` helper functions are tested.
  laanwj:
    Code review ACK faa3ec2

Tree-SHA512: b1f6af39f03ea4dfebf20d4a8538fa993a6104e7fc92ddf0c4606a7efc3ca9a8c1a4741d98a1418569c11bb9ce9258bf0c0c06d93d85ed7e208902a2db04e407
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Nov 24, 2021
faa3ec2 span: Add std::byte helpers (MarcoFalke)
fa18038 refactor: Use ignore helper when unserializing an invalid pubkey (MarcoFalke)
fabe18d Use value_type in CDataStream where possible (MarcoFalke)

Pull request description:

  This adds (currently unused) span std::byte helpers, so that they can be used in new code.

  The refactors are also required for bitcoin#23438, but they are split up because the other pull doesn't compile with msvc right now.

  The third commit is not needed for the other pull, but still nice.

ACKs for top commit:
  klementtan:
    reACK  faa3ec2. Verified that all the new `std::byte` helper functions are tested.
  laanwj:
    Code review ACK faa3ec2

Tree-SHA512: b1f6af39f03ea4dfebf20d4a8538fa993a6104e7fc92ddf0c4606a7efc3ca9a8c1a4741d98a1418569c11bb9ce9258bf0c0c06d93d85ed7e208902a2db04e407
Copy link

@Bigboy1982 Bigboy1982 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good

@bitcoin bitcoin locked and limited conversation to collaborators May 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants