Skip to content

Commit fa19c91

Browse files
author
MarcoFalke
committed
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-
1 parent fa2f241 commit fa19c91

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

src/bench/streams_findbyte.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static void FindByte(benchmark::Bench& bench)
1616
data[file_size-1] = 1;
1717
fwrite(&data, sizeof(uint8_t), file_size, file);
1818
rewind(file);
19-
CBufferedFile bf{file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size, 0};
19+
BufferedFile bf{file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size, 0};
2020

2121
bench.run([&] {
2222
bf.SetPos(0);

src/streams.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ class CAutoFile : public AutoFile
577577
* Will automatically close the file when it goes out of scope if not null.
578578
* If you need to close the file early, use file.fclose() instead of fclose(file).
579579
*/
580-
class CBufferedFile
580+
class BufferedFile
581581
{
582582
private:
583583
const int nVersion;
@@ -600,7 +600,7 @@ class CBufferedFile
600600
return false;
601601
size_t nBytes = fread((void*)&vchBuf[pos], 1, readNow, src);
602602
if (nBytes == 0) {
603-
throw std::ios_base::failure(feof(src) ? "CBufferedFile::Fill: end of file" : "CBufferedFile::Fill: fread failed");
603+
throw std::ios_base::failure(feof(src) ? "BufferedFile::Fill: end of file" : "BufferedFile::Fill: fread failed");
604604
}
605605
nSrcPos += nBytes;
606606
return true;
@@ -629,22 +629,22 @@ class CBufferedFile
629629
}
630630

631631
public:
632-
CBufferedFile(FILE* fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nVersionIn)
632+
BufferedFile(FILE* fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nVersionIn)
633633
: nVersion{nVersionIn}, nReadLimit{std::numeric_limits<uint64_t>::max()}, nRewind{nRewindIn}, vchBuf(nBufSize, std::byte{0})
634634
{
635635
if (nRewindIn >= nBufSize)
636636
throw std::ios_base::failure("Rewind limit must be less than buffer size");
637637
src = fileIn;
638638
}
639639

640-
~CBufferedFile()
640+
~BufferedFile()
641641
{
642642
fclose();
643643
}
644644

645645
// Disallow copies
646-
CBufferedFile(const CBufferedFile&) = delete;
647-
CBufferedFile& operator=(const CBufferedFile&) = delete;
646+
BufferedFile(const BufferedFile&) = delete;
647+
BufferedFile& operator=(const BufferedFile&) = delete;
648648

649649
int GetVersion() const { return nVersion; }
650650

@@ -711,7 +711,7 @@ class CBufferedFile
711711
}
712712

713713
template<typename T>
714-
CBufferedFile& operator>>(T&& obj) {
714+
BufferedFile& operator>>(T&& obj) {
715715
::Unserialize(*this, obj);
716716
return (*this);
717717
}

src/test/fuzz/buffered_file.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ FUZZ_TARGET(buffered_file)
1818
{
1919
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
2020
FuzzedFileProvider fuzzed_file_provider = ConsumeFile(fuzzed_data_provider);
21-
std::optional<CBufferedFile> opt_buffered_file;
21+
std::optional<BufferedFile> opt_buffered_file;
2222
FILE* fuzzed_file = fuzzed_file_provider.open();
2323
try {
2424
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>());

src/test/streams_tests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,15 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file)
260260
// The buffer size (second arg) must be greater than the rewind
261261
// amount (third arg).
262262
try {
263-
CBufferedFile bfbad{file, 25, 25, 333};
263+
BufferedFile bfbad{file, 25, 25, 333};
264264
BOOST_CHECK(false);
265265
} catch (const std::exception& e) {
266266
BOOST_CHECK(strstr(e.what(),
267267
"Rewind limit must be less than buffer size") != nullptr);
268268
}
269269

270270
// The buffer is 25 bytes, allow rewinding 10 bytes.
271-
CBufferedFile bf{file, 25, 10, 333};
271+
BufferedFile bf{file, 25, 10, 333};
272272
BOOST_CHECK(!bf.eof());
273273

274274
// This member has no functional effect.
@@ -356,7 +356,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file)
356356
BOOST_CHECK(false);
357357
} catch (const std::exception& e) {
358358
BOOST_CHECK(strstr(e.what(),
359-
"CBufferedFile::Fill: end of file") != nullptr);
359+
"BufferedFile::Fill: end of file") != nullptr);
360360
}
361361
// Attempting to read beyond the end sets the EOF indicator.
362362
BOOST_CHECK(bf.eof());
@@ -391,7 +391,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file_skip)
391391
rewind(file);
392392

393393
// The buffer is 25 bytes, allow rewinding 10 bytes.
394-
CBufferedFile bf{file, 25, 10, 333};
394+
BufferedFile bf{file, 25, 10, 333};
395395

396396
uint8_t i;
397397
// 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)
445445

446446
size_t bufSize = InsecureRandRange(300) + 1;
447447
size_t rewindSize = InsecureRandRange(bufSize);
448-
CBufferedFile bf{file, bufSize, rewindSize, 333};
448+
BufferedFile bf{file, bufSize, rewindSize, 333};
449449
size_t currentPos = 0;
450450
size_t maxPos = 0;
451451
for (int step = 0; step < 100; ++step) {

src/validation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4519,8 +4519,8 @@ void ChainstateManager::LoadExternalBlockFile(
45194519

45204520
int nLoaded = 0;
45214521
try {
4522-
// This takes over fileIn and calls fclose() on it in the CBufferedFile destructor
4523-
CBufferedFile blkdat{fileIn, 2 * MAX_BLOCK_SERIALIZED_SIZE, MAX_BLOCK_SERIALIZED_SIZE + 8, CLIENT_VERSION};
4522+
// This takes over fileIn and calls fclose() on it in the BufferedFile destructor
4523+
BufferedFile blkdat{fileIn, 2 * MAX_BLOCK_SERIALIZED_SIZE, MAX_BLOCK_SERIALIZED_SIZE + 8, CLIENT_VERSION};
45244524
// nRewind indicates where to resume scanning in case something goes wrong,
45254525
// such as a block fails to deserialize.
45264526
uint64_t nRewind = blkdat.GetPos();

0 commit comments

Comments
 (0)