@@ -92,7 +92,7 @@ DATABASE DB = STATIC "yachts.lnk";
92
92
#define DB db_handle
93
93
#define isc_status status_vector
94
94
95
- const SSHORT BUCKETS= 5;
95
+ constexpr SSHORT BUCKETS= 5;
96
96
//#define WINDOW_SIZE (1 << 17)
97
97
98
98
struct dba_idx
@@ -130,7 +130,7 @@ struct dba_blob_statistics
130
130
FB_UINT64 blob_space = 0;
131
131
FB_UINT64 blob_pages = 0;
132
132
133
- dba_blob_statistics& operator+=(const dba_blob_statistics& rhs)
133
+ dba_blob_statistics& operator+=(const dba_blob_statistics& rhs) noexcept
134
134
{
135
135
blob_count += rhs.blob_count;
136
136
blob_space += rhs.blob_space;
@@ -202,9 +202,9 @@ static void analyze_index(const dba_rel*, dba_idx*);
202
202
static ULONG lastUsedPage(ULONG);
203
203
204
204
#if (defined WIN_NT)
205
- static void db_error(SLONG);
205
+ [[noreturn]] static void db_error(SLONG);
206
206
#else
207
- static void db_error(int);
207
+ [[noreturn]] static void db_error(int);
208
208
#endif
209
209
210
210
static USHORT get_format_length(ISC_STATUS*, isc_db_handle, isc_tr_handle, ISC_QUAD&);
@@ -216,7 +216,7 @@ static void db_close(void* file_desc);
216
216
#else
217
217
static void db_close(int);
218
218
#endif
219
- static void dba_error(USHORT, const SafeArg& arg = SafeArg());
219
+ [[noreturn]] static void dba_error(USHORT, const SafeArg& arg = SafeArg());
220
220
static void dba_print(bool, USHORT, const SafeArg& arg = SafeArg());
221
221
static void print_distribution(const SCHAR*, const ULONG*);
222
222
static void print_help();
@@ -239,45 +239,30 @@ struct dba_mem
239
239
240
240
// threading declarations for thread data
241
241
242
- class tdba : public ThreadData
242
+ class tdba final : public ThreadData
243
243
{
244
244
public:
245
245
explicit tdba(Firebird::UtilSvc* us)
246
246
: ThreadData(tddDBA), uSvc(us)
247
247
{
248
- //dba_throw = false;
249
- file = nullptr;
250
- relations = nullptr;
251
- schemas = nullptr;
252
- page_size = 0;
253
- dp_per_pp = 0;
254
- max_records = 0;
255
- page_number = 0;
256
- buffer1 = nullptr;
257
- buffer2 = nullptr;
258
- global_buffer = nullptr;
259
- exit_code = 0;
260
- head_of_mem_list = nullptr;
261
- memset(dba_status_vector, 0, sizeof (dba_status_vector));
262
248
dba_status = dba_status_vector;
263
249
}
264
250
265
- //bool dba_throw;
266
251
Firebird::UtilSvc* uSvc;
267
- dba_fil* file;
268
- dba_rel* relations;
269
- dba_schema* schemas;
270
- USHORT page_size;
271
- USHORT dp_per_pp;
272
- USHORT max_records;
273
- ULONG page_number;
274
- pag* buffer1;
275
- pag* buffer2;
276
- pag* global_buffer;
277
- int exit_code;
278
- dba_mem *head_of_mem_list;
252
+ dba_fil* file = nullptr ;
253
+ dba_rel* relations = nullptr ;
254
+ dba_schema* schemas = nullptr ;
255
+ USHORT page_size = 0 ;
256
+ USHORT dp_per_pp = 0 ;
257
+ USHORT max_records = 0 ;
258
+ ULONG page_number = 0 ;
259
+ pag* buffer1 = nullptr ;
260
+ pag* buffer2 = nullptr ;
261
+ pag* global_buffer = nullptr ;
262
+ int exit_code = 0 ;
263
+ dba_mem *head_of_mem_list = nullptr ;
279
264
ISC_STATUS *dba_status;
280
- ISC_STATUS_ARRAY dba_status_vector;
265
+ ISC_STATUS_ARRAY dba_status_vector{} ;
281
266
282
267
static inline tdba* getSpecific()
283
268
{
@@ -295,7 +280,7 @@ public:
295
280
};
296
281
297
282
298
- void inline dba_exit(int code, tdba* tddba)
283
+ [[noreturn]] void inline dba_exit(int code, tdba* tddba)
299
284
{
300
285
tddba->exit_code = code;
301
286
// Throw this kind of exception, because gstat uses status vector (and stuffException) to
@@ -310,7 +295,7 @@ namespace
310
295
311
296
bool shutdownRequested = false;
312
297
313
- int gstatShutdown(const int reason, const int, void*)
298
+ int gstatShutdown(const int reason, const int, void*) noexcept
314
299
{
315
300
if (reason == fb_shutrsn_signal)
316
301
{
@@ -328,7 +313,7 @@ namespace
328
313
}
329
314
}
330
315
331
- void getDateTime(char* datetime, FB_SIZE_T sizeof_datetime)
316
+ void getDateTime(char* datetime, FB_SIZE_T sizeof_datetime) noexcept
332
317
{
333
318
time_t t;
334
319
time(&t);
@@ -342,7 +327,7 @@ namespace
342
327
}
343
328
} // namespace
344
329
345
- const USHORT GSTAT_MSG_FAC = 21 ;
330
+ constexpr USHORT GSTAT_MSG_FAC = FB_IMPL_MSG_FACILITY_GSTAT ;
346
331
347
332
348
333
int main_gstat(Firebird::UtilSvc* uSvc)
@@ -651,7 +636,7 @@ int gstat(Firebird::UtilSvc* uSvc)
651
636
expandDatabaseName(fileName, tempStr, NULL);
652
637
fileName = tempStr;
653
638
654
- dba_fil* file = db_open(fileName.c_str(), fileName.length());
639
+ const dba_fil* file = db_open(fileName.c_str(), fileName.length());
655
640
656
641
alignas(DIRECT_IO_BLOCK_SIZE) SCHAR temp[MAX(RAW_HEADER_SIZE, DIRECT_IO_BLOCK_SIZE)];
657
642
tddba->page_size = MAX(RAW_HEADER_SIZE, DIRECT_IO_BLOCK_SIZE);
@@ -704,25 +689,25 @@ int gstat(Firebird::UtilSvc* uSvc)
704
689
class Statist
705
690
{
706
691
public:
707
- Statist()
692
+ Statist() noexcept
708
693
: enc(0), non(0)
709
694
{ }
710
695
711
- void print(USHORT messageNo)
696
+ void print(USHORT messageNo) const
712
697
{
713
698
dba_print(false, messageNo, SafeArg() << enc + non << enc << non);
714
699
// msg 5[2-4]: <TYPE> pages: total @1, encrypted @2, non-crypted @3
715
700
}
716
701
717
- void log(UCHAR flags)
702
+ void log(UCHAR flags) noexcept
718
703
{
719
704
if (flags & crypted_page)
720
705
++enc;
721
706
else
722
707
++non;
723
708
}
724
709
725
- bool hasCrypted()
710
+ bool hasCrypted() const noexcept
726
711
{
727
712
return enc > 0;
728
713
}
@@ -733,7 +718,7 @@ int gstat(Firebird::UtilSvc* uSvc)
733
718
734
719
Statist data, index, blob, generator, other;
735
720
736
- ULONG last = lastUsedPage(header->hdr_page_size);
721
+ const ULONG last = lastUsedPage(header->hdr_page_size);
737
722
for (page = 0; page <= last; ++page)
738
723
{
739
724
const pag* p = db_read(page, true);
@@ -782,7 +767,7 @@ int gstat(Firebird::UtilSvc* uSvc)
782
767
dpb.insertTag(isc_dpb_no_garbage_collect);
783
768
784
769
const unsigned char* authBlock;
785
- unsigned int authBlockSize = uSvc->getAuthBlock(&authBlock);
770
+ const unsigned int authBlockSize = uSvc->getAuthBlock(&authBlock);
786
771
if (authBlockSize)
787
772
{
788
773
dpb.insertBytes(isc_dpb_auth_block, authBlock, authBlockSize);
@@ -1052,7 +1037,7 @@ int gstat(Firebird::UtilSvc* uSvc)
1052
1037
1053
1038
average = relation->rel_records ?
1054
1039
(double) relation->rel_format_space / relation->rel_records : 0.0;
1055
- double average2 = relation->rel_record_space ?
1040
+ const double average2 = relation->rel_record_space ?
1056
1041
(double) relation->rel_format_space / relation->rel_record_space : 0.0;
1057
1042
uSvc->printf(false, " Average unpacked length: %.2f, compression ratio: %.2f\n",
1058
1043
average, average2);
@@ -1247,10 +1232,10 @@ int gstat(Firebird::UtilSvc* uSvc)
1247
1232
1248
1233
static ULONG lastUsedPage(ULONG pageSize)
1249
1234
{
1250
- const ULONG pipFirst = FIRST_PIP_PAGE;
1235
+ constexpr ULONG pipFirst = FIRST_PIP_PAGE;
1251
1236
ULONG pipLast = pipFirst;
1252
- ULONG pagesPerPIP = Ods::pagesPerPIP(pageSize);
1253
- ULONG bytesBitPIP = Ods::bytesBitPIP(pageSize);
1237
+ const ULONG pagesPerPIP = Ods::pagesPerPIP(pageSize);
1238
+ const ULONG bytesBitPIP = Ods::bytesBitPIP(pageSize);
1254
1239
page_inv_page* pip;
1255
1240
1256
1241
while (true)
@@ -1267,7 +1252,7 @@ static ULONG lastUsedPage(ULONG pageSize)
1267
1252
if (pip->pip_used != pagesPerPIP)
1268
1253
break;
1269
1254
1270
- UCHAR lastByte = pip->pip_bits[bytesBitPIP - 1];
1255
+ const UCHAR lastByte = pip->pip_bits[bytesBitPIP - 1];
1271
1256
if (lastByte & 0x80)
1272
1257
break;
1273
1258
@@ -1577,7 +1562,7 @@ static void analyze_index( const dba_rel* relation, dba_idx* index)
1577
1562
* Functional description
1578
1563
*
1579
1564
**************************************/
1580
- tdba* tddba = tdba::getSpecific();
1565
+ const tdba* tddba = tdba::getSpecific();
1581
1566
1582
1567
const index_root_page* index_root = (const index_root_page*) db_read(relation->rel_index_root);
1583
1568
@@ -1816,7 +1801,7 @@ static void db_close(void* file_desc)
1816
1801
CloseHandle(file_desc);
1817
1802
}
1818
1803
1819
- static void db_error( SLONG status)
1804
+ [[noreturn]] static void db_error( SLONG status)
1820
1805
{
1821
1806
/**************************************
1822
1807
*
@@ -1927,7 +1912,7 @@ static const pag* db_read( ULONG page_number, bool ok_enc)
1927
1912
if (SetFilePointer(tddba->file->fil_desc, (LONG) liOffset.LowPart, &liOffset.HighPart, FILE_BEGIN) ==
1928
1913
(DWORD) -1)
1929
1914
{
1930
- int lastError = GetLastError();
1915
+ const int lastError = GetLastError();
1931
1916
if (lastError != NO_ERROR)
1932
1917
{
1933
1918
tddba->uSvc->getStatusAccessor().setServiceStatus(GSTAT_MSG_FAC, 30, SafeArg());
@@ -1983,7 +1968,7 @@ static void db_close( int file_desc)
1983
1968
close(file_desc);
1984
1969
}
1985
1970
1986
- static void db_error( int status)
1971
+ [[noreturn]] static void db_error( int status)
1987
1972
{
1988
1973
/**************************************
1989
1974
*
@@ -2103,7 +2088,7 @@ static const pag* db_read( ULONG page_number, bool ok_enc)
2103
2088
#endif
2104
2089
2105
2090
2106
- static void dba_error(USHORT errcode, const SafeArg& arg)
2091
+ [[noreturn]] static void dba_error(USHORT errcode, const SafeArg& arg)
2107
2092
{
2108
2093
/**************************************
2109
2094
*
0 commit comments