Skip to content

Commit 2af5dca

Browse files
committed
Fix conversion warnings in blob
+ constexpr and misc other changes
1 parent 2935c4c commit 2af5dca

File tree

3 files changed

+106
-107
lines changed

3 files changed

+106
-107
lines changed

src/jrd/blb.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,10 @@ blb* blb::create2(thread_db* tdbb,
279279
Database* dbb = tdbb->getDatabase();
280280
CHECK_DBB(dbb);
281281

282-
const int maxTempBlobs = MAX_TEMP_BLOBS;
283-
if (maxTempBlobs > 0 && transaction->tra_temp_blobs_count >= maxTempBlobs)
282+
if constexpr (MAX_TEMP_BLOBS == 0) {
283+
// unlimited temp blobs
284+
}
285+
else if (transaction->tra_temp_blobs_count >= MAX_TEMP_BLOBS)
284286
{
285287
const Request* request = tdbb->getRequest();
286288
string info;
@@ -308,7 +310,7 @@ blb* blb::create2(thread_db* tdbb,
308310
}
309311
}
310312

311-
gds__log("Too many temporary blobs (%i allowed)\n%s", maxTempBlobs, info.c_str());
313+
gds__log("Too many temporary blobs (%u allowed)\n%s", MAX_TEMP_BLOBS, info.c_str());
312314

313315
ERR_post(Arg::Gds(isc_random) << Arg::Str("Too many temporary blobs"));
314316
}
@@ -984,13 +986,12 @@ SLONG blb::BLB_lseek(USHORT mode, SLONG offset)
984986
else if (mode == 2)
985987
position += blb_length;
986988

987-
if (position < 0)
988-
position = 0;
989-
990-
if (position > blb_length)
991-
position = blb_length;
992-
993-
blb_seek = (FB_UINT64) position;
989+
if (position <= 0)
990+
blb_seek = 0;
991+
else if (static_cast<FB_UINT64>(position) > blb_length)
992+
blb_seek = blb_length;
993+
else
994+
blb_seek = static_cast<FB_UINT64>(position);
994995
blb_flags |= BLB_seek;
995996
blb_flags &= ~BLB_eof;
996997

@@ -2127,7 +2128,7 @@ static ISC_STATUS blob_filter(USHORT action, BlobControl* control)
21272128

21282129
case isc_blob_filter_seek:
21292130
fb_assert(false);
2130-
// fail through ...
2131+
[[fallthrough]];
21312132

21322133
default:
21332134
ERR_post(Arg::Gds(isc_uns_ext));
@@ -2930,7 +2931,7 @@ static blb* store_array(thread_db* tdbb, jrd_tra* transaction, bid* blob_id)
29302931
array->arr_desc.iad_length);
29312932

29322933
// Write out actual array
2933-
const USHORT seg_limit = 32768;
2934+
constexpr USHORT seg_limit = 32768;
29342935
const BLOB_PTR* p = array->arr_data;
29352936
SLONG length = array->arr_effective_length;
29362937
while (length > seg_limit)

src/jrd/blb.h

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,19 @@ class blb : public pool_alloc<type_blb>
6767
{
6868
public:
6969
blb(MemoryPool& pool, USHORT page_size)
70-
: blb_interface(NULL),
71-
blb_buffer(pool, page_size / sizeof(SLONG)),
70+
: blb_buffer(pool, page_size / sizeof(SLONG)),
7271
blb_has_buffer(true)
7372
{
7473
}
7574

76-
jrd_rel* blb_relation; // Relation, if known
77-
JBlob* blb_interface;
75+
jrd_rel* blb_relation = nullptr; // Relation, if known
76+
JBlob* blb_interface = nullptr;
7877

79-
FB_UINT64 blb_length; // Blob's total length (in bytes)
80-
USHORT blb_flags; // Interesting stuff (see below)
78+
FB_UINT64 blb_length = 0; // Blob's total length (in bytes)
79+
USHORT blb_flags = 0; // Interesting stuff (see below)
8180

82-
SSHORT blb_sub_type; // Blob's declared sub-type
83-
UCHAR blb_charset; // Blob's charset
81+
SSHORT blb_sub_type = isc_blob_untyped; // Blob's declared sub-type
82+
UCHAR blb_charset = 0; // Blob's charset
8483

8584
// inline functions
8685
bool hasBuffer() const;
@@ -140,48 +139,48 @@ class blb : public pool_alloc<type_blb>
140139
void insert_page(thread_db*);
141140
void destroy(const bool purge_flag);
142141

143-
FB_SIZE_T blb_temp_size; // size stored in transaction temp space
144-
offset_t blb_temp_offset; // offset in transaction temp space
145-
Attachment* blb_attachment; // database attachment
146-
jrd_tra* blb_transaction; // Parent transaction block
147-
UCHAR* blb_segment; // Next segment to be addressed
148-
BlobControl* blb_filter; // Blob filter control block, if any
149-
bid blb_blob_id; // Id of materialized blob
150-
vcl* blb_pages; // Vector of pages
151-
152-
Firebird::Array<SLONG> blb_buffer; // buffer used in opened blobs - must be longword aligned
153-
154-
ULONG blb_temp_id; // ID of newly created blob in transaction
155-
ULONG blb_sequence; // Blob page sequence
156-
ULONG blb_lead_page; // First page number
157-
FB_UINT64 blb_seek; // Seek location
158-
ULONG blb_max_sequence; // Number of data pages
159-
ULONG blb_count; // Number of segments
160-
161-
USHORT blb_pointers; // Max pointer on a page
162-
USHORT blb_clump_size; // Size of data clump
163-
USHORT blb_space_remaining; // Data space left
164-
USHORT blb_max_pages; // Max pages in vector
165-
USHORT blb_level; // Storage type
166-
USHORT blb_pg_space_id; // page space
167-
USHORT blb_fragment_size; // Residual fragment size
168-
USHORT blb_max_segment; // Longest segment
142+
FB_SIZE_T blb_temp_size = 0; // size stored in transaction temp space
143+
offset_t blb_temp_offset = 0; // offset in transaction temp space
144+
Attachment* blb_attachment = nullptr; // database attachment
145+
jrd_tra* blb_transaction = nullptr; // Parent transaction block
146+
UCHAR* blb_segment = nullptr; // Next segment to be addressed
147+
BlobControl* blb_filter = nullptr; // Blob filter control block, if any
148+
bid blb_blob_id{}; // Id of materialized blob
149+
vcl* blb_pages = nullptr; // Vector of pages
150+
151+
Firebird::Array<SLONG> blb_buffer; // buffer used in opened blobs - must be longword aligned
152+
153+
ULONG blb_temp_id = 0; // ID of newly created blob in transaction
154+
ULONG blb_sequence = 0; // Blob page sequence
155+
ULONG blb_lead_page = 0; // First page number
156+
FB_UINT64 blb_seek = 0; // Seek location
157+
ULONG blb_max_sequence = 0; // Number of data pages
158+
ULONG blb_count = 0; // Number of segments
159+
160+
USHORT blb_pointers = 0; // Max pointer on a page
161+
USHORT blb_clump_size = 0; // Size of data clump
162+
USHORT blb_space_remaining = 0; // Data space left
163+
USHORT blb_max_pages = 0; // Max pages in vector
164+
USHORT blb_level = 0; // Storage type
165+
USHORT blb_pg_space_id = 0; // page space
166+
USHORT blb_fragment_size = 0; // Residual fragment size
167+
USHORT blb_max_segment = 0; // Longest segment
169168
#ifdef CHECK_BLOB_FIELD_ACCESS_FOR_SELECT
170-
USHORT blb_fld_id; // Field ID
169+
USHORT blb_fld_id = 0; // Field ID
171170
#endif
172171
bool blb_has_buffer;
173172
};
174173

175-
const int BLB_temporary = 1; // Newly created blob
176-
const int BLB_eof = 2; // This blob is exhausted
177-
const int BLB_stream = 4; // Stream style blob
178-
const int BLB_closed = 8; // Temporary blob has been closed
179-
const int BLB_damaged = 16; // Blob is busted
180-
const int BLB_seek = 32; // Seek is pending
181-
const int BLB_large_scan = 64; // Blob is larger than page buffer cache
182-
const int BLB_close_on_read = 128; // Temporary blob is not closed until read
183-
const int BLB_bulk = 256; // Blob created by bulk insert operation
184-
const int BLB_user = 512; // User-defined blob
174+
inline constexpr int BLB_temporary = 1; // Newly created blob
175+
inline constexpr int BLB_eof = 2; // This blob is exhausted
176+
inline constexpr int BLB_stream = 4; // Stream style blob
177+
inline constexpr int BLB_closed = 8; // Temporary blob has been closed
178+
inline constexpr int BLB_damaged = 16; // Blob is busted
179+
inline constexpr int BLB_seek = 32; // Seek is pending
180+
inline constexpr int BLB_large_scan = 64; // Blob is larger than page buffer cache
181+
inline constexpr int BLB_close_on_read = 128; // Temporary blob is not closed until read
182+
inline constexpr int BLB_bulk = 256; // Blob created by bulk insert operation
183+
inline constexpr int BLB_user = 512; // User-defined blob
185184

186185
/* Blob levels are:
187186

src/jrd/tra.h

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,21 @@ class SecDbContext
8484
struct BlobIndex
8585
{
8686
ULONG bli_temp_id;
87-
bool bli_materialized;
88-
Request* bli_request;
87+
bool bli_materialized = false;
88+
Request* bli_request = nullptr;
8989
union
9090
{
9191
bid bli_blob_id; // ID of materialized blob
9292
blb* bli_blob_object; // Blob object
9393
};
94-
static const ULONG& generate(const void* /*sender*/, const BlobIndex& item)
94+
static const ULONG& generate(const void* /*sender*/, const BlobIndex& item) noexcept
9595
{
9696
return item.bli_temp_id;
9797
}
9898
// Empty default constructor to make it behave like POD structure
99-
BlobIndex() {}
100-
BlobIndex(ULONG temp_id, blb* blob_object) :
101-
bli_temp_id(temp_id), bli_materialized(false), bli_request(NULL),
102-
bli_blob_object(blob_object)
99+
BlobIndex() noexcept : bli_temp_id(0), bli_blob_object(nullptr) {}
100+
BlobIndex(ULONG temp_id, blb* blob_object) noexcept :
101+
bli_temp_id(temp_id), bli_blob_object(blob_object)
103102
{ }
104103
};
105104

@@ -147,10 +146,10 @@ struct CallerName
147146
typedef Firebird::GenericMap<Firebird::Pair<Firebird::NonPooled<SINT64, ULONG> > > ReplBlobMap;
148147
typedef Firebird::GenericMap<Firebird::Pair<Firebird::NonPooled<SLONG, blb*> > > BlobUtilMap;
149148

150-
const int DEFAULT_LOCK_TIMEOUT = -1; // infinite
151-
const char* const TRA_BLOB_SPACE = "fb_blob_";
152-
const char* const TRA_UNDO_SPACE = "fb_undo_";
153-
const int MAX_TEMP_BLOBS = 1000;
149+
inline constexpr int DEFAULT_LOCK_TIMEOUT = -1; // infinite
150+
inline constexpr const char* TRA_BLOB_SPACE = "fb_blob_";
151+
inline constexpr const char* TRA_UNDO_SPACE = "fb_undo_";
152+
inline constexpr ULONG MAX_TEMP_BLOBS = 1000;
154153

155154
class jrd_tra : public pool_alloc<type_tra>
156155
{
@@ -243,12 +242,12 @@ class jrd_tra : public pool_alloc<type_tra>
243242
}
244243
}
245244

246-
Attachment* getAttachment()
245+
Attachment* getAttachment() noexcept
247246
{
248247
return tra_attachment;
249248
}
250249

251-
dsql_dbb* getDsqlAttachment()
250+
dsql_dbb* getDsqlAttachment() noexcept
252251
{
253252
return tra_attachment->att_dsql_instance;
254253
}
@@ -329,7 +328,7 @@ class jrd_tra : public pool_alloc<type_tra>
329328
void releaseAutonomousPool(MemoryPool* toRelease);
330329
jrd_tra* getOuter();
331330

332-
SSHORT getLockWait() const
331+
SSHORT getLockWait() const noexcept
333332
{
334333
return -tra_lock_timeout;
335334
}
@@ -409,42 +408,42 @@ class jrd_tra : public pool_alloc<type_tra>
409408
};
410409

411410
// System transaction is always transaction 0.
412-
const TraNumber TRA_system_transaction = 0;
411+
inline constexpr TraNumber TRA_system_transaction = 0;
413412

414413
// Flag definitions for tra_flags.
415414

416-
const ULONG TRA_system = 0x1L; // system transaction
417-
const ULONG TRA_prepared = 0x2L; // transaction is in limbo
418-
const ULONG TRA_reconnected = 0x4L; // reconnect in progress
419-
const ULONG TRA_degree3 = 0x8L; // serializeable transaction
420-
const ULONG TRA_write = 0x10L; // transaction has written
421-
const ULONG TRA_readonly = 0x20L; // transaction is readonly
422-
const ULONG TRA_prepare2 = 0x40L; // transaction has updated RDB$TRANSACTIONS
423-
const ULONG TRA_ignore_limbo = 0x80L; // ignore transactions in limbo
424-
const ULONG TRA_invalidated = 0x100L; // transaction invalidated by failed write
425-
const ULONG TRA_deferred_meta = 0x200L; // deferred meta work posted
426-
const ULONG TRA_read_committed = 0x400L; // can see latest committed records
427-
const ULONG TRA_autocommit = 0x800L; // autocommits all updates
428-
const ULONG TRA_perform_autocommit = 0x1000L; // indicates autocommit is necessary
429-
const ULONG TRA_rec_version = 0x2000L; // don't wait for uncommitted versions
430-
const ULONG TRA_restart_requests = 0x4000L; // restart all requests in attachment
431-
const ULONG TRA_no_auto_undo = 0x8000L; // don't start a savepoint in TRA_start
432-
const ULONG TRA_precommitted = 0x10000L; // transaction committed at startup
433-
const ULONG TRA_own_interface = 0x20000L; // tra_interface was created for internal needs
434-
const ULONG TRA_read_consistency = 0x40000L; // ensure read consistency in this transaction
435-
const ULONG TRA_ex_restart = 0x80000L; // Exception was raised to restart request
436-
const ULONG TRA_replicating = 0x100000L; // transaction is allowed to be replicated
437-
const ULONG TRA_no_blob_check = 0x200000L; // disable blob access checking
438-
const ULONG TRA_auto_release_temp_blobid = 0x400000L; // remove temp ids of materialized user blobs from tra_blobs
415+
inline constexpr ULONG TRA_system = 0x1L; // system transaction
416+
inline constexpr ULONG TRA_prepared = 0x2L; // transaction is in limbo
417+
inline constexpr ULONG TRA_reconnected = 0x4L; // reconnect in progress
418+
inline constexpr ULONG TRA_degree3 = 0x8L; // serializeable transaction
419+
inline constexpr ULONG TRA_write = 0x10L; // transaction has written
420+
inline constexpr ULONG TRA_readonly = 0x20L; // transaction is readonly
421+
inline constexpr ULONG TRA_prepare2 = 0x40L; // transaction has updated RDB$TRANSACTIONS
422+
inline constexpr ULONG TRA_ignore_limbo = 0x80L; // ignore transactions in limbo
423+
inline constexpr ULONG TRA_invalidated = 0x100L; // transaction invalidated by failed write
424+
inline constexpr ULONG TRA_deferred_meta = 0x200L; // deferred meta work posted
425+
inline constexpr ULONG TRA_read_committed = 0x400L; // can see latest committed records
426+
inline constexpr ULONG TRA_autocommit = 0x800L; // autocommits all updates
427+
inline constexpr ULONG TRA_perform_autocommit = 0x1000L; // indicates autocommit is necessary
428+
inline constexpr ULONG TRA_rec_version = 0x2000L; // don't wait for uncommitted versions
429+
inline constexpr ULONG TRA_restart_requests = 0x4000L; // restart all requests in attachment
430+
inline constexpr ULONG TRA_no_auto_undo = 0x8000L; // don't start a savepoint in TRA_start
431+
inline constexpr ULONG TRA_precommitted = 0x10000L; // transaction committed at startup
432+
inline constexpr ULONG TRA_own_interface = 0x20000L; // tra_interface was created for internal needs
433+
inline constexpr ULONG TRA_read_consistency = 0x40000L; // ensure read consistency in this transaction
434+
inline constexpr ULONG TRA_ex_restart = 0x80000L; // Exception was raised to restart request
435+
inline constexpr ULONG TRA_replicating = 0x100000L; // transaction is allowed to be replicated
436+
inline constexpr ULONG TRA_no_blob_check = 0x200000L; // disable blob access checking
437+
inline constexpr ULONG TRA_auto_release_temp_blobid = 0x400000L;// remove temp ids of materialized user blobs from tra_blobs
439438

440439
// flags derived from TPB, see also transaction_options() at tra.cpp
441-
const ULONG TRA_OPTIONS_MASK = (TRA_degree3 | TRA_readonly | TRA_ignore_limbo | TRA_read_committed |
440+
inline constexpr ULONG TRA_OPTIONS_MASK = (TRA_degree3 | TRA_readonly | TRA_ignore_limbo | TRA_read_committed |
442441
TRA_autocommit | TRA_rec_version | TRA_read_consistency | TRA_no_auto_undo | TRA_restart_requests | TRA_auto_release_temp_blobid);
443442

444-
const int TRA_MASK = 3;
445-
//const int TRA_BITS_PER_TRANS = 2;
446-
//const int TRA_TRANS_PER_BYTE = 4;
447-
const int TRA_SHIFT = 2;
443+
inline constexpr int TRA_MASK = 3;
444+
//inline constexpr int TRA_BITS_PER_TRANS = 2;
445+
//inline constexpr int TRA_TRANS_PER_BYTE = 4;
446+
inline constexpr int TRA_SHIFT = 2;
448447

449448
#define TRANS_SHIFT(number) (((number) & TRA_MASK) << 1)
450449
#define TRANS_OFFSET(number) ((number) >> TRA_SHIFT)
@@ -453,18 +452,18 @@ const int TRA_SHIFT = 2;
453452
// for "dead" active transactions every so often at transaction
454453
// startup
455454

456-
const int TRA_ACTIVE_CLEANUP = 100;
455+
inline constexpr int TRA_ACTIVE_CLEANUP = 100;
457456

458457
// Transaction states. The first four are states found
459458
// in the transaction inventory page; the last two are
460459
// returned internally
461460

462-
const int tra_active = 0; // Transaction is active
463-
const int tra_limbo = 1;
464-
const int tra_dead = 2;
465-
const int tra_committed = 3;
466-
const int tra_us = 4; // Transaction is us
467-
const int tra_precommitted = 5; // Transaction is precommitted
461+
inline constexpr int tra_active = 0; // Transaction is active
462+
inline constexpr int tra_limbo = 1;
463+
inline constexpr int tra_dead = 2;
464+
inline constexpr int tra_committed = 3;
465+
inline constexpr int tra_us = 4; // Transaction is us
466+
inline constexpr int tra_precommitted = 5; // Transaction is precommitted
468467

469468
// Deferred work blocks are used by the meta data handler to keep track
470469
// of work deferred to commit time. This are usually used to perform

0 commit comments

Comments
 (0)