mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-12 11:19:08 -05:00
scripted-diff: Rename CBufferedFile to BufferedFile
While touching all constructors in the previous commit, the class name can be adjusted to comply with the style guide. -BEGIN VERIFY SCRIPT- sed -i 's/CBufferedFile/BufferedFile/g' $( git grep -l CBufferedFile ) -END VERIFY SCRIPT-
This commit is contained in:
parent
fa2f2413b8
commit
fa19c914f7
5 changed files with 16 additions and 16 deletions
|
@ -16,7 +16,7 @@ static void FindByte(benchmark::Bench& bench)
|
||||||
data[file_size-1] = 1;
|
data[file_size-1] = 1;
|
||||||
fwrite(&data, sizeof(uint8_t), file_size, file);
|
fwrite(&data, sizeof(uint8_t), file_size, file);
|
||||||
rewind(file);
|
rewind(file);
|
||||||
CBufferedFile bf{file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size, 0};
|
BufferedFile bf{file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size, 0};
|
||||||
|
|
||||||
bench.run([&] {
|
bench.run([&] {
|
||||||
bf.SetPos(0);
|
bf.SetPos(0);
|
||||||
|
|
|
@ -577,7 +577,7 @@ public:
|
||||||
* Will automatically close the file when it goes out of scope if not null.
|
* Will automatically close the file when it goes out of scope if not null.
|
||||||
* If you need to close the file early, use file.fclose() instead of fclose(file).
|
* If you need to close the file early, use file.fclose() instead of fclose(file).
|
||||||
*/
|
*/
|
||||||
class CBufferedFile
|
class BufferedFile
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
const int nVersion;
|
const int nVersion;
|
||||||
|
@ -600,7 +600,7 @@ private:
|
||||||
return false;
|
return false;
|
||||||
size_t nBytes = fread((void*)&vchBuf[pos], 1, readNow, src);
|
size_t nBytes = fread((void*)&vchBuf[pos], 1, readNow, src);
|
||||||
if (nBytes == 0) {
|
if (nBytes == 0) {
|
||||||
throw std::ios_base::failure(feof(src) ? "CBufferedFile::Fill: end of file" : "CBufferedFile::Fill: fread failed");
|
throw std::ios_base::failure(feof(src) ? "BufferedFile::Fill: end of file" : "BufferedFile::Fill: fread failed");
|
||||||
}
|
}
|
||||||
nSrcPos += nBytes;
|
nSrcPos += nBytes;
|
||||||
return true;
|
return true;
|
||||||
|
@ -629,7 +629,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CBufferedFile(FILE* fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nVersionIn)
|
BufferedFile(FILE* fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nVersionIn)
|
||||||
: nVersion{nVersionIn}, nReadLimit{std::numeric_limits<uint64_t>::max()}, nRewind{nRewindIn}, vchBuf(nBufSize, std::byte{0})
|
: nVersion{nVersionIn}, nReadLimit{std::numeric_limits<uint64_t>::max()}, nRewind{nRewindIn}, vchBuf(nBufSize, std::byte{0})
|
||||||
{
|
{
|
||||||
if (nRewindIn >= nBufSize)
|
if (nRewindIn >= nBufSize)
|
||||||
|
@ -637,14 +637,14 @@ public:
|
||||||
src = fileIn;
|
src = fileIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
~CBufferedFile()
|
~BufferedFile()
|
||||||
{
|
{
|
||||||
fclose();
|
fclose();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disallow copies
|
// Disallow copies
|
||||||
CBufferedFile(const CBufferedFile&) = delete;
|
BufferedFile(const BufferedFile&) = delete;
|
||||||
CBufferedFile& operator=(const CBufferedFile&) = delete;
|
BufferedFile& operator=(const BufferedFile&) = delete;
|
||||||
|
|
||||||
int GetVersion() const { return nVersion; }
|
int GetVersion() const { return nVersion; }
|
||||||
|
|
||||||
|
@ -711,7 +711,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
CBufferedFile& operator>>(T&& obj) {
|
BufferedFile& operator>>(T&& obj) {
|
||||||
::Unserialize(*this, obj);
|
::Unserialize(*this, obj);
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ FUZZ_TARGET(buffered_file)
|
||||||
{
|
{
|
||||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||||
FuzzedFileProvider fuzzed_file_provider = ConsumeFile(fuzzed_data_provider);
|
FuzzedFileProvider fuzzed_file_provider = ConsumeFile(fuzzed_data_provider);
|
||||||
std::optional<CBufferedFile> opt_buffered_file;
|
std::optional<BufferedFile> opt_buffered_file;
|
||||||
FILE* fuzzed_file = fuzzed_file_provider.open();
|
FILE* fuzzed_file = fuzzed_file_provider.open();
|
||||||
try {
|
try {
|
||||||
opt_buffered_file.emplace(fuzzed_file, fuzzed_data_provider.ConsumeIntegralInRange<uint64_t>(0, 4096), fuzzed_data_provider.ConsumeIntegralInRange<uint64_t>(0, 4096), fuzzed_data_provider.ConsumeIntegral<int>());
|
opt_buffered_file.emplace(fuzzed_file, fuzzed_data_provider.ConsumeIntegralInRange<uint64_t>(0, 4096), fuzzed_data_provider.ConsumeIntegralInRange<uint64_t>(0, 4096), fuzzed_data_provider.ConsumeIntegral<int>());
|
||||||
|
|
|
@ -260,7 +260,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file)
|
||||||
// The buffer size (second arg) must be greater than the rewind
|
// The buffer size (second arg) must be greater than the rewind
|
||||||
// amount (third arg).
|
// amount (third arg).
|
||||||
try {
|
try {
|
||||||
CBufferedFile bfbad{file, 25, 25, 333};
|
BufferedFile bfbad{file, 25, 25, 333};
|
||||||
BOOST_CHECK(false);
|
BOOST_CHECK(false);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
BOOST_CHECK(strstr(e.what(),
|
BOOST_CHECK(strstr(e.what(),
|
||||||
|
@ -268,7 +268,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The buffer is 25 bytes, allow rewinding 10 bytes.
|
// The buffer is 25 bytes, allow rewinding 10 bytes.
|
||||||
CBufferedFile bf{file, 25, 10, 333};
|
BufferedFile bf{file, 25, 10, 333};
|
||||||
BOOST_CHECK(!bf.eof());
|
BOOST_CHECK(!bf.eof());
|
||||||
|
|
||||||
// This member has no functional effect.
|
// This member has no functional effect.
|
||||||
|
@ -356,7 +356,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file)
|
||||||
BOOST_CHECK(false);
|
BOOST_CHECK(false);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
BOOST_CHECK(strstr(e.what(),
|
BOOST_CHECK(strstr(e.what(),
|
||||||
"CBufferedFile::Fill: end of file") != nullptr);
|
"BufferedFile::Fill: end of file") != nullptr);
|
||||||
}
|
}
|
||||||
// Attempting to read beyond the end sets the EOF indicator.
|
// Attempting to read beyond the end sets the EOF indicator.
|
||||||
BOOST_CHECK(bf.eof());
|
BOOST_CHECK(bf.eof());
|
||||||
|
@ -391,7 +391,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file_skip)
|
||||||
rewind(file);
|
rewind(file);
|
||||||
|
|
||||||
// The buffer is 25 bytes, allow rewinding 10 bytes.
|
// The buffer is 25 bytes, allow rewinding 10 bytes.
|
||||||
CBufferedFile bf{file, 25, 10, 333};
|
BufferedFile bf{file, 25, 10, 333};
|
||||||
|
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
// This is like bf >> (7-byte-variable), in that it will cause data
|
// This is like bf >> (7-byte-variable), in that it will cause data
|
||||||
|
@ -445,7 +445,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file_rand)
|
||||||
|
|
||||||
size_t bufSize = InsecureRandRange(300) + 1;
|
size_t bufSize = InsecureRandRange(300) + 1;
|
||||||
size_t rewindSize = InsecureRandRange(bufSize);
|
size_t rewindSize = InsecureRandRange(bufSize);
|
||||||
CBufferedFile bf{file, bufSize, rewindSize, 333};
|
BufferedFile bf{file, bufSize, rewindSize, 333};
|
||||||
size_t currentPos = 0;
|
size_t currentPos = 0;
|
||||||
size_t maxPos = 0;
|
size_t maxPos = 0;
|
||||||
for (int step = 0; step < 100; ++step) {
|
for (int step = 0; step < 100; ++step) {
|
||||||
|
|
|
@ -4519,8 +4519,8 @@ void ChainstateManager::LoadExternalBlockFile(
|
||||||
|
|
||||||
int nLoaded = 0;
|
int nLoaded = 0;
|
||||||
try {
|
try {
|
||||||
// This takes over fileIn and calls fclose() on it in the CBufferedFile destructor
|
// This takes over fileIn and calls fclose() on it in the BufferedFile destructor
|
||||||
CBufferedFile blkdat{fileIn, 2 * MAX_BLOCK_SERIALIZED_SIZE, MAX_BLOCK_SERIALIZED_SIZE + 8, CLIENT_VERSION};
|
BufferedFile blkdat{fileIn, 2 * MAX_BLOCK_SERIALIZED_SIZE, MAX_BLOCK_SERIALIZED_SIZE + 8, CLIENT_VERSION};
|
||||||
// nRewind indicates where to resume scanning in case something goes wrong,
|
// nRewind indicates where to resume scanning in case something goes wrong,
|
||||||
// such as a block fails to deserialize.
|
// such as a block fails to deserialize.
|
||||||
uint64_t nRewind = blkdat.GetPos();
|
uint64_t nRewind = blkdat.GetPos();
|
||||||
|
|
Loading…
Add table
Reference in a new issue