diff --git a/src/alice/alice.cpp b/src/alice/alice.cpp index a3a7af6634a..06b1ce4357a 100644 --- a/src/alice/alice.cpp +++ b/src/alice/alice.cpp @@ -600,7 +600,7 @@ int alice(Firebird::UtilSvc* uSvc) #if defined(DEBUG_GDS_ALLOC) if (!uSvc->isService()) { - gds_alloc_report(0 ALLOC_ARGS); + gds_alloc_report(0, __FILE__, __LINE__); } #endif diff --git a/src/alice/exe.cpp b/src/alice/exe.cpp index 3b1b179956a..6592c9c9545 100644 --- a/src/alice/exe.cpp +++ b/src/alice/exe.cpp @@ -73,7 +73,7 @@ int EXE_action(const TEXT* database, const SINT64 switches) bool error = false; AliceGlobals* tdgbl = AliceGlobals::getSpecific(); { - Firebird::AutoMemoryPool newPool(MemoryPool::createPool(ALLOC_ARGS0)); + Firebird::AutoMemoryPool newPool(MemoryPool::createPool()); AliceContextPoolHolder context(tdgbl, newPool); for (USHORT i = 0; i < MAX_VAL_ERRORS; i++) @@ -145,7 +145,7 @@ int EXE_two_phase(const TEXT* database, const SINT64 switches) bool error = false; AliceGlobals* tdgbl = AliceGlobals::getSpecific(); { - Firebird::AutoMemoryPool newPool(MemoryPool::createPool(ALLOC_ARGS0)); + Firebird::AutoMemoryPool newPool(MemoryPool::createPool()); AliceContextPoolHolder context(tdgbl, newPool); for (USHORT i = 0; i < MAX_VAL_ERRORS; i++) diff --git a/src/burp/burp.h b/src/burp/burp.h index 71680b43b03..3fb58a76b9e 100644 --- a/src/burp/burp.h +++ b/src/burp/burp.h @@ -985,7 +985,7 @@ class GblPool } explicit GblPool(bool ownPool) - : gbl_pool(ownPool ? MemoryPool::createPool(ALLOC_ARGS1 getDefaultMemoryPool()) : getDefaultMemoryPool()) + : gbl_pool(ownPool ? MemoryPool::createPool(getDefaultMemoryPool()) : getDefaultMemoryPool()) { } ~GblPool() @@ -1386,13 +1386,13 @@ class OutputVersion : public Firebird::IVersionCallbackImplgetPool().allocate(size ALLOC_ARGS)); + return (UCHAR*)(tdgbl->getPool().allocate(size)); } static inline UCHAR* BURP_alloc_zero(ULONG size) { BurpGlobals* tdgbl = BurpGlobals::getSpecific(); - return (UCHAR*)(tdgbl->getPool().calloc(size ALLOC_ARGS)); + return (UCHAR*)(tdgbl->getPool().calloc(size)); } static inline void BURP_free(void* block) noexcept diff --git a/src/common/StdHelper.h b/src/common/StdHelper.h index d875b1ae6a4..57ebbf4ba37 100644 --- a/src/common/StdHelper.h +++ b/src/common/StdHelper.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include "boost/type_traits/copy_cv.hpp" @@ -157,6 +158,22 @@ constexpr auto getVariantIndexAndSpan(V& message) } +struct CustomSourceLocation +{ + static constexpr CustomSourceLocation current( + const std::source_location& location = std::source_location::current()) + { + return { + .fileName = location.file_name(), + .line = static_cast(location.line()) + }; + } + + const char* fileName; + int line; +}; + + } // namespace Firebird #endif // FB_COMMON_STD_HELPER_H diff --git a/src/common/classes/alloc.cpp b/src/common/classes/alloc.cpp index ead597f385a..c7132e9661f 100644 --- a/src/common/classes/alloc.cpp +++ b/src/common/classes/alloc.cpp @@ -293,8 +293,7 @@ class MemHeader public: #ifdef DEBUG_GDS_ALLOC - INT32 lineNumber = -1; - const char *fileName = nullptr; + Firebird::CustomSourceLocation location; #elif (SIZEOF_VOID_P == 4) FB_UINT64 dummyAlign; #endif @@ -412,8 +411,8 @@ class MemHeader { bool filter = filter_path != NULL; - if (isActive() && filter && fileName) - filter = strncmp(filter_path, fileName, filter_len) != 0; + if (isActive() && filter && location.fileName) + filter = strncmp(filter_path, location.fileName, filter_len) != 0; if (!filter) { @@ -421,7 +420,7 @@ class MemHeader { fprintf(file, "%s %p: size=%" SIZEFORMAT " allocated at %s:%d", isExtent() ? "EXTN" : redirected() ? "RDIR" : "USED", - this, getSize(), fileName, lineNumber); + this, getSize(), location.fileName, location.line); } else fprintf(file, "FREE %p: size=%" SIZEFORMAT, this, getSize()); @@ -2126,7 +2125,7 @@ void MemPool::newExtent(size_t& size, Extent** linkedList) size = extent->spaceRemaining; } -MemoryPool* MemoryPool::createPool(ALLOC_PARAMS1 MemoryPool* parentPool, MemoryStats& stats) +MemoryPool* MemoryPool::createPool(MemoryPool* parentPool, MemoryStats& stats ALLOC_PARAMS_DEF) { if (!parentPool) parentPool = getDefaultMemoryPool(); @@ -2134,8 +2133,7 @@ MemoryPool* MemoryPool::createPool(ALLOC_PARAMS1 MemoryPool* parentPool, MemoryS MemPool* p = new(*parentPool ALLOC_PASS_ARGS) MemPool(*(parentPool->pool), stats, &defaultExtentsCache); #ifdef MEM_DEBUG #ifdef DEBUG_LOST_POOLS - p->fileName = file; - p->lineNum = line; + p->location = location; static std::atomic seqGen = 0; p->seq = ++seqGen; @@ -2231,7 +2229,7 @@ MemBlock* MemPool::allocateInternal2(size_t from, size_t& length, bool flagRedir return hunk->block; } -MemBlock* MemPool::allocateRange(size_t from, size_t& size ALLOC_PARAMS) +MemBlock* MemPool::allocateRange(size_t from, size_t& size ALLOC_PARAMS_DEF) { size_t length = from ? size : ROUNDUP(size + VALGRIND_REDZONE, roundingSize) + GUARD_BYTES; MemBlock* memory = allocateInternal(from, length, true); @@ -2242,8 +2240,7 @@ MemBlock* MemPool::allocateRange(size_t from, size_t& size ALLOC_PARAMS) #endif #ifdef DEBUG_GDS_ALLOC - memory->fileName = file; - memory->lineNumber = line; + memory->location = location; #endif #ifdef MEM_DEBUG @@ -2260,7 +2257,7 @@ MemBlock* MemPool::allocateRange(size_t from, size_t& size ALLOC_PARAMS) } -void* MemPool::allocate(size_t size ALLOC_PARAMS) +void* MemPool::allocate(size_t size ALLOC_PARAMS_DEF) { #ifdef VALIDATE_POOL MutexLockGuard guard(mutex, "MemPool::allocate"); @@ -2335,7 +2332,7 @@ void MemPool::releaseMemory(void* object, bool flagExtent) noexcept block->valgrindInternal(); #ifdef DEBUG_GDS_ALLOC - block->fileName = NULL; + block->location.fileName = nullptr; #endif // Finally delete it @@ -2506,7 +2503,7 @@ void* MemPool::getExtent(size_t from, size_t& to) // pass desired minimum size, #ifdef VALIDATE_POOL MutexLockGuard guard(mutex, "MemPool::getExtent"); #endif - MemBlock* extent = allocateRange(from, to ALLOC_ARGS); + MemBlock* extent = allocateRange(from, to); extent->setExtent(); return &extent->body; } @@ -2622,7 +2619,7 @@ void MemPool::globalFree(void* block) noexcept deallocate(block); } -void* MemoryPool::calloc(size_t size ALLOC_PARAMS) +void* MemoryPool::calloc(size_t size ALLOC_PARAMS_DEF) { void* block = allocate(size ALLOC_PASS_ARGS); memset(block, 0, size); @@ -2768,7 +2765,7 @@ MemoryPool& AutoStorage::getAutoMemoryPool() return *p; } -void* MemoryPool::allocate(size_t size ALLOC_PARAMS) +void* MemoryPool::allocate(size_t size ALLOC_PARAMS_DEF) { return pool->allocate(size ALLOC_PASS_ARGS); } @@ -3037,12 +3034,12 @@ void AutoStorage::ProbeStack() const noexcept void* operator new(size_t s) { - return getExternalMemoryPool()->allocate(s ALLOC_ARGS); + return getExternalMemoryPool()->allocate(s); } void* operator new[](size_t s) { - return getExternalMemoryPool()->allocate(s ALLOC_ARGS); + return getExternalMemoryPool()->allocate(s); } void operator delete(void* mem) noexcept diff --git a/src/common/classes/alloc.h b/src/common/classes/alloc.h index 44ec635e4ff..7807476a5f1 100644 --- a/src/common/classes/alloc.h +++ b/src/common/classes/alloc.h @@ -58,16 +58,13 @@ #include #include - #ifdef DEBUG_GDS_ALLOC -#define FB_NEW new(*getDefaultMemoryPool(), __FILE__, __LINE__) -#define FB_NEW_POOL(pool) new(pool, __FILE__, __LINE__) -#define FB_NEW_RPT(pool, count) new(pool, count, __FILE__, __LINE__) -#else // DEBUG_GDS_ALLOC +#include "../common/StdHelper.h" +#endif + #define FB_NEW new(*getDefaultMemoryPool()) #define FB_NEW_POOL(pool) new(pool) #define FB_NEW_RPT(pool, count) new(pool, count) -#endif // DEBUG_GDS_ALLOC namespace Firebird { @@ -185,29 +182,23 @@ friend class ExternalMemoryHandler; public: #ifdef DEBUG_GDS_ALLOC -#define ALLOC_ARGS , __FILE__, __LINE__ -#define ALLOC_ARGS1 __FILE__, __LINE__, -#define ALLOC_ARGS0 __FILE__, __LINE__ -#define ALLOC_PARAMS , const char* file, int line -#define ALLOC_PARAMS1 const char* file, int line, -#define ALLOC_PARAMS0 const char* file, int line -#define ALLOC_PASS_ARGS , file, line -#define ALLOC_PASS_ARGS1 file, line, -#define ALLOC_PASS_ARGS0 file, line +#define ALLOC_PARAMS , const Firebird::CustomSourceLocation location = Firebird::CustomSourceLocation::current() +#define ALLOC_PARAMS_NO_COMMA const Firebird::CustomSourceLocation location = Firebird::CustomSourceLocation::current() +#define ALLOC_PARAMS_DEF , const Firebird::CustomSourceLocation location +#define ALLOC_PARAMS_NO_COMMA_DEF const Firebird::CustomSourceLocation location +#define ALLOC_PASS_ARGS , location +#define ALLOC_PASS_ARGS_NO_COMMA location #else -#define ALLOC_ARGS #define ALLOC_PARAMS +#define ALLOC_PARAMS_NO_COMMA +#define ALLOC_PARAMS_DEF +#define ALLOC_PARAMS_NO_COMMA_DEF #define ALLOC_PASS_ARGS -#define ALLOC_ARGS1 -#define ALLOC_PARAMS1 -#define ALLOC_PASS_ARGS1 -#define ALLOC_ARGS0 -#define ALLOC_PARAMS0 -#define ALLOC_PASS_ARGS0 +#define ALLOC_PASS_ARGS_NO_COMMA #endif // DEBUG_GDS_ALLOC // Create memory pool instance - static MemoryPool* createPool(ALLOC_PARAMS1 MemoryPool* parent = NULL, MemoryStats& stats = *default_stats_group); + static MemoryPool* createPool(MemoryPool* parent = NULL, MemoryStats& stats = *default_stats_group ALLOC_PARAMS); // Delete memory pool instance static void deletePool(MemoryPool* pool); @@ -524,7 +515,7 @@ namespace Firebird public: constexpr pointer allocate(size_type n, const void* hint = nullptr) { - return static_cast(pool.allocate(n * sizeof(T) ALLOC_ARGS)); + return static_cast(pool.allocate(n * sizeof(T))); } constexpr void deallocate(pointer p, size_type n) diff --git a/src/common/classes/array.h b/src/common/classes/array.h index 0b586b6dfad..92bc569799a 100644 --- a/src/common/classes/array.h +++ b/src/common/classes/array.h @@ -572,7 +572,7 @@ class Array : public Storage fb_assert(newcapacity < FB_MAX_SIZEOF / sizeof(T)); T* newdata = static_cast - (this->getPool().allocate(sizeof(T) * newcapacity ALLOC_ARGS)); + (this->getPool().allocate(sizeof(T) * newcapacity)); if (preserve) memcpy(static_cast(newdata), data, sizeof(T) * count); freeData(); diff --git a/src/common/classes/misc/class_perf.cpp b/src/common/classes/misc/class_perf.cpp index bde62fcd1ae..142bfde3262 100644 --- a/src/common/classes/misc/class_perf.cpp +++ b/src/common/classes/misc/class_perf.cpp @@ -204,7 +204,7 @@ static void testAllocatorMemoryPool() { printf("Test run for Firebird::MemoryPool...\n"); start(); - Firebird::MemoryPool* pool = Firebird::MemoryPool::createPool(ALLOC_ARGS0); + Firebird::MemoryPool* pool = Firebird::MemoryPool::createPool(); MallocAllocator allocator; BePlusTree, AllocItem> items(&allocator), bigItems(&allocator); diff --git a/src/common/classes/misc/class_test.cpp b/src/common/classes/misc/class_test.cpp index eb562e3359b..dc28d164471 100644 --- a/src/common/classes/misc/class_test.cpp +++ b/src/common/classes/misc/class_test.cpp @@ -506,7 +506,7 @@ void testAllocator() printf("Allocate %d large items: ", LARGE_ITEMS); int i; for (i = 0; iallocate(LARGE_ITEM_SIZE ALLOC_ARGS)); + la.add(pool->allocate(LARGE_ITEM_SIZE)); VERIFY_POOL(pool); } VERIFY_POOL(pool); @@ -518,7 +518,7 @@ void testAllocator() for (i = 0; i < ALLOC_ITEMS; i++) { n = n * 47163 - 57412; // n = n * 45578 - 17651; - AllocItem temp = {n, pool->allocate((n % MAX_ITEM_SIZE + MAX_ITEM_SIZE) / 2 + 1 ALLOC_ARGS)}; + AllocItem temp = {n, pool->allocate((n % MAX_ITEM_SIZE + MAX_ITEM_SIZE) / 2 + 1)}; items.add(temp); } printf(" DONE\n"); @@ -541,7 +541,7 @@ void testAllocator() for (i = 0; i < BIG_ITEMS; i++) { n = n * 47163 - 57412; // n = n * 45578 - 17651; - AllocItem temp = {n, pool->allocate((n % BIG_SIZE + BIG_SIZE) / 2 + 1 ALLOC_ARGS)}; + AllocItem temp = {n, pool->allocate((n % BIG_SIZE + BIG_SIZE) / 2 + 1)}; bigItems.add(temp); } printf(" DONE\n"); @@ -549,7 +549,7 @@ void testAllocator() VERIFY_POOL(parent); printf("Allocate max recommended medium buffer (%d bytes): ", MemoryPool::MAX_MEDIUM_BLOCK_SIZE); - void* maxMedium = pool->allocate(MemoryPool::MAX_MEDIUM_BLOCK_SIZE ALLOC_ARGS); + void* maxMedium = pool->allocate(MemoryPool::MAX_MEDIUM_BLOCK_SIZE); printf(" DONE\n"); VERIFY_POOL(pool); VERIFY_POOL(parent); diff --git a/src/common/classes/zip.cpp b/src/common/classes/zip.cpp index e62b3b291b4..3997da39231 100644 --- a/src/common/classes/zip.cpp +++ b/src/common/classes/zip.cpp @@ -60,7 +60,7 @@ void* ZLib::allocFunc(void*, uInt items, uInt size) { try { - return MemoryPool::globalAlloc(items * size ALLOC_ARGS); + return MemoryPool::globalAlloc(items * size); } catch (const Exception&) { diff --git a/src/common/tests/StringTest.cpp b/src/common/tests/StringTest.cpp index 8928d0ad1c9..aa168b1d5f9 100644 --- a/src/common/tests/StringTest.cpp +++ b/src/common/tests/StringTest.cpp @@ -638,7 +638,7 @@ BOOST_AUTO_TEST_CASE(DefaultPoolMoveTest) BOOST_AUTO_TEST_CASE(NewPoolMoveTest) { - AutoMemoryPool pool(MemoryPool::createPool(ALLOC_ARGS0)); + AutoMemoryPool pool(MemoryPool::createPool()); string sourceString(*pool, BigStringValue.data(), length(BigStringValue)); // Move c'tor @@ -664,7 +664,7 @@ BOOST_AUTO_TEST_SUITE(CannotMoveTests) // Do not move BOOST_AUTO_TEST_CASE(DifferentVsDefaultPoolMove) { - AutoMemoryPool pool(MemoryPool::createPool(ALLOC_ARGS0)); + AutoMemoryPool pool(MemoryPool::createPool()); string sourceString(*pool, BigStringValue.data(), length(BigStringValue)); // Move c'tor @@ -685,8 +685,8 @@ BOOST_AUTO_TEST_CASE(DifferentVsDefaultPoolMove) // Do not move BOOST_AUTO_TEST_CASE(DifferentPoolsMove) { - AutoMemoryPool pool1(MemoryPool::createPool(ALLOC_ARGS0)); - AutoMemoryPool pool2(MemoryPool::createPool(ALLOC_ARGS0)); + AutoMemoryPool pool1(MemoryPool::createPool()); + AutoMemoryPool pool2(MemoryPool::createPool()); string sourceString(*pool1, BigStringValue.data(), length(BigStringValue)); // Move c'tor diff --git a/src/dsql/DdlNodes.epp b/src/dsql/DdlNodes.epp index fe93aa172ab..b5b4b77bafe 100644 --- a/src/dsql/DdlNodes.epp +++ b/src/dsql/DdlNodes.epp @@ -8483,7 +8483,7 @@ void RelationNode::makeVersion(thread_db* tdbb, jrd_tra* transaction, const Qual if (notNull && !defaultValue->isEmpty()) { - Jrd::ContextPoolHolder context(tdbb, dbb->createPool(ALLOC_ARGS0)); + Jrd::ContextPoolHolder context(tdbb, dbb->createPool()); Statement* defaultStatement = NULL; try { @@ -12362,7 +12362,7 @@ MetaId StoreIndexNode::create(thread_db* tdbb, Cached::Relation* rel, jrd_tra* t { // Allocate a new pool to contain the expression tree // for index condition - const auto new_pool = dbb->createPool(ALLOC_ARGS0); + const auto new_pool = dbb->createPool(); CompilerScratch* csb = nullptr; try @@ -12641,7 +12641,7 @@ MetaId StoreIndexNode::createExpression(thread_db* tdbb, Cached::Relation* rel, // Allocate a new pool to contain the expression tree // for index expression - const auto new_pool = dbb->createPool(ALLOC_ARGS0); + const auto new_pool = dbb->createPool(); try { @@ -12674,7 +12674,7 @@ MetaId StoreIndexNode::createExpression(thread_db* tdbb, Cached::Relation* rel, { // Allocate a new pool to contain the expression tree // for index condition - const auto new_pool = dbb->createPool(ALLOC_ARGS0); + const auto new_pool = dbb->createPool(); try { diff --git a/src/dsql/StmtNodes.cpp b/src/dsql/StmtNodes.cpp index 92a00d7758e..9ca993597a6 100644 --- a/src/dsql/StmtNodes.cpp +++ b/src/dsql/StmtNodes.cpp @@ -7626,7 +7626,7 @@ UCHAR* MessageNode::getBuffer(Request* request) const if (data->buffer == nullptr) { const ULONG length = data->format == nullptr ? format->fmt_length : data->format->fmt_length; - data->buffer = reinterpret_cast(request->req_pool->calloc(length ALLOC_ARGS)); + data->buffer = reinterpret_cast(request->req_pool->calloc(length)); } return data->buffer; } diff --git a/src/dsql/dsql.cpp b/src/dsql/dsql.cpp index b65863088f8..2beb3594acb 100644 --- a/src/dsql/dsql.cpp +++ b/src/dsql/dsql.cpp @@ -131,9 +131,9 @@ dsql_dbb::~dsql_dbb() { } -MemoryPool* dsql_dbb::createPool(ALLOC_PARAMS0) +MemoryPool* dsql_dbb::createPool(ALLOC_PARAMS_NO_COMMA_DEF) { - return dbb_attachment->att_database->createPool(ALLOC_PASS_ARGS0); + return dbb_attachment->att_database->createPool(true ALLOC_PASS_ARGS); } void dsql_dbb::deletePool(MemoryPool* pool) @@ -439,7 +439,7 @@ static dsql_dbb* init(thread_db* tdbb, Jrd::Attachment* attachment) if (attachment->att_dsql_instance) return attachment->att_dsql_instance; - MemoryPool& pool = *attachment->att_database->createPool(ALLOC_ARGS0); + MemoryPool& pool = *attachment->att_database->createPool(); dsql_dbb* const database = FB_NEW_POOL(pool) dsql_dbb(pool, attachment); attachment->att_dsql_instance = database; @@ -579,12 +579,12 @@ static RefPtr prepareStatement(thread_db* tdbb, dsql_dbb* databas MemoryPool* scratchPool = nullptr; DsqlCompilerScratch* scratch = nullptr; - MemoryPool* statementPool = database->createPool(ALLOC_ARGS0); + MemoryPool* statementPool = database->createPool(); Jrd::ContextPoolHolder statementContext(tdbb, statementPool); try { - scratchPool = database->createPool(ALLOC_ARGS0); + scratchPool = database->createPool(); if (!transaction) // Useful for session management statements transaction = database->dbb_attachment->getSysTransaction(); diff --git a/src/dsql/dsql.h b/src/dsql/dsql.h index 2065e2f14c6..c81cf09dff2 100644 --- a/src/dsql/dsql.h +++ b/src/dsql/dsql.h @@ -133,7 +133,7 @@ class dsql_dbb : public pool_alloc dsql_dbb(MemoryPool& p, Attachment* attachment); ~dsql_dbb(); - MemoryPool* createPool(ALLOC_PARAMS0); + MemoryPool* createPool(ALLOC_PARAMS_NO_COMMA); void deletePool(MemoryPool* pool); }; diff --git a/src/include/fb_blk.h b/src/include/fb_blk.h index 4228524d0d3..5f9ed765626 100644 --- a/src/include/fb_blk.h +++ b/src/include/fb_blk.h @@ -2,6 +2,9 @@ #define INCLUDE_FB_BLK #include "../common/classes/alloc.h" +#ifdef DEBUG_GDS_ALLOC +#include +#endif enum BlockType { @@ -115,17 +118,10 @@ template class pool_alloc : public TypedHandle { public: -#ifdef DEBUG_GDS_ALLOC - void* operator new(size_t s, MemoryPool& p, const char* file, int line) - { return p.calloc(s, file, line); } - void* operator new[](size_t s, MemoryPool& p, const char* file, int line) - { return p.calloc(s, file, line); } -#else - void* operator new(size_t s, MemoryPool& p ) - { return p.calloc(s); } - void* operator new[](size_t s, MemoryPool& p) - { return p.calloc(s); } -#endif + void* operator new(size_t s, MemoryPool& p ALLOC_PARAMS) + { return p.calloc(s ALLOC_PASS_ARGS); } + void* operator new[](size_t s, MemoryPool& p ALLOC_PARAMS) + { return p.calloc(s ALLOC_PASS_ARGS); } void operator delete(void* mem, MemoryPool& p) { @@ -162,13 +158,10 @@ class pool_alloc_rpt : public TypedHandle { public: typedef RPT blk_repeat_type; -#ifdef DEBUG_GDS_ALLOC - void* operator new(size_t s, MemoryPool& p, size_t rpt, const char* file, int line) - { return p.calloc(s + sizeof(RPT) * rpt, file, line); } -#else - void* operator new(size_t s, MemoryPool& p, size_t rpt) - { return p.calloc(s + sizeof(RPT) * rpt); } -#endif + + void* operator new(size_t s, MemoryPool& p, size_t rpt ALLOC_PARAMS) + { return p.calloc(s + sizeof(RPT) * rpt ALLOC_PASS_ARGS); } + void operator delete(void* mem, MemoryPool& p) { if (mem) diff --git a/src/isql/isql.epp b/src/isql/isql.epp index f05745663cc..c46536dc65d 100644 --- a/src/isql/isql.epp +++ b/src/isql/isql.epp @@ -873,7 +873,7 @@ int ISQL_main(int argc, char* argv[]) // As ISQL can run under windows, all memory should be freed before // returning. In debug mode this call will report unfreed blocks. - //gds_alloc_report(0 ALLOC_ARGS); + //gds_alloc_report(0, __FILE__, __LINE__); char fn[] = __FILE__; fn[strlen(fn) - 8] = 0; // all isql files in gen dir gds_alloc_report(0, fn, 0); diff --git a/src/jrd/Attachment.cpp b/src/jrd/Attachment.cpp index 61578bd07a4..cc4c22550da 100644 --- a/src/jrd/Attachment.cpp +++ b/src/jrd/Attachment.cpp @@ -92,7 +92,7 @@ CommitNumber ActiveSnapshots::getSnapshotForVersion(CommitNumber version_cn) // static method Jrd::Attachment* Jrd::Attachment::create(Database* dbb, JProvider* provider) { - MemoryPool* const pool = dbb->createPool(ALLOC_ARGS1 false); + MemoryPool* const pool = dbb->createPool(false); try { diff --git a/src/jrd/Database.cpp b/src/jrd/Database.cpp index 79681623d5f..c133351d659 100644 --- a/src/jrd/Database.cpp +++ b/src/jrd/Database.cpp @@ -156,9 +156,9 @@ namespace Jrd return dbb_file_id; } - MemoryPool* Database::createPool(ALLOC_PARAMS1 bool separateStats) + MemoryPool* Database::createPool(bool separateStats ALLOC_PARAMS_DEF) { - MemoryPool* const pool = MemoryPool::createPool(ALLOC_PASS_ARGS1 dbb_permanent, dbb_memory_stats); + MemoryPool* const pool = MemoryPool::createPool(dbb_permanent, dbb_memory_stats ALLOC_PASS_ARGS); if (separateStats) { diff --git a/src/jrd/Database.h b/src/jrd/Database.h index e39ec0e6203..f8bf181a969 100644 --- a/src/jrd/Database.h +++ b/src/jrd/Database.h @@ -295,7 +295,7 @@ class Database : public pool_alloc static Database* create(Firebird::IPluginConfig* pConf, bool shared) { Firebird::MemoryStats temp_stats; - MemoryPool* const pool = MemoryPool::createPool(ALLOC_ARGS1 NULL, temp_stats); + MemoryPool* const pool = MemoryPool::createPool(NULL, temp_stats); Database* const dbb = FB_NEW_POOL(*pool) Database(pool, pConf, shared); pool->setStatsGroup(dbb->dbb_memory_stats); return dbb; @@ -477,7 +477,7 @@ class Database : public pool_alloc } #endif - MemoryPool* createPool(ALLOC_PARAMS1 bool separateStats = true); + MemoryPool* createPool(bool separateStats = true ALLOC_PARAMS); void deletePool(MemoryPool* pool); void registerModule(Module&); diff --git a/src/jrd/Function.epp b/src/jrd/Function.epp index 709feae7726..d29f41a2a82 100644 --- a/src/jrd/Function.epp +++ b/src/jrd/Function.epp @@ -237,7 +237,7 @@ ScanResult Function::scan(thread_db* tdbb, ObjectBase::Flag flags) { setDefaultCount(getDefaultCount() + 1); - MemoryPool* const csb_pool = dbb->createPool(ALLOC_ARGS0); + MemoryPool* const csb_pool = dbb->createPool(); Jrd::ContextPoolHolder context(tdbb, csb_pool); try @@ -306,7 +306,7 @@ ScanResult Function::scan(thread_db* tdbb, ObjectBase::Flag flags) } else if (!X.RDB$ENGINE_NAME.NULL || !X.RDB$FUNCTION_BLR.NULL) { - MemoryPool* const csb_pool = dbb->createPool(ALLOC_ARGS0); + MemoryPool* const csb_pool = dbb->createPool(); Jrd::ContextPoolHolder context(tdbb, csb_pool); try @@ -418,7 +418,7 @@ ScanResult Function::reload(thread_db* tdbb, ObjectBase::Flag /*unused*/) found = true; - MemoryPool* const csb_pool = dbb->createPool(ALLOC_ARGS0); + MemoryPool* const csb_pool = dbb->createPool(); Jrd::ContextPoolHolder context(tdbb, csb_pool); try diff --git a/src/jrd/InitCDSLib.cpp b/src/jrd/InitCDSLib.cpp index a995953bc9b..dd27722a90d 100644 --- a/src/jrd/InitCDSLib.cpp +++ b/src/jrd/InitCDSLib.cpp @@ -52,7 +52,7 @@ static GlobalPtr initCDS; InitCDS::InitCDS(MemoryPool&) { - m_pool = MemoryPool::createPool(ALLOC_ARGS1 nullptr, m_stats); + m_pool = MemoryPool::createPool(nullptr, m_stats); m_pools = FB_NEW_POOL(*m_pool) Array(*m_pool); cds::Initialize(); @@ -133,7 +133,7 @@ static InitInstance mutex; // guard InitCDS::m_pools MemoryPool* InitCDS::createPool() { - MemoryPool* pool = MemoryPool::createPool(ALLOC_ARGS1 nullptr, m_stats); + MemoryPool* pool = MemoryPool::createPool(nullptr, m_stats); MemoryStats* newStats = FB_NEW_POOL(*pool) MemoryStats; pool->setStatsGroup(*newStats); diff --git a/src/jrd/InitCDSLib.h b/src/jrd/InitCDSLib.h index b2dc2ee53ae..1aea3705351 100644 --- a/src/jrd/InitCDSLib.h +++ b/src/jrd/InitCDSLib.h @@ -52,7 +52,7 @@ class InitCDS private: static void* alloc(size_t size) { - return m_pool->allocate(size ALLOC_ARGS); + return m_pool->allocate(size); } static void free(void* p) @@ -97,7 +97,7 @@ class InitPool void* alloc(size_t size) { - return m_pool->allocate(size ALLOC_ARGS); + return m_pool->allocate(size); } private: diff --git a/src/jrd/Relation.cpp b/src/jrd/Relation.cpp index 062df42d37b..aa5371daa6d 100644 --- a/src/jrd/Relation.cpp +++ b/src/jrd/Relation.cpp @@ -339,7 +339,7 @@ RelationPages* RelationPermanent::getPagesInternal(thread_db* tdbb, TraNumber tr const bool poolCreated = !pool; if (poolCreated) - pool = dbb->createPool(ALLOC_ARGS1 false); + pool = dbb->createPool(false); Jrd::ContextPoolHolder context(tdbb, pool); jrd_tra* idxTran = tdbb->getTransaction(); diff --git a/src/jrd/Statement.cpp b/src/jrd/Statement.cpp index f40d30a4f04..bf5418ee4b0 100644 --- a/src/jrd/Statement.cpp +++ b/src/jrd/Statement.cpp @@ -531,7 +531,7 @@ Request* Statement::getRequest(thread_db* tdbb, const Requests::ReadAccessor& g, return g->value(level); // Create the request. - AutoMemoryPool reqPool(MemoryPool::createPool(ALLOC_ARGS1 pool)); + AutoMemoryPool reqPool(MemoryPool::createPool(pool)); #ifdef DEBUG_LOST_POOLS fprintf(stderr, "%p %s %s\n", reqPool->mp(), sqlText ? sqlText->c_str() : "", procedure ? procedure->getName().toQuotedString().c_str() : diff --git a/src/jrd/cch.cpp b/src/jrd/cch.cpp index 35a358ec1b8..b38f17f5e3e 100644 --- a/src/jrd/cch.cpp +++ b/src/jrd/cch.cpp @@ -4269,7 +4269,7 @@ static ULONG memory_init(thread_db* tdbb, BufferControl* bcb, ULONG number) try { - memory = (UCHAR*) bcb->bcb_bufferpool->allocate(memory_size ALLOC_ARGS); + memory = (UCHAR*) bcb->bcb_bufferpool->allocate(memory_size); memory_end = memory + memory_size; break; } @@ -5169,7 +5169,7 @@ void requeueRecentlyUsed(BufferControl* bcb) BufferControl* BufferControl::create(Database* dbb) { - MemoryPool* const pool = dbb->createPool(ALLOC_ARGS1 false); + MemoryPool* const pool = dbb->createPool(false); BufferControl* const bcb = FB_NEW_POOL(*pool) BufferControl(*pool, dbb->dbb_memory_stats); pool->setStatsGroup(bcb->bcb_memory_stats); return bcb; diff --git a/src/jrd/cmp.cpp b/src/jrd/cmp.cpp index 45d3189b34f..84d0fafcc55 100644 --- a/src/jrd/cmp.cpp +++ b/src/jrd/cmp.cpp @@ -153,7 +153,7 @@ Statement* CMP_compile(thread_db* tdbb, const UCHAR* blr, ULONG blrLength, bool // 26.09.2002 Nickolay Samofatov: default memory pool will become statement pool // and will be freed by CMP_release - const auto newPool = dbb->createPool(ALLOC_ARGS0); + const auto newPool = dbb->createPool(); try { diff --git a/src/jrd/dfw.epp b/src/jrd/dfw.epp index 14512b641d1..aadb253cd90 100644 --- a/src/jrd/dfw.epp +++ b/src/jrd/dfw.epp @@ -718,7 +718,7 @@ namespace SSHORT validBlr = FALSE; Jrd::Database* dbb = tdbb->getDatabase(); - MemoryPool* newPool = dbb->createPool(ALLOC_ARGS0); + MemoryPool* newPool = dbb->createPool(); try { Jrd::ContextPoolHolder context(tdbb, newPool); @@ -847,7 +847,7 @@ namespace { Statement* statement = NULL; // Nickolay Samofatov: allocate statement memory pool... - MemoryPool* new_pool = dbb->createPool(ALLOC_ARGS0); + MemoryPool* new_pool = dbb->createPool(); // block is used to ensure verify_cache() // works in not deleted context { @@ -2946,7 +2946,7 @@ static bool create_field(thread_db* tdbb, SSHORT phase, DeferredWork* work, jrd_ if (!validation.isEmpty()) { Jrd::Database* dbb = tdbb->getDatabase(); - MemoryPool* new_pool = dbb->createPool(ALLOC_ARGS0); + MemoryPool* new_pool = dbb->createPool(); Jrd::ContextPoolHolder context(tdbb, new_pool); MET_get_dependencies(tdbb, nullptr, NULL, 0, NULL, &validation, @@ -3118,7 +3118,7 @@ static bool modify_field(thread_db* tdbb, SSHORT phase, DeferredWork* work, jrd_ if (!validation.isEmpty()) { Jrd::Database* dbb = tdbb->getDatabase(); - MemoryPool* new_pool = dbb->createPool(ALLOC_ARGS0); + MemoryPool* new_pool = dbb->createPool(); Jrd::ContextPoolHolder context(tdbb, new_pool); MET_get_dependencies(tdbb, nullptr, NULL, 0, NULL, &validation, @@ -4143,7 +4143,7 @@ static bool modify_trigger(thread_db* tdbb, SSHORT phase, DeferredWork* work, jr auto* rel = relation->getVersioned(tdbb, 0); - MemoryPool* new_pool = dbb->createPool(ALLOC_ARGS0); + MemoryPool* new_pool = dbb->createPool(); TrigArray triggers(*new_pool); try @@ -4300,7 +4300,7 @@ static void get_trigger_dependencies(DeferredWork* work, bool compile, jrd_tra* { Statement* statement = NULL; // Nickolay Samofatov: allocate statement memory pool... - MemoryPool* new_pool = dbb->createPool(ALLOC_ARGS0); + MemoryPool* new_pool = dbb->createPool(); USHORT par_flags; Cleanup mem([&] diff --git a/src/jrd/evl_string.h b/src/jrd/evl_string.h index 6a5ead5aa36..00f7bafffee 100644 --- a/src/jrd/evl_string.h +++ b/src/jrd/evl_string.h @@ -97,7 +97,7 @@ class StaticAllocator } else { - result = pool.allocate(count ALLOC_ARGS); + result = pool.allocate(count); chunksToFree.add(result); } return result; diff --git a/src/jrd/fun.epp b/src/jrd/fun.epp index 6f61a741356..94163f4de2d 100644 --- a/src/jrd/fun.epp +++ b/src/jrd/fun.epp @@ -177,7 +177,7 @@ void* IbUtil::alloc(long size) { thread_db* tdbb = JRD_get_thread_data(); - void* const ptr = tdbb->getDefaultPool()->allocate(size ALLOC_ARGS); + void* const ptr = tdbb->getDefaultPool()->allocate(size); if (ptr) tdbb->getAttachment()->att_udf_pointers.add(ptr); diff --git a/src/jrd/idx.cpp b/src/jrd/idx.cpp index 16cf61feb33..4a23500f23f 100644 --- a/src/jrd/idx.cpp +++ b/src/jrd/idx.cpp @@ -530,7 +530,7 @@ bool IndexCreateTask::handler(WorkItem& _item) fb_assert(!m_exprBlob.isEmpty()); CompilerScratch* csb = NULL; - Jrd::ContextPoolHolder context(tdbb, dbb->createPool(ALLOC_ARGS0)); + Jrd::ContextPoolHolder context(tdbb, dbb->createPool()); idx->idx_expression_node = static_cast (MET_parse_blob(tdbb, &relation->getName().schema, getPermanent(relation), &m_exprBlob, &csb, &idx->idx_expression_statement, false, false)); @@ -543,7 +543,7 @@ bool IndexCreateTask::handler(WorkItem& _item) fb_assert(!m_condBlob.isEmpty()); CompilerScratch* csb = NULL; - Jrd::ContextPoolHolder context(tdbb, dbb->createPool(ALLOC_ARGS0)); + Jrd::ContextPoolHolder context(tdbb, dbb->createPool()); idx->idx_condition_node = static_cast (MET_parse_blob(tdbb, &relation->getName().schema, getPermanent(relation), &m_condBlob, &csb, &idx->idx_condition_statement, false, false)); diff --git a/src/jrd/jrd.cpp b/src/jrd/jrd.cpp index 98203b7aa71..f3cb774e90b 100644 --- a/src/jrd/jrd.cpp +++ b/src/jrd/jrd.cpp @@ -4815,7 +4815,7 @@ void JAttachment::transactRequest(CheckStatusWrapper* user_status, ITransaction* const MessageNode* outMessage = NULL; Request* request = NULL; - MemoryPool* new_pool = att->att_database->createPool(ALLOC_ARGS0); + MemoryPool* new_pool = att->att_database->createPool(); try { diff --git a/src/jrd/jrd.h b/src/jrd/jrd.h index 132170ea5e8..220634bdcd4 100644 --- a/src/jrd/jrd.h +++ b/src/jrd/jrd.h @@ -256,14 +256,14 @@ class ThreadStatusGuard // duplicate context of firebird string inline char* stringDup(MemoryPool& p, const Firebird::string& s) { - char* rc = (char*) p.allocate(s.length() + 1 ALLOC_ARGS); + char* rc = (char*) p.allocate(s.length() + 1); strcpy(rc, s.c_str()); return rc; } inline char* stringDup(MemoryPool& p, const char* s, size_t l) { - char* rc = (char*) p.allocate(l + 1 ALLOC_ARGS); + char* rc = (char*) p.allocate(l + 1); memcpy(rc, s, l); rc[l] = 0; return rc; diff --git a/src/jrd/met.epp b/src/jrd/met.epp index a1ef049d924..f68e9cfc824 100644 --- a/src/jrd/met.epp +++ b/src/jrd/met.epp @@ -2629,7 +2629,7 @@ ScanResult jrd_prc::scan(thread_db* tdbb, ObjectBase::Flag flags) (fb_utils::implicit_domain(F.RDB$FIELD_NAME) && !F.RDB$DEFAULT_VALUE.NULL))) { setDefaultCount(getDefaultCount() + 1); - MemoryPool* pool = dbb->createPool(ALLOC_ARGS0); + MemoryPool* pool = dbb->createPool(); Jrd::ContextPoolHolder context(tdbb, pool); try @@ -2683,7 +2683,7 @@ ScanResult jrd_prc::scan(thread_db* tdbb, ObjectBase::Flag flags) if (external || !P.RDB$PROCEDURE_BLR.NULL) { - MemoryPool* const csb_pool = dbb->createPool(ALLOC_ARGS0); + MemoryPool* const csb_pool = dbb->createPool(); Jrd::ContextPoolHolder context(tdbb, csb_pool); try @@ -2814,7 +2814,7 @@ ScanResult jrd_prc::reload(thread_db* tdbb, ObjectBase::Flag /*unused*/) if (compiling || P.RDB$PROCEDURE_BLR.NULL) return ScanResult::REPEAT; - MemoryPool* const csb_pool = tdbb->getDatabase()->createPool(ALLOC_ARGS0); + MemoryPool* const csb_pool = tdbb->getDatabase()->createPool(); Jrd::ContextPoolHolder context(tdbb, csb_pool); try @@ -4664,7 +4664,7 @@ void Trigger::compile(thread_db* tdbb) const auto att = tdbb->getAttachment(); // Allocate statement memory pool - MemoryPool* new_pool = dbb->createPool(ALLOC_ARGS0); + MemoryPool* new_pool = dbb->createPool(); // Trigger request is not compiled yet. Lets do it now USHORT par_flags = (USHORT) (flags & TRG_ignore_perm) ? csb_ignore_perm : 0; @@ -4866,7 +4866,7 @@ ScanResult IndexVersion::scan(thread_db* tdbb, ObjectBase::Flag flags) if (expression.hasData()) { - MemoryPool* stmtPool = dbb->createPool(ALLOC_ARGS0); + MemoryPool* stmtPool = dbb->createPool(); try { Jrd::ContextPoolHolder context(tdbb, stmtPool); @@ -4885,7 +4885,7 @@ ScanResult IndexVersion::scan(thread_db* tdbb, ObjectBase::Flag flags) if (condition.hasData()) { - MemoryPool* stmtPool = dbb->createPool(ALLOC_ARGS0); + MemoryPool* stmtPool = dbb->createPool(); try { Jrd::ContextPoolHolder context(tdbb, stmtPool); diff --git a/src/jrd/misc/evl_string_test.cpp b/src/jrd/misc/evl_string_test.cpp index 798e9059bb0..faf9fd5f734 100644 --- a/src/jrd/misc/evl_string_test.cpp +++ b/src/jrd/misc/evl_string_test.cpp @@ -89,7 +89,7 @@ class StringContainsEvaluator : public ContainsEvaluator int main() { - MemoryPool *p = MemoryPool::createPool(ALLOC_ARGS0); + MemoryPool *p = MemoryPool::createPool(); // The tests below attempt to do full code coverage for the LikeEvaluator // Every line of evl_string.h code is covered by the tests diff --git a/src/jrd/replication/Applier.cpp b/src/jrd/replication/Applier.cpp index e00b4a0764d..e28e2a52d4f 100644 --- a/src/jrd/replication/Applier.cpp +++ b/src/jrd/replication/Applier.cpp @@ -239,7 +239,7 @@ Applier* Applier::create(thread_db* tdbb) status_exception::raise(Arg::Gds(isc_miss_prvlg) << "REPLICATE_INTO_DATABASE"); Request* request = nullptr; - const auto req_pool = dbb->createPool(ALLOC_ARGS0); + const auto req_pool = dbb->createPool(); try { diff --git a/src/jrd/tra.cpp b/src/jrd/tra.cpp index 95acecdc038..6d03cceb0bb 100644 --- a/src/jrd/tra.cpp +++ b/src/jrd/tra.cpp @@ -1159,7 +1159,7 @@ jrd_tra* TRA_reconnect(thread_db* tdbb, const UCHAR* id, USHORT length) Arg::Gds(isc_tra_state) << Arg::Int64(number) << Arg::Str(text)); } - MemoryPool* const pool = dbb->createPool(ALLOC_ARGS0); + MemoryPool* const pool = dbb->createPool(); Jrd::ContextPoolHolder context(tdbb, pool); jrd_tra* const trans = jrd_tra::create(pool, attachment, NULL); trans->tra_number = number; @@ -1678,7 +1678,7 @@ jrd_tra* TRA_start(thread_db* tdbb, ULONG flags, SSHORT lock_timeout, Jrd::jrd_t // To handle the problems of relation locks, allocate a temporary // transaction block first, seize relation locks, then go ahead and // make up the real transaction block. - MemoryPool* const pool = outer ? outer->getAutonomousPool() : dbb->createPool(ALLOC_ARGS0); + MemoryPool* const pool = outer ? outer->getAutonomousPool() : dbb->createPool(); Jrd::ContextPoolHolder context(tdbb, pool); jrd_tra* const transaction = jrd_tra::create(pool, attachment, outer); @@ -1735,7 +1735,7 @@ jrd_tra* TRA_start(thread_db* tdbb, int tpb_length, const UCHAR* tpb, Jrd::jrd_t // To handle the problems of relation locks, allocate a temporary // transaction block first, seize relation locks, then go ahead and // make up the real transaction block. - MemoryPool* const pool = outer ? outer->getAutonomousPool() : dbb->createPool(ALLOC_ARGS0); + MemoryPool* const pool = outer ? outer->getAutonomousPool() : dbb->createPool(); Jrd::ContextPoolHolder context(tdbb, pool); jrd_tra* const transaction = jrd_tra::create(pool, attachment, outer); @@ -3935,7 +3935,7 @@ MemoryPool* jrd_tra::getAutonomousPool() pool = outer->tra_pool; outer = outer->tra_outer; } - tra_autonomous_pool = MemoryPool::createPool(ALLOC_ARGS1 pool, tra_memory_stats); + tra_autonomous_pool = MemoryPool::createPool(pool, tra_memory_stats); tra_autonomous_cnt = 0; } diff --git a/src/jrd/validation.cpp b/src/jrd/validation.cpp index f5d7b4eff5c..183e2489a34 100644 --- a/src/jrd/validation.cpp +++ b/src/jrd/validation.cpp @@ -759,7 +759,7 @@ static int validate(Firebird::UtilSvc* svc) att->att_use_count++; - val_pool = dbb->createPool(ALLOC_ARGS1 false); + val_pool = dbb->createPool(false); Jrd::ContextPoolHolder context(tdbb, val_pool); Validation control(tdbb, svc); @@ -1027,7 +1027,7 @@ bool Validation::run(thread_db* tdbb, USHORT flags) try { - val_pool = dbb->createPool(ALLOC_ARGS1 false); + val_pool = dbb->createPool(false); Jrd::ContextPoolHolder context(tdbb, val_pool); vdr_flags = flags; diff --git a/src/remote/server/ReplServer.cpp b/src/remote/server/ReplServer.cpp index 517c8ad0d3d..fd7d7a46b95 100644 --- a/src/remote/server/ReplServer.cpp +++ b/src/remote/server/ReplServer.cpp @@ -1014,7 +1014,7 @@ namespace const auto config = target->getConfig(); const auto dbName = config->dbName.c_str(); - AutoMemoryPool workingPool(MemoryPool::createPool(ALLOC_ARGS0)); + AutoMemoryPool workingPool(MemoryPool::createPool()); ContextPoolHolder threadContext(workingPool); target->verbose("Started replication for database %s", dbName); diff --git a/src/yvalve/gds.cpp b/src/yvalve/gds.cpp index e114def3ad7..162fa9d8d65 100644 --- a/src/yvalve/gds.cpp +++ b/src/yvalve/gds.cpp @@ -269,11 +269,15 @@ VoidPtr API_ROUTINE gds__alloc_debug(SLONG size_request, const TEXT* filename, U { try { - return getDefaultMemoryPool()->allocate(size_request #ifdef DEBUG_GDS_ALLOC - , filename, lineno + Firebird::CustomSourceLocation location{ + .fileName = filename, + .line = static_cast(lineno) + }; + return getDefaultMemoryPool()->allocate(size_request, location); +#else + return getDefaultMemoryPool()->allocate(size_request); #endif - ); } catch (const Firebird::Exception&) { @@ -4568,7 +4572,7 @@ VoidPtr API_ROUTINE gds__alloc(SLONG size_request) { try { - return getDefaultMemoryPool()->allocate(size_request ALLOC_ARGS); + return getDefaultMemoryPool()->allocate(size_request); } catch (const Firebird::Exception&) {