1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-11-25 22:12:03 +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: