Skip to content

Commit 1ff3c46

Browse files
committed
Check for simple (trivially copyable) type in Array, some more or less related fixes around
1 parent 9054816 commit 1ff3c46

33 files changed

+183
-199
lines changed

src/common/classes/MetaString.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class MetaString
6060
MetaString() { init(); count = 0; }
6161
MetaString(const char* s) { assign(s); }
6262
MetaString(const char* s, FB_SIZE_T l) { assign(s, l); }
63-
MetaString(const MetaString& m) { set(m); }
63+
MetaString(const MetaString& m) = default; //{ set(m); }
6464
MetaString(const AbstractString& s) { assign(s.c_str(), s.length()); }
6565
explicit MetaString(MemoryPool&) { init(); count = 0; }
6666
MetaString(MemoryPool&, const char* s) { assign(s); }
@@ -72,7 +72,7 @@ class MetaString
7272
MetaString& assign(const char* s) { return assign(s, s ? fb_strlen(s) : 0); }
7373
MetaString& operator=(const char* s) { return assign(s); }
7474
MetaString& operator=(const AbstractString& s) { return assign(s.c_str(), s.length()); }
75-
MetaString& operator=(const MetaString& m) { return set(m); }
75+
MetaString& operator=(const MetaString& m) = default; //{ return set(m); }
7676
char* getBuffer(const FB_SIZE_T l);
7777

7878
FB_SIZE_T length() const { return count; }

src/common/classes/Nullable.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ template <typename T> class Nullable : public BaseNullable<T>
129129
this->specified = true;
130130
}
131131

132-
Nullable<T>(const Nullable<T>& o)
133-
{
132+
Nullable<T>(const Nullable<T>& o) = default;
133+
/* {
134134
this->value = o.value;
135135
this->specified = o.specified;
136136
}
137-
137+
*/
138138
Nullable<T>()
139139
{
140140
invalidate();

src/common/classes/array.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include "../common/gdsassert.h"
3131
#include <initializer_list>
32+
#include <type_traits>
3233
#include <string.h>
3334
#include "../common/classes/vector.h"
3435
#include "../common/classes/alloc.h"
@@ -71,6 +72,8 @@ class EmptyStorage : public AutoStorage
7172
template <typename T, typename Storage = EmptyStorage<T> >
7273
class Array : protected Storage
7374
{
75+
static_assert(std::is_trivially_copyable<T>(), "Only simple (trivially copyable) types supported in array");
76+
7477
public:
7578
typedef FB_SIZE_T size_type;
7679
typedef FB_SSIZE_T difference_type;

src/common/classes/fb_pair.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ template<typename parLeft, typename parRight>
4747
: first(v1), second(v2) { }
4848
explicit NonPooled(MemoryPool&, const NonPooled& lp)
4949
: first(lp.first), second(lp.second) { }
50+
NonPooled(const NonPooled& lp) = default;
5051
parLeft first;
5152
parRight second;
5253
};
@@ -64,6 +65,8 @@ template<typename parLeft, typename parRight>
6465
: first(v1), second(p, v2) { }
6566
explicit Right(MemoryPool& p, const Right& lp)
6667
: first(lp.first), second(p, lp.second) { }
68+
Right(const Right& lp)
69+
: first(lp.first), second(AutoStorage::getAutoMemoryPool(), lp.second) { }
6770
parLeft first;
6871
parRight second;
6972
};
@@ -81,6 +84,8 @@ template<typename parLeft, typename parRight>
8184
: first(p, v1), second(v2) { }
8285
explicit Left(MemoryPool& p, const Left& lp)
8386
: first(p, lp.first), second(lp.second) { }
87+
Left(const Left& lp)
88+
: first(AutoStorage::getAutoMemoryPool(), lp.first), second(lp.second) { }
8489
parLeft first;
8590
parRight second;
8691
};
@@ -97,6 +102,9 @@ template<typename parLeft, typename parRight>
97102
: first(p, v1), second(p, v2) { }
98103
explicit Full(MemoryPool& p, const Full& lp)
99104
: first(p, lp.first), second(p, lp.second) { }
105+
Full(const Full& lp)
106+
: first(AutoStorage::getAutoMemoryPool(), lp.first),
107+
second(AutoStorage::getAutoMemoryPool(), lp.second) { }
100108
parLeft first;
101109
parRight second;
102110
};
@@ -116,8 +124,7 @@ template<typename BasePair>
116124
Pair() : BasePair(AutoStorage::getAutoMemoryPool()) { }
117125
Pair(const Pair_first_type& v1, const Pair_second_type& v2)
118126
: BasePair(AutoStorage::getAutoMemoryPool(), v1, v2) { }
119-
Pair(const Pair& lp)
120-
: BasePair(AutoStorage::getAutoMemoryPool(), lp) { }
127+
Pair(const Pair& lp) = default;
121128
bool operator==(const Pair& v) const
122129
{
123130
return this->first == v.first && this->second == v.second;

src/dsql/dsql.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "../dsql/movd_proto.h"
5454
#include "../dsql/pass1_proto.h"
5555
#include "../dsql/metd_proto.h"
56+
#include "../jrd/Database.h"
5657
#include "../jrd/DataTypeUtil.h"
5758
#include "../jrd/blb_proto.h"
5859
#include "../jrd/cmp_proto.h"
@@ -113,6 +114,16 @@ dsql_dbb::~dsql_dbb()
113114
{
114115
}
115116

117+
MemoryPool* dsql_dbb::createPool()
118+
{
119+
return dbb_attachment->att_database->createPool();
120+
}
121+
122+
void dsql_dbb::deletePool(MemoryPool* pool)
123+
{
124+
dbb_attachment->att_database->deletePool(pool);
125+
}
126+
116127

117128
// Execute a dynamic SQL statement.
118129
void DSQL_execute(thread_db* tdbb,
@@ -410,7 +421,7 @@ static dsql_dbb* init(thread_db* tdbb, Jrd::Attachment* attachment)
410421
if (attachment->att_dsql_instance)
411422
return attachment->att_dsql_instance;
412423

413-
MemoryPool& pool = *attachment->createPool();
424+
MemoryPool& pool = *attachment->att_database->createPool();
414425
dsql_dbb* const database = FB_NEW_POOL(pool) dsql_dbb(pool);
415426
database->dbb_attachment = attachment;
416427
attachment->att_dsql_instance = database;

src/dsql/dsql.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,8 @@ class dsql_dbb : public pool_alloc<dsql_type_dbb>
149149
{}
150150

151151
~dsql_dbb();
152-
153-
MemoryPool* createPool()
154-
{
155-
return dbb_attachment->createPool();
156-
}
157-
158-
void deletePool(MemoryPool* pool)
159-
{
160-
dbb_attachment->deletePool(pool);
161-
}
152+
MemoryPool* createPool();
153+
void deletePool(MemoryPool* pool);
162154
};
163155

164156
//! Relation block

src/jrd/Attachment.cpp

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
#include "../jrd/extds/ExtDS.h"
4545
#include "../jrd/met.h"
46+
#include "../jrd/Statement.h"
4647

4748
#include "../jrd/replication/Applier.h"
4849
#include "../jrd/replication/Manager.h"
@@ -150,42 +151,6 @@ void Jrd::Attachment::destroy(Attachment* const attachment)
150151
}
151152

152153

153-
MemoryPool* Jrd::Attachment::createPool()
154-
{
155-
MemoryPool* const pool = MemoryPool::createPool(att_pool, att_memory_stats);
156-
att_pools.add(pool);
157-
return pool;
158-
}
159-
160-
161-
void Jrd::Attachment::deletePool(MemoryPool* pool)
162-
{
163-
if (pool)
164-
{
165-
FB_SIZE_T pos;
166-
if (att_pools.find(pool, pos))
167-
att_pools.remove(pos);
168-
169-
#ifdef DEBUG_LCK_LIST
170-
// hvlad: this could be slow, use only when absolutely necessary
171-
for (Lock* lock = att_long_locks; lock; )
172-
{
173-
Lock* next = lock->lck_next;
174-
if (BtrPageGCLock::checkPool(lock, pool))
175-
{
176-
gds__log("DEBUG_LCK_LIST: found not detached lock 0x%p in deleting pool 0x%p", lock, pool);
177-
178-
//delete lock;
179-
lock->setLockAttachment(NULL);
180-
}
181-
lock = next;
182-
}
183-
#endif
184-
MemoryPool::deletePool(pool);
185-
}
186-
}
187-
188-
189154
bool Jrd::Attachment::backupStateWriteLock(thread_db* tdbb, SSHORT wait)
190155
{
191156
if (att_backup_state_counter++)
@@ -267,7 +232,6 @@ Jrd::Attachment::Attachment(MemoryPool* pool, Database* dbb, JProvider* provider
267232
att_repl_appliers(*pool),
268233
att_utility(UTIL_NONE),
269234
att_dec_status(DecimalStatus::DEFAULT),
270-
att_pools(*pool),
271235
att_idle_timeout(0),
272236
att_stmt_timeout(0),
273237
att_batches(*pool),
@@ -290,9 +254,6 @@ Jrd::Attachment::~Attachment()
290254
for (unsigned n = 0; n < att_batches.getCount(); ++n)
291255
att_batches[n]->resetHandle();
292256

293-
while (att_pools.hasData())
294-
deletePool(att_pools.pop());
295-
296257
// For normal attachments that happens in release_attachment(),
297258
// but for special ones like GC should be done also in dtor -
298259
// they do not (and should not) call release_attachment().

src/jrd/Attachment.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -577,15 +577,6 @@ class Attachment : public pool_alloc<type_att>
577577
static int blockingAstMonitor(void*);
578578
static int blockingAstReplSet(void*);
579579

580-
/// former Database members - start
581-
582-
Firebird::Array<MemoryPool*> att_pools; // pools
583-
584-
MemoryPool* createPool();
585-
void deletePool(MemoryPool* pool);
586-
587-
/// former Database members - end
588-
589580
bool locksmith(thread_db* tdbb, SystemPrivilege sp) const;
590581
jrd_tra* getSysTransaction();
591582
void setSysTransaction(jrd_tra* trans); // used only by TRA_init

src/jrd/Function.epp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "../common/utils_proto.h"
4848
#include "../jrd/DebugInterface.h"
4949
#include "../jrd/QualifiedName.h"
50+
#include "../jrd/Statement.h"
5051

5152
#include "../jrd/Function.h"
5253

@@ -328,7 +329,7 @@ HazardPtr<Function> Function::loadMetadata(thread_db* tdbb, USHORT id, bool nosc
328329
{
329330
function->setDefaultCount(function->getDefaultCount() + 1);
330331

331-
MemoryPool* const csb_pool = attachment->createPool();
332+
MemoryPool* const csb_pool = dbb->createPool();
332333
Jrd::ContextPoolHolder context(tdbb, csb_pool);
333334

334335
try
@@ -338,7 +339,7 @@ HazardPtr<Function> Function::loadMetadata(thread_db* tdbb, USHORT id, bool nosc
338339
}
339340
catch (const Exception&)
340341
{
341-
attachment->deletePool(csb_pool);
342+
dbb->deletePool(csb_pool);
342343
throw; // an explicit error message would be better
343344
}
344345
}
@@ -396,7 +397,7 @@ HazardPtr<Function> Function::loadMetadata(thread_db* tdbb, USHORT id, bool nosc
396397
}
397398
else if (!X.RDB$ENGINE_NAME.NULL || !X.RDB$FUNCTION_BLR.NULL)
398399
{
399-
MemoryPool* const csb_pool = attachment->createPool();
400+
MemoryPool* const csb_pool = dbb->createPool();
400401
Jrd::ContextPoolHolder context(tdbb, csb_pool);
401402

402403
try
@@ -442,7 +443,7 @@ HazardPtr<Function> Function::loadMetadata(thread_db* tdbb, USHORT id, bool nosc
442443
}
443444
catch (const Exception&)
444445
{
445-
attachment->deletePool(csb_pool);
446+
dbb->deletePool(csb_pool);
446447
throw;
447448
}
448449

@@ -525,7 +526,7 @@ void Function::releaseLocks(thread_db* tdbb)
525526
{
526527
LCK_release(tdbb, existenceLock);
527528
flags |= Routine::FLAG_CHECK_EXISTENCE;
528-
useCount = 0;
529+
// !!!!!!!!!!!!!! useCount = 0;
529530
}
530531
}
531532

@@ -544,6 +545,7 @@ bool Function::reload(thread_db* tdbb)
544545
fb_assert(this->flags & Routine::FLAG_RELOAD);
545546

546547
Attachment* attachment = tdbb->getAttachment();
548+
Database* dbb = tdbb->getDatabase();
547549
AutoCacheRequest request(tdbb, irq_l_funct_blr, IRQ_REQUESTS);
548550

549551
FOR(REQUEST_HANDLE request)
@@ -553,7 +555,7 @@ bool Function::reload(thread_db* tdbb)
553555
if (X.RDB$FUNCTION_BLR.NULL)
554556
continue;
555557

556-
MemoryPool* const csb_pool = attachment->createPool();
558+
MemoryPool* const csb_pool = dbb->createPool();
557559
Jrd::ContextPoolHolder context(tdbb, csb_pool);
558560

559561
try
@@ -580,7 +582,7 @@ bool Function::reload(thread_db* tdbb)
580582
}
581583
catch (const Exception&)
582584
{
583-
attachment->deletePool(csb_pool);
585+
dbb->deletePool(csb_pool);
584586
throw;
585587
}
586588
}

src/jrd/MetaName.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,12 @@ class MetaName
171171
: word(get(s, l))
172172
{ }
173173

174-
MetaName(const MetaName& m)
175-
: word(m.word)
176-
{
177-
test();
178-
}
174+
MetaName(const MetaName& m) = default;
179175

180176
MetaName(const Firebird::AbstractString& s)
181177
: word(get(s.c_str(), s.length()))
182178
{ }
183179

184-
185180
explicit MetaName(MemoryPool&)
186181
: word(nullptr)
187182
{ }
@@ -229,12 +224,7 @@ class MetaName
229224
return *this;
230225
}
231226

232-
MetaName& operator=(const MetaName& m)
233-
{
234-
word = m.word;
235-
test();
236-
return *this;
237-
}
227+
MetaName& operator=(const MetaName& m) = default;
238228

239229
MetaName& operator=(const Firebird::MetaString& s);
240230

0 commit comments

Comments
 (0)