aboutsummaryrefslogtreecommitdiff
path: root/src/span.h
AgeCommit message (Collapse)Author
2023-12-22Allow int8_t optimized vector serializationMarcoFalke
int8_t serialization is allowed, but not the optimized vector serialization. Fix that.
2023-12-15refactor: Print verbose serialize compiler error messagesMarcoFalke
2023-10-20span: Make Span template deduction guides work in SFINAE contextRyan Ofsky
Also add test to make sure this doesn't get broken in the future. This was breaking vector<bool> serialization in multiprocess code because template current deduction guides would make it appear like vector<bool> could be converted to a span, but then the actual conversion to span would fail.
2023-07-24refactor: Use reinterpret_cast where appropriateMarcoFalke
Also, wrap reinterpret_cast into a CharCast to ensure it is only called on byte pointers.
2023-07-24refactor: Avoid casting away constnessMarcoFalke
Seems confusing and brittle to remove const and then add it back in the return type.
2023-06-28refactor: Drop unsafe AsBytePtr functionRyan Ofsky
Replace calls to AsBytePtr with direct calls to AsBytes or reinterpret_cast. AsBytePtr is just a wrapper around reinterpret_cast. It accepts any type of pointer as an argument and uses reinterpret_cast to cast the argument to a std::byte pointer. Despite taking any type of pointer as an argument, it is not useful to call AsBytePtr on most types of pointers, because byte representations of most types will be implmentation-specific. Also, because it is named similarly to the AsBytes function, AsBytePtr looks safer than it actually is. Both AsBytes and AsBytePtr call reinterpret_cast internally and may be unsafe to use with certain types, but AsBytes at least has some type checking and can only be called on Span objects, while AsBytePtr can be called on any pointer argument. Co-authored-by: Pieter Wuille <pieter@wuille.net>
2023-06-23Add ElligatorSwift key creation and ECDH logicPieter Wuille
Co-authored-by: Dhruv Mehta <856960+dhruv@users.noreply.github.com>
2023-01-31clang-tidy: Fix `modernize-use-default-member-init` in headersHennadii Stepanov
See https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-default-member-init.html
2022-12-24scripted-diff: Bump copyright headersHennadii Stepanov
-BEGIN VERIFY SCRIPT- ./contrib/devtools/copyright_header.py update ./ -END VERIFY SCRIPT- Commits of previous years: - 2021: f47dda2c58b5d8d623e0e7ff4e74bc352dfa83d7 - 2020: fa0074e2d82928016a43ca408717154a1c70a4db - 2019: aaaaad6ac95b402fe18d019d67897ced6b316ee0
2022-04-26scripted-diff: rename BytePtr to AsBytePtrJoão Barbosa
Building with iPhoneOS SDK fails because it also has `BytePtr` defined in /usr/include/MacTypes.h. -BEGIN VERIFY SCRIPT- sed -i 's/BytePtr/AsBytePtr/' $(git grep -l "BytePtr" src) -END VERIFY SCRIPT-
2022-01-02span: Add BytePtr helperMarcoFalke
2021-12-30scripted-diff: Bump copyright headersHennadii Stepanov
-BEGIN VERIFY SCRIPT- ./contrib/devtools/copyright_header.py update ./ -END VERIFY SCRIPT- Commits of previous years: * 2020: fa0074e2d82928016a43ca408717154a1c70a4db * 2019: aaaaad6ac95b402fe18d019d67897ced6b316ee0
2021-11-29More Span simplificationsPieter Wuille
Based on suggestions by MarcoFalke <falke.marco@gmail.com>
2021-11-29Replace MakeSpan helper with Span deduction guidePieter Wuille
2021-11-24Merge bitcoin/bitcoin#23451: span: Add std::byte helpersMarcoFalke
faa3ec2304051be7cfbe301cfbfbda3faf7514fc span: Add std::byte helpers (MarcoFalke) fa18038f519db76befb9a7bd0b1540143bfeb12b refactor: Use ignore helper when unserializing an invalid pubkey (MarcoFalke) fabe18d0b39b4b918bf60e3a313eaa36fb4067f2 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 https://github.com/bitcoin/bitcoin/pull/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 faa3ec2304051be7cfbe301cfbfbda3faf7514fc Tree-SHA512: b1f6af39f03ea4dfebf20d4a8538fa993a6104e7fc92ddf0c4606a7efc3ca9a8c1a4741d98a1418569c11bb9ce9258bf0c0c06d93d85ed7e208902a2db04e407
2021-11-17Merge bitcoin/bitcoin#22881: doc: provide context for ↵W. J. van der Laan
CNetAddr::UnserializeV1Array() and span.h with lifetimebound 33c6a208a9e2512a174c99c224a933a59f091bc2 span, doc: provide span.h context and explain lifetimebound definition (Jon Atack) d14395bc5db55331115fa3c1e71741d1de7f092f net, doc: provide context for UnserializeV1Array() (Jon Atack) Pull request description: Add contextual documentation for developers and future readers of the code regarding - CNetAddr::UnserializeV1Array (see #22140) - Span and why it defines Clang lifetimebound locally rather than using the one in attributes.h ACKs for top commit: laanwj: Documentation review ACK 33c6a208a9e2512a174c99c224a933a59f091bc2 Tree-SHA512: cb8e6a6c23b36c9ef7499257e97c5378ec895bb9122b79b63b572d9721a1ae6ce6c0be7ad61bdf976c255527ae750fc9ff4b3e03c07c6c797d14dbc82ea9fb3a
2021-11-16doc: Fix typos in endif header commentsMarcoFalke
2021-11-09span: Add std::byte helpersMarcoFalke
Also, add Span<std::byte> interface to strencondings.
2021-09-23span, doc: provide span.h context and explain lifetimebound definitionJon Atack
2020-11-25Merge #19387: span: update constructors to match c++20 draft spec and add ↵MarcoFalke
lifetimebound attribute e3e7446305329ce96e9cf5f5161658eb2e1ea888 Add lifetimebound to attributes for general-purpose usage (Cory Fields) 1d58cc7cb040a70f768b632f294db4e0797d3a34 span: add lifetimebound attribute (Cory Fields) 62733fee874bfe7e833e71380eb8efd6a3126fbd span: (almost) match std::span's constructor behavior (Cory Fields) Pull request description: Replaces #19382 with a different approach. See [this comment](https://github.com/bitcoin/bitcoin/pull/19382#discussion_r446332852) for the reasoning behind the switch. -- Description from #19382: See [here](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0936r0.pdf) for more detail on lifetimebound. This is implemented using preprocesor macros rather than configure checks in order to keep span.h self-contained. The ```[[clang::lifetimebound]]``` syntax was chosen over ```__attribute__((lifetimebound))``` because the former is more flexible and works to guard ```this``` as well as function parameters, and also because at least for now, it's available only in clang. There are currently no violations in our codebase, but this can easily be tested by inserting one like this somewhere and compiling with a modern clang: ```c++ Span<const int> bad(std::vector<int>{1,2,3}); ``` The result: > warning: temporary whose address is used as value of local variable 'bad' will be destroyed at the end of the full-expression [-Wdangling] Span<const int> bad(std::vector<int>{1,2,3}); ``` ACKs for top commit: sipa: ACK e3e7446305329ce96e9cf5f5161658eb2e1ea888 ajtowns: ACK e3e7446305329ce96e9cf5f5161658eb2e1ea888 (drive by; only a quick skim of code and some basic sanity checks) MarcoFalke: review ACK e3e7446305329ce96e9cf5f5161658eb2e1ea888 🔗 jonatack: ACK e3e7446 change since last review is adding `[[clang::lifetimebound]]` as `LIFETIMEBOUND` to src/attributes.h as suggested in https://github.com/bitcoin/bitcoin/pull/19387#issuecomment-650752959. Tree-SHA512: 05a3440ee595ef0e8d693a2820b360707695c016a68e15df47c20cd8d053646cc6c8cca8addd7db40e72b3fce208879a41c8102ba7ae9223e4366e5de1175211
2020-07-30Add MakeUCharSpan, to help constructing Span<[const] unsigned char>Pieter Wuille
Based on a suggestion by Russell Yanofsky.
2020-07-19span: Add Span::empty() and use it in script/descriptorMarcoFalke
2020-06-29span: add lifetimebound attributeCory Fields
See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0936r0.pdf for reference. This helps to guard against dangling references caused by construction from temporaries such as: Span<const int> sp(std::vector<int>{1,2,3});
2020-06-29span: (almost) match std::span's constructor behaviorCory Fields
c++20's draft of std::span no longer includes move constructors.
2020-06-26doc: Document Span pitfallsPieter Wuille
2020-06-17Add sanity check asserts to span when -DDEBUGPieter Wuille
2020-05-12Add Span constructors for arrays and vectorsPieter Wuille
2020-05-12Make pointer-based Span construction saferPieter Wuille
This prevents constructing a Span<A> given two pointers into an array of B (where B is a subclass of A), at least without explicit cast to pointers to A.
2020-05-12Make Span size type unsignedPieter Wuille
This matches a change in the C++20 std::span proposal.
2020-04-30Merge #18591: Add C++17 build to TravisWladimir J. van der Laan
c31cbe7cfefc18123eb85ffb2ce509748435efde Add C++17 test to Travis (Pieter Wuille) 7829685e27aae25efb32e07368175c8f664b2218 Add configure option for c++17 (Pieter Wuille) 0fbde488b24f62b4bbbde216647941dcac65c81a Support conversion between Spans of compatible types (Pieter Wuille) 7cbfebbf3df0d26f518811e0bfb7abf270c83e37 Update ax_cxx_compile_stdcxx.m4 (Pieter Wuille) Pull request description: This adds a `--enable-c++17` option to the configure script, fixes the only C++17 incompatibility (with a commit taken from #18468), and adds a Travis test for it. This is all off by default, and release builds remain C++11. It implements the first step of the plan in https://github.com/bitcoin/bitcoin/issues/16684. ACKs for top commit: elichai: tACK c31cbe7cfefc18123eb85ffb2ce509748435efde practicalswift: Tested ACK c31cbe7cfefc18123eb85ffb2ce509748435efde hebasto: ACK c31cbe7cfefc18123eb85ffb2ce509748435efde, tested on Linux Mint 19.3 both C++11 and C++17 modes. Compiled and passed tests locally. Tree-SHA512: a4b00776dbceef9c12abbb404c6bcd48f7916ce24c8c7a14116355f64e817578b7fcddbedd5ce435322319d1e4de43429b68553f4d96d970c308fe3e3e59b9d1
2020-04-16scripted-diff: Bump copyright headersMarcoFalke
-BEGIN VERIFY SCRIPT- ./contrib/devtools/copyright_header.py update ./ -END VERIFY SCRIPT-
2020-04-11Support conversion between Spans of compatible typesPieter Wuille
2020-03-23Make VerifyWitnessProgram use a Span stackPieter Wuille
This allows for very cheap transformations on the range of elements that are to be passed to ExecuteWitnessScript.
2018-07-27Add more methods to Span classPieter Wuille
This introduces a rudimentary begin(), end(), operator[], and subspan to Span.
2018-04-05Add Slice: a (pointer, size) array view that acts like a containerPieter Wuille