1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-01 00:25:06 +02:00

Add MEM_CONTEXT_PRIOR() block and update current call sites.

This macro block encapsulates the common pattern of switching to the prior (formerly called old) mem context to return results from a function.

Also rename MEM_CONTEXT_OLD() to memContextPrior().  This violates our convention of macros being in all caps but memContextPrior() will become a function very soon so this will reduce churn.
This commit is contained in:
David Steele
2020-01-17 13:29:49 -07:00
parent b5fa9951e3
commit ec173f12fb
54 changed files with 399 additions and 296 deletions

View File

@ -65,12 +65,9 @@ Error handling macros that throw a Perl error when a C error is caught
/***********************************************************************************************************************************
Core context handling macros, only intended to be called from other macros
***********************************************************************************************************************************/
#define MEM_CONTEXT_XS_OLD() \
MEM_CONTEXT_XS_memContextOld
#define MEM_CONTEXT_XS_CORE_BEGIN(memContext) \
/* Switch to the new memory context */ \
MemContext *MEM_CONTEXT_XS_OLD() = memContextSwitch(memContext); \
MemContext *MEM_CONTEXT_memContextPrior = memContextSwitch(memContext); \
\
/* Store any errors to be croaked to Perl at the end */ \
bool MEM_CONTEXT_XS_croak = false; \
@ -87,7 +84,7 @@ Core context handling macros, only intended to be called from other macros
/* Free the context on error */ \
FINALLY() \
{ \
memContextSwitch(MEM_CONTEXT_XS_OLD()); \
memContextSwitch(memContextPrior()); \
} \
TRY_END();
@ -164,8 +161,8 @@ Simplifies switching to a temp memory context in functions and includes error ha
/* Free the context on error */ \
FINALLY() \
{ \
memContextSwitch(MEM_CONTEXT_XS_OLD()); \
memContextFree(MEM_CONTEXT_XS_TEMP()); \
memContextSwitch(memContextPrior()); \
memContextFree(MEM_CONTEXT_XS_TEMP()); \
} \
TRY_END(); \
\

View File

@ -110,9 +110,11 @@ perlOptionJson(void)
kvPut(configKv, VARSTRZ(cfgOptionName(optionId)), optionVar);
}
memContextSwitch(MEM_CONTEXT_OLD());
result = jsonFromKv(configKv);
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result = jsonFromKv(configKv);
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();

View File

@ -19,9 +19,11 @@ INPUT:
CODE:
CHECK(strEqZ(class, PACKAGE_NAME_LIBC "::PgClient"));
memContextSwitch(MEM_CONTEXT_XS_OLD());
RETVAL = pgClientNew(host, port, database, NULL, queryTimeout);
memContextSwitch(MEM_CONTEXT_XS_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
RETVAL = pgClientNew(host, port, database, NULL, queryTimeout);
}
MEM_CONTEXT_PRIOR_END();
OUTPUT:
RETVAL
CLEANUP:

View File

@ -19,10 +19,12 @@ CODE:
if (strEqZ(type, "<LOCAL>"))
{
memContextSwitch(MEM_CONTEXT_XS_OLD());
RETVAL = storagePosixNew(
path == NULL ? STRDEF("/") : path, STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
memContextSwitch(MEM_CONTEXT_XS_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
RETVAL = storagePosixNew(
path == NULL ? STRDEF("/") : path, STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
}
MEM_CONTEXT_PRIOR_END();
}
else if (strEqZ(type, "<REPO>"))
{
@ -33,9 +35,11 @@ CODE:
{
CHECK(path == NULL);
memContextSwitch(MEM_CONTEXT_XS_OLD());
RETVAL = storagePosixNew(cfgOptionStr(cfgOptPgPath), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
memContextSwitch(MEM_CONTEXT_XS_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
RETVAL = storagePosixNew(cfgOptionStr(cfgOptPgPath), STORAGE_MODE_FILE_DEFAULT, STORAGE_MODE_PATH_DEFAULT, true, NULL);
}
MEM_CONTEXT_PRIOR_END();
}
else
THROW_FMT(AssertError, "unexpected storage type '%s'", strPtr(type));

View File

@ -18,7 +18,7 @@ INPUT:
CODE:
CHECK(strEqZ(class, PACKAGE_NAME_LIBC "::StorageRead"));
RETVAL = storageReadMove(storageNewReadP(storage, file, .ignoreMissing = ignoreMissing), MEM_CONTEXT_XS_OLD());
RETVAL = storageReadMove(storageNewReadP(storage, file, .ignoreMissing = ignoreMissing), memContextPrior());
OUTPUT:
RETVAL
CLEANUP:

View File

@ -28,7 +28,7 @@ CODE:
storage, file, .modeFile = mode, .user = user, .group = group, .timeModified = (time_t)timeModified,
.noCreatePath = storageFeature(storage, storageFeaturePath) ? !pathCreate : false, .noSyncPath = !atomic,
.noAtomic = !atomic),
MEM_CONTEXT_XS_OLD());
memContextPrior());
OUTPUT:
RETVAL
CLEANUP:

View File

@ -361,10 +361,12 @@ walSegmentFind(const Storage *storage, const String *archiveId, const String *wa
strPtr(walSegment), strPtr(strLstJoin(strLstSort(list, sortOrderAsc), ", ")));
}
// Copy file name of WAL segment found into the calling context
memContextSwitch(MEM_CONTEXT_OLD());
result = strDup(strLstGet(list, 0));
memContextSwitch(MEM_CONTEXT_TEMP());
// Copy file name of WAL segment found into the prior context
MEM_CONTEXT_PRIOR_BEGIN()
{
result = strDup(strLstGet(list, 0));
}
MEM_CONTEXT_PRIOR_END();
}
}
while (result == NULL && wait != NULL && waitMore(wait));
@ -469,7 +471,7 @@ walSegmentRange(const String *walSegmentBegin, size_t walSegmentSize, unsigned i
}
}
strLstMove(result, MEM_CONTEXT_OLD());
strLstMove(result, memContextPrior());
}
MEM_CONTEXT_TEMP_END();

View File

@ -97,10 +97,12 @@ archiveGetCheck(const String *archiveFile, CipherType cipherType, const String *
if (archiveFileActual != NULL)
{
memContextSwitch(MEM_CONTEXT_OLD());
result.archiveFileActual = strNewFmt("%s/%s", strPtr(archiveId), strPtr(archiveFileActual));
result.cipherPass = strDup(infoArchiveCipherPass(info));
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result.archiveFileActual = strNewFmt("%s/%s", strPtr(archiveId), strPtr(archiveFileActual));
result.cipherPass = strDup(infoArchiveCipherPass(info));
}
MEM_CONTEXT_PRIOR_END();
}
}
MEM_CONTEXT_TEMP_END();

View File

@ -88,12 +88,14 @@ archivePushFile(
if (strEq(walSegmentChecksum, walSegmentRepoChecksum))
{
memContextSwitch(MEM_CONTEXT_OLD());
result = strNewFmt(
"WAL file '%s' already exists in the archive with the same checksum"
"\nHINT: this is valid in some recovery scenarios but may also indicate a problem.",
strPtr(archiveFile));
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result = strNewFmt(
"WAL file '%s' already exists in the archive with the same checksum"
"\nHINT: this is valid in some recovery scenarios but may also indicate a problem.",
strPtr(archiveFile));
}
MEM_CONTEXT_PRIOR_END();
}
else
THROW_FMT(ArchiveDuplicateError, "WAL file '%s' already exists in the archive", strPtr(archiveFile));

View File

@ -107,7 +107,7 @@ archivePushReadyList(const String *walPath)
strSubN(strLstGet(readyListRaw, readyIdx), 0, strSize(strLstGet(readyListRaw, readyIdx)) - STATUS_EXT_READY_SIZE));
}
strLstMove(result, MEM_CONTEXT_OLD());
strLstMove(result, memContextPrior());
}
MEM_CONTEXT_TEMP_END();
@ -173,7 +173,7 @@ archivePushProcessList(const String *walPath)
}
// Return all ready files that are not in the ok list
result = strLstMove(strLstMergeAnti(readyList, okList), MEM_CONTEXT_OLD());
result = strLstMove(strLstMergeAnti(readyList, okList), memContextPrior());
}
MEM_CONTEXT_TEMP_END();
@ -233,13 +233,15 @@ archivePushCheck(CipherType cipherType, const String *cipherPass)
archiveInfo.systemId);
}
memContextSwitch(MEM_CONTEXT_OLD());
result.pgVersion = controlInfo.version;
result.pgSystemId = controlInfo.systemId;
result.pgWalSegmentSize = controlInfo.walSegmentSize;
result.archiveId = strDup(archiveId);
result.archiveCipherPass = strDup(infoArchiveCipherPass(info));
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result.pgVersion = controlInfo.version;
result.pgSystemId = controlInfo.systemId;
result.pgWalSegmentSize = controlInfo.walSegmentSize;
result.archiveId = strDup(archiveId);
result.archiveCipherPass = strDup(infoArchiveCipherPass(info));
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();

View File

@ -161,9 +161,11 @@ backupLabelCreate(BackupType type, const String *backupLabelPrior, time_t timest
sleepMSec(MSEC_PER_SEC - (timeMSec() % MSEC_PER_SEC));
}
memContextSwitch(MEM_CONTEXT_OLD());
result = strDup(result);
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result = strDup(result);
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();
@ -443,7 +445,7 @@ backupBuildIncrPrior(const InfoBackup *infoBackup)
cfgOptionSet(cfgOptChecksumPage, cfgSourceParam, VARBOOL(checksumPagePrior));
}
manifestMove(result, MEM_CONTEXT_OLD());
manifestMove(result, memContextPrior());
}
else
{
@ -732,7 +734,7 @@ backupResumeFind(const Manifest *manifest, const String *cipherPassBackup)
// If the backup is usable then return the manifest
if (usable)
{
result = manifestMove(manifestResume, MEM_CONTEXT_OLD());
result = manifestMove(manifestResume, memContextPrior());
}
// Else warn and remove the unusable backup
else
@ -865,12 +867,14 @@ backupStart(BackupData *backupData)
DbBackupStartResult dbBackupStartResult = dbBackupStart(
backupData->dbPrimary, cfgOptionBool(cfgOptStartFast), cfgOptionBool(cfgOptStopAuto));
memContextSwitch(MEM_CONTEXT_OLD());
result.lsn = strDup(dbBackupStartResult.lsn);
result.walSegmentName = strDup(dbBackupStartResult.walSegmentName);
result.dbList = dbList(backupData->dbPrimary);
result.tablespaceList = dbTablespaceList(backupData->dbPrimary);
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result.lsn = strDup(dbBackupStartResult.lsn);
result.walSegmentName = strDup(dbBackupStartResult.walSegmentName);
result.dbList = dbList(backupData->dbPrimary);
result.tablespaceList = dbTablespaceList(backupData->dbPrimary);
}
MEM_CONTEXT_PRIOR_END();
LOG_INFO_FMT("backup start archive = %s, lsn = %s", strPtr(result.walSegmentName), strPtr(result.lsn));
@ -1011,11 +1015,13 @@ backupStop(BackupData *backupData, Manifest *manifest)
DbBackupStopResult dbBackupStopResult = dbBackupStop(backupData->dbPrimary);
memContextSwitch(MEM_CONTEXT_OLD());
result.timestamp = backupTime(backupData, false);
result.lsn = strDup(dbBackupStopResult.lsn);
result.walSegmentName = strDup(dbBackupStopResult.walSegmentName);
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result.timestamp = backupTime(backupData, false);
result.lsn = strDup(dbBackupStopResult.lsn);
result.walSegmentName = strDup(dbBackupStopResult.walSegmentName);
}
MEM_CONTEXT_PRIOR_END();
LOG_INFO_FMT("backup stop archive = %s, lsn = %s", strPtr(result.walSegmentName), strPtr(result.lsn));
@ -1378,8 +1384,8 @@ backupProcessQueue(Manifest *manifest, List **queueList)
for (unsigned int targetIdx = 0; targetIdx < strLstSize(targetList); targetIdx++)
lstSort(*(List **)lstGet(*queueList, targetIdx), sortOrderDesc);
// Move process queues to calling context
lstMove(*queueList, MEM_CONTEXT_OLD());
// Move process queues to prior context
lstMove(*queueList, memContextPrior());
}
MEM_CONTEXT_TEMP_END();
@ -1475,7 +1481,7 @@ static ProtocolParallelJob *backupJobCallback(void *data, unsigned int clientIdx
lstRemoveIdx(queue, 0);
// Assign job to result
result = protocolParallelJobMove(protocolParallelJobNew(VARSTR(file->name), command), MEM_CONTEXT_OLD());
result = protocolParallelJobMove(protocolParallelJobNew(VARSTR(file->name), command), memContextPrior());
// Break out of the loop early since we found a job
break;

View File

@ -107,11 +107,13 @@ backupFile(
// If it matches and is a reference to a previous backup then no need to copy the file
if (repoFileHasReference)
{
memContextSwitch(MEM_CONTEXT_OLD());
result.backupCopyResult = backupCopyResultNoOp;
result.copySize = pgTestSize;
result.copyChecksum = strDup(pgTestChecksum);
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result.backupCopyResult = backupCopyResultNoOp;
result.copySize = pgTestSize;
result.copyChecksum = strDup(pgTestChecksum);
}
MEM_CONTEXT_PRIOR_END();
}
}
}
@ -162,11 +164,13 @@ backupFile(
// No need to recopy if checksum/size match
if (pgFileSize == pgTestSize && strEq(pgFileChecksum, pgTestChecksum))
{
memContextSwitch(MEM_CONTEXT_OLD());
result.backupCopyResult = backupCopyResultChecksum;
result.copySize = pgTestSize;
result.copyChecksum = strDup(pgTestChecksum);
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result.backupCopyResult = backupCopyResultChecksum;
result.copySize = pgTestSize;
result.copyChecksum = strDup(pgTestChecksum);
}
MEM_CONTEXT_PRIOR_END();
}
// Else recopy when repo file is not as expected
else
@ -221,24 +225,24 @@ backupFile(
// Open the source and destination and copy the file
if (storageCopy(read, write))
{
memContextSwitch(MEM_CONTEXT_OLD());
// Get sizes and checksum
result.copySize = varUInt64Force(
ioFilterGroupResult(ioReadFilterGroup(storageReadIo(read)), SIZE_FILTER_TYPE_STR));
result.copyChecksum = strDup(
varStr(ioFilterGroupResult(ioReadFilterGroup(storageReadIo(read)), CRYPTO_HASH_FILTER_TYPE_STR)));
result.repoSize =
varUInt64Force(ioFilterGroupResult(ioWriteFilterGroup(storageWriteIo(write)), SIZE_FILTER_TYPE_STR));
// Get results of page checksum validation
if (pgFileChecksumPage)
MEM_CONTEXT_PRIOR_BEGIN()
{
result.pageChecksumResult = kvDup(
varKv(ioFilterGroupResult(ioReadFilterGroup(storageReadIo(read)), PAGE_CHECKSUM_FILTER_TYPE_STR)));
}
// Get sizes and checksum
result.copySize = varUInt64Force(
ioFilterGroupResult(ioReadFilterGroup(storageReadIo(read)), SIZE_FILTER_TYPE_STR));
result.copyChecksum = strDup(
varStr(ioFilterGroupResult(ioReadFilterGroup(storageReadIo(read)), CRYPTO_HASH_FILTER_TYPE_STR)));
result.repoSize =
varUInt64Force(ioFilterGroupResult(ioWriteFilterGroup(storageWriteIo(write)), SIZE_FILTER_TYPE_STR));
memContextSwitch(MEM_CONTEXT_TEMP());
// Get results of page checksum validation
if (pgFileChecksumPage)
{
result.pageChecksumResult = kvDup(
varKv(ioFilterGroupResult(ioReadFilterGroup(storageReadIo(read)), PAGE_CHECKSUM_FILTER_TYPE_STR)));
}
}
MEM_CONTEXT_PRIOR_END();
}
// Else if source file is missing and the read setup indicated ignore a missing file, the database removed it so skip it
else

View File

@ -802,9 +802,11 @@ infoRender(void)
else
resultStr = jsonFromVar(varNewVarLst(infoList));
memContextSwitch(MEM_CONTEXT_OLD());
result = strDup(resultStr);
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result = strDup(resultStr);
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();

View File

@ -151,9 +151,11 @@ restoreBackupSet(InfoBackup *infoBackup)
THROW_FMT(BackupSetInvalidError, "backup set %s is not valid", strPtr(backupSet));
}
memContextSwitch(MEM_CONTEXT_OLD());
result = strDup(backupSet);
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result = strDup(backupSet);
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();
@ -493,16 +495,16 @@ restoreManifestOwner(Manifest *manifest)
if (groupNull)
LOG_WARN_FMT("unknown group in backup manifest mapped to '%s'", strPtr(pathInfo.group));
memContextSwitch(MEM_CONTEXT_OLD());
MEM_CONTEXT_PRIOR_BEGIN()
{
const String *user = strDup(pathInfo.user);
const String *group = strDup(pathInfo.group);
const String *user = strDup(pathInfo.user);
const String *group = strDup(pathInfo.group);
RESTORE_MANIFEST_OWNER_NULL_UPDATE(File, user, group)
RESTORE_MANIFEST_OWNER_NULL_UPDATE(Link, user, group)
RESTORE_MANIFEST_OWNER_NULL_UPDATE(Path, user, group)
memContextSwitch(MEM_CONTEXT_TEMP());
RESTORE_MANIFEST_OWNER_NULL_UPDATE(File, user, group)
RESTORE_MANIFEST_OWNER_NULL_UPDATE(Link, user, group)
RESTORE_MANIFEST_OWNER_NULL_UPDATE(Path, user, group)
}
MEM_CONTEXT_PRIOR_END();
}
}
// Else set owners to NULL. This means we won't make any attempt to update ownership and will just leave it as written by
@ -1147,9 +1149,11 @@ restoreSelectiveExpression(Manifest *manifest)
// Else return the expression
else
{
memContextSwitch(MEM_CONTEXT_OLD());
result = strDup(expression);
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result = strDup(expression);
}
MEM_CONTEXT_PRIOR_END();
}
}
MEM_CONTEXT_TEMP_END();
@ -1285,8 +1289,8 @@ restoreRecoveryOption(unsigned int pgVersion)
if (cfgOptionTest(cfgOptTargetTimeline))
kvPut(result, VARSTRZ(RECOVERY_TARGET_TIMELINE), VARSTR(cfgOptionStr(cfgOptTargetTimeline)));
// Move to calling context
kvMove(result, MEM_CONTEXT_OLD());
// Move to prior context
kvMove(result, memContextPrior());
}
MEM_CONTEXT_TEMP_END();
@ -1318,10 +1322,12 @@ restoreRecoveryConf(unsigned int pgVersion, const String *restoreLabel)
strCatFmt(result, "%s = '%s'\n", strPtr(varStr(optionKey)), strPtr(varStr(kvGet(optionKv, optionKey))));
}
// Move to calling context
memContextSwitch(MEM_CONTEXT_OLD());
result = strDup(result);
memContextSwitch(MEM_CONTEXT_TEMP());
// Move to prior context
MEM_CONTEXT_PRIOR_BEGIN()
{
result = strDup(result);
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();
@ -1626,8 +1632,8 @@ restoreProcessQueue(Manifest *manifest, List **queueList)
for (unsigned int targetIdx = 0; targetIdx < strLstSize(targetList); targetIdx++)
lstSort(*(List **)lstGet(*queueList, targetIdx), sortOrderDesc);
// Move process queues to calling context
lstMove(*queueList, MEM_CONTEXT_OLD());
// Move process queues to prior context
lstMove(*queueList, memContextPrior());
}
MEM_CONTEXT_TEMP_END();
@ -1840,7 +1846,7 @@ static ProtocolParallelJob *restoreJobCallback(void *data, unsigned int clientId
lstRemoveIdx(queue, 0);
// Assign job to result
result = protocolParallelJobMove(protocolParallelJobNew(VARSTR(file->name), command), MEM_CONTEXT_OLD());
result = protocolParallelJobMove(protocolParallelJobNew(VARSTR(file->name), command), memContextPrior());
// Break out of the loop early since we found a job
break;

View File

@ -212,9 +212,11 @@ cryptoHashOne(const String *type, const Buffer *message)
const Buffer *buffer = cryptoHash((CryptoHash *)ioFilterDriver(hash));
memContextSwitch(MEM_CONTEXT_OLD());
result = bufDup(buffer);
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result = bufDup(buffer);
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();

View File

@ -200,7 +200,7 @@ iniSectionKeyList(const Ini *this, const String *section)
else
result = strLstNew();
strLstMove(result, MEM_CONTEXT_OLD());
strLstMove(result, memContextPrior());
}
MEM_CONTEXT_TEMP_END();
@ -226,7 +226,7 @@ iniSectionList(const Ini *this)
// Get the sections from the keyList
result = strLstNewVarLst(kvKeyList(this->store));
strLstMove(result, MEM_CONTEXT_OLD());
strLstMove(result, memContextPrior());
}
MEM_CONTEXT_TEMP_END();
@ -389,9 +389,11 @@ iniLoad(
THROW_FMT(FormatError, "ini section should end with ] at line %u: %s", lineIdx + 1, linePtr);
// Assign section
memContextSwitch(MEM_CONTEXT_OLD());
section = strNewN(linePtr + 1, strSize(line) - 2);
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
section = strNewN(linePtr + 1, strSize(line) - 2);
}
MEM_CONTEXT_PRIOR_END();
}
// Else it should be a key/value
else

View File

@ -452,7 +452,7 @@ httpClientRequest(
RETHROW();
// Move the result buffer (if any) to the parent context
bufMove(result, MEM_CONTEXT_OLD());
bufMove(result, memContextPrior());
httpClientStatLocal.request++;
}

View File

@ -67,9 +67,9 @@ ioReadBuf(IoRead *read)
}
while (!ioReadEof(read));
// Resize the buffer and move to calling context
// Resize the buffer and move to prior context
bufResize(result, bufUsed(result));
bufMove(result, MEM_CONTEXT_OLD());
bufMove(result, memContextPrior());
}
MEM_CONTEXT_TEMP_END();

View File

@ -32,7 +32,7 @@ Space is reserved for this many allocations when a context is created. When mor
Memory context management functions
MemContext *context = memContextNew();
MemContext *contextOld = memContextSwitch(context);
MemContext *contextPrior = memContextSwitch(context);
TRY_BEGIN()
{
@ -47,7 +47,7 @@ CATCH_ANY()
}
FINALLY
{
memContextSwitch(context);
memContextSwitch(contextPrior);
}
TRY_END();
@ -78,39 +78,67 @@ void *memGrowRaw(const void *buffer, size_t size);
void memFree(void *buffer);
/***********************************************************************************************************************************
Ensure that the old memory context is restored after the block executes (even on error)
Ensure that the prior memory context is restored after the block executes (even on error)
MEM_CONTEXT_BEGIN(memContext)
{
<The mem context specified is now the current context>
<Old context can be accessed with the MEM_CONTEXT_OLD() macro>
<Prior context can be accessed with the memContextPrior() macro>
}
MEM_CONTEXT_END();
<Old memory context is restored>
<Prior memory context is restored>
***********************************************************************************************************************************/
#define MEM_CONTEXT_BEGIN(memContext) \
{ \
/* Switch to the new memory context */ \
MemContext *MEM_CONTEXT_memContextOld = memContextSwitch(memContext); \
MemContext *MEM_CONTEXT_memContextPrior = memContextSwitch(memContext); \
\
/* Try the statement block */ \
TRY_BEGIN()
#define MEM_CONTEXT_OLD() \
MEM_CONTEXT_memContextOld
#define memContextPrior() \
MEM_CONTEXT_memContextPrior
#define MEM_CONTEXT_END() \
/* Switch back to the old context */ \
/* Switch back to the prior context */ \
FINALLY() \
{ \
memContextSwitch(MEM_CONTEXT_OLD()); \
memContextSwitch(memContextPrior()); \
} \
TRY_END(); \
}
/***********************************************************************************************************************************
Create a new context and make sure it is freed on error and old context is restored in all cases
Switch to prior context and ensure that the previous prior memory context is restored after the block executes (even on error)
MEM_CONTEXT_PRIOR_BEGIN(memContext)
{
<The mem context specified is now the prior context>
}
MEM_CONTEXT_PRIOR_END();
<Previous prior memory context is restored>
***********************************************************************************************************************************/
#define MEM_CONTEXT_PRIOR_BEGIN(memContext) \
{ \
/* Switch to the new memory context */ \
MemContext *MEM_CONTEXT_memContextRestore = memContextSwitch(memContextPrior()); \
\
/* Try the statement block */ \
TRY_BEGIN()
#define MEM_CONTEXT_PRIOR_END() \
/* Switch back to the prior context */ \
FINALLY() \
{ \
memContextSwitch(MEM_CONTEXT_memContextRestore); \
} \
TRY_END(); \
}
/***********************************************************************************************************************************
Create a new context and make sure it is freed on error and prior context is restored in all cases
MEM_CONTEXT_NEW_BEGIN(memContextName)
{
@ -119,12 +147,12 @@ MEM_CONTEXT_NEW_BEGIN(memContextName)
ObjectType *object = memNew(sizeof(ObjectType));
object->memContext = MEM_CONTEXT_NEW();
<Old context can be accessed with the MEM_CONTEXT_OLD() macro>
<Prior context can be accessed with the memContextPrior() macro>
<On error the newly created context will be freed and the error rethrown>
}
MEM_CONTEXT_NEW_END();
<Old memory context is restored>
<Prior memory context is restored>
Note that memory context names are expected to live for the lifetime of the context -- no copy is made.
***********************************************************************************************************************************/
@ -140,7 +168,7 @@ Note that memory context names are expected to live for the lifetime of the cont
#define MEM_CONTEXT_NEW_END() \
CATCH_ANY() \
{ \
memContextSwitch(MEM_CONTEXT_OLD()); \
memContextSwitch(memContextPrior()); \
memContextFree(MEM_CONTEXT_NEW()); \
RETHROW(); \
} \
@ -154,11 +182,11 @@ MEM_CONTEXT_TEMP_BEGIN()
{
<A temp memory context is now the current context>
<Temp context can be accessed with the MEM_CONTEXT_TEMP() macro>
<Old context can be accessed with the MEM_CONTEXT_OLD() macro>
<Prior context can be accessed with the memContextPrior() macro>
}
MEM_CONTEXT_TEMP_END();
<Old memory context is restored>
<Prior memory context is restored>
<Temp memory context is freed>
***********************************************************************************************************************************/
#define MEM_CONTEXT_TEMP() \
@ -184,7 +212,7 @@ MEM_CONTEXT_TEMP_END();
\
if (MEM_CONTEXT_TEMP_loopTotal >= resetTotal) \
{ \
memContextSwitch(MEM_CONTEXT_OLD()); \
memContextSwitch(memContextPrior()); \
memContextFree(MEM_CONTEXT_TEMP()); \
MEM_CONTEXT_TEMP() = memContextNew("temporary"); \
memContextSwitch(MEM_CONTEXT_TEMP()); \
@ -194,10 +222,10 @@ MEM_CONTEXT_TEMP_END();
while (0)
#define MEM_CONTEXT_TEMP_END() \
/* Switch back to the old context and free temp context */ \
/* Switch back to the prior context and free temp context */ \
FINALLY() \
{ \
memContextSwitch(MEM_CONTEXT_OLD()); \
memContextSwitch(memContextPrior()); \
memContextFree(MEM_CONTEXT_TEMP()); \
} \
TRY_END(); \

View File

@ -118,14 +118,14 @@ jsonToNumberInternal(const char *json, unsigned int *jsonPos)
String *resultStr = strNewN(json + beginPos, *jsonPos - beginPos);
// Convert the string to a integer variant
memContextSwitch(MEM_CONTEXT_OLD());
if (intSigned)
result = varNewInt64(cvtZToInt64(strPtr(resultStr)));
else
result = varNewUInt64(cvtZToUInt64(strPtr(resultStr)));
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
if (intSigned)
result = varNewInt64(cvtZToInt64(strPtr(resultStr)));
else
result = varNewUInt64(cvtZToUInt64(strPtr(resultStr)));
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();
@ -442,9 +442,11 @@ jsonToVarLstInternal(const char *json, unsigned int *jsonPos)
jsonConsumeWhiteSpace(json, jsonPos);
}
memContextSwitch(MEM_CONTEXT_OLD());
varLstAdd(result, jsonToVarInternal(json, jsonPos));
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
varLstAdd(result, jsonToVarInternal(json, jsonPos));
}
MEM_CONTEXT_PRIOR_END();
jsonConsumeWhiteSpace(json, jsonPos);
}
@ -863,10 +865,12 @@ jsonFromKv(const KeyValue *kv)
{
String *jsonStr = jsonFromKvInternal(kv);
// Duplicate the string into the calling context
memContextSwitch(MEM_CONTEXT_OLD());
result = strDup(jsonStr);
memContextSwitch(MEM_CONTEXT_TEMP());
// Duplicate the string into the prior context
MEM_CONTEXT_PRIOR_BEGIN()
{
result = strDup(jsonStr);
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();
@ -981,10 +985,12 @@ jsonFromVar(const Variant *var)
else
THROW(JsonFormatError, "variant type is invalid");
// Duplicate the string into the calling context
memContextSwitch(MEM_CONTEXT_OLD());
result = strDup(jsonStr);
memContextSwitch(MEM_CONTEXT_TEMP());
// Duplicate the string into the prior context
MEM_CONTEXT_PRIOR_BEGIN()
{
result = strDup(jsonStr);
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();

View File

@ -669,14 +669,14 @@ strPathAbsolute(const String *this, const String *base)
strLstRemoveIdx(pathList, 0);
}
memContextSwitch(MEM_CONTEXT_OLD());
if (strLstSize(baseList) == 1)
result = strDup(FSLASH_STR);
else
result = strLstJoin(baseList, "/");
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
if (strLstSize(baseList) == 1)
result = strDup(FSLASH_STR);
else
result = strLstJoin(baseList, "/");
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();
}

View File

@ -9,9 +9,12 @@ old context and then back. Below is a simplified example:
MEM_CONTEXT_TEMP_BEGIN() <--- begins a new temporary context
{
String *resultStr = strNewN("myNewStr"); <--- creates a string in the temporary memory context
memContextSwitch(MEM_CONTEXT_OLD()); <--- switch to the old context so the duplication of the string is in that context
result = strDup(resultStr); <--- recreates a copy of the string in the old context where "result" was created.
memContextSwitch(MEM_CONTEXT_TEMP()); <--- switch back to the temporary context
MEM_CONTEXT_PRIOR_BEGIN() <--- switch to the old context so the duplication of the string is in that context
{
result = strDup(resultStr); <--- recreates a copy of the string in the old context where "result" was created
}
MEM_CONTEXT_PRIOR_END(); <--- switch back to the temporary context
}
MEM_CONTEXT_TEMP_END(); <-- frees everything created inside this temporary memory context - i.e resultStr
***********************************************************************************************************************************/

View File

@ -538,7 +538,7 @@ strLstMergeAnti(const StringList *this, const StringList *anti)
strLstAdd(result, listItem);
}
strLstMove(result, MEM_CONTEXT_OLD());
strLstMove(result, memContextPrior());
}
MEM_CONTEXT_TEMP_END();

View File

@ -9,9 +9,12 @@ old context and then back. Below is a simplified example:
MEM_CONTEXT_TEMP_BEGIN() <--- begins a new temporary context
{
String *resultStr = strNewN("myNewStr"); <--- creates a string in the temporary memory context
memContextSwitch(MEM_CONTEXT_OLD()); <--- switch to old context so creation of the variant from the string is in old context
result = varNewUInt64(cvtZToUInt64(strPtr(resultStr))); <--- recreates variant from the string in the old context.
memContextSwitch(MEM_CONTEXT_TEMP()); <--- switch back to the temporary context
MEM_CONTEXT_PRIOR_BEGIN() <--- switch to old context so creation of the variant from the string is in old context
{
result = varNewUInt64(cvtZToUInt64(strPtr(resultStr))); <--- recreates variant from the string in the old context.
}
MEM_CONTEXT_PRIOR_END(); <--- switch back to the temporary context
}
MEM_CONTEXT_TEMP_END(); <-- frees everything created inside this temporary memory context - i.e resultStr
***********************************************************************************************************************************/

View File

@ -686,9 +686,11 @@ cfgOptionHostPort(ConfigOption optionId, unsigned int *port)
}
// Set the host
memContextSwitch(MEM_CONTEXT_OLD());
result = strDup(strLstGet(hostPart, 0));
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result = strDup(strLstGet(hostPart, 0));
}
MEM_CONTEXT_PRIOR_END();
// Set the port and error if it is not a positive integer
TRY_BEGIN()
@ -708,9 +710,11 @@ cfgOptionHostPort(ConfigOption optionId, unsigned int *port)
// Else there is no port and just copy the host
else
{
memContextSwitch(MEM_CONTEXT_OLD());
result = strDup(host);
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result = strDup(host);
}
MEM_CONTEXT_PRIOR_END();
}
}
MEM_CONTEXT_TEMP_END();

View File

@ -128,8 +128,8 @@ cfgExecParam(ConfigCommand commandId, ConfigCommandRole commandRoleId, const Key
// Add the command
strLstAdd(result, cfgCommandRoleNameParam(commandId, commandRoleId, COLON_STR));
// Move list to the calling context
strLstMove(result, MEM_CONTEXT_OLD());
// Move list to the prior context
strLstMove(result, memContextPrior());
}
MEM_CONTEXT_TEMP_END();

View File

@ -71,9 +71,11 @@ configProtocolOption(ProtocolClient *client, const VariantList *paramList)
for (unsigned int paramIdx = 0; paramIdx < varLstSize(paramList); paramIdx++)
protocolCommandParamAdd(command, varLstGet(paramList, paramIdx));
memContextSwitch(MEM_CONTEXT_OLD());
result = varVarLst(protocolClientExecute(client, command, true));
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result = varVarLst(protocolClientExecute(client, command, true));
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();

View File

@ -328,10 +328,12 @@ dbBackupStart(Db *this, bool startFast, bool stopAuto)
VariantList *row = dbQueryRow(this, dbBackupStartQuery(dbPgVersion(this), startFast));
// Return results
memContextSwitch(MEM_CONTEXT_OLD());
result.lsn = strDup(varStr(varLstGet(row, 0)));
result.walSegmentName = strDup(varStr(varLstGet(row, 1)));
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result.lsn = strDup(varStr(varLstGet(row, 0)));
result.walSegmentName = strDup(varStr(varLstGet(row, 1)));
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();
@ -411,20 +413,20 @@ dbBackupStop(Db *this)
dbPgVersion(this) >= PG_VERSION_96 ? strSize(strTrim(strDup(varStr(varLstGet(row, 3))))) == 0 : false;
// Return results
memContextSwitch(MEM_CONTEXT_OLD());
result.lsn = strDup(varStr(varLstGet(row, 0)));
result.walSegmentName = strDup(varStr(varLstGet(row, 1)));
if (dbPgVersion(this) >= PG_VERSION_96)
MEM_CONTEXT_PRIOR_BEGIN()
{
result.backupLabel = strDup(varStr(varLstGet(row, 2)));
result.lsn = strDup(varStr(varLstGet(row, 0)));
result.walSegmentName = strDup(varStr(varLstGet(row, 1)));
if (!tablespaceMapEmpty)
result.tablespaceMap = strDup(varStr(varLstGet(row, 3)));
if (dbPgVersion(this) >= PG_VERSION_96)
{
result.backupLabel = strDup(varStr(varLstGet(row, 2)));
if (!tablespaceMapEmpty)
result.tablespaceMap = strDup(varStr(varLstGet(row, 3)));
}
}
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();
@ -628,10 +630,12 @@ dbWalSwitch(Db *this)
const String *walFileName = varStr(
dbQueryColumn(this, strNewFmt("select pg_catalog.pg_%sfile_name(pg_catalog.pg_switch_%s())::text", walName, walName)));
// Copy WAL segment name to the calling context
memContextSwitch(MEM_CONTEXT_OLD());
result = strDup(walFileName);
memContextSwitch(MEM_CONTEXT_TEMP());
// Copy WAL segment name to the prior context
MEM_CONTEXT_PRIOR_BEGIN()
{
result = strDup(walFileName);
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();

View File

@ -39,7 +39,7 @@ dbGetId(unsigned int pgId)
else
result = dbNew(NULL, protocolRemoteGet(protocolStorageTypePg, pgId), applicationName);
dbMove(result, MEM_CONTEXT_OLD());
dbMove(result, memContextPrior());
}
MEM_CONTEXT_TEMP_END();
@ -135,8 +135,8 @@ dbGet(bool primaryOnly, bool primaryRequired, bool standbyRequired)
if (result.standbyId == 0 && standbyRequired)
THROW(DbConnectError, "unable to find standby cluster - cannot proceed");
dbMove(result.primary, MEM_CONTEXT_OLD());
dbMove(result.standby, MEM_CONTEXT_OLD());
dbMove(result.primary, memContextPrior());
dbMove(result.standby, memContextPrior());
}
MEM_CONTEXT_TEMP_END();

View File

@ -49,12 +49,14 @@ dbProtocol(const String *command, const VariantList *paramList, ProtocolServer *
{
if (strEq(command, PROTOCOL_COMMAND_DB_OPEN_STR))
{
// If the db list does not exist then create it in the calling context (which should be persistent)
// If the db list does not exist then create it in the prior context (which should be persistent)
if (dbProtocolLocal.pgClientList == NULL)
{
memContextSwitch(MEM_CONTEXT_OLD());
dbProtocolLocal.pgClientList = lstNew(sizeof(PgClient *));
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
dbProtocolLocal.pgClientList = lstNew(sizeof(PgClient *));
}
MEM_CONTEXT_PRIOR_END();
}
// Add db to the list

View File

@ -2788,9 +2788,11 @@ manifestTargetPath(const Manifest *this, const ManifestTarget *target)
strCat(pgPath, strPtr(target->path));
memContextSwitch(MEM_CONTEXT_OLD());
result = strPathAbsolute(pgPath, manifestTargetBase(this)->path);
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result = strPathAbsolute(pgPath, manifestTargetBase(this)->path);
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();

View File

@ -330,7 +330,7 @@ pgClientQuery(PgClient *this, const String *query)
}
TRY_END();
varLstMove(result, MEM_CONTEXT_OLD());
varLstMove(result, memContextPrior());
}
MEM_CONTEXT_TEMP_END();

View File

@ -565,9 +565,11 @@ pgTablespaceId(unsigned int pgVersion)
{
String *pgVersionStr = pgVersionToStr(pgVersion);
memContextSwitch(MEM_CONTEXT_OLD());
result = strNewFmt("PG_%s_%u", strPtr(pgVersionStr), pgCatalogVersion(pgVersion));
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result = strNewFmt("PG_%s_%u", strPtr(pgVersionStr), pgCatalogVersion(pgVersion));
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();
}
@ -675,7 +677,7 @@ pgLsnRangeToWalSegmentList(
strLstAdd(result, strNewFmt("%08X%08X%08X", timeline, startMajor, startMinor));
}
strLstMove(result, MEM_CONTEXT_OLD());
strLstMove(result, memContextPrior());
}
MEM_CONTEXT_TEMP_END();

View File

@ -208,7 +208,7 @@ protocolClientReadOutput(ProtocolClient *this, bool outputRequired)
if (outputRequired)
{
// Just move the entire response kv since the output is the largest part if it
kvMove(responseKv, MEM_CONTEXT_OLD());
kvMove(responseKv, memContextPrior());
}
// Else if no output is required then there should not be any
else if (result != NULL)
@ -322,9 +322,11 @@ protocolClientReadLine(ProtocolClient *this)
else if (strPtr(result)[0] != '.')
THROW_FMT(FormatError, "invalid prefix in '%s'", strPtr(result));
memContextSwitch(MEM_CONTEXT_OLD());
result = strSub(result, 1);
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result = strSub(result, 1);
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();

View File

@ -104,9 +104,11 @@ protocolCommandJson(const ProtocolCommand *this)
if (this->parameterList != NULL)
kvPut(command, VARSTR(PROTOCOL_KEY_PARAMETER_STR), this->parameterList);
memContextSwitch(MEM_CONTEXT_OLD());
result = jsonFromKv(command);
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
result = jsonFromKv(command);
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();

View File

@ -145,7 +145,7 @@ protocolLocalParam(ProtocolStorageType protocolStorageType, unsigned int hostId,
// Disable output to stdout since it is used by the protocol
kvPut(optionReplace, VARSTR(CFGOPT_LOG_LEVEL_CONSOLE_STR), VARSTRDEF("off"));
result = strLstMove(cfgExecParam(cfgCommand(), cfgCmdRoleLocal, optionReplace, true, false), MEM_CONTEXT_OLD());
result = strLstMove(cfgExecParam(cfgCommand(), cfgCmdRoleLocal, optionReplace, true, false), memContextPrior());
}
MEM_CONTEXT_TEMP_END();

View File

@ -292,7 +292,7 @@ storagePosixList(THIS_VOID, const String *path, StorageInterfaceListParam param)
}
// Move finished list up to the old context
strLstMove(result, MEM_CONTEXT_OLD());
strLstMove(result, memContextPrior());
}
MEM_CONTEXT_TEMP_END();
}

View File

@ -142,13 +142,15 @@ storageRemoteInfo(THIS_VOID, const String *file, StorageInterfaceInfoParam param
// Acknowledge command completed
protocolClientReadOutput(this->client, false);
// Duplicate strings into the calling context
memContextSwitch(MEM_CONTEXT_OLD());
result.name = strDup(result.name);
result.linkDestination = strDup(result.linkDestination);
result.user = strDup(result.user);
result.group = strDup(result.group);
memContextSwitch(MEM_CONTEXT_TEMP());
// Duplicate strings into the prior context
MEM_CONTEXT_PRIOR_BEGIN()
{
result.name = strDup(result.name);
result.linkDestination = strDup(result.linkDestination);
result.user = strDup(result.user);
result.group = strDup(result.group);
}
MEM_CONTEXT_PRIOR_END();
}
}
MEM_CONTEXT_TEMP_END();
@ -231,7 +233,7 @@ storageRemoteList(THIS_VOID, const String *path, StorageInterfaceListParam param
protocolCommandParamAdd(command, VARSTR(path));
protocolCommandParamAdd(command, VARSTR(param.expression));
result = strLstMove(strLstNewVarLst(varVarLst(protocolClientExecute(this->client, command, true))), MEM_CONTEXT_OLD());
result = strLstMove(strLstNewVarLst(varVarLst(protocolClientExecute(this->client, command, true))), memContextPrior());
}
MEM_CONTEXT_TEMP_END();
@ -504,9 +506,11 @@ storageRemoteNew(
protocolClientReadOutput(driver->client, false);
// Dup path into parent context
memContextSwitch(MEM_CONTEXT_OLD());
path = strDup(path);
memContextSwitch(MEM_CONTEXT_TEMP());
MEM_CONTEXT_PRIOR_BEGIN()
{
path = strDup(path);
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();

View File

@ -382,11 +382,11 @@ storageS3Request(
}
else
{
// On success move the buffer to the calling context
// On success move the buffer to the prior context
result.httpClient = httpClient;
result.responseHeader = httpHeaderMove(
httpHeaderDup(httpClientResponseHeader(httpClient), NULL), MEM_CONTEXT_OLD());
result.response = bufMove(response, MEM_CONTEXT_OLD());
httpHeaderDup(httpClientResponseHeader(httpClient), NULL), memContextPrior());
result.response = bufMove(response, memContextPrior());
}
}
@ -514,9 +514,11 @@ storageS3ListInternal(
}
// Get the continuation token and store it in the outer temp context
memContextSwitch(MEM_CONTEXT_OLD());
MEM_CONTEXT_PRIOR_BEGIN()
{
continuationToken = xmlNodeContent(xmlNodeChild(xmlRoot, S3_XML_TAG_NEXT_CONTINUATION_TOKEN_STR, false));
memContextSwitch(MEM_CONTEXT_TEMP());
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();
}
@ -712,7 +714,7 @@ storageS3List(THIS_VOID, const String *path, StorageInterfaceListParam param)
result = strLstNew();
storageS3ListInternal(this, path, param.expression, false, storageS3ListCallback, result);
strLstMove(result, MEM_CONTEXT_OLD());
strLstMove(result, memContextPrior());
}
MEM_CONTEXT_TEMP_END();

View File

@ -226,7 +226,7 @@ storageGet(StorageRead *file, StorageGetParam param)
}
// Move buffer to parent context on success
bufMove(result, MEM_CONTEXT_OLD());
bufMove(result, memContextPrior());
}
MEM_CONTEXT_TEMP_END();
@ -267,12 +267,14 @@ storageInfo(const Storage *this, const String *fileExp, StorageInfoParam param)
if (!result.exists && !param.ignoreMissing)
THROW_SYS_ERROR_FMT(FileOpenError, STORAGE_ERROR_INFO_MISSING, strPtr(file));
// Dup the strings into the calling context
memContextSwitch(MEM_CONTEXT_OLD());
result.linkDestination = strDup(result.linkDestination);
result.user = strDup(result.user);
result.group = strDup(result.group);
memContextSwitch(MEM_CONTEXT_TEMP());
// Dup the strings into the prior context
MEM_CONTEXT_PRIOR_BEGIN()
{
result.linkDestination = strDup(result.linkDestination);
result.user = strDup(result.user);
result.group = strDup(result.group);
}
MEM_CONTEXT_PRIOR_END();
}
MEM_CONTEXT_TEMP_END();
@ -531,7 +533,7 @@ storageList(const Storage *this, const String *pathExp, StorageListParam param)
}
// Move list up to the old context
result = strLstMove(result, MEM_CONTEXT_OLD());
result = strLstMove(result, memContextPrior());
}
MEM_CONTEXT_TEMP_END();
@ -602,7 +604,7 @@ storageNewRead(const Storage *this, const String *fileExp, StorageNewReadParam p
result = storageReadMove(
storageInterfaceNewReadP(
this->driver, storagePathP(this, fileExp), param.ignoreMissing, .compressible = param.compressible),
MEM_CONTEXT_OLD());
memContextPrior());
}
MEM_CONTEXT_TEMP_END();
@ -643,7 +645,7 @@ storageNewWrite(const Storage *this, const String *fileExp, StorageNewWriteParam
.modePath = param.modePath != 0 ? param.modePath : this->modePath, .user = param.user, .group = param.group,
.timeModified = param.timeModified, .createPath = !param.noCreatePath, .syncFile = !param.noSyncFile,
.syncPath = !param.noSyncPath, .atomic = !param.noAtomic, .compressible = param.compressible),
MEM_CONTEXT_OLD());
memContextPrior());
}
MEM_CONTEXT_TEMP_END();

View File

@ -94,7 +94,7 @@ harnessInfoChecksum(const String *info)
bufCat(result, BUFSTR(jsonFromVar(ioFilterResult(data.checksum))));
bufCat(result, BUFSTRDEF("\n"));
bufMove(result, MEM_CONTEXT_OLD());
bufMove(result, memContextPrior());
}
MEM_CONTEXT_TEMP_END();

View File

@ -134,8 +134,8 @@ testRun(void)
TEST_RESULT_VOID(iniSet(ini, strNew("section1"), strNew("key1"), strNew("11")), "set section, key");
TEST_RESULT_VOID(iniSet(ini, strNew("section1"), strNew("key2"), strNew("1.234")), "set section, key");
TEST_RESULT_VOID(iniMove(ini, MEM_CONTEXT_OLD()), "move ini");
TEST_RESULT_VOID(iniMove(NULL, MEM_CONTEXT_OLD()), "move null ini");
TEST_RESULT_VOID(iniMove(ini, memContextPrior()), "move ini");
TEST_RESULT_VOID(iniMove(NULL, memContextPrior()), "move null ini");
}
MEM_CONTEXT_TEMP_END();

View File

@ -330,8 +330,8 @@ testRun(void)
{
TEST_ASSIGN(header, httpHeaderNew(NULL), "new header");
TEST_RESULT_PTR(httpHeaderMove(header, MEM_CONTEXT_OLD()), header, "move to new context");
TEST_RESULT_PTR(httpHeaderMove(NULL, MEM_CONTEXT_OLD()), NULL, "move null to new context");
TEST_RESULT_PTR(httpHeaderMove(header, memContextPrior()), header, "move to new context");
TEST_RESULT_PTR(httpHeaderMove(NULL, memContextPrior()), NULL, "move null to new context");
}
MEM_CONTEXT_TEMP_END();
@ -384,8 +384,8 @@ testRun(void)
{
TEST_ASSIGN(query, httpQueryNew(), "new query");
TEST_RESULT_PTR(httpQueryMove(query, MEM_CONTEXT_OLD()), query, "move to new context");
TEST_RESULT_PTR(httpQueryMove(NULL, MEM_CONTEXT_OLD()), NULL, "move null to new context");
TEST_RESULT_PTR(httpQueryMove(query, memContextPrior()), query, "move to new context");
TEST_RESULT_PTR(httpQueryMove(NULL, memContextPrior()), NULL, "move null to new context");
}
MEM_CONTEXT_TEMP_END();

View File

@ -383,12 +383,12 @@ testRun(void)
// Null out the mem context in the parent so the move will fail
memContextCurrent()->contextChildList[1] = NULL;
TEST_ERROR(memContextMove(memContext, MEM_CONTEXT_OLD()), AssertError, "unable to find mem context in old parent");
TEST_ERROR(memContextMove(memContext, memContextPrior()), AssertError, "unable to find mem context in old parent");
// Set it back so the move will succeed
memContextCurrent()->contextChildList[1] = memContext;
TEST_RESULT_VOID(memContextMove(memContext, MEM_CONTEXT_OLD()), "move context");
TEST_RESULT_VOID(memContextMove(memContext, MEM_CONTEXT_OLD()), "move context again");
TEST_RESULT_VOID(memContextMove(memContext, memContextPrior()), "move context");
TEST_RESULT_VOID(memContextMove(memContext, memContextPrior()), "move context again");
// Move another context
MEM_CONTEXT_NEW_BEGIN("inner2")
@ -398,7 +398,7 @@ testRun(void)
}
MEM_CONTEXT_NEW_END();
TEST_RESULT_VOID(memContextMove(memContext2, MEM_CONTEXT_OLD()), "move context");
TEST_RESULT_VOID(memContextMove(memContext2, memContextPrior()), "move context");
}
MEM_CONTEXT_TEMP_END();

View File

@ -83,8 +83,8 @@ testRun(void)
MEM_CONTEXT_TEMP_BEGIN()
{
TEST_ASSIGN(testObject, testObjectNew(), "new test object");
TEST_RESULT_VOID(testObjectMove(testObject, MEM_CONTEXT_OLD()), "move object to parent context");
TEST_RESULT_VOID(testObjectMove(NULL, MEM_CONTEXT_OLD()), "move null object");
TEST_RESULT_VOID(testObjectMove(testObject, memContextPrior()), "move object to parent context");
TEST_RESULT_VOID(testObjectMove(NULL, memContextPrior()), "move null object");
}
MEM_CONTEXT_TEMP_END();

View File

@ -18,7 +18,7 @@ testRun(void)
MEM_CONTEXT_TEMP_BEGIN()
{
TEST_ASSIGN(buffer, bufNew(256), "new buffer");
bufMove(buffer, MEM_CONTEXT_OLD());
bufMove(buffer, memContextPrior());
}
MEM_CONTEXT_TEMP_END();

View File

@ -31,8 +31,8 @@ testRun(void)
MEM_CONTEXT_TEMP_BEGIN()
{
TEST_ASSIGN(store, kvNew(), "new store");
TEST_RESULT_PTR(kvMove(NULL, MEM_CONTEXT_OLD()), NULL, "move null to old context");
TEST_RESULT_PTR(kvMove(store, MEM_CONTEXT_OLD()), store, "move kv to old context");
TEST_RESULT_PTR(kvMove(NULL, memContextPrior()), NULL, "move null to old context");
TEST_RESULT_PTR(kvMove(store, memContextPrior()), store, "move kv to old context");
}
MEM_CONTEXT_TEMP_END();

View File

@ -83,7 +83,7 @@ testRun(void)
for (int listIdx = 1; listIdx <= LIST_INITIAL_SIZE; listIdx++)
TEST_RESULT_VOID(lstAdd(list, &listIdx), "add item %d", listIdx);
lstMove(list, MEM_CONTEXT_OLD());
lstMove(list, memContextPrior());
}
MEM_CONTEXT_TEMP_END();

View File

@ -288,7 +288,7 @@ testRun(void)
}
}
strLstMove(list, MEM_CONTEXT_OLD());
strLstMove(list, memContextPrior());
}
MEM_CONTEXT_TEMP_END();

View File

@ -411,8 +411,8 @@ testRun(void)
MEM_CONTEXT_TEMP_BEGIN()
{
TEST_ASSIGN(list, varLstNew(), "new list");
TEST_RESULT_PTR(varLstMove(NULL, MEM_CONTEXT_OLD()), NULL, "move null to old context");
TEST_RESULT_PTR(varLstMove(list, MEM_CONTEXT_OLD()), list, "move var list to old context");
TEST_RESULT_PTR(varLstMove(NULL, memContextPrior()), NULL, "move null to old context");
TEST_RESULT_PTR(varLstMove(list, memContextPrior()), list, "move var list to old context");
}
MEM_CONTEXT_TEMP_END();

View File

@ -1580,7 +1580,7 @@ testRun(void)
MEM_CONTEXT_TEMP_BEGIN()
{
TEST_ASSIGN(manifest, manifestNewLoad(ioBufferReadNew(contentLoad)), "load manifest");
TEST_RESULT_VOID(manifestMove(manifest, MEM_CONTEXT_OLD()), "move manifest");
TEST_RESULT_VOID(manifestMove(manifest, memContextPrior()), "move manifest");
}
MEM_CONTEXT_TEMP_END();

View File

@ -60,8 +60,8 @@ testRun(void)
MEM_CONTEXT_TEMP_BEGIN()
{
TEST_ASSIGN(client, pgClientNew(NULL, 5433, strNew("postg '\\res"), NULL, 3000), "new client");
TEST_RESULT_VOID(pgClientMove(client, MEM_CONTEXT_OLD()), "move client");
TEST_RESULT_VOID(pgClientMove(NULL, MEM_CONTEXT_OLD()), "move null client");
TEST_RESULT_VOID(pgClientMove(client, memContextPrior()), "move client");
TEST_RESULT_VOID(pgClientMove(NULL, memContextPrior()), "move null client");
}
MEM_CONTEXT_TEMP_END();

View File

@ -334,8 +334,8 @@ testRun(void)
TEST_RESULT_PTR(protocolCommandParamAdd(command, varNewStr(strNew("param1"))), command, "add param");
TEST_RESULT_PTR(protocolCommandParamAdd(command, varNewStr(strNew("param2"))), command, "add param");
TEST_RESULT_PTR(protocolCommandMove(command, MEM_CONTEXT_OLD()), command, "move protocol command");
TEST_RESULT_PTR(protocolCommandMove(NULL, MEM_CONTEXT_OLD()), NULL, "move null protocol command");
TEST_RESULT_PTR(protocolCommandMove(command, memContextPrior()), command, "move protocol command");
TEST_RESULT_PTR(protocolCommandMove(NULL, memContextPrior()), NULL, "move null protocol command");
}
MEM_CONTEXT_TEMP_END();
@ -465,9 +465,9 @@ testRun(void)
TEST_ASSIGN(
client,
protocolClientMove(
protocolClientNew(strNew("test client"), strNew("test"), read, write), MEM_CONTEXT_OLD()),
protocolClientNew(strNew("test client"), strNew("test"), read, write), memContextPrior()),
"create client");
TEST_RESULT_VOID(protocolClientMove(NULL, MEM_CONTEXT_OLD()), "move null client");
TEST_RESULT_VOID(protocolClientMove(NULL, memContextPrior()), "move null client");
}
MEM_CONTEXT_TEMP_END();
@ -604,9 +604,9 @@ testRun(void)
TEST_ASSIGN(
server,
protocolServerMove(
protocolServerNew(strNew("test server"), strNew("test"), read, write), MEM_CONTEXT_OLD()),
protocolServerNew(strNew("test server"), strNew("test"), read, write), memContextPrior()),
"create server");
TEST_RESULT_VOID(protocolServerMove(NULL, MEM_CONTEXT_OLD()), "move null server");
TEST_RESULT_VOID(protocolServerMove(NULL, memContextPrior()), "move null server");
}
MEM_CONTEXT_TEMP_END();
@ -632,8 +632,8 @@ testRun(void)
MEM_CONTEXT_TEMP_BEGIN()
{
TEST_ASSIGN(job, protocolParallelJobNew(varNewStr(strNew("test")), protocolCommandNew(strNew("command"))), "new job");
TEST_RESULT_PTR(protocolParallelJobMove(job, MEM_CONTEXT_OLD()), job, "move job");
TEST_RESULT_PTR(protocolParallelJobMove(NULL, MEM_CONTEXT_OLD()), NULL, "move null job");
TEST_RESULT_PTR(protocolParallelJobMove(job, memContextPrior()), job, "move job");
TEST_RESULT_PTR(protocolParallelJobMove(NULL, memContextPrior()), NULL, "move null job");
}
MEM_CONTEXT_TEMP_END();

View File

@ -864,7 +864,7 @@ testRun(void)
MEM_CONTEXT_TEMP_BEGIN()
{
TEST_ASSIGN(file, storageReadMove(storageNewReadP(storageTest, fileName), MEM_CONTEXT_OLD()), "new read file");
TEST_ASSIGN(file, storageReadMove(storageNewReadP(storageTest, fileName), memContextPrior()), "new read file");
}
MEM_CONTEXT_TEMP_END();
@ -994,7 +994,7 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
MEM_CONTEXT_TEMP_BEGIN()
{
TEST_ASSIGN(file, storageWriteMove(storageNewWriteP(storageTest, fileName), MEM_CONTEXT_OLD()), "new write file");
TEST_ASSIGN(file, storageWriteMove(storageNewWriteP(storageTest, fileName), memContextPrior()), "new write file");
}
MEM_CONTEXT_TEMP_END();