CAutoFile
instead of re-implementing it allows to delete code and complexity.
refactor: Return CAutoFile from BlockManager::Open*File() #28483
pull maflcko wants to merge 3 commits into bitcoin:master from maflcko:2309-rework-block-file- changing 12 files +66 −84-
maflcko commented at 3:13 pm on September 14, 2023: memberThis is required for #28052, but makes sense on its own, because offloading logic to
-
DrahtBot commented at 3:13 pm on September 14, 2023: contributor
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Reviews
See the guideline for information on the review process.
Type Reviewers ACK TheCharlatan, willcl-ark If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
Conflicts
Reviewers, this pull request conflicts with the following ones:
- #28052 (blockstorage: XOR blocksdir *.dat files by MarcoFalke)
- #24230 (indexes: Stop using node internal types and locking cs_main, improve sync logic 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.
-
DrahtBot renamed this:
refactor: Return CAutoFile from BlockManager::Open*File()
refactor: Return CAutoFile from BlockManager::Open*File()
on Sep 14, 2023 -
DrahtBot added the label Refactoring on Sep 14, 2023
-
in src/streams.h:647 in faa45328e6 outdated
642- fclose(); 643- } 644- 645- // Disallow copies 646- BufferedFile(const BufferedFile&) = delete; 647- BufferedFile& operator=(const BufferedFile&) = delete;
TheCharlatan commented at 11:28 am on September 15, 2023:Nit: Would removing this in the second commit when theFILE *
is changed toCAutoFile
make more sense?
maflcko commented at 12:21 pm on September 15, 2023:Now thatfclose
is removed, copies are allowed, because they no longer lead to a double-free undefined behavior segfault (Callingfclose
twice on the same pointer)in src/streams.h:599 in fa33b6fba2 outdated
595@@ -598,9 +596,9 @@ class BufferedFile 596 readNow = nAvail; 597 if (readNow == 0) 598 return false; 599- size_t nBytes = fread((void*)&vchBuf[pos], 1, readNow, src); 600+ size_t nBytes{m_src.detail_fread(Span{vchBuf}.subspan(pos,readNow))};
TheCharlatan commented at 12:01 pm on September 15, 2023:Nit (clang-format): Space afterpos,
.
maflcko commented at 12:38 pm on September 15, 2023:Thanks, donein src/bench/streams_findbyte.cpp:22 in fa33b6fba2 outdated
17 data[file_size-1] = 1; 18- fwrite(&data, sizeof(uint8_t), file_size, file); 19- rewind(file); 20- BufferedFile bf{file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size, 0}; 21+ file << data; 22+ std::rewind(file.Get());
TheCharlatan commented at 12:08 pm on September 15, 2023:Nit: Includecstdio
where this is used?
maflcko commented at 12:38 pm on September 15, 2023:Added iwyu suggestions hereTheCharlatan approvedTheCharlatan commented at 12:11 pm on September 15, 2023: contributorACK fa33b6fba270e5867f208b242f50145e1ed3550erefactor: Drop unused fclose() from BufferedFile
This was only explicitly used in the tests, where it can be replaced by wrapping the original raw file pointer into a CAutoFile on creation and then calling CAutoFile::fclose(). Also, it was used in LoadExternalBlockFile(), where it can also be replaced by the (implicit call to the) CAutoFile destructor after wrapping the original raw file pointer in a CAutoFile.
Make BufferedFile to be a CAutoFile wrapper
This refactor allows to forward some calls to the underlying CAutoFile, instead of re-implementing the logic in the buffered file.
Return CAutoFile from BlockManager::Open*File()
This is a refactor.
maflcko force-pushed on Sep 15, 2023DrahtBot added the label CI failed on Sep 15, 2023DrahtBot removed the label CI failed on Sep 15, 2023TheCharlatan approvedTheCharlatan commented at 7:05 pm on September 15, 2023: contributorRe-ACK fa56c421be04af846f479c30749b17e6663ab418
Just addressing nits.
fanquake requested review from stickies-v on Sep 16, 2023willcl-ark approvedwillcl-ark commented at 12:43 pm on September 26, 2023: membertACK fa56c421be
Clean refactor needed for future work.
fanquake merged this on Sep 26, 2023fanquake closed this on Sep 26, 2023
Frank-GER referenced this in commit 45c80f5aa8 on Sep 27, 2023maflcko deleted the branch on Sep 28, 2023bitcoin locked this on Dec 3, 2024
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-12-22 06:12 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me