1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-05 00:28:52 +02:00

Allow additional memory to be allocated with a mem context.

The primary benefit is that objects can allocate memory for their struct with the context, which saves an additional allocation and makes it easier to read context/allocation dumps. Also, the memory context does not need to be stored with the object since it can be determined using the object pointer.

Object pointers cannot be moved, so this means whatever additional memory is allocated cannot be resized. That makes the additional memory ideal for object structs, but not so much for allocating a list that might change size.

Mem contexts can no longer be reused since they will probably be the wrong size so their memory is freed on memContextFree(). This still means fewer allocations and frees overall.

Interfaces still need to be freed by mem context so the old objMove() and objFree() have been preserved as objMoveContext() and objFreeContext(). This will be addressed in a future commit.
This commit is contained in:
David Steele
2021-09-01 11:10:35 -04:00
parent 02b06aa495
commit 475b57c89b
117 changed files with 754 additions and 769 deletions

View File

@ -59,7 +59,7 @@ The following sections provide information on some important concepts needed for
### Memory Contexts
Memory is allocated inside contexts and can be long lasting (for objects) or temporary (for functions). In general, use `MEM_CONTEXT_NEW_BEGIN("SomeName")` for objects and `MEM_CONTEXT_TEMP_BEGIN()` for functions. See [memContext.h](https://github.com/pgbackrest/pgbackrest/blob/master/src/common/memContext.h) for more details and the [Coding Example](#coding-example) below.
Memory is allocated inside contexts and can be long lasting (for objects) or temporary (for functions). In general, use `OBJ_NEW_BEGIN(MyObj)` for objects and `MEM_CONTEXT_TEMP_BEGIN()` for functions. See [memContext.h](https://github.com/pgbackrest/pgbackrest/blob/master/src/common/memContext.h) for more details and the [Coding Example](#coding-example) below.
### Logging
@ -86,7 +86,6 @@ MyObj *myObjNew(unsigned int myData, const String *secretName);
// Declare the publicly accessible variables in a structure with Pub appended to the name
typedef struct MyObjPub // First letter upper case
{
MemContext *memContext; // Pointer to memContext in which this object resides
unsigned int myData; // Contents of the myData variable
} MyObjPub;
@ -135,21 +134,20 @@ myObjNew(unsigned int myData, const String *secretName)
MyObj *this = NULL; // Declare the object in the parent memory context: it will live only as long as the parent
MEM_CONTEXT_NEW_BEGIN("MyObj") // Create a long lasting memory context with the name of the object
OBJ_NEW_BEGIN(MyObj) // Create a long lasting memory context with the name of the object
{
this = memNew(sizeof(MyObj)); // Allocate the memory required by the object
this = OBJ_NEW_ALLOC(); // Allocate the memory required by the object
*this = (MyObj) // Initialize the object
{
.pub =
{
.memContext = memContextCurrent(), // Set the memory context to the current MyObj memory context
.myData = myData, // Copy the simple data type to this object
},
.name = strDup(secretName), // Duplicate the String data type to the this object's memory context
};
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(MyObj, this);
}

View File

@ -153,7 +153,7 @@
<section id="memory-context">
<title>Memory Contexts</title>
<p>Memory is allocated inside contexts and can be long lasting (for objects) or temporary (for functions). In general, use <code>MEM_CONTEXT_NEW_BEGIN("SomeName")</code> for objects and <code>MEM_CONTEXT_TEMP_BEGIN()</code> for functions. See <link url="{[github-url-src-common]}/memContext.h">memContext.h</link> for more details and the <link section="/coding/coding-example">Coding Example</link> below.</p>
<p>Memory is allocated inside contexts and can be long lasting (for objects) or temporary (for functions). In general, use <code>OBJ_NEW_BEGIN(MyObj)</code> for objects and <code>MEM_CONTEXT_TEMP_BEGIN()</code> for functions. See <link url="{[github-url-src-common]}/memContext.h">memContext.h</link> for more details and the <link section="/coding/coding-example">Coding Example</link> below.</p>
</section>
<section id="message-logging">
@ -186,7 +186,6 @@ MyObj *myObjNew(unsigned int myData, const String *secretName);
// Declare the publicly accessible variables in a structure with Pub appended to the name
typedef struct MyObjPub // First letter upper case
{
MemContext *memContext; // Pointer to memContext in which this object resides
unsigned int myData; // Contents of the myData variable
} MyObjPub;
@ -235,21 +234,20 @@ myObjNew(unsigned int myData, const String *secretName)
MyObj *this = NULL; // Declare the object in the parent memory context: it will live only as long as the parent
MEM_CONTEXT_NEW_BEGIN("MyObj") // Create a long lasting memory context with the name of the object
OBJ_NEW_BEGIN(MyObj) // Create a long lasting memory context with the name of the object
{
this = memNew(sizeof(MyObj)); // Allocate the memory required by the object
this = OBJ_NEW_ALLOC(); // Allocate the memory required by the object
*this = (MyObj) // Initialize the object
{
.pub =
{
.memContext = memContextCurrent(), // Set the memory context to the current MyObj memory context
.myData = myData, // Copy the simple data type to this object
},
.name = strDup(secretName), // Duplicate the String data type to the this object's memory context
};
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(MyObj, this);
}

View File

@ -7,7 +7,6 @@ Yaml Handler
#include "common/debug.h"
#include "common/log.h"
#include "common/memContext.h"
#include "build/common/yaml.h"
@ -16,7 +15,6 @@ Object type
***********************************************************************************************************************************/
struct Yaml
{
MemContext *memContext; // Mem context
yaml_parser_t parser; // Parse context
};
@ -49,19 +47,15 @@ yamlNew(const Buffer *const buffer)
Yaml *this = NULL;
MEM_CONTEXT_NEW_BEGIN("Yaml")
OBJ_NEW_BEGIN(Yaml)
{
// Create object
this = memNew(sizeof(Yaml));
*this = (Yaml)
{
.memContext = MEM_CONTEXT_NEW(),
};
this = OBJ_NEW_ALLOC();
*this = (Yaml){0};
// Initialize parser context
CHECK(yaml_parser_initialize(&this->parser));
memContextCallbackSet(this->memContext, yamlFreeResource, this);
memContextCallbackSet(objMemContext(this), yamlFreeResource, this);
// Set yaml string
yaml_parser_set_input_string(&this->parser, bufPtrConst(buffer), bufUsed(buffer));
@ -70,7 +64,7 @@ yamlNew(const Buffer *const buffer)
CHECK(yamlEventNext(this).type == yamlEventTypeStreamBegin);
CHECK(yamlEventNext(this).type == yamlEventTypeDocBegin);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_TEST_RETURN(this);
}

View File

@ -8,7 +8,6 @@ Page Checksum Filter
#include "command/backup/pageChecksum.h"
#include "common/log.h"
#include "common/macro.h"
#include "common/memContext.h"
#include "common/type/object.h"
#include "postgres/interface.h"
#include "postgres/interface/static.vendor.h"
@ -229,9 +228,9 @@ pageChecksumNew(unsigned int segmentNo, unsigned int segmentPageTotal, uint64_t
IoFilter *this = NULL;
MEM_CONTEXT_NEW_BEGIN("PageChecksum")
OBJ_NEW_BEGIN(PageChecksum)
{
PageChecksum *driver = memNew(sizeof(PageChecksum));
PageChecksum *driver = OBJ_NEW_ALLOC();
*driver = (PageChecksum)
{
@ -251,7 +250,7 @@ pageChecksumNew(unsigned int segmentNo, unsigned int segmentPageTotal, uint64_t
this = ioFilterNewP(
PAGE_CHECKSUM_FILTER_TYPE_STR, driver, paramList, .in = pageChecksumProcess, .result = pageChecksumResult);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_FILTER, this);
}

View File

@ -12,7 +12,6 @@ BZ2 Compress
#include "common/io/filter/filter.h"
#include "common/log.h"
#include "common/macro.h"
#include "common/memContext.h"
#include "common/type/object.h"
/***********************************************************************************************************************************
@ -25,7 +24,6 @@ Object type
***********************************************************************************************************************************/
typedef struct Bz2Compress
{
MemContext *memContext; // Context to store data
bz_stream stream; // Compression stream
bool inputSame; // Is the same input required on the next process call?
@ -173,13 +171,12 @@ bz2CompressNew(int level)
IoFilter *this = NULL;
MEM_CONTEXT_NEW_BEGIN("Bz2Compress")
OBJ_NEW_BEGIN(Bz2Compress)
{
Bz2Compress *driver = memNew(sizeof(Bz2Compress));
Bz2Compress *driver = OBJ_NEW_ALLOC();
*driver = (Bz2Compress)
{
.memContext = MEM_CONTEXT_NEW(),
.stream = {.bzalloc = NULL},
};
@ -187,7 +184,7 @@ bz2CompressNew(int level)
bz2Error(BZ2_bzCompressInit(&driver->stream, level, 0, 0));
// Set callback to ensure bz2 stream is freed
memContextCallbackSet(driver->memContext, bz2CompressFreeResource, driver);
memContextCallbackSet(objMemContext(driver), bz2CompressFreeResource, driver);
// Create param list
VariantList *paramList = varLstNew();
@ -198,7 +195,7 @@ bz2CompressNew(int level)
BZ2_COMPRESS_FILTER_TYPE_STR, driver, paramList, .done = bz2CompressDone, .inOut = bz2CompressProcess,
.inputSame = bz2CompressInputSame);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_FILTER, this);
}

View File

@ -12,7 +12,6 @@ BZ2 Decompress
#include "common/io/filter/filter.h"
#include "common/log.h"
#include "common/macro.h"
#include "common/memContext.h"
#include "common/type/object.h"
/***********************************************************************************************************************************
@ -25,7 +24,6 @@ Object type
***********************************************************************************************************************************/
typedef struct Bz2Decompress
{
MemContext *memContext; // Context to store data
bz_stream stream; // Decompression stream state
int result; // Result of last operation
@ -157,14 +155,13 @@ bz2DecompressNew(void)
IoFilter *this = NULL;
MEM_CONTEXT_NEW_BEGIN("Bz2Decompress")
OBJ_NEW_BEGIN(Bz2Decompress)
{
// Allocate state and set context
Bz2Decompress *driver = memNew(sizeof(Bz2Decompress));
Bz2Decompress *driver = OBJ_NEW_ALLOC();
*driver = (Bz2Decompress)
{
.memContext = MEM_CONTEXT_NEW(),
.stream = {.bzalloc = NULL},
};
@ -172,14 +169,14 @@ bz2DecompressNew(void)
bz2Error(driver->result = BZ2_bzDecompressInit(&driver->stream, 0, 0));
// Set free callback to ensure bz2 context is freed
memContextCallbackSet(driver->memContext, bz2DecompressFreeResource, driver);
memContextCallbackSet(objMemContext(driver), bz2DecompressFreeResource, driver);
// Create filter interface
this = ioFilterNewP(
BZ2_DECOMPRESS_FILTER_TYPE_STR, driver, NULL, .done = bz2DecompressDone, .inOut = bz2DecompressProcess,
.inputSame = bz2DecompressInputSame);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_FILTER, this);
}

View File

@ -12,7 +12,6 @@ Gz Compress
#include "common/io/filter/filter.h"
#include "common/log.h"
#include "common/macro.h"
#include "common/memContext.h"
#include "common/type/object.h"
/***********************************************************************************************************************************
@ -25,7 +24,6 @@ Object type
***********************************************************************************************************************************/
typedef struct GzCompress
{
MemContext *memContext; // Context to store data
z_stream stream; // Compression stream state
bool inputSame; // Is the same input required on the next process call?
@ -178,13 +176,12 @@ gzCompressNew(int level)
IoFilter *this = NULL;
MEM_CONTEXT_NEW_BEGIN("GzCompress")
OBJ_NEW_BEGIN(GzCompress)
{
GzCompress *driver = memNew(sizeof(GzCompress));
GzCompress *driver = OBJ_NEW_ALLOC();
*driver = (GzCompress)
{
.memContext = MEM_CONTEXT_NEW(),
.stream = {.zalloc = NULL},
};
@ -192,7 +189,7 @@ gzCompressNew(int level)
gzError(deflateInit2(&driver->stream, level, Z_DEFLATED, WANT_GZ | WINDOW_BITS, MEM_LEVEL, Z_DEFAULT_STRATEGY));
// Set free callback to ensure gz context is freed
memContextCallbackSet(driver->memContext, gzCompressFreeResource, driver);
memContextCallbackSet(objMemContext(driver), gzCompressFreeResource, driver);
// Create param list
VariantList *paramList = varLstNew();
@ -203,7 +200,7 @@ gzCompressNew(int level)
GZ_COMPRESS_FILTER_TYPE_STR, driver, paramList, .done = gzCompressDone, .inOut = gzCompressProcess,
.inputSame = gzCompressInputSame);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_FILTER, this);
}

View File

@ -12,7 +12,6 @@ Gz Decompress
#include "common/io/filter/filter.h"
#include "common/log.h"
#include "common/macro.h"
#include "common/memContext.h"
#include "common/type/object.h"
/***********************************************************************************************************************************
@ -25,7 +24,6 @@ Object type
***********************************************************************************************************************************/
typedef struct GzDecompress
{
MemContext *memContext; // Context to store data
z_stream stream; // Decompression stream state
int result; // Result of last operation
@ -157,14 +155,13 @@ gzDecompressNew(void)
IoFilter *this = NULL;
MEM_CONTEXT_NEW_BEGIN("GzDecompress")
OBJ_NEW_BEGIN(GzDecompress)
{
// Allocate state and set context
GzDecompress *driver = memNew(sizeof(GzDecompress));
GzDecompress *driver = OBJ_NEW_ALLOC();
*driver = (GzDecompress)
{
.memContext = MEM_CONTEXT_NEW(),
.stream = {.zalloc = NULL},
};
@ -172,14 +169,14 @@ gzDecompressNew(void)
gzError(driver->result = inflateInit2(&driver->stream, WANT_GZ | WINDOW_BITS));
// Set free callback to ensure gz context is freed
memContextCallbackSet(driver->memContext, gzDecompressFreeResource, driver);
memContextCallbackSet(objMemContext(driver), gzDecompressFreeResource, driver);
// Create filter interface
this = ioFilterNewP(
GZ_DECOMPRESS_FILTER_TYPE_STR, driver, NULL, .done = gzDecompressDone, .inOut = gzDecompressProcess,
.inputSame = gzDecompressInputSame);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_FILTER, this);
}

View File

@ -16,7 +16,6 @@ Developed against version r131 using the documentation in https://github.com/lz4
#include "common/debug.h"
#include "common/io/filter/filter.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
/***********************************************************************************************************************************
@ -36,7 +35,6 @@ Object type
***********************************************************************************************************************************/
typedef struct Lz4Compress
{
MemContext *memContext; // Context to store data
LZ4F_compressionContext_t context; // LZ4 compression context
LZ4F_preferences_t prefs; // Preferences -- just compress level set
IoFilter *filter; // Filter interface
@ -259,13 +257,12 @@ lz4CompressNew(int level)
IoFilter *this = NULL;
MEM_CONTEXT_NEW_BEGIN("Lz4Compress")
OBJ_NEW_BEGIN(Lz4Compress)
{
Lz4Compress *driver = memNew(sizeof(Lz4Compress));
Lz4Compress *driver = OBJ_NEW_ALLOC();
*driver = (Lz4Compress)
{
.memContext = MEM_CONTEXT_NEW(),
.prefs = {.compressionLevel = level, .frameInfo = {.contentChecksumFlag = LZ4F_contentChecksumEnabled}},
.first = true,
.buffer = bufNew(0),
@ -275,7 +272,7 @@ lz4CompressNew(int level)
lz4Error(LZ4F_createCompressionContext(&driver->context, LZ4F_VERSION));
// Set callback to ensure lz4 context is freed
memContextCallbackSet(driver->memContext, lz4CompressFreeResource, driver);
memContextCallbackSet(objMemContext(driver), lz4CompressFreeResource, driver);
// Create param list
VariantList *paramList = varLstNew();
@ -286,7 +283,7 @@ lz4CompressNew(int level)
LZ4_COMPRESS_FILTER_TYPE_STR, driver, paramList, .done = lz4CompressDone, .inOut = lz4CompressProcess,
.inputSame = lz4CompressInputSame);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_FILTER, this);
}

View File

@ -13,7 +13,6 @@ LZ4 Decompress
#include "common/debug.h"
#include "common/io/filter/filter.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
/***********************************************************************************************************************************
@ -26,7 +25,6 @@ Object type
***********************************************************************************************************************************/
typedef struct Lz4Decompress
{
MemContext *memContext; // Context to store data
LZ4F_decompressionContext_t context; // LZ4 decompression context
IoFilter *filter; // Filter interface
@ -170,27 +168,23 @@ lz4DecompressNew(void)
IoFilter *this = NULL;
MEM_CONTEXT_NEW_BEGIN("Lz4Decompress")
OBJ_NEW_BEGIN(Lz4Decompress)
{
Lz4Decompress *driver = memNew(sizeof(Lz4Decompress));
*driver = (Lz4Decompress)
{
.memContext = MEM_CONTEXT_NEW(),
};
Lz4Decompress *driver = OBJ_NEW_ALLOC();
*driver = (Lz4Decompress){0};
// Create lz4 context
lz4Error(LZ4F_createDecompressionContext(&driver->context, LZ4F_VERSION));
// Set callback to ensure lz4 context is freed
memContextCallbackSet(driver->memContext, lz4DecompressFreeResource, driver);
memContextCallbackSet(objMemContext(driver), lz4DecompressFreeResource, driver);
// Create filter interface
this = ioFilterNewP(
LZ4_DECOMPRESS_FILTER_TYPE_STR, driver, NULL, .done = lz4DecompressDone, .inOut = lz4DecompressProcess,
.inputSame = lz4DecompressInputSame);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_FILTER, this);
}

View File

@ -12,7 +12,6 @@ ZST Compress
#include "common/debug.h"
#include "common/io/filter/filter.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
/***********************************************************************************************************************************
@ -25,7 +24,6 @@ Object type
***********************************************************************************************************************************/
typedef struct ZstCompress
{
MemContext *memContext; // Context to store data
ZSTD_CStream *context; // Compression context
int level; // Compression level
IoFilter *filter; // Filter interface
@ -180,19 +178,18 @@ zstCompressNew(int level)
IoFilter *this = NULL;
MEM_CONTEXT_NEW_BEGIN("ZstCompress")
OBJ_NEW_BEGIN(ZstCompress)
{
ZstCompress *driver = memNew(sizeof(ZstCompress));
ZstCompress *driver = OBJ_NEW_ALLOC();
*driver = (ZstCompress)
{
.memContext = MEM_CONTEXT_NEW(),
.context = ZSTD_createCStream(),
.level = level,
};
// Set callback to ensure zst context is freed
memContextCallbackSet(driver->memContext, zstCompressFreeResource, driver);
memContextCallbackSet(objMemContext(driver), zstCompressFreeResource, driver);
// Initialize context
zstError(ZSTD_initCStream(driver->context, driver->level));
@ -206,7 +203,7 @@ zstCompressNew(int level)
ZST_COMPRESS_FILTER_TYPE_STR, driver, paramList, .done = zstCompressDone, .inOut = zstCompressProcess,
.inputSame = zstCompressInputSame);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_FILTER, this);
}

View File

@ -12,7 +12,6 @@ ZST Decompress
#include "common/debug.h"
#include "common/io/filter/filter.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
/***********************************************************************************************************************************
@ -25,7 +24,6 @@ Object type
***********************************************************************************************************************************/
typedef struct ZstDecompress
{
MemContext *memContext; // Context to store data
ZSTD_DStream *context; // Decompression context
IoFilter *filter; // Filter interface
@ -169,18 +167,17 @@ zstDecompressNew(void)
IoFilter *this = NULL;
MEM_CONTEXT_NEW_BEGIN("ZstDecompress")
OBJ_NEW_BEGIN(ZstDecompress)
{
ZstDecompress *driver = memNew(sizeof(ZstDecompress));
ZstDecompress *driver = OBJ_NEW_ALLOC();
*driver = (ZstDecompress)
{
.memContext = MEM_CONTEXT_NEW(),
.context = ZSTD_createDStream(),
};
// Set callback to ensure zst context is freed
memContextCallbackSet(driver->memContext, zstDecompressFreeResource, driver);
memContextCallbackSet(objMemContext(driver), zstDecompressFreeResource, driver);
// Initialize context
zstError(ZSTD_initDStream(driver->context));
@ -190,7 +187,7 @@ zstDecompressNew(void)
ZST_DECOMPRESS_FILTER_TYPE_STR, driver, NULL, .done = zstDecompressDone, .inOut = zstDecompressProcess,
.inputSame = zstDecompressInputSame);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_FILTER, this);
}

View File

@ -13,7 +13,6 @@ Block Cipher
#include "common/debug.h"
#include "common/io/filter/filter.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
/***********************************************************************************************************************************
@ -37,7 +36,6 @@ Object type
***********************************************************************************************************************************/
typedef struct CipherBlock
{
MemContext *memContext; // Context to store data
CipherMode mode; // Mode encrypt/decrypt
bool saltDone; // Has the salt been read/generated?
bool processDone; // Has any data been processed?
@ -194,7 +192,7 @@ cipherBlockProcessBlock(CipherBlock *this, const unsigned char *source, size_t s
cryptoError(!(this->cipherContext = EVP_CIPHER_CTX_new()), "unable to create context");
// Set free callback to ensure cipher context is freed
memContextCallbackSet(this->memContext, cipherBlockFreeResource, this);
memContextCallbackSet(objMemContext(this), cipherBlockFreeResource, this);
// Initialize cipher
cryptoError(
@ -306,7 +304,7 @@ cipherBlockProcess(THIS_VOID, const Buffer *source, Buffer *destination)
if (destinationSize > bufRemains(destination))
{
// Allocate the buffer if needed
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
if (this->buffer == NULL)
{
@ -425,13 +423,12 @@ cipherBlockNew(CipherMode mode, CipherType cipherType, const Buffer *pass, const
// Allocate memory to hold process state
IoFilter *this = NULL;
MEM_CONTEXT_NEW_BEGIN("CipherBlock")
OBJ_NEW_BEGIN(CipherBlock)
{
CipherBlock *driver = memNew(sizeof(CipherBlock));
CipherBlock *driver = OBJ_NEW_ALLOC();
*driver = (CipherBlock)
{
.memContext = MEM_CONTEXT_NEW(),
.mode = mode,
.cipher = cipher,
.digest = digest,
@ -456,7 +453,7 @@ cipherBlockNew(CipherMode mode, CipherType cipherType, const Buffer *pass, const
CIPHER_BLOCK_FILTER_TYPE_STR, driver, paramList, .done = cipherBlockDone, .inOut = cipherBlockProcess,
.inputSame = cipherBlockInputSame);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_FILTER, this);
}

View File

@ -13,7 +13,6 @@ Cryptographic Hash
#include "common/debug.h"
#include "common/io/filter/filter.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
#include "common/crypto/common.h"
@ -45,7 +44,6 @@ Object type
***********************************************************************************************************************************/
typedef struct CryptoHash
{
MemContext *memContext; // Context to store data
const EVP_MD *hashType; // Hash type (sha1, md5, etc.)
EVP_MD_CTX *hashContext; // Message hash context
MD5_CTX *md5Context; // MD5 context (used to bypass FIPS restrictions)
@ -122,7 +120,7 @@ cryptoHash(CryptoHash *this)
if (this->hash == NULL)
{
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
// Standard OpenSSL implementation
if (this->hashContext != NULL)
@ -178,14 +176,10 @@ cryptoHashNew(const String *type)
// Allocate memory to hold process state
IoFilter *this = NULL;
MEM_CONTEXT_NEW_BEGIN("CryptoHash")
OBJ_NEW_BEGIN(CryptoHash)
{
CryptoHash *driver = memNew(sizeof(CryptoHash));
*driver = (CryptoHash)
{
.memContext = MEM_CONTEXT_NEW(),
};
CryptoHash *driver = OBJ_NEW_ALLOC();
*driver = (CryptoHash){0};
// Use local MD5 implementation since FIPS-enabled systems do not allow MD5. This is a bit misguided since there are valid
// cases for using MD5 which do not involve, for example, password hashes. Since popular object stores, e.g. S3, require
@ -207,7 +201,7 @@ cryptoHashNew(const String *type)
cryptoError((driver->hashContext = EVP_MD_CTX_create()) == NULL, "unable to create hash context");
// Set free callback to ensure hash context is freed
memContextCallbackSet(driver->memContext, cryptoHashFreeResource, driver);
memContextCallbackSet(objMemContext(driver), cryptoHashFreeResource, driver);
// Initialize context
cryptoError(!EVP_DigestInit_ex(driver->hashContext, driver->hashType, NULL), "unable to initialize hash context");
@ -220,7 +214,7 @@ cryptoHashNew(const String *type)
// Create filter interface
this = ioFilterNewP(CRYPTO_HASH_FILTER_TYPE_STR, driver, paramList, .in = cryptoHashProcess, .result = cryptoHashResult);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_FILTER, this);
}

View File

@ -127,16 +127,12 @@ execNew(const String *command, const StringList *param, const String *name, Time
Exec *this = NULL;
MEM_CONTEXT_NEW_BEGIN("Exec")
OBJ_NEW_BEGIN(Exec)
{
this = memNew(sizeof(Exec));
this = OBJ_NEW_ALLOC();
*this = (Exec)
{
.pub =
{
.memContext = MEM_CONTEXT_NEW(),
},
.command = strDup(command),
.name = strDup(name),
.timeout = timeout,
@ -148,7 +144,7 @@ execNew(const String *command, const StringList *param, const String *name, Time
// The first parameter must be the command
strLstInsert(this->param, 0, this->command);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(EXEC, this);
}
@ -369,7 +365,7 @@ execOpen(Exec *this)
ioWriteOpen(execIoWrite(this));
// Set a callback so the file descriptors will get freed
memContextCallbackSet(execMemContext(this), execFreeResource, this);
memContextCallbackSet(objMemContext(this), execFreeResource, this);
FUNCTION_LOG_RETURN_VOID();
}

View File

@ -29,7 +29,6 @@ Getters/Setters
***********************************************************************************************************************************/
typedef struct ExecPub
{
MemContext *memContext; // Mem context
IoRead *ioReadExec; // Wrapper for file descriptor read interface
IoWrite *ioWriteExec; // Wrapper for file descriptor write interface
} ExecPub;
@ -52,7 +51,7 @@ execIoWrite(Exec *const this)
__attribute__((always_inline)) static inline MemContext *
execMemContext(Exec *const this)
{
return THIS_PUB(Exec)->memContext;
return objMemContext(this);
}
/***********************************************************************************************************************************

View File

@ -8,7 +8,6 @@ Ini Handler
#include <string.h>
#include "common/debug.h"
#include "common/memContext.h"
#include "common/log.h"
#include "common/ini.h"
#include "common/type/json.h"
@ -19,7 +18,6 @@ Object type
***********************************************************************************************************************************/
struct Ini
{
MemContext *memContext; // Context that contains the ini
KeyValue *store; // Key value store that contains the ini data
};
@ -31,17 +29,16 @@ iniNew(void)
Ini *this = NULL;
MEM_CONTEXT_NEW_BEGIN("Ini")
OBJ_NEW_BEGIN(Ini)
{
this = memNew(sizeof(Ini));
this = OBJ_NEW_ALLOC();
*this = (Ini)
{
.memContext = MEM_CONTEXT_NEW(),
.store = kvNew(),
};
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_TEST_RETURN(this);
}
@ -228,7 +225,7 @@ iniParse(Ini *this, const String *content)
ASSERT(this != NULL);
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
kvFree(this->store);
this->store = kvNew();

View File

@ -7,7 +7,6 @@ Buffer IO Read
#include "common/io/bufferRead.h"
#include "common/io/read.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
/***********************************************************************************************************************************
@ -15,7 +14,6 @@ Object type
***********************************************************************************************************************************/
typedef struct IoBufferRead
{
MemContext *memContext; // Object memory context
const Buffer *read; // Buffer to read data from
size_t readPos; // Current position in the read buffer
@ -96,19 +94,18 @@ ioBufferReadNew(const Buffer *buffer)
IoRead *this = NULL;
MEM_CONTEXT_NEW_BEGIN("IoBufferRead")
OBJ_NEW_BEGIN(IoBufferRead)
{
IoBufferRead *driver = memNew(sizeof(IoBufferRead));
IoBufferRead *driver = OBJ_NEW_ALLOC();
*driver = (IoBufferRead)
{
.memContext = MEM_CONTEXT_NEW(),
.read = buffer,
};
this = ioReadNewP(driver, .eof = ioBufferReadEof, .read = ioBufferRead);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_READ, this);
}

View File

@ -7,7 +7,6 @@ Buffer IO Write
#include "common/io/bufferWrite.h"
#include "common/io/write.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
/***********************************************************************************************************************************
@ -15,7 +14,6 @@ Object type
***********************************************************************************************************************************/
typedef struct IoBufferWrite
{
MemContext *memContext; // Object memory context
Buffer *write; // Buffer to write into
} IoBufferWrite;
@ -60,19 +58,18 @@ ioBufferWriteNew(Buffer *buffer)
IoWrite *this = NULL;
MEM_CONTEXT_NEW_BEGIN("IoBufferWrite")
OBJ_NEW_BEGIN(IoBufferWrite)
{
IoBufferWrite *driver = memNew(sizeof(IoBufferWrite));
IoBufferWrite *driver = OBJ_NEW_ALLOC();
*driver = (IoBufferWrite)
{
.memContext = memContextCurrent(),
.write = buffer,
};
this = ioWriteNewP(driver, .write = ioBufferWrite);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_WRITE, this);
}

View File

@ -6,7 +6,6 @@ Io Client Interface
#include "common/debug.h"
#include "common/io/client.h"
#include "common/log.h"
#include "common/memContext.h"
/***********************************************************************************************************************************
Object type

View File

@ -40,7 +40,7 @@ Functions
__attribute__((always_inline)) static inline IoClient *
ioClientMove(IoClient *const this, MemContext *const parentNew)
{
return objMove(this, parentNew);
return objMoveContext(this, parentNew);
}
// Open session
@ -56,7 +56,7 @@ Destructor
__attribute__((always_inline)) static inline void
ioClientFree(IoClient *const this)
{
objFree(this);
objFreeContext(this);
}
/***********************************************************************************************************************************

View File

@ -10,7 +10,6 @@ File Descriptor Io Read
#include "common/io/fdRead.h"
#include "common/io/read.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
/***********************************************************************************************************************************
@ -18,7 +17,6 @@ Object type
***********************************************************************************************************************************/
typedef struct IoFdRead
{
MemContext *memContext; // Object memory context
const String *name; // File descriptor name for error messages
int fd; // File descriptor to read data from
TimeMSec timeout; // Timeout for read operation
@ -158,13 +156,12 @@ ioFdReadNew(const String *name, int fd, TimeMSec timeout)
IoRead *this = NULL;
MEM_CONTEXT_NEW_BEGIN("IoFdRead")
OBJ_NEW_BEGIN(IoFdRead)
{
IoFdRead *driver = memNew(sizeof(IoFdRead));
IoFdRead *driver = OBJ_NEW_ALLOC();
*driver = (IoFdRead)
{
.memContext = memContextCurrent(),
.name = strDup(name),
.fd = fd,
.timeout = timeout,
@ -172,7 +169,7 @@ ioFdReadNew(const String *name, int fd, TimeMSec timeout)
this = ioReadNewP(driver, .block = true, .eof = ioFdReadEof, .fd = ioFdReadFd, .read = ioFdRead, .ready = ioFdReadReady);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_READ, this);
}

View File

@ -10,7 +10,6 @@ File Descriptor Io Write
#include "common/io/fdWrite.h"
#include "common/io/write.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
/***********************************************************************************************************************************
@ -18,7 +17,6 @@ Object type
***********************************************************************************************************************************/
typedef struct IoFdWrite
{
MemContext *memContext; // Object memory context
const String *name; // File descriptor name for error messages
int fd; // File descriptor to write to
TimeMSec timeout; // Timeout for write operation
@ -114,13 +112,12 @@ ioFdWriteNew(const String *name, int fd, TimeMSec timeout)
IoWrite *this = NULL;
MEM_CONTEXT_NEW_BEGIN("IoFdWrite")
OBJ_NEW_BEGIN(IoFdWrite)
{
IoFdWrite *driver = memNew(sizeof(IoFdWrite));
IoFdWrite *driver = OBJ_NEW_ALLOC();
*driver = (IoFdWrite)
{
.memContext = memContextCurrent(),
.name = strDup(name),
.fd = fd,
.timeout = timeout,
@ -128,7 +125,7 @@ ioFdWriteNew(const String *name, int fd, TimeMSec timeout)
this = ioWriteNewP(driver, .fd = ioFdWriteFd, .ready = ioFdWriteReady, .write = ioFdWrite);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_WRITE, this);
}

View File

@ -9,7 +9,6 @@ IO Buffer Filter
#include "common/io/filter/buffer.h"
#include "common/io/filter/filter.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
/***********************************************************************************************************************************
@ -23,8 +22,6 @@ Object type
***********************************************************************************************************************************/
typedef struct IoBuffer
{
MemContext *memContext; // Mem context of filter
size_t inputPos; // Position in input buffer
bool inputSame; // Is the same input required again?
} IoBuffer;
@ -114,18 +111,14 @@ ioBufferNew(void)
IoFilter *this = NULL;
MEM_CONTEXT_NEW_BEGIN("IoBuffer")
OBJ_NEW_BEGIN(IoBuffer)
{
IoBuffer *driver = memNew(sizeof(IoBuffer));
*driver = (IoBuffer)
{
.memContext = memContextCurrent(),
};
IoBuffer *driver = OBJ_NEW_ALLOC();
*driver = (IoBuffer){0};
this = ioFilterNewP(BUFFER_FILTER_TYPE_STR, driver, NULL, .inOut = ioBufferProcess, .inputSame = ioBufferInputSame);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_FILTER, this);
}

View File

@ -40,7 +40,7 @@ Destructor
__attribute__((always_inline)) static inline void
ioFilterFree(IoFilter *const this)
{
objFree(this);
objFreeContext(this);
}
/***********************************************************************************************************************************

View File

@ -113,7 +113,7 @@ void ioFilterProcessInOut(IoFilter *this, const Buffer *input, Buffer *output);
__attribute__((always_inline)) static inline IoFilter *
ioFilterMove(IoFilter *this, MemContext *parentNew)
{
return objMove(this, parentNew);
return objMoveContext(this, parentNew);
}
/***********************************************************************************************************************************

View File

@ -11,7 +11,6 @@ IO Filter Group
#include "common/io/filter/group.h"
#include "common/io/io.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/list.h"
/***********************************************************************************************************************************
@ -55,21 +54,20 @@ ioFilterGroupNew(void)
IoFilterGroup *this = NULL;
MEM_CONTEXT_NEW_BEGIN("IoFilterGroup")
OBJ_NEW_BEGIN(IoFilterGroup)
{
this = memNew(sizeof(IoFilterGroup));
this = OBJ_NEW_ALLOC();
*this = (IoFilterGroup)
{
.pub =
{
.memContext = memContextCurrent(),
.done = false,
.filterList = lstNewP(sizeof(IoFilterData)),
},
};
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_FILTER_GROUP, this);
}
@ -88,7 +86,7 @@ ioFilterGroupAdd(IoFilterGroup *this, IoFilter *filter)
ASSERT(filter != NULL);
// Move the filter to this object's mem context
ioFilterMove(filter, this->pub.memContext);
ioFilterMove(filter, objMemContext(this));
// Add the filter
IoFilterData filterData = {.filter = filter};
@ -111,7 +109,7 @@ ioFilterGroupInsert(IoFilterGroup *this, unsigned int listIdx, IoFilter *filter)
ASSERT(filter != NULL);
// Move the filter to this object's mem context
ioFilterMove(filter, this->pub.memContext);
ioFilterMove(filter, objMemContext(this));
// Add the filter
IoFilterData filterData = {.filter = filter};
@ -167,7 +165,7 @@ ioFilterGroupOpen(IoFilterGroup *this)
ASSERT(this != NULL);
MEM_CONTEXT_BEGIN(this->pub.memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
// If the last filter is not an output filter then add a filter to buffer/copy data. Input filters won't copy to an output
// buffer so we need some way to get the data to the output buffer.
@ -362,7 +360,7 @@ ioFilterGroupClose(IoFilterGroup *this)
if (this->filterResult == NULL)
{
MEM_CONTEXT_BEGIN(this->pub.memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
this->filterResult = kvNew();
}
@ -461,7 +459,7 @@ ioFilterGroupResultAllSet(IoFilterGroup *this, const Variant *filterResult)
if (filterResult != NULL)
{
MEM_CONTEXT_BEGIN(this->pub.memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
this->filterResult = kvDup(varKv(filterResult));
}

View File

@ -29,7 +29,6 @@ Getters/Setters
***********************************************************************************************************************************/
typedef struct IoFilterGroupPub
{
MemContext *memContext; // Mem context
List *filterList; // List of filters to apply
bool inputSame; // Same input required again?
bool done; // Is processing done?

View File

@ -7,7 +7,6 @@ IO Sink Filter
#include "common/io/filter/filter.h"
#include "common/io/filter/sink.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
/***********************************************************************************************************************************
@ -20,7 +19,7 @@ Object type
***********************************************************************************************************************************/
typedef struct IoSink
{
MemContext *memContext; // Mem context of filter
bool dummy; // Struct requires one member
} IoSink;
/***********************************************************************************************************************************
@ -60,18 +59,12 @@ ioSinkNew(void)
IoFilter *this = NULL;
MEM_CONTEXT_NEW_BEGIN("IoSink")
OBJ_NEW_BEGIN(IoSink)
{
IoSink *driver = memNew(sizeof(IoSink));
*driver = (IoSink)
{
.memContext = memContextCurrent(),
};
IoSink *driver = OBJ_NEW_ALLOC();
this = ioFilterNewP(SINK_FILTER_TYPE_STR, driver, NULL, .inOut = ioSinkProcess);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_FILTER, this);
}

View File

@ -9,7 +9,6 @@ IO Size Filter
#include "common/io/filter/filter.h"
#include "common/io/filter/size.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
/***********************************************************************************************************************************
@ -22,8 +21,6 @@ Object type
***********************************************************************************************************************************/
typedef struct IoSize
{
MemContext *memContext; // Mem context of filter
uint64_t size; // Total size of al input
} IoSize;
@ -87,18 +84,14 @@ ioSizeNew(void)
IoFilter *this = NULL;
MEM_CONTEXT_NEW_BEGIN("IoSize")
OBJ_NEW_BEGIN(IoSize)
{
IoSize *driver = memNew(sizeof(IoSize));
*driver = (IoSize)
{
.memContext = memContextCurrent(),
};
IoSize *driver = OBJ_NEW_ALLOC();
*driver = (IoSize){0};
this = ioFilterNewP(SIZE_FILTER_TYPE_STR, driver, NULL, .in = ioSizeProcess, .result = ioSizeResult);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_FILTER, this);
}

View File

@ -25,7 +25,6 @@ Object type
struct HttpClient
{
HttpClientPub pub; // Publicly accessible variables
MemContext *memContext; // Mem context
IoClient *ioClient; // Io client (e.g. TLS or socket client)
List *sessionReuseList; // List of HTTP sessions that can be reused
@ -44,9 +43,9 @@ httpClientNew(IoClient *ioClient, TimeMSec timeout)
HttpClient *this = NULL;
MEM_CONTEXT_NEW_BEGIN("HttpClient")
OBJ_NEW_BEGIN(HttpClient)
{
this = memNew(sizeof(HttpClient));
this = OBJ_NEW_ALLOC();
*this = (HttpClient)
{
@ -54,14 +53,13 @@ httpClientNew(IoClient *ioClient, TimeMSec timeout)
{
.timeout = timeout,
},
.memContext = MEM_CONTEXT_NEW(),
.ioClient = ioClient,
.sessionReuseList = lstNewP(sizeof(HttpSession *)),
};
statInc(HTTP_STAT_CLIENT_STR);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(HTTP_CLIENT, this);
}

View File

@ -5,7 +5,6 @@ HTTP Header
#include "common/debug.h"
#include "common/io/http/header.h"
#include "common/memContext.h"
#include "common/type/keyValue.h"
/***********************************************************************************************************************************
@ -13,7 +12,6 @@ Object type
***********************************************************************************************************************************/
struct HttpHeader
{
MemContext *memContext; // Mem context
const StringList *redactList; // List of headers to redact during logging
KeyValue *kv; // KeyValue store
};
@ -26,19 +24,18 @@ httpHeaderNew(const StringList *redactList)
HttpHeader *this = NULL;
MEM_CONTEXT_NEW_BEGIN("HttpHeader")
OBJ_NEW_BEGIN(HttpHeader)
{
// Allocate state and set context
this = memNew(sizeof(HttpHeader));
this = OBJ_NEW_ALLOC();
*this = (HttpHeader)
{
.memContext = MEM_CONTEXT_NEW(),
.redactList = strLstDup(redactList),
.kv = kvNew(),
};
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_TEST_RETURN(this);
}
@ -56,19 +53,18 @@ httpHeaderDup(const HttpHeader *header, const StringList *redactList)
if (header != NULL)
{
MEM_CONTEXT_NEW_BEGIN("HttpHeader")
OBJ_NEW_BEGIN(HttpHeader)
{
// Allocate state and set context
this = memNew(sizeof(HttpHeader));
this = OBJ_NEW_ALLOC();
*this = (HttpHeader)
{
.memContext = MEM_CONTEXT_NEW(),
.redactList = redactList == NULL ? strLstDup(header->redactList) : strLstDup(redactList),
.kv = kvDup(header->kv),
};
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
}
FUNCTION_TEST_RETURN(this);

View File

@ -6,7 +6,6 @@ HTTP Query
#include "common/debug.h"
#include "common/io/http/common.h"
#include "common/io/http/query.h"
#include "common/memContext.h"
#include "common/type/keyValue.h"
/***********************************************************************************************************************************
@ -14,7 +13,6 @@ Object type
***********************************************************************************************************************************/
struct HttpQuery
{
MemContext *memContext; // Mem context
KeyValue *kv; // KeyValue store
const StringList *redactList; // List of keys to redact values for
};
@ -29,19 +27,18 @@ httpQueryNew(HttpQueryNewParam param)
HttpQuery *this = NULL;
MEM_CONTEXT_NEW_BEGIN("HttpQuery")
OBJ_NEW_BEGIN(HttpQuery)
{
// Allocate state and set context
this = memNew(sizeof(HttpQuery));
this = OBJ_NEW_ALLOC();
*this = (HttpQuery)
{
.memContext = MEM_CONTEXT_NEW(),
.kv = kvNew(),
.redactList = strLstDup(param.redactList),
};
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_TEST_RETURN(this);
}
@ -58,13 +55,12 @@ httpQueryNewStr(const String *query)
HttpQuery *this = NULL;
MEM_CONTEXT_NEW_BEGIN("HttpQuery")
OBJ_NEW_BEGIN(HttpQuery)
{
this = memNew(sizeof(HttpQuery));
this = OBJ_NEW_ALLOC();
*this = (HttpQuery)
{
.memContext = MEM_CONTEXT_NEW(),
.kv = kvNew(),
};
@ -94,7 +90,7 @@ httpQueryNewStr(const String *query)
}
MEM_CONTEXT_TEMP_END();
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_TEST_RETURN(this);
}
@ -112,19 +108,18 @@ httpQueryDup(const HttpQuery *query, HttpQueryDupParam param)
if (query != NULL)
{
MEM_CONTEXT_NEW_BEGIN("HttpQuery")
OBJ_NEW_BEGIN(HttpQuery)
{
// Allocate state and set context
this = memNew(sizeof(HttpQuery));
this = OBJ_NEW_ALLOC();
*this = (HttpQuery)
{
.memContext = MEM_CONTEXT_NEW(),
.kv = kvDup(query->kv),
.redactList = param.redactList != NULL ? strLstDup(param.redactList) : strLstDup(query->redactList),
};
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
}
FUNCTION_TEST_RETURN(this);

View File

@ -126,7 +126,7 @@ httpRequestProcess(HttpRequest *this, bool waitForResponse, bool contentCache)
// If not waiting for the response then move the session to the object context
if (!waitForResponse)
this->session = httpSessionMove(session, this->pub.memContext);
this->session = httpSessionMove(session, objMemContext(this));
}
// Wait for response
@ -189,15 +189,14 @@ httpRequestNew(HttpClient *client, const String *verb, const String *path, HttpR
HttpRequest *this = NULL;
MEM_CONTEXT_NEW_BEGIN("HttpRequest")
OBJ_NEW_BEGIN(HttpRequest)
{
this = memNew(sizeof(HttpRequest));
this = OBJ_NEW_ALLOC();
*this = (HttpRequest)
{
.pub =
{
.memContext = MEM_CONTEXT_NEW(),
.verb = strDup(verb),
.path = strDup(path),
.query = httpQueryDupP(param.query),
@ -211,7 +210,7 @@ httpRequestNew(HttpClient *client, const String *verb, const String *path, HttpR
httpRequestProcess(this, false, false);
statInc(HTTP_STAT_REQUEST_STR);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(HTTP_REQUEST, this);
}

View File

@ -80,7 +80,6 @@ Getters/Setters
***********************************************************************************************************************************/
typedef struct HttpRequestPub
{
MemContext *memContext; // Mem context
const String *verb; // HTTP verb (GET, POST, etc.)
const String *path; // HTTP path
const HttpQuery *query; // HTTP query

View File

@ -202,15 +202,14 @@ httpResponseNew(HttpSession *session, const String *verb, bool contentCache)
HttpResponse *this = NULL;
MEM_CONTEXT_NEW_BEGIN("HttpResponse")
OBJ_NEW_BEGIN(HttpResponse)
{
this = memNew(sizeof(HttpResponse));
this = OBJ_NEW_ALLOC();
*this = (HttpResponse)
{
.pub =
{
.memContext = MEM_CONTEXT_NEW(),
.header = httpHeaderNew(NULL),
},
.session = httpSessionMove(session, memContextCurrent()),
@ -251,7 +250,7 @@ httpResponseNew(HttpSession *session, const String *verb, bool contentCache)
this->pub.code = cvtZToUInt(strZ(strSubN(status, 0, (size_t)spacePos)));
// Read reason phrase. A missing reason phrase will be represented as an empty string.
MEM_CONTEXT_BEGIN(this->pub.memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
this->pub.reason = strSub(status, (size_t)spacePos + 1);
}
@ -321,7 +320,7 @@ httpResponseNew(HttpSession *session, const String *verb, bool contentCache)
// Create an io object, even if there is no content. This makes the logic for readers easier -- they can just check eof
// rather than also checking if the io object exists.
MEM_CONTEXT_BEGIN(this->pub.memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
this->pub.contentRead = ioReadNewP(this, .eof = httpResponseEof, .read = httpResponseRead);
ioReadOpen(httpResponseIoRead(this));
@ -336,7 +335,7 @@ httpResponseNew(HttpSession *session, const String *verb, bool contentCache)
// Else cache content when requested or on error
else if (contentCache || !httpResponseCodeOk(this))
{
MEM_CONTEXT_BEGIN(this->pub.memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
httpResponseContent(this);
}
@ -345,7 +344,7 @@ httpResponseNew(HttpSession *session, const String *verb, bool contentCache)
}
MEM_CONTEXT_TEMP_END();
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(HTTP_RESPONSE, this);
}

View File

@ -34,7 +34,6 @@ Getters/Setters
***********************************************************************************************************************************/
typedef struct HttpResponsePub
{
MemContext *memContext; // Mem context
IoRead *contentRead; // Read interface for response content
unsigned int code; // Response code (e.g. 200, 404)
HttpHeader *header; // Response headers

View File

@ -7,14 +7,12 @@ HTTP Session
#include "common/io/http/session.h"
#include "common/io/io.h"
#include "common/log.h"
#include "common/memContext.h"
/***********************************************************************************************************************************
Object type
***********************************************************************************************************************************/
struct HttpSession
{
MemContext *memContext; // Mem context
HttpClient *httpClient; // HTTP client
IoSession *ioSession; // IO session
};
@ -33,18 +31,17 @@ httpSessionNew(HttpClient *httpClient, IoSession *ioSession)
HttpSession *this = NULL;
MEM_CONTEXT_NEW_BEGIN("HttpSession")
OBJ_NEW_BEGIN(HttpSession)
{
this = memNew(sizeof(HttpSession));
this = OBJ_NEW_ALLOC();
*this = (HttpSession)
{
.memContext = MEM_CONTEXT_NEW(),
.httpClient = httpClient,
.ioSession = ioSessionMove(ioSession, memContextCurrent()),
};
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(HTTP_SESSION, this);
}

View File

@ -5,7 +5,6 @@ HTTP URL
#include "common/debug.h"
#include "common/io/http/url.h"
#include "common/memContext.h"
#include "common/type/stringList.h"
#include "common/regExp.h"
@ -63,16 +62,15 @@ httpUrlNewParse(const String *const url, HttpUrlNewParseParam param)
HttpUrl *this = NULL;
MEM_CONTEXT_NEW_BEGIN("HttpUrl")
OBJ_NEW_BEGIN(HttpUrl)
{
// Allocate state and set context
this = memNew(sizeof(HttpUrl));
this = OBJ_NEW_ALLOC();
*this = (HttpUrl)
{
.pub =
{
.memContext = MEM_CONTEXT_NEW(),
.url = strDup(url),
},
};
@ -191,7 +189,7 @@ httpUrlNewParse(const String *const url, HttpUrlNewParseParam param)
}
MEM_CONTEXT_TEMP_END();
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_TEST_RETURN(this);
}

View File

@ -44,7 +44,6 @@ Getters/setters
***********************************************************************************************************************************/
typedef struct HttpUrlPub
{
MemContext *memContext; // Mem context
const String *url; // Original URL
HttpProtocolType type; // Protocol type, e.g. http
const String *host; // Host

View File

@ -9,7 +9,6 @@ IO Read Interface
#include "common/io/io.h"
#include "common/io/read.h"
#include "common/log.h"
#include "common/memContext.h"
/***********************************************************************************************************************************
Object type
@ -36,9 +35,9 @@ ioReadNew(void *driver, IoReadInterface interface)
IoRead *this = NULL;
MEM_CONTEXT_NEW_BEGIN("IoRead")
OBJ_NEW_BEGIN(IoRead)
{
this = memNew(sizeof(IoRead));
this = OBJ_NEW_ALLOC();
*this = (IoRead)
{
@ -52,7 +51,7 @@ ioReadNew(void *driver, IoReadInterface interface)
.input = bufNew(ioBufferSize()),
};
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_READ, this);
}

View File

@ -91,7 +91,7 @@ Destructor
__attribute__((always_inline)) static inline void
ioReadFree(IoRead *const this)
{
objFree(this);
objFreeContext(this);
}
/***********************************************************************************************************************************

View File

@ -6,7 +6,6 @@ Io Session Interface
#include "common/debug.h"
#include "common/io/session.h"
#include "common/log.h"
#include "common/memContext.h"
/***********************************************************************************************************************************
Object type

View File

@ -76,7 +76,7 @@ ioSessionClose(IoSession *const this)
__attribute__((always_inline)) static inline IoSession *
ioSessionMove(IoSession *const this, MemContext *const parentNew)
{
return objMove(this, parentNew);
return objMoveContext(this, parentNew);
}
/***********************************************************************************************************************************
@ -85,7 +85,7 @@ Destructor
__attribute__((always_inline)) static inline void
ioSessionFree(IoSession *const this)
{
objFree(this);
objFreeContext(this);
}
/***********************************************************************************************************************************

View File

@ -14,7 +14,6 @@ Socket Client
#include "common/io/socket/client.h"
#include "common/io/socket/common.h"
#include "common/io/socket/session.h"
#include "common/memContext.h"
#include "common/stat.h"
#include "common/type/object.h"
#include "common/wait.h"
@ -31,7 +30,6 @@ Object type
***********************************************************************************************************************************/
typedef struct SocketClient
{
MemContext *memContext; // Mem context
String *host; // Hostname or IP address
unsigned int port; // Port to connect to host on
String *name; // Socket name (host:port)
@ -190,13 +188,12 @@ sckClientNew(const String *host, unsigned int port, TimeMSec timeout)
IoClient *this = NULL;
MEM_CONTEXT_NEW_BEGIN("SocketClient")
OBJ_NEW_BEGIN(SocketClient)
{
SocketClient *driver = memNew(sizeof(SocketClient));
SocketClient *driver = OBJ_NEW_ALLOC();
*driver = (SocketClient)
{
.memContext = MEM_CONTEXT_NEW(),
.host = strDup(host),
.port = port,
.name = strNewFmt("%s:%u", strZ(host), port),
@ -207,7 +204,7 @@ sckClientNew(const String *host, unsigned int port, TimeMSec timeout)
this = ioClientNew(driver, &sckClientInterface);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_CLIENT, this);
}

View File

@ -11,7 +11,6 @@ Socket Session
#include "common/io/fdWrite.h"
#include "common/io/socket/client.h"
#include "common/io/session.h"
#include "common/memContext.h"
#include "common/type/object.h"
/***********************************************************************************************************************************
@ -19,7 +18,6 @@ Object type
***********************************************************************************************************************************/
typedef struct SocketSession
{
MemContext *memContext; // Mem context
IoSessionRole role; // Role (server or client)
int fd; // File descriptor
String *host; // Hostname or IP address
@ -81,7 +79,7 @@ sckSessionClose(THIS_VOID)
if (this->fd != -1)
{
// Clear the callback to close the socket
memContextCallbackClear(this->memContext);
memContextCallbackClear(objMemContext(this));
// Close the socket
close(this->fd);
@ -179,15 +177,14 @@ sckSessionNew(IoSessionRole role, int fd, const String *host, unsigned int port,
IoSession *this = NULL;
MEM_CONTEXT_NEW_BEGIN("SocketSession")
OBJ_NEW_BEGIN(SocketSession)
{
SocketSession *driver = memNew(sizeof(SocketSession));
SocketSession *driver = OBJ_NEW_ALLOC();
String *name = strNewFmt("%s:%u", strZ(host), port);
*driver = (SocketSession)
{
.memContext = MEM_CONTEXT_NEW(),
.role = role,
.fd = fd,
.host = strDup(host),
@ -200,11 +197,11 @@ sckSessionNew(IoSessionRole role, int fd, const String *host, unsigned int port,
strFree(name);
// Ensure file descriptor is closed
memContextCallbackSet(driver->memContext, sckSessionFreeResource, driver);
memContextCallbackSet(objMemContext(driver), sckSessionFreeResource, driver);
this = ioSessionNew(driver, &sckSessionInterface);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_SESSION, this);
}

View File

@ -15,7 +15,6 @@ TLS Client
#include "common/io/io.h"
#include "common/io/tls/client.h"
#include "common/io/tls/session.h"
#include "common/memContext.h"
#include "common/stat.h"
#include "common/type/object.h"
#include "common/wait.h"
@ -32,7 +31,6 @@ Object type
***********************************************************************************************************************************/
typedef struct TlsClient
{
MemContext *memContext; // Mem context
const String *host; // Host to use for peer verification
TimeMSec timeout; // Timeout for any i/o operation (connect, read, etc.)
bool verifyPeer; // Should the peer (server) certificate be verified?
@ -51,7 +49,7 @@ tlsClientToLog(const THIS_VOID)
return strNewFmt(
"{ioClient: %s, timeout: %" PRIu64", verifyPeer: %s}",
memContextFreeing(this->memContext) ? NULL_Z : strZ(ioClientToLog(this->ioClient)), this->timeout,
objMemContextFreeing(this) ? NULL_Z : strZ(ioClientToLog(this->ioClient)), this->timeout,
cvtBoolToConstZ(this->verifyPeer));
}
@ -353,13 +351,12 @@ tlsClientNew(IoClient *ioClient, const String *host, TimeMSec timeout, bool veri
IoClient *this = NULL;
MEM_CONTEXT_NEW_BEGIN("TlsClient")
OBJ_NEW_BEGIN(TlsClient)
{
TlsClient *driver = memNew(sizeof(TlsClient));
TlsClient *driver = OBJ_NEW_ALLOC();
*driver = (TlsClient)
{
.memContext = MEM_CONTEXT_NEW(),
.ioClient = ioClientMove(ioClient, MEM_CONTEXT_NEW()),
.host = strDup(host),
.timeout = timeout,
@ -379,7 +376,7 @@ tlsClientNew(IoClient *ioClient, const String *host, TimeMSec timeout, bool veri
driver->context = SSL_CTX_new(method);
cryptoError(driver->context == NULL, "unable to create TLS context");
memContextCallbackSet(driver->memContext, tlsClientFreeResource, driver);
memContextCallbackSet(objMemContext(driver), tlsClientFreeResource, driver);
// Exclude SSL versions to only allow TLS and also disable compression
SSL_CTX_set_options(driver->context, (long)(SSL_OP_ALL | SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_COMPRESSION));
@ -411,7 +408,7 @@ tlsClientNew(IoClient *ioClient, const String *host, TimeMSec timeout, bool veri
// Create client interface
this = ioClientNew(driver, &tlsClientInterface);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_CLIENT, this);
}

View File

@ -14,7 +14,6 @@ TLS Session
#include "common/io/tls/session.h"
#include "common/io/write.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
/***********************************************************************************************************************************
@ -22,7 +21,6 @@ Object type
***********************************************************************************************************************************/
typedef struct TlsSession
{
MemContext *memContext; // Mem context
IoSession *ioSession; // Io session
SSL *session; // TLS session on the file descriptor
TimeMSec timeout; // Timeout for any i/o operation (connect, read, etc.)
@ -42,7 +40,7 @@ tlsSessionToLog(const THIS_VOID)
return strNewFmt(
"{ioSession: %s, timeout: %" PRIu64", shutdownOnClose: %s}",
memContextFreeing(this->memContext) ? NULL_Z : strZ(ioSessionToLog(this->ioSession)), this->timeout,
objMemContextFreeing(this) ? NULL_Z : strZ(ioSessionToLog(this->ioSession)), this->timeout,
cvtBoolToConstZ(this->shutdownOnClose));
}
@ -93,7 +91,7 @@ tlsSessionClose(THIS_VOID)
ioSessionClose(this->ioSession);
// Free the TLS session
memContextCallbackClear(this->memContext);
memContextCallbackClear(objMemContext(this));
tlsSessionFreeResource(this);
this->session = NULL;
}
@ -363,13 +361,12 @@ tlsSessionNew(SSL *session, IoSession *ioSession, TimeMSec timeout)
IoSession *this = NULL;
MEM_CONTEXT_NEW_BEGIN("TlsSession")
OBJ_NEW_BEGIN(TlsSession)
{
TlsSession *driver = memNew(sizeof(TlsSession));
TlsSession *driver = OBJ_NEW_ALLOC();
*driver = (TlsSession)
{
.memContext = MEM_CONTEXT_NEW(),
.session = session,
.ioSession = ioSessionMove(ioSession, MEM_CONTEXT_NEW()),
.timeout = timeout,
@ -377,7 +374,7 @@ tlsSessionNew(SSL *session, IoSession *ioSession, TimeMSec timeout)
};
// Ensure session is freed
memContextCallbackSet(driver->memContext, tlsSessionFreeResource, driver);
memContextCallbackSet(objMemContext(driver), tlsSessionFreeResource, driver);
// Assign file descriptor to TLS session
cryptoError(SSL_set_fd(driver->session, ioSessionFd(driver->ioSession)) != 1, "unable to add fd to TLS session");
@ -404,7 +401,7 @@ tlsSessionNew(SSL *session, IoSession *ioSession, TimeMSec timeout)
// Create session interface
this = ioSessionNew(driver, &tlsSessionInterface);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_SESSION, this);
}

View File

@ -9,7 +9,6 @@ IO Write Interface
#include "common/io/io.h"
#include "common/io/write.h"
#include "common/log.h"
#include "common/memContext.h"
/***********************************************************************************************************************************
Object type
@ -42,9 +41,9 @@ ioWriteNew(void *driver, IoWriteInterface interface)
IoWrite *this = NULL;
MEM_CONTEXT_NEW_BEGIN("IoWrite")
OBJ_NEW_BEGIN(IoWrite)
{
this = memNew(sizeof(IoWrite));
this = OBJ_NEW_ALLOC();
*this = (IoWrite)
{
@ -58,7 +57,7 @@ ioWriteNew(void *driver, IoWriteInterface interface)
.output = bufNew(ioBufferSize()),
};
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(IO_WRITE, this);
}

View File

@ -79,7 +79,7 @@ Destructor
__attribute__((always_inline)) static inline void
ioWriteFree(IoWrite *const this)
{
objFree(this);
objFreeContext(this);
}
/***********************************************************************************************************************************

View File

@ -15,8 +15,7 @@ Memory context states
***********************************************************************************************************************************/
typedef enum
{
memContextStateFree = 0,
memContextStateFreeing,
memContextStateFreeing = 0,
memContextStateActive
} MemContextState;
@ -51,7 +50,8 @@ Contains information about the memory context
struct MemContext
{
const char *name; // Indicates what the context is being used for
MemContextState state; // Current state of the context
MemContextState state:1; // Current state of the context
size_t allocExtra:16; // Size of extra allocation (1kB max)
unsigned int contextParentIdx; // Index in the parent context list
MemContext *contextParent; // All contexts have a parent except top
@ -210,11 +210,10 @@ memFreeInternal(void *buffer)
Find space for a new mem context
***********************************************************************************************************************************/
static unsigned int
memContextNewIndex(MemContext *memContext, bool allowFree)
memContextNewIndex(MemContext *memContext)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(MEM_CONTEXT, memContext);
FUNCTION_TEST_PARAM(BOOL, allowFree);
FUNCTION_TEST_END();
ASSERT(memContext != NULL);
@ -222,12 +221,9 @@ memContextNewIndex(MemContext *memContext, bool allowFree)
// Try to find space for the new context
for (; memContext->contextChildFreeIdx < memContext->contextChildListSize; memContext->contextChildFreeIdx++)
{
if (memContext->contextChildList[memContext->contextChildFreeIdx] == NULL ||
(allowFree && memContext->contextChildList[memContext->contextChildFreeIdx]->state == memContextStateFree))
{
if (memContext->contextChildList[memContext->contextChildFreeIdx] == NULL)
break;
}
}
// If no space was found then allocate more
if (memContext->contextChildFreeIdx == memContext->contextChildListSize)
@ -261,37 +257,35 @@ memContextNewIndex(MemContext *memContext, bool allowFree)
/**********************************************************************************************************************************/
MemContext *
memContextNew(const char *name)
memContextNew(const char *const name, const MemContextNewParam param)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(STRINGZ, name);
FUNCTION_TEST_PARAM(SIZE, param.allocExtra);
FUNCTION_TEST_END();
ASSERT(name != NULL);
// Check context name length
ASSERT(name[0] != '\0');
// Find space for the new context
MemContext *contextCurrent = memContextStack[memContextCurrentStackIdx].memContext;
unsigned int contextIdx = memContextNewIndex(contextCurrent, true);
unsigned int contextIdx = memContextNewIndex(contextCurrent);
// If the context has not been allocated yet
if (contextCurrent->contextChildList[contextIdx] == NULL)
contextCurrent->contextChildList[contextIdx] = memAllocInternal(sizeof(MemContext));
// Allocate memory for the context
contextCurrent->contextChildList[contextIdx] = memAllocInternal(sizeof(MemContext) + param.allocExtra);
// Get the context
MemContext *this = contextCurrent->contextChildList[contextIdx];
*this = (MemContext)
{
// Create initial space for allocations
.allocList = memAllocPtrArrayInternal(MEM_CONTEXT_ALLOC_INITIAL_SIZE),
.allocListSize = MEM_CONTEXT_ALLOC_INITIAL_SIZE,
// Set the context name
.name = name,
// Set extra allocation
.allocExtra = param.allocExtra,
// Set new context active
.state = memContextStateActive,
@ -317,6 +311,47 @@ memContextNew(const char *name)
FUNCTION_TEST_RETURN(this);
}
/**********************************************************************************************************************************/
void *
memContextAllocExtra(MemContext *const this)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(MEM_CONTEXT, this);
FUNCTION_TEST_END();
ASSERT(this != NULL);
ASSERT(this->allocExtra != 0);
FUNCTION_TEST_RETURN(this + 1);
}
/**********************************************************************************************************************************/
MemContext *
memContextFromAllocExtra(void *const allocExtra)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM_P(VOID, allocExtra);
FUNCTION_TEST_END();
ASSERT(allocExtra != NULL);
ASSERT(((MemContext *)allocExtra - 1)->allocExtra != 0);
FUNCTION_TEST_RETURN((MemContext *)allocExtra - 1);
}
const MemContext *
memContextConstFromAllocExtra(const void *const allocExtra)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM_P(VOID, allocExtra);
FUNCTION_TEST_END();
ASSERT(allocExtra != NULL);
ASSERT(((MemContext *)allocExtra - 1)->allocExtra != 0);
FUNCTION_TEST_RETURN((MemContext *)allocExtra - 1);
}
/**********************************************************************************************************************************/
void
memContextCallbackSet(MemContext *this, void (*callbackFunction)(void *), void *callbackArgument)
@ -544,8 +579,7 @@ memContextMove(MemContext *this, MemContext *parentNew)
// Find a place in the new parent context and assign it. The child list may be moved while finding a new index so store the
// index and use it with (what might be) the new pointer.
this->contextParent = parentNew;
this->contextParentIdx = memContextNewIndex(parentNew, false);
ASSERT(parentNew->contextChildList[this->contextParentIdx] == NULL);
this->contextParentIdx = memContextNewIndex(parentNew);
parentNew->contextChildList[this->contextParentIdx] = this;
}
@ -727,7 +761,7 @@ memContextSize(const MemContext *this)
// Size of struct and child context/alloc arrays
size_t result =
sizeof(MemContext) + (this->contextChildListSize * sizeof(MemContext *)) +
sizeof(MemContext) + this->allocExtra + (this->contextChildListSize * sizeof(MemContext *)) +
(this->allocListSize * sizeof(MemContextAlloc *));
// Add child contexts
@ -797,14 +831,12 @@ memContextFree(MemContext *this)
if (this == memContextStack[memContextCurrentStackIdx].memContext && this != &contextTop)
THROW_FMT(AssertError, "cannot free current context '%s'", this->name);
// Error if context is not active
if (this->state != memContextStateActive)
THROW(AssertError, "cannot free inactive context");
// Free child contexts
for (unsigned int contextIdx = 0; contextIdx < this->contextChildListSize; contextIdx++)
if (this->contextChildList[contextIdx] && this->contextChildList[contextIdx]->state == memContextStateActive)
{
if (this->contextChildList[contextIdx] != NULL)
memContextFree(this->contextChildList[contextIdx]);
}
// Set state to freeing now that there are no child contexts. Child contexts might need to interact with their parent while
// freeing so the parent needs to remain active until they are all gone.
@ -819,18 +851,14 @@ memContextFree(MemContext *this)
// Finish cleanup even if the callback fails
FINALLY()
{
// Free child context allocations
// Free child context allocation list
if (this->contextChildListSize > 0)
{
for (unsigned int contextIdx = 0; contextIdx < this->contextChildListSize; contextIdx++)
if (this->contextChildList[contextIdx])
memFreeInternal(this->contextChildList[contextIdx]);
memFreeInternal(this->contextChildList);
this->contextChildListSize = 0;
}
// Free memory allocations
// Free memory allocations and list
if (this->allocListSize > 0)
{
for (unsigned int allocIdx = 0; allocIdx < this->allocListSize; allocIdx++)
@ -847,10 +875,17 @@ memContextFree(MemContext *this)
// Make top context active again
if (this == &contextTop)
{
this->state = memContextStateActive;
// Else reset the memory context so it can be reused
}
// Else free the memory context so the slot can be reused
else
*this = (MemContext){.state = memContextStateFree};
{
ASSERT(this->contextParent != NULL);
this->contextParent->contextChildList[this->contextParentIdx] = NULL;
memFreeInternal(this);
}
}
TRY_END();
}

View File

@ -13,6 +13,7 @@ See the sections on memory context management and memory allocations below for m
#define COMMON_MEMCONTEXT_H
#include <stddef.h>
#include <stdint.h>
/***********************************************************************************************************************************
Memory context object
@ -20,6 +21,7 @@ Memory context object
typedef struct MemContext MemContext;
#include "common/error.h"
#include "common/type/param.h"
/***********************************************************************************************************************************
Define initial number of memory contexts
@ -97,13 +99,10 @@ MEM_CONTEXT_PRIOR_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)
MEM_CONTEXT_NEW_BEGIN(memContextName, ...)
{
<The mem context created is now the current context and can be accessed with the MEM_CONTEXT_NEW() macro>
ObjectType *object = memNew(sizeof(ObjectType));
object->memContext = MEM_CONTEXT_NEW();
<If extra memory was allocation with the context if can be accessed with the MEM_CONTEXT_NEW_ALLOC() macro>
<Prior context can be accessed with the memContextPrior() function>
<On error the newly created context will be freed and the error rethrown>
}
@ -116,12 +115,15 @@ Note that memory context names are expected to live for the lifetime of the cont
#define MEM_CONTEXT_NEW() \
MEM_CONTEXT_NEW_memContext
#define MEM_CONTEXT_NEW_BEGIN(memContextName) \
#define MEM_CONTEXT_NEW_BEGIN(memContextName, ...) \
do \
{ \
MemContext *MEM_CONTEXT_NEW() = memContextNew(memContextName); \
MemContext *MEM_CONTEXT_NEW() = memContextNewP(memContextName, __VA_ARGS__); \
memContextSwitch(MEM_CONTEXT_NEW());
#define MEM_CONTEXT_NEW_ALLOC() \
memContextAllocExtra(MEM_CONTEXT_NEW())
#define MEM_CONTEXT_NEW_END() \
memContextSwitchBack(); \
memContextKeep(); \
@ -148,7 +150,7 @@ MEM_CONTEXT_TEMP_END();
#define MEM_CONTEXT_TEMP_BEGIN() \
do \
{ \
MemContext *MEM_CONTEXT_TEMP() = memContextNew("temporary"); \
MemContext *MEM_CONTEXT_TEMP() = memContextNewP("temporary"); \
memContextSwitch(MEM_CONTEXT_TEMP());
#define MEM_CONTEXT_TEMP_RESET_BEGIN() \
@ -164,7 +166,7 @@ MEM_CONTEXT_TEMP_END();
{ \
memContextSwitchBack(); \
memContextDiscard(); \
MEM_CONTEXT_TEMP() = memContextNew("temporary"); \
MEM_CONTEXT_TEMP() = memContextNewP("temporary"); \
memContextSwitch(MEM_CONTEXT_TEMP()); \
MEM_CONTEXT_TEMP_loopTotal = 0; \
} \
@ -180,7 +182,7 @@ MEM_CONTEXT_TEMP_END();
/***********************************************************************************************************************************
Memory context management functions
memContextSwitch(memContextNew());
memContextSwitch(memContextNewP());
<Do something with the memory context, e.g. allocation memory with memNew()>
<Current memory context can be accessed with memContextCurrent()>
@ -199,22 +201,31 @@ Use the MEM_CONTEXT*() macros when possible rather than reimplement the boilerpl
***********************************************************************************************************************************/
// Create a new mem context in the current mem context. The new context must be either kept with memContextKeep() or discarded with
// memContextDisard() before switching back from the parent context.
MemContext *memContextNew(const char *name);
typedef struct MemContextNewParam
{
VAR_PARAM_HEADER;
uint16_t allocExtra; // Extra memory to allocate with the context
} MemContextNewParam;
#define memContextNewP(name, ...) \
memContextNew(name, (MemContextNewParam){VAR_PARAM_INIT, __VA_ARGS__})
MemContext *memContextNew(const char *name, MemContextNewParam param);
// Switch to a context making it the current mem context
void memContextSwitch(MemContext *this);
// Switch back to the context that was current before the last switch. If the last function called was memContextNew(), then
// Switch back to the context that was current before the last switch. If the last function called was memContextNewP(), then
// memContextKeep()/memContextDiscard() must be called before calling memContextSwitchBack(), otherwise an error will occur in
// debug builds and the behavior is undefined in production builds.
void memContextSwitchBack(void);
// Keep a context created by memContextNew() so that it will not be automatically freed if an error occurs. If the context was
// switched after the call to memContextNew(), then it must be switched back before calling memContextKeep() or an error will occur
// Keep a context created by memContextNewP() so that it will not be automatically freed if an error occurs. If the context was
// switched after the call to memContextNewP(), then it must be switched back before calling memContextKeep() or an error will occur
// in debug builds and the behavior is undefined in production builds.
void memContextKeep(void);
// Discard a context created by memContextNew(). If the context was switched after the call to memContextNew(), then it must be
// Discard a context created by memContextNewP(). If the context was switched after the call to memContextNewP(), then it must be
// switched back before calling memContextDiscard() or an error will occur in debug builds and the behavior is undefined in
// production builds.
void memContextDiscard(void);
@ -237,6 +248,13 @@ void memContextFree(MemContext *this);
/***********************************************************************************************************************************
Memory context getters
***********************************************************************************************************************************/
// Pointer to the extra memory allocated with the mem context
void *memContextAllocExtra(MemContext *this);
// Get mem context using pointer to the memory allocated with the mem context
MemContext *memContextFromAllocExtra(void *allocExtra);
const MemContext *memContextConstFromAllocExtra(const void *allocExtra);
// Current memory context
MemContext *memContextCurrent(void);

View File

@ -7,7 +7,6 @@ Regular Expression Handler
#include <sys/types.h>
#include "common/debug.h"
#include "common/memContext.h"
#include "common/regExp.h"
/***********************************************************************************************************************************
@ -15,7 +14,6 @@ Contains information about the regular expression handler
***********************************************************************************************************************************/
struct RegExp
{
MemContext *memContext;
regex_t regExp;
const char *matchPtr;
size_t matchSize;
@ -76,14 +74,10 @@ regExpNew(const String *expression)
RegExp *this = NULL;
MEM_CONTEXT_NEW_BEGIN("RegExp")
OBJ_NEW_BEGIN(RegExp)
{
this = memNew(sizeof(RegExp));
*this = (RegExp)
{
.memContext = MEM_CONTEXT_NEW(),
};
this = OBJ_NEW_ALLOC();
*this = (RegExp){{0}}; // Extra braces are required for older gcc versions
// Compile the regexp and process errors
int result = 0;
@ -92,9 +86,9 @@ regExpNew(const String *expression)
regExpError(result);
// Set free callback to ensure cipher context is freed
memContextCallbackSet(this->memContext, regExpFreeResource, this);
memContextCallbackSet(objMemContext(this), regExpFreeResource, this);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_TEST_RETURN(this);
}

View File

@ -41,16 +41,15 @@ bufNew(size_t size)
Buffer *this = NULL;
MEM_CONTEXT_NEW_BEGIN("Buffer")
OBJ_NEW_BEGIN(Buffer)
{
// Create object
this = memNew(sizeof(Buffer));
this = OBJ_NEW_ALLOC();
*this = (Buffer)
{
.pub =
{
.memContext = MEM_CONTEXT_NEW(),
.sizeAlloc = size,
.size = size,
},
@ -60,7 +59,7 @@ bufNew(size_t size)
if (size > 0)
this->pub.buffer = memNew(this->pub.sizeAlloc);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_TEST_RETURN(this);
}
@ -245,7 +244,7 @@ bufResize(Buffer *this, size_t size)
// When setting size down to 0 the buffer should always be allocated
ASSERT(bufPtrConst(this) != NULL);
MEM_CONTEXT_BEGIN(this->pub.memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
memFree(bufPtr(this));
}
@ -257,7 +256,7 @@ bufResize(Buffer *this, size_t size)
// Else allocate or resize
else
{
MEM_CONTEXT_BEGIN(this->pub.memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
if (bufPtrConst(this) == NULL)
this->pub.buffer = memNew(size);

View File

@ -32,7 +32,6 @@ Getters/Setters
***********************************************************************************************************************************/
typedef struct BufferPub
{
MemContext *memContext; // Mem context
size_t sizeAlloc; // Allocated size of the buffer
size_t size; // Reported size of the buffer
bool sizeLimit; // Is the size limited to make the buffer appear smaller?

View File

@ -6,7 +6,6 @@ Key Value Handler
#include <limits.h>
#include "common/debug.h"
#include "common/memContext.h"
#include "common/type/keyValue.h"
#include "common/type/list.h"
#include "common/type/variantList.h"
@ -37,22 +36,21 @@ kvNew(void)
KeyValue *this = NULL;
MEM_CONTEXT_NEW_BEGIN("KeyValue")
OBJ_NEW_BEGIN(KeyValue)
{
// Allocate state and set context
this = memNew(sizeof(KeyValue));
this = OBJ_NEW_ALLOC();
*this = (KeyValue)
{
.pub =
{
.memContext = MEM_CONTEXT_NEW(),
.keyList = varLstNew(),
},
.list = lstNewP(sizeof(KeyValuePair)),
};
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_TEST_RETURN(this);
}
@ -179,7 +177,7 @@ kvPut(KeyValue *this, const Variant *key, const Variant *value)
ASSERT(this != NULL);
ASSERT(key != NULL);
MEM_CONTEXT_BEGIN(this->pub.memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
kvPutInternal(this, key, varDup(value));
}
@ -201,7 +199,7 @@ kvAdd(KeyValue *this, const Variant *key, const Variant *value)
ASSERT(this != NULL);
ASSERT(key != NULL);
MEM_CONTEXT_BEGIN(this->pub.memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
// Find the key
unsigned int listIdx = kvGetIdx(this, key);
@ -248,7 +246,7 @@ kvPutKv(KeyValue *this, const Variant *key)
KeyValue *result = NULL;
MEM_CONTEXT_BEGIN(this->pub.memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
result = kvNew();
kvPutInternal(this, key, varNewKv(result));

View File

@ -28,7 +28,6 @@ Getters/Setters
***********************************************************************************************************************************/
typedef struct KeyValuePub
{
MemContext *memContext; // Mem context
VariantList *keyList; // List of keys
} KeyValuePub;

View File

@ -36,23 +36,19 @@ lstNew(size_t itemSize, ListParam param)
List *this = NULL;
MEM_CONTEXT_NEW_BEGIN("List")
OBJ_NEW_BEGIN(List)
{
// Create object
this = memNew(sizeof(List));
this = OBJ_NEW_ALLOC();
*this = (List)
{
.pub =
{
.memContext = MEM_CONTEXT_NEW(),
},
.itemSize = itemSize,
.sortOrder = param.sortOrder,
.comparator = param.comparator,
};
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_TEST_RETURN(this);
}

View File

@ -69,7 +69,6 @@ Getters/Setters
***********************************************************************************************************************************/
typedef struct ListPub
{
MemContext *memContext; // Mem context
unsigned int listSize; // List size
} ListPub;
@ -78,9 +77,9 @@ List *lstComparatorSet(List *this, ListComparator *comparator);
// Memory context for this list
__attribute__((always_inline)) static inline MemContext *
lstMemContext(const List *const this)
lstMemContext(List *const this)
{
return THIS_PUB(List)->memContext;
return objMemContext(this);
}
// List size

View File

@ -13,7 +13,6 @@ Object type
***********************************************************************************************************************************/
struct MostCommonValue
{
MemContext *memContext; // Mem context
List *list; // List of unique values
};
@ -31,17 +30,16 @@ mcvNew(void)
MostCommonValue *this = NULL;
MEM_CONTEXT_NEW_BEGIN("MostCommonValue")
OBJ_NEW_BEGIN(MostCommonValue)
{
this = memNew(sizeof(MostCommonValue));
this = OBJ_NEW_ALLOC();
*this = (MostCommonValue)
{
.memContext = MEM_CONTEXT_NEW(),
.list = lstNewP(sizeof(MostCommonValueEntry)),
};
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_TEST_RETURN(this);
}
@ -75,7 +73,7 @@ mcvUpdate(MostCommonValue *this, const Variant *value)
// Add the value if it doesn't
if (!found)
{
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
MostCommonValueEntry entry = {.value = varDup(value), .total = 1};
lstAdd(this->list, &entry);

View File

@ -8,6 +8,16 @@ Object Helper Macros and Functions
/**********************************************************************************************************************************/
void *
objMove(THIS_VOID, MemContext *parentNew)
{
if (thisVoid != NULL)
memContextMove(memContextFromAllocExtra(thisVoid), parentNew);
return thisVoid;
}
/**********************************************************************************************************************************/
void *
objMoveContext(THIS_VOID, MemContext *parentNew)
{
if (thisVoid != NULL)
memContextMove(*(MemContext **)thisVoid, parentNew);
@ -18,6 +28,14 @@ objMove(THIS_VOID, MemContext *parentNew)
/**********************************************************************************************************************************/
void
objFree(THIS_VOID)
{
if (thisVoid != NULL)
memContextFree(memContextFromAllocExtra(thisVoid));
}
/**********************************************************************************************************************************/
void
objFreeContext(THIS_VOID)
{
if (thisVoid != NULL)
memContextFree(*(MemContext **)thisVoid);

View File

@ -7,8 +7,37 @@ These macros and functions implement common object functionality.
#define COMMON_TYPE_OBJECT_H
#include "common/assert.h"
#include "common/macro.h"
#include "common/memContext.h"
/***********************************************************************************************************************************
Create a new object
This is a thin wrapper on MEM_CONTEXT_NEW_*() to do object specific initialization. The general pattern
for a new object is:
MyObj *this = NULL;
OBJ_NEW_BEGIN(MyObj)
{
this = OBJ_NEW_ALLOC();
*this = (MyObj)
{
.data = ...
};
}
OBJ_NEW_END();
***********************************************************************************************************************************/
#define OBJ_NEW_BEGIN(type) \
MEM_CONTEXT_NEW_BEGIN(STRINGIFY(type), .allocExtra = sizeof(type))
#define OBJ_NEW_ALLOC() \
memContextAllocExtra(memContextCurrent())
#define OBJ_NEW_END() \
MEM_CONTEXT_NEW_END()
/***********************************************************************************************************************************
Used in interface function parameter lists to discourage use of the untyped thisVoid parameter, e.g.:
@ -23,6 +52,12 @@ Create a local "this" variable of the correct type from a THIS_VOID parameter
***********************************************************************************************************************************/
#define THIS(type) type *this = thisVoid
/***********************************************************************************************************************************
Get the mem context of this object
***********************************************************************************************************************************/
#define THIS_MEM_CONTEXT() \
memContextFromAllocExtra(this)
/***********************************************************************************************************************************
Cast this private struct, e.g. List, to the associated public struct, e.g. ListPub. Note that the public struct must be the first
member of the private struct. For example:
@ -55,10 +90,32 @@ storageFree(Storage *this)
objFree(this);
}
***********************************************************************************************************************************/
// Move an object to a new context if this != NULL. The mem context to move must be the first member of the object struct.
// Get the object mem context
__attribute__((always_inline)) static inline MemContext *
objMemContext(void *const this)
{
return memContextFromAllocExtra(this);
}
// Is the object mem context currently being freed?
__attribute__((always_inline)) static inline bool
objMemContextFreeing(const void *const this)
{
return memContextFreeing(memContextConstFromAllocExtra(this));
}
// Move an object to a new context if this != NULL
void *objMove(THIS_VOID, MemContext *parentNew);
// Free the object mem context if this != NULL. The mem context to be freed must be the first member of the object struct.
// Move an object to a new context if this != NULL. The mem context to move must be the first member of the object struct. This
// pattern is typically used by interfaces.
void *objMoveContext(THIS_VOID, MemContext *parentNew);
// Free the object mem context if this != NULL
void objFree(THIS_VOID);
// Free the object mem context if not NULL. The mem context to be freed must be the first member of the object struct. This pattern
// is typically used by interfaces.
void objFreeContext(THIS_VOID);
#endif

View File

@ -229,7 +229,6 @@ typedef struct PackTagStack
struct PackRead
{
MemContext *memContext; // Mem context
IoRead *read; // Read pack from
Buffer *buffer; // Buffer containing read data
const uint8_t *bufferPtr; // Pointer to buffer
@ -246,7 +245,6 @@ struct PackRead
struct PackWrite
{
MemContext *memContext; // Mem context
IoWrite *write; // Write pack to
Buffer *buffer; // Buffer to contain write data
@ -263,19 +261,18 @@ pckReadNewInternal(void)
PackRead *this = NULL;
MEM_CONTEXT_NEW_BEGIN("PackRead")
OBJ_NEW_BEGIN(PackRead)
{
this = memNew(sizeof(PackRead));
this = OBJ_NEW_ALLOC();
*this = (PackRead)
{
.memContext = MEM_CONTEXT_NEW(),
.tagStack = lstNewP(sizeof(PackTagStack)),
};
this->tagStackTop = lstAdd(this->tagStack, &(PackTagStack){.typeMap = pckTypeMapObj});
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_TEST_RETURN(this);
}
@ -291,7 +288,7 @@ pckReadNew(IoRead *read)
PackRead *this = pckReadNewInternal();
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
this->read = read;
this->buffer = bufNew(ioBufferSize());
@ -887,7 +884,7 @@ pckReadPack(PackRead *this, PckReadPackParam param)
PackRead *const result = pckReadNewBuf(buffer);
if (result != NULL)
bufMove(buffer, result->memContext);
bufMove(buffer, objMemContext(result));
FUNCTION_TEST_RETURN(result);
}
@ -1121,19 +1118,18 @@ pckWriteNewInternal(void)
PackWrite *this = NULL;
MEM_CONTEXT_NEW_BEGIN("PackWrite")
OBJ_NEW_BEGIN(PackWrite)
{
this = memNew(sizeof(PackWrite));
this = OBJ_NEW_ALLOC();
*this = (PackWrite)
{
.memContext = MEM_CONTEXT_NEW(),
.tagStack = lstNewP(sizeof(PackTagStack)),
};
this->tagStackTop = lstAdd(this->tagStack, &(PackTagStack){.typeMap = pckTypeMapObj});
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_TEST_RETURN(this);
}
@ -1149,7 +1145,7 @@ pckWriteNew(IoWrite *write)
PackWrite *this = pckWriteNewInternal();
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
this->write = write;
this->buffer = bufNew(ioBufferSize());

View File

@ -332,26 +332,22 @@ xmlDocumentNew(const String *rootName)
// Create object
XmlDocument *this = NULL;
MEM_CONTEXT_NEW_BEGIN("XmlDocument")
OBJ_NEW_BEGIN(XmlDocument)
{
this = memNew(sizeof(XmlDocument));
this = OBJ_NEW_ALLOC();
*this = (XmlDocument)
{
.pub =
{
.memContext = MEM_CONTEXT_NEW(),
},
.xml = xmlNewDoc(BAD_CAST "1.0"),
};
// Set callback to ensure xml document is freed
memContextCallbackSet(this->pub.memContext, xmlDocumentFreeResource, this);
memContextCallbackSet(objMemContext(this), xmlDocumentFreeResource, this);
this->pub.root = xmlNodeNew(xmlNewNode(NULL, BAD_CAST strZ(rootName)));
xmlDocSetRootElement(this->xml, xmlDocumentRoot(this)->node);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_TEST_RETURN(this);
}
@ -372,28 +368,21 @@ xmlDocumentNewBuf(const Buffer *buffer)
// Create object
XmlDocument *this = NULL;
MEM_CONTEXT_NEW_BEGIN("XmlDocument")
OBJ_NEW_BEGIN(XmlDocument)
{
this = memNew(sizeof(XmlDocument));
*this = (XmlDocument)
{
.pub =
{
.memContext = MEM_CONTEXT_NEW(),
},
};
this = OBJ_NEW_ALLOC();
*this = (XmlDocument){{0}}; // Extra braces are required for older gcc versions
if ((this->xml = xmlReadMemory((const char *)bufPtrConst(buffer), (int)bufUsed(buffer), "noname.xml", NULL, 0)) == NULL)
THROW_FMT(FormatError, "invalid xml");
// Set callback to ensure xml document is freed
memContextCallbackSet(this->pub.memContext, xmlDocumentFreeResource, this);
memContextCallbackSet(objMemContext(this), xmlDocumentFreeResource, this);
// Get the root node
this->pub.root = xmlNodeNew(xmlDocGetRootElement(this->xml));
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_TEST_RETURN(this);
}

View File

@ -34,7 +34,6 @@ Document Getters
***********************************************************************************************************************************/
typedef struct XmlDocumentPub
{
MemContext *memContext; // Mem context
XmlNode *root; // Root node
} XmlDocumentPub;

View File

@ -5,7 +5,6 @@ Wait Handler
#include "common/debug.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/wait.h"
/***********************************************************************************************************************************
@ -33,16 +32,15 @@ waitNew(TimeMSec waitTime)
// Allocate wait object
Wait *this = NULL;
MEM_CONTEXT_NEW_BEGIN("wait")
OBJ_NEW_BEGIN(Wait)
{
// Create object
this = memNew(sizeof(Wait));
this = OBJ_NEW_ALLOC();
*this = (Wait)
{
.pub =
{
.memContext = MEM_CONTEXT_NEW(),
.remainTime = waitTime,
},
.waitTime = waitTime,
@ -58,7 +56,7 @@ waitNew(TimeMSec waitTime)
// Get beginning time
this->beginTime = timeMSec();
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(WAIT, this);
}

View File

@ -22,7 +22,6 @@ Getters/Setters
***********************************************************************************************************************************/
typedef struct WaitPub
{
MemContext *memContext; // Mem context
TimeMSec remainTime; // Wait time remaining (in usec)
} WaitPub;

View File

@ -1170,9 +1170,9 @@ configParse(const Storage *storage, unsigned int argListSize, const char *argLis
// Create the config struct
Config *config;
MEM_CONTEXT_NEW_BEGIN("Config")
OBJ_NEW_BEGIN(Config)
{
config = memNew(sizeof(Config));
config = OBJ_NEW_ALLOC();
*config = (Config)
{
@ -1181,7 +1181,7 @@ configParse(const Storage *storage, unsigned int argListSize, const char *argLis
.exe = strNewZ(argList[0]),
};
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
// Phase 1: parse command line parameters
// -------------------------------------------------------------------------------------------------------------------------

View File

@ -5,7 +5,6 @@ Database Client
#include "common/debug.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/json.h"
#include "common/wait.h"
#include "db/db.h"
@ -69,9 +68,9 @@ dbNew(PgClient *client, ProtocolClient *remoteClient, const String *applicationN
Db *this = NULL;
MEM_CONTEXT_NEW_BEGIN("Db")
OBJ_NEW_BEGIN(Db)
{
this = memNew(sizeof(Db));
this = OBJ_NEW_ALLOC();
*this = (Db)
{
@ -85,7 +84,7 @@ dbNew(PgClient *client, ProtocolClient *remoteClient, const String *applicationN
this->client = pgClientMove(client, this->pub.memContext);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(DB, this);
}

View File

@ -13,7 +13,6 @@ Info Handler
#include "common/io/filter/filter.h"
#include "common/ini.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/json.h"
#include "common/type/object.h"
#include "info/info.h"
@ -115,7 +114,7 @@ infoNewInternal(void)
{
FUNCTION_TEST_VOID();
Info *this = memNew(sizeof(Info));
Info *this = OBJ_NEW_ALLOC();
*this = (Info)
{
@ -135,7 +134,7 @@ infoNew(const String *cipherPass)
Info *this = NULL;
MEM_CONTEXT_NEW_BEGIN("Info")
OBJ_NEW_BEGIN(Info)
{
this = infoNewInternal();
@ -143,7 +142,7 @@ infoNew(const String *cipherPass)
infoCipherPassSet(this, cipherPass);
this->pub.backrestVersion = STRDEF(PROJECT_VERSION);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(INFO, this);
}
@ -270,7 +269,7 @@ infoNewLoad(IoRead *read, InfoLoadNewCallback *callbackFunction, void *callbackD
Info *this = NULL;
MEM_CONTEXT_NEW_BEGIN("Info")
OBJ_NEW_BEGIN(Info)
{
this = infoNewInternal();
@ -314,7 +313,7 @@ infoNewLoad(IoRead *read, InfoLoadNewCallback *callbackFunction, void *callbackD
}
MEM_CONTEXT_TEMP_END();
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(INFO, this);
}

View File

@ -14,7 +14,6 @@ Archive Info Handler
#include "common/ini.h"
#include "common/io/bufferWrite.h"
#include "common/io/io.h"
#include "common/memContext.h"
#include "info/infoArchive.h"
#include "info/infoPg.h"
#include "postgres/interface.h"
@ -43,7 +42,7 @@ infoArchiveNewInternal(void)
{
FUNCTION_TEST_VOID();
InfoArchive *this = memNew(sizeof(InfoArchive));
InfoArchive *this = OBJ_NEW_ALLOC();
*this = (InfoArchive)
{
@ -70,7 +69,7 @@ infoArchiveNew(unsigned int pgVersion, uint64_t pgSystemId, const String *cipher
InfoArchive *this = NULL;
MEM_CONTEXT_NEW_BEGIN("InfoArchive")
OBJ_NEW_BEGIN(InfoArchive)
{
this = infoArchiveNewInternal();
@ -78,7 +77,7 @@ infoArchiveNew(unsigned int pgVersion, uint64_t pgSystemId, const String *cipher
this->pub.infoPg = infoPgNew(infoPgArchive, cipherPassSub);
infoArchivePgSet(this, pgVersion, pgSystemId);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(INFO_ARCHIVE, this);
}
@ -95,12 +94,12 @@ infoArchiveNewLoad(IoRead *read)
InfoArchive *this = NULL;
MEM_CONTEXT_NEW_BEGIN("InfoArchive")
OBJ_NEW_BEGIN(InfoArchive)
{
this = infoArchiveNewInternal();
this->pub.infoPg = infoPgNewLoad(read, infoPgArchive, NULL, NULL);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(INFO_ARCHIVE, this);
}

View File

@ -15,7 +15,6 @@ Backup Info Handler
#include "common/io/bufferWrite.h"
#include "common/io/io.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/regExp.h"
#include "common/type/json.h"
#include "common/type/list.h"
@ -71,7 +70,7 @@ infoBackupNewInternal(void)
{
FUNCTION_TEST_VOID();
InfoBackup *this = memNew(sizeof(InfoBackup));
InfoBackup *this = OBJ_NEW_ALLOC();
*this = (InfoBackup)
{
@ -100,7 +99,7 @@ infoBackupNew(unsigned int pgVersion, uint64_t pgSystemId, unsigned int pgCatalo
InfoBackup *this = NULL;
MEM_CONTEXT_NEW_BEGIN("InfoBackup")
OBJ_NEW_BEGIN(InfoBackup)
{
this = infoBackupNewInternal();
@ -108,7 +107,7 @@ infoBackupNew(unsigned int pgVersion, uint64_t pgSystemId, unsigned int pgCatalo
this->pub.infoPg = infoPgNew(infoPgBackup, cipherPassSub);
infoBackupPgSet(this, pgVersion, pgSystemId, pgCatalogVersion);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(INFO_BACKUP, this);
}
@ -199,12 +198,12 @@ infoBackupNewLoad(IoRead *read)
InfoBackup *this = NULL;
MEM_CONTEXT_NEW_BEGIN("InfoBackup")
OBJ_NEW_BEGIN(InfoBackup)
{
this = infoBackupNewInternal();
this->pub.infoPg = infoPgNewLoad(read, infoPgBackup, infoBackupLoadCallback, this);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(INFO_BACKUP, this);
}

View File

@ -13,7 +13,6 @@ PostgreSQL Info Handler
#include "common/debug.h"
#include "common/ini.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/json.h"
#include "common/type/list.h"
#include "common/type/object.h"
@ -57,7 +56,7 @@ infoPgNewInternal(InfoPgType type)
FUNCTION_TEST_PARAM(STRING_ID, type);
FUNCTION_TEST_END();
InfoPg *this = memNew(sizeof(InfoPg));
InfoPg *this = OBJ_NEW_ALLOC();
*this = (InfoPg)
{
@ -83,12 +82,12 @@ infoPgNew(InfoPgType type, const String *cipherPassSub)
InfoPg *this = NULL;
MEM_CONTEXT_NEW_BEGIN("InfoPg")
OBJ_NEW_BEGIN(InfoPg)
{
this = infoPgNewInternal(type);
this->pub.info = infoNew(cipherPassSub);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(INFO_PG, this);
}
@ -169,7 +168,7 @@ infoPgNewLoad(IoRead *read, InfoPgType type, InfoLoadNewCallback *callbackFuncti
InfoPg *this = NULL;
MEM_CONTEXT_NEW_BEGIN("InfoPg")
OBJ_NEW_BEGIN(InfoPg)
{
this = infoPgNewInternal(type);
@ -202,7 +201,7 @@ infoPgNewLoad(IoRead *read, InfoPgType type, InfoLoadNewCallback *callbackFuncti
// If the current id did not match the history list then the file is corrupt
CHECK(this->historyCurrent != UINT_MAX);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(INFO_PG, this);
}

View File

@ -361,7 +361,7 @@ manifestNewInternal(void)
{
FUNCTION_TEST_VOID();
Manifest *this = memNew(sizeof(Manifest));
Manifest *this = OBJ_NEW_ALLOC();
*this = (Manifest)
{
@ -1065,7 +1065,7 @@ manifestNewBuild(
Manifest *this = NULL;
MEM_CONTEXT_NEW_BEGIN("Manifest")
OBJ_NEW_BEGIN(Manifest)
{
this = manifestNewInternal();
this->pub.info = infoNew(NULL);
@ -1251,7 +1251,7 @@ manifestNewBuild(
}
MEM_CONTEXT_TEMP_END();
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(MANIFEST, this);
}
@ -1942,14 +1942,14 @@ manifestNewLoad(IoRead *read)
Manifest *this = NULL;
MEM_CONTEXT_NEW_BEGIN("Manifest")
OBJ_NEW_BEGIN(Manifest)
{
this = manifestNewInternal();
// Load the manifest
ManifestLoadData loadData =
{
.memContext = memContextNew("load"),
.memContext = memContextNewP("load"),
.manifest = this,
};
@ -2029,7 +2029,7 @@ manifestNewLoad(IoRead *read)
// Discard the context holding temporary load data
memContextDiscard();
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(MANIFEST, this);
}

View File

@ -7,7 +7,6 @@ Postgres Client
#include "common/debug.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/list.h"
#include "common/wait.h"
#include "postgres/client.h"
@ -17,7 +16,6 @@ Object type
***********************************************************************************************************************************/
struct PgClient
{
MemContext *memContext;
const String *host;
unsigned int port;
const String *database;
@ -63,13 +61,12 @@ pgClientNew(const String *host, const unsigned int port, const String *database,
PgClient *this = NULL;
MEM_CONTEXT_NEW_BEGIN("PgClient")
OBJ_NEW_BEGIN(PgClient)
{
this = memNew(sizeof(PgClient));
this = OBJ_NEW_ALLOC();
*this = (PgClient)
{
.memContext = MEM_CONTEXT_NEW(),
.host = strDup(host),
.port = port,
.database = strDup(database),
@ -77,7 +74,7 @@ pgClientNew(const String *host, const unsigned int port, const String *database,
.queryTimeout = queryTimeout,
};
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(PG_CLIENT, this);
}
@ -151,7 +148,7 @@ pgClientOpen(PgClient *this)
this->connection = PQconnectdb(strZ(connInfo));
// Set a callback to shutdown the connection
memContextCallbackSet(this->memContext, pgClientFreeResource, this);
memContextCallbackSet(objMemContext(this), pgClientFreeResource, this);
// Handle errors
if (PQstatus(this->connection) != CONNECTION_OK)
@ -347,7 +344,7 @@ pgClientClose(PgClient *this)
if (this->connection != NULL)
{
memContextCallbackClear(this->memContext);
memContextCallbackClear(objMemContext(this));
PQfinish(this->connection);
this->connection = NULL;
}

View File

@ -5,7 +5,6 @@ Protocol Client
#include "common/debug.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/time.h"
#include "common/type/json.h"
#include "common/type/keyValue.h"
@ -73,15 +72,14 @@ protocolClientNew(const String *name, const String *service, IoRead *read, IoWri
ProtocolClient *this = NULL;
MEM_CONTEXT_NEW_BEGIN("ProtocolClient")
OBJ_NEW_BEGIN(ProtocolClient)
{
this = memNew(sizeof(ProtocolClient));
this = OBJ_NEW_ALLOC();
*this = (ProtocolClient)
{
.pub =
{
.memContext = memContextCurrent(),
.read = read,
},
.write = write,
@ -129,9 +127,9 @@ protocolClientNew(const String *name, const String *service, IoRead *read, IoWri
MEM_CONTEXT_TEMP_END();
// Set a callback to shutdown the protocol
memContextCallbackSet(this->pub.memContext, protocolClientFreeResource, this);
memContextCallbackSet(objMemContext(this), protocolClientFreeResource, this);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(PROTOCOL_CLIENT, this);
}

View File

@ -68,7 +68,6 @@ Getters/Setters
***********************************************************************************************************************************/
typedef struct ProtocolClientPub
{
MemContext *memContext; // Mem context
IoRead *read; // Read interface
} ProtocolClientPub;

View File

@ -5,7 +5,6 @@ Protocol Command
#include "common/debug.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/keyValue.h"
#include "protocol/command.h"
#include "protocol/client.h"
@ -15,7 +14,6 @@ Object type
***********************************************************************************************************************************/
struct ProtocolCommand
{
MemContext *memContext;
StringId command;
PackWrite *pack;
};
@ -32,17 +30,16 @@ protocolCommandNew(const StringId command)
ProtocolCommand *this = NULL;
MEM_CONTEXT_NEW_BEGIN("ProtocolCommand")
OBJ_NEW_BEGIN(ProtocolCommand)
{
this = memNew(sizeof(ProtocolCommand));
this = OBJ_NEW_ALLOC();
*this = (ProtocolCommand)
{
.memContext = memContextCurrent(),
.command = command,
};
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_TEST_RETURN(this);
}
@ -94,7 +91,7 @@ protocolCommandParam(ProtocolCommand *this)
if (this->pack == NULL)
{
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
this->pack = protocolPackNew();
}

View File

@ -9,7 +9,6 @@ Protocol Parallel Executor
#include "common/debug.h"
#include "common/log.h"
#include "common/macro.h"
#include "common/memContext.h"
#include "common/type/keyValue.h"
#include "common/type/list.h"
#include "protocol/command.h"
@ -21,7 +20,6 @@ Object type
***********************************************************************************************************************************/
struct ProtocolParallel
{
MemContext *memContext;
TimeMSec timeout; // Max time to wait for jobs before returning
ParallelJobCallback *callbackFunction; // Function to get new jobs
void *callbackData; // Data to pass to callback function
@ -49,13 +47,12 @@ protocolParallelNew(TimeMSec timeout, ParallelJobCallback *callbackFunction, voi
ProtocolParallel *this = NULL;
MEM_CONTEXT_NEW_BEGIN("ProtocolParallel")
OBJ_NEW_BEGIN(ProtocolParallel)
{
this = memNew(sizeof(ProtocolParallel));
this = OBJ_NEW_ALLOC();
*this = (ProtocolParallel)
{
.memContext = MEM_CONTEXT_NEW(),
.timeout = timeout,
.callbackFunction = callbackFunction,
.callbackData = callbackData,
@ -64,7 +61,7 @@ protocolParallelNew(TimeMSec timeout, ParallelJobCallback *callbackFunction, voi
.state = protocolParallelJobStatePending,
};
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(PROTOCOL_PARALLEL, this);
}
@ -108,7 +105,7 @@ protocolParallelProcess(ProtocolParallel *this)
// If called for the first time, initialize processing
if (this->state == protocolParallelJobStatePending)
{
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
this->clientJobList = memNewPtrArray(lstSize(this->clientList));
}

View File

@ -5,7 +5,6 @@ Protocol Parallel Job
#include "common/debug.h"
#include "common/log.h"
#include "common/memContext.h"
#include "protocol/command.h"
#include "protocol/parallelJob.h"
@ -28,23 +27,22 @@ protocolParallelJobNew(const Variant *key, ProtocolCommand *command)
ProtocolParallelJob *this = NULL;
MEM_CONTEXT_NEW_BEGIN("ProtocolParallelJob")
OBJ_NEW_BEGIN(ProtocolParallelJob)
{
this = memNew(sizeof(ProtocolParallelJob));
this = OBJ_NEW_ALLOC();
*this = (ProtocolParallelJob)
{
.pub =
{
.memContext = memContextCurrent(),
.state = protocolParallelJobStatePending,
.key = varDup(key),
},
};
this->pub.command = protocolCommandMove(command, this->pub.memContext);
this->pub.command = protocolCommandMove(command, objMemContext(this));
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(PROTOCOL_PARALLEL_JOB, this);
}
@ -63,7 +61,7 @@ protocolParallelJobErrorSet(ProtocolParallelJob *this, int code, const String *m
ASSERT(code != 0);
ASSERT(message != NULL);
MEM_CONTEXT_BEGIN(this->pub.memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
this->pub.code = code;
this->pub.message = strDup(message);
@ -102,7 +100,7 @@ protocolParallelJobResultSet(ProtocolParallelJob *const this, PackRead *const re
ASSERT(this != NULL);
ASSERT(protocolParallelJobErrorCode(this) == 0);
this->pub.result = pckReadMove(result, this->pub.memContext);
this->pub.result = pckReadMove(result, objMemContext(this));
FUNCTION_LOG_RETURN_VOID();
}

View File

@ -36,7 +36,6 @@ Getters/Setters
***********************************************************************************************************************************/
typedef struct ProtocolParallelJobPub
{
MemContext *memContext; // Mem context
const Variant *key; // Unique key used to identify the job
ProtocolCommand *command; // Command to be executed
unsigned int processId; // Process that executed this job

View File

@ -7,7 +7,6 @@ Protocol Server
#include "common/debug.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/time.h"
#include "common/type/json.h"
#include "common/type/keyValue.h"
@ -21,7 +20,6 @@ Object type
***********************************************************************************************************************************/
struct ProtocolServer
{
MemContext *memContext; // Mem context
IoRead *read; // Read interface
IoWrite *write; // Write interface
const String *name; // Name displayed in logging
@ -44,13 +42,12 @@ protocolServerNew(const String *name, const String *service, IoRead *read, IoWri
ProtocolServer *this = NULL;
MEM_CONTEXT_NEW_BEGIN("ProtocolServer")
OBJ_NEW_BEGIN(ProtocolServer)
{
this = memNew(sizeof(ProtocolServer));
this = OBJ_NEW_ALLOC();
*this = (ProtocolServer)
{
.memContext = memContextCurrent(),
.read = read,
.write = write,
.name = strDup(name),
@ -69,7 +66,7 @@ protocolServerNew(const String *name, const String *service, IoRead *read, IoWri
}
MEM_CONTEXT_TEMP_END();
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(PROTOCOL_SERVER, this);
}
@ -184,7 +181,7 @@ protocolServerProcess(
{
// Send the command to the handler. Run the handler in the server's memory context in case any persistent data
// needs to be stored by the handler.
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(objMemContext(this))
{
// Initialize retries in case of command failure
bool retry = false;

View File

@ -6,7 +6,6 @@ Azure Storage Read
#include "common/debug.h"
#include "common/io/http/client.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
#include "storage/azure/read.h"
#include "storage/read.intern.h"
@ -16,7 +15,6 @@ Object type
***********************************************************************************************************************************/
typedef struct StorageReadAzure
{
MemContext *memContext; // Object mem context
StorageReadInterface interface; // Interface
StorageAzure *storage; // Storage that created this object
@ -49,7 +47,7 @@ storageReadAzureOpen(THIS_VOID)
bool result = false;
// Request the file
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
{
this->httpResponse = storageAzureRequestP(
this->storage, HTTP_VERB_GET_STR, .path = this->interface.name, .allowMissing = true, .contentIo = true);
@ -121,13 +119,12 @@ storageReadAzureNew(StorageAzure *storage, const String *name, bool ignoreMissin
StorageRead *this = NULL;
MEM_CONTEXT_NEW_BEGIN("StorageReadAzure")
OBJ_NEW_BEGIN(StorageReadAzure)
{
StorageReadAzure *driver = memNew(sizeof(StorageReadAzure));
StorageReadAzure *driver = OBJ_NEW_ALLOC();
*driver = (StorageReadAzure)
{
.memContext = MEM_CONTEXT_NEW(),
.storage = storage,
.interface = (StorageReadInterface)
@ -147,7 +144,7 @@ storageReadAzureNew(StorageAzure *storage, const String *name, bool ignoreMissin
this = storageReadNew(driver, &driver->interface);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(STORAGE_READ, this);
}

View File

@ -13,7 +13,6 @@ Azure Storage
#include "common/io/socket/client.h"
#include "common/io/tls/client.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/regExp.h"
#include "common/type/object.h"
#include "common/type/xml.h"
@ -58,7 +57,6 @@ Object type
struct StorageAzure
{
STORAGE_COMMON_MEMBER;
MemContext *memContext;
HttpClient *httpClient; // Http client to service requests
StringList *headerRedactList; // List of headers to redact from logging
StringList *queryRedactList; // List of query keys to redact from logging
@ -714,13 +712,12 @@ storageAzureNew(
Storage *this = NULL;
MEM_CONTEXT_NEW_BEGIN("StorageAzure")
OBJ_NEW_BEGIN(StorageAzure)
{
StorageAzure *driver = memNew(sizeof(StorageAzure));
StorageAzure *driver = OBJ_NEW_ALLOC();
*driver = (StorageAzure)
{
.memContext = MEM_CONTEXT_NEW(),
.interface = storageInterfaceAzure,
.container = strDup(container),
.account = strDup(account),
@ -753,7 +750,7 @@ storageAzureNew(
this = storageNew(STORAGE_AZURE_TYPE, path, 0, 0, write, pathExpressionFunction, driver, driver->interface);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(STORAGE, this);
}

View File

@ -7,7 +7,6 @@ Azure Storage File Write
#include "common/debug.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
#include "common/type/xml.h"
#include "storage/azure/write.h"
@ -38,7 +37,6 @@ Object type
***********************************************************************************************************************************/
typedef struct StorageWriteAzure
{
MemContext *memContext; // Object mem context
StorageWriteInterface interface; // Interface
StorageAzure *storage; // Storage that created this object
@ -73,7 +71,7 @@ storageWriteAzureOpen(THIS_VOID)
ASSERT(this->blockBuffer == NULL);
// Allocate the block buffer
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
{
this->blockBuffer = bufNew(this->blockSize);
}
@ -125,7 +123,7 @@ storageWriteAzureBlockAsync(StorageWriteAzure *this)
// Create the block id list
if (this->blockIdList == NULL)
{
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
{
this->blockIdList = strLstNew();
}
@ -143,7 +141,7 @@ storageWriteAzureBlockAsync(StorageWriteAzure *this)
httpQueryAdd(query, AZURE_QUERY_COMP_STR, AZURE_QUERY_VALUE_BLOCK_STR);
httpQueryAdd(query, AZURE_QUERY_BLOCK_ID_STR, blockId);
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
{
this->request = storageAzureRequestAsyncP(
this->storage, HTTP_VERB_PUT_STR, .path = this->interface.name, .query = query, .content = this->blockBuffer);
@ -276,13 +274,12 @@ storageWriteAzureNew(StorageAzure *storage, const String *name, uint64_t fileId,
StorageWrite *this = NULL;
MEM_CONTEXT_NEW_BEGIN("StorageWriteAzure")
OBJ_NEW_BEGIN(StorageWriteAzure)
{
StorageWriteAzure *driver = memNew(sizeof(StorageWriteAzure));
StorageWriteAzure *driver = OBJ_NEW_ALLOC();
*driver = (StorageWriteAzure)
{
.memContext = MEM_CONTEXT_NEW(),
.storage = storage,
.fileId = fileId,
.blockSize = blockSize,
@ -307,7 +304,7 @@ storageWriteAzureNew(StorageAzure *storage, const String *name, uint64_t fileId,
this = storageWriteNew(driver, &driver->interface);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(STORAGE_WRITE, this);
}

View File

@ -5,7 +5,6 @@ CIFS Storage
#include "common/debug.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/regExp.h"
#include "storage/cifs/storage.h"
#include "storage/posix/storage.intern.h"

View File

@ -7,7 +7,6 @@ GCS Storage Read
#include "common/io/http/client.h"
#include "common/io/read.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
#include "storage/gcs/read.h"
#include "storage/read.intern.h"
@ -22,7 +21,6 @@ Object type
***********************************************************************************************************************************/
typedef struct StorageReadGcs
{
MemContext *memContext; // Object mem context
StorageReadInterface interface; // Interface
StorageGcs *storage; // Storage that created this object
@ -55,7 +53,7 @@ storageReadGcsOpen(THIS_VOID)
bool result = false;
// Request the file
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
{
this->httpResponse = storageGcsRequestP(
this->storage, HTTP_VERB_GET_STR, .object = this->interface.name, .allowMissing = true, .contentIo = true,
@ -128,13 +126,12 @@ storageReadGcsNew(StorageGcs *storage, const String *name, bool ignoreMissing)
StorageRead *this = NULL;
MEM_CONTEXT_NEW_BEGIN("StorageReadGcs")
OBJ_NEW_BEGIN(StorageReadGcs)
{
StorageReadGcs *driver = memNew(sizeof(StorageReadGcs));
StorageReadGcs *driver = OBJ_NEW_ALLOC();
*driver = (StorageReadGcs)
{
.memContext = MEM_CONTEXT_NEW(),
.storage = storage,
.interface = (StorageReadInterface)
@ -154,7 +151,7 @@ storageReadGcsNew(StorageGcs *storage, const String *name, bool ignoreMissing)
this = storageReadNew(driver, &driver->interface);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(STORAGE_READ, this);
}

View File

@ -18,7 +18,6 @@ GCS Storage
#include "common/io/socket/client.h"
#include "common/io/tls/client.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/regExp.h"
#include "common/type/json.h"
#include "common/type/object.h"
@ -81,7 +80,6 @@ Object type
struct StorageGcs
{
STORAGE_COMMON_MEMBER;
MemContext *memContext;
HttpClient *httpClient; // Http client to service requests
StringList *headerRedactList; // List of headers to redact from logging
StringList *queryRedactList; // List of query keys to redact from logging
@ -336,7 +334,7 @@ storageGcsAuth(StorageGcs *this, HttpHeader *httpHeader)
StorageGcsAuthTokenResult tokenResult = this->keyType == storageGcsKeyTypeAuto ?
storageGcsAuthAuto(this, timeBegin) : storageGcsAuthService(this, timeBegin);
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
{
strFree(this->token);
this->token = strNewFmt("%s %s", strZ(tokenResult.tokenType), strZ(tokenResult.token));
@ -934,13 +932,12 @@ storageGcsNew(
Storage *this = NULL;
MEM_CONTEXT_NEW_BEGIN("StorageGcs")
OBJ_NEW_BEGIN(StorageGcs)
{
StorageGcs *driver = memNew(sizeof(StorageGcs));
StorageGcs *driver = OBJ_NEW_ALLOC();
*driver = (StorageGcs)
{
.memContext = MEM_CONTEXT_NEW(),
.interface = storageInterfaceGcs,
.write = write,
.bucket = strDup(bucket),
@ -1007,7 +1004,7 @@ storageGcsNew(
this = storageNew(STORAGE_GCS_TYPE, path, 0, 0, write, pathExpressionFunction, driver, driver->interface);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(STORAGE, this);
}

View File

@ -7,7 +7,6 @@ GCS Storage File Write
#include "common/debug.h"
#include "common/io/filter/filter.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/json.h"
#include "common/type/keyValue.h"
#include "common/type/object.h"
@ -26,7 +25,6 @@ Object type
***********************************************************************************************************************************/
typedef struct StorageWriteGcs
{
MemContext *memContext; // Object mem context
StorageWriteInterface interface; // Interface
StorageGcs *storage; // Storage that created this object
@ -62,7 +60,7 @@ storageWriteGcsOpen(THIS_VOID)
ASSERT(this->chunkBuffer == NULL);
// Allocate the chunk buffer
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
{
this->chunkBuffer = bufNew(this->chunkSize);
this->md5hash = cryptoHashNew(HASH_TYPE_MD5_STR);
@ -174,7 +172,7 @@ storageWriteGcsBlockAsync(StorageWriteGcs *this, bool done)
{
HttpResponse *response = storageGcsRequestP(this->storage, HTTP_VERB_POST_STR, .upload = true, .query = query);
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
{
this->uploadId = strDup(httpHeaderGet(httpResponseHeader(response), GCS_HEADER_UPLOAD_ID_STR));
CHECK(this->uploadId != NULL);
@ -200,7 +198,7 @@ storageWriteGcsBlockAsync(StorageWriteGcs *this, bool done)
if (done)
httpQueryAdd(query, GCS_QUERY_FIELDS_STR, GCS_QUERY_FIELDS_VALUE_STR);
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
{
this->request = storageGcsRequestAsyncP(
this->storage, HTTP_VERB_PUT_STR, .upload = true, .noAuth = true, .header = header, .query = query,
@ -330,13 +328,12 @@ storageWriteGcsNew(StorageGcs *storage, const String *name, size_t chunkSize)
StorageWrite *this = NULL;
MEM_CONTEXT_NEW_BEGIN("StorageWriteGcs")
OBJ_NEW_BEGIN(StorageWriteGcs)
{
StorageWriteGcs *driver = memNew(sizeof(StorageWriteGcs));
StorageWriteGcs *driver = OBJ_NEW_ALLOC();
*driver = (StorageWriteGcs)
{
.memContext = MEM_CONTEXT_NEW(),
.storage = storage,
.chunkSize = chunkSize,
@ -360,7 +357,7 @@ storageWriteGcsNew(StorageGcs *storage, const String *name, size_t chunkSize)
this = storageWriteNew(driver, &driver->interface);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(STORAGE_WRITE, this);
}

View File

@ -9,7 +9,6 @@ Posix Storage Read
#include "common/debug.h"
#include "common/io/read.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
#include "storage/posix/read.h"
#include "storage/posix/storage.intern.h"
@ -20,7 +19,6 @@ Object types
***********************************************************************************************************************************/
typedef struct StorageReadPosix
{
MemContext *memContext; // Object mem context
StorageReadInterface interface; // Interface
StoragePosix *storage; // Storage that created this object
@ -93,7 +91,7 @@ storageReadPosixOpen(THIS_VOID)
// On success set free callback to ensure the file descriptor is freed
if (this->fd != -1)
{
memContextCallbackSet(this->memContext, storageReadPosixFreeResource, this);
memContextCallbackSet(THIS_MEM_CONTEXT(), storageReadPosixFreeResource, this);
result = true;
}
@ -162,7 +160,7 @@ storageReadPosixClose(THIS_VOID)
ASSERT(this != NULL);
memContextCallbackClear(this->memContext);
memContextCallbackClear(THIS_MEM_CONTEXT());
storageReadPosixFreeResource(this);
this->fd = -1;
@ -217,13 +215,12 @@ storageReadPosixNew(StoragePosix *storage, const String *name, bool ignoreMissin
StorageRead *this = NULL;
MEM_CONTEXT_NEW_BEGIN("StorageReadPosix")
OBJ_NEW_BEGIN(StorageReadPosix)
{
StorageReadPosix *driver = memNew(sizeof(StorageReadPosix));
StorageReadPosix *driver = OBJ_NEW_ALLOC();
*driver = (StorageReadPosix)
{
.memContext = MEM_CONTEXT_NEW(),
.storage = storage,
.fd = -1,
@ -252,7 +249,7 @@ storageReadPosixNew(StoragePosix *storage, const String *name, bool ignoreMissin
this = storageReadNew(driver, &driver->interface);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(STORAGE_READ, this);
}

View File

@ -14,7 +14,6 @@ Posix Storage
#include "common/debug.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/regExp.h"
#include "common/user.h"
#include "storage/posix/read.h"
@ -34,7 +33,6 @@ Object type
struct StoragePosix
{
STORAGE_COMMON_MEMBER;
MemContext *memContext; // Object memory context
};
/**********************************************************************************************************************************/
@ -586,13 +584,12 @@ storagePosixNewInternal(
// Create the object
Storage *this = NULL;
MEM_CONTEXT_NEW_BEGIN("StoragePosix")
OBJ_NEW_BEGIN(StoragePosix)
{
StoragePosix *driver = memNew(sizeof(StoragePosix));
StoragePosix *driver = OBJ_NEW_ALLOC();
*driver = (StoragePosix)
{
.memContext = MEM_CONTEXT_NEW(),
.interface = storageInterfacePosix,
};
@ -608,7 +605,7 @@ storagePosixNewInternal(
this = storageNew(type, path, modeFile, modePath, write, pathExpressionFunction, driver, driver->interface);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(STORAGE, this);
}

View File

@ -11,7 +11,6 @@ Posix Storage File write
#include "common/debug.h"
#include "common/io/write.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
#include "common/user.h"
#include "storage/posix/storage.intern.h"
@ -23,7 +22,6 @@ Object type
***********************************************************************************************************************************/
typedef struct StorageWritePosix
{
MemContext *memContext; // Object mem context
StorageWriteInterface interface; // Interface
StoragePosix *storage; // Storage that created this object
@ -105,7 +103,7 @@ storageWritePosixOpen(THIS_VOID)
}
// Set free callback to ensure the file descriptor is freed
memContextCallbackSet(this->memContext, storageWritePosixFreeResource, this);
memContextCallbackSet(THIS_MEM_CONTEXT(), storageWritePosixFreeResource, this);
// Update user/group owner
if (this->interface.user != NULL || this->interface.group != NULL)
@ -174,7 +172,7 @@ storageWritePosixClose(THIS_VOID)
THROW_ON_SYS_ERROR_FMT(fsync(this->fd) == -1, FileSyncError, STORAGE_ERROR_WRITE_SYNC, strZ(this->nameTmp));
// Close the file
memContextCallbackClear(this->memContext);
memContextCallbackClear(THIS_MEM_CONTEXT());
THROW_ON_SYS_ERROR_FMT(close(this->fd) == -1, FileCloseError, STORAGE_ERROR_WRITE_CLOSE, strZ(this->nameTmp));
this->fd = -1;
@ -247,13 +245,12 @@ storageWritePosixNew(
StorageWrite *this = NULL;
MEM_CONTEXT_NEW_BEGIN("StorageWritePosix")
OBJ_NEW_BEGIN(StorageWritePosix)
{
StorageWritePosix *driver = memNew(sizeof(StorageWritePosix));
StorageWritePosix *driver = OBJ_NEW_ALLOC();
*driver = (StorageWritePosix)
{
.memContext = MEM_CONTEXT_NEW(),
.storage = storage,
.path = strPath(name),
.fd = -1,
@ -287,7 +284,7 @@ storageWritePosixNew(
this = storageWriteNew(driver, &driver->interface);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(STORAGE_WRITE, this);
}

View File

@ -20,7 +20,7 @@ Functions
__attribute__((always_inline)) static inline StorageRead *
storageReadMove(StorageRead *const this, MemContext *const parentNew)
{
return objMove(this, parentNew);
return objMoveContext(this, parentNew);
}
/***********************************************************************************************************************************
@ -74,7 +74,7 @@ Destructor
__attribute__((always_inline)) static inline void
storageReadFree(StorageRead *const this)
{
objFree(this);
objFreeContext(this);
}
/***********************************************************************************************************************************

View File

@ -12,7 +12,6 @@ Remote Storage Protocol Handler
#include "common/io/filter/size.h"
#include "common/io/io.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/regExp.h"
#include "common/type/pack.h"
#include "common/type/json.h"

View File

@ -10,7 +10,6 @@ Remote Storage Read
#include "common/debug.h"
#include "common/io/read.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/convert.h"
#include "common/type/json.h"
#include "common/type/object.h"
@ -23,7 +22,6 @@ Object type
***********************************************************************************************************************************/
typedef struct StorageReadRemote
{
MemContext *memContext; // Object mem context
StorageReadInterface interface; // Interface
StorageRemote *storage; // Storage that created this object
StorageRead *read; // Storage read interface
@ -137,7 +135,7 @@ storageReadRemote(THIS_VOID, Buffer *buffer, bool block)
// If binary then read the next block
if (pckReadType(read) == pckTypeBin)
{
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
{
this->block = pckReadBinP(read);
this->remaining = bufUsed(this->block);
@ -228,13 +226,12 @@ storageReadRemoteNew(
StorageReadRemote *this = NULL;
MEM_CONTEXT_NEW_BEGIN("StorageReadRemote")
OBJ_NEW_BEGIN(StorageReadRemote)
{
this = memNew(sizeof(StorageReadRemote));
this = OBJ_NEW_ALLOC();
*this = (StorageReadRemote)
{
.memContext = MEM_CONTEXT_NEW(),
.storage = storage,
.client = client,
@ -258,7 +255,7 @@ storageReadRemoteNew(
this->read = storageReadNew(this, &this->interface);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
ASSERT(this != NULL);
FUNCTION_LOG_RETURN(STORAGE_READ, this->read);

View File

@ -20,7 +20,6 @@ Object type
struct StorageRemote
{
STORAGE_COMMON_MEMBER;
MemContext *memContext;
ProtocolClient *client; // Protocol client
unsigned int compressLevel; // Protocol compression level
};
@ -452,13 +451,12 @@ storageRemoteNew(
Storage *this = NULL;
MEM_CONTEXT_NEW_BEGIN("StorageRemote")
OBJ_NEW_BEGIN(StorageRemote)
{
StorageRemote *driver = memNew(sizeof(StorageRemote));
StorageRemote *driver = OBJ_NEW_ALLOC();
*driver = (StorageRemote)
{
.memContext = MEM_CONTEXT_NEW(),
.client = client,
.compressLevel = compressLevel,
.interface = storageInterfaceRemote,
@ -485,7 +483,7 @@ storageRemoteNew(
this = storageNew(STORAGE_REMOTE_TYPE, path, modeFile, modePath, write, pathExpressionFunction, driver, driver->interface);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(STORAGE, this);
}

View File

@ -8,7 +8,6 @@ Remote Storage File write
#include "common/io/io.h"
#include "common/io/write.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/json.h"
#include "common/type/object.h"
#include "storage/remote/protocol.h"
@ -20,7 +19,6 @@ Object type
***********************************************************************************************************************************/
typedef struct StorageWriteRemote
{
MemContext *memContext; // Object mem context
StorageWriteInterface interface; // Interface
StorageRemote *storage; // Storage that created this object
StorageWrite *write; // Storage write interface
@ -110,7 +108,7 @@ storageWriteRemoteOpen(THIS_VOID)
}
// Set free callback to ensure remote file is freed
memContextCallbackSet(this->memContext, storageWriteRemoteFreeResource, this);
memContextCallbackSet(THIS_MEM_CONTEXT(), storageWriteRemoteFreeResource, this);
}
MEM_CONTEXT_TEMP_END();
@ -174,7 +172,7 @@ storageWriteRemoteClose(THIS_VOID)
MEM_CONTEXT_TEMP_END();
this->client = NULL;
memContextCallbackClear(this->memContext);
memContextCallbackClear(THIS_MEM_CONTEXT());
}
FUNCTION_LOG_RETURN_VOID();
@ -211,13 +209,12 @@ storageWriteRemoteNew(
StorageWriteRemote *this = NULL;
MEM_CONTEXT_NEW_BEGIN("StorageWriteRemote")
OBJ_NEW_BEGIN(StorageWriteRemote)
{
this = memNew(sizeof(StorageWriteRemote));
this = OBJ_NEW_ALLOC();
*this = (StorageWriteRemote)
{
.memContext = MEM_CONTEXT_NEW(),
.storage = storage,
.client = client,
@ -248,7 +245,7 @@ storageWriteRemoteNew(
this->write = storageWriteNew(this, &this->interface);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
ASSERT(this != NULL);
FUNCTION_LOG_RETURN(STORAGE_WRITE, this->write);

View File

@ -6,7 +6,6 @@ S3 Storage Read
#include "common/debug.h"
#include "common/io/http/client.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
#include "storage/s3/read.h"
#include "storage/read.intern.h"
@ -19,7 +18,6 @@ Object type
typedef struct StorageReadS3
{
MemContext *memContext; // Object mem context
StorageReadInterface interface; // Interface
StorageS3 *storage; // Storage that created this object
@ -52,7 +50,7 @@ storageReadS3Open(THIS_VOID)
bool result = false;
// Request the file
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
{
this->httpResponse = storageS3RequestP(
this->storage, HTTP_VERB_GET_STR, this->interface.name, .allowMissing = true, .contentIo = true);
@ -124,13 +122,12 @@ storageReadS3New(StorageS3 *storage, const String *name, bool ignoreMissing)
StorageRead *this = NULL;
MEM_CONTEXT_NEW_BEGIN("StorageReadS3")
OBJ_NEW_BEGIN(StorageReadS3)
{
StorageReadS3 *driver = memNew(sizeof(StorageReadS3));
StorageReadS3 *driver = OBJ_NEW_ALLOC();
*driver = (StorageReadS3)
{
.memContext = MEM_CONTEXT_NEW(),
.storage = storage,
.interface = (StorageReadInterface)
@ -150,7 +147,7 @@ storageReadS3New(StorageS3 *storage, const String *name, bool ignoreMissing)
this = storageReadNew(driver, &driver->interface);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(STORAGE_READ, this);
}

View File

@ -12,7 +12,6 @@ S3 Storage
#include "common/io/socket/client.h"
#include "common/io/tls/client.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/regExp.h"
#include "common/type/object.h"
#include "common/type/json.h"
@ -100,7 +99,6 @@ Object type
struct StorageS3
{
STORAGE_COMMON_MEMBER;
MemContext *memContext;
HttpClient *httpClient; // HTTP client to service requests
StringList *headerRedactList; // List of headers to redact from logging
@ -232,7 +230,7 @@ storageS3Auth(
const Buffer *serviceKey = cryptoHmacOne(HASH_TYPE_SHA256_STR, regionKey, S3_BUF);
// Switch to the object context so signing key and date are not lost
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
{
this->signingKey = cryptoHmacOne(HASH_TYPE_SHA256_STR, serviceKey, AWS4_REQUEST_BUF);
this->signingKeyDate = strDup(date);
@ -339,7 +337,7 @@ storageS3RequestAsync(StorageS3 *this, const String *verb, const String *path, S
httpRequestError(request, response);
// Get role from the text response
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
{
this->credRole = strNewBuf(httpResponseContent(response));
}
@ -373,7 +371,7 @@ storageS3RequestAsync(StorageS3 *this, const String *verb, const String *path, S
// Get credentials from the JSON response
KeyValue *credential = jsonToKv(strNewBuf(httpResponseContent(response)));
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
{
// Check the code field for errors
const Variant *code = kvGetDefault(credential, S3_JSON_TAG_CODE_VAR, VARSTRDEF("code field is missing"));
@ -969,13 +967,12 @@ storageS3New(
Storage *this = NULL;
MEM_CONTEXT_NEW_BEGIN("StorageS3")
OBJ_NEW_BEGIN(StorageS3)
{
StorageS3 *driver = memNew(sizeof(StorageS3));
StorageS3 *driver = OBJ_NEW_ALLOC();
*driver = (StorageS3)
{
.memContext = MEM_CONTEXT_NEW(),
.interface = storageInterfaceS3,
.bucket = strDup(bucket),
.region = strDup(region),
@ -1014,7 +1011,7 @@ storageS3New(
this = storageNew(STORAGE_S3_TYPE, path, 0, 0, write, pathExpressionFunction, driver, driver->interface);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(STORAGE, this);
}

View File

@ -5,7 +5,6 @@ S3 Storage File Write
#include "common/debug.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/object.h"
#include "common/type/xml.h"
#include "storage/s3/write.h"
@ -32,7 +31,6 @@ Object type
***********************************************************************************************************************************/
typedef struct StorageWriteS3
{
MemContext *memContext; // Object mem context
StorageWriteInterface interface; // Interface
StorageS3 *storage; // Storage that created this object
@ -67,7 +65,7 @@ storageWriteS3Open(THIS_VOID)
ASSERT(this->partBuffer == NULL);
// Allocate the part buffer
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
{
this->partBuffer = bufNew(this->partSize);
}
@ -130,7 +128,7 @@ storageWriteS3PartAsync(StorageWriteS3 *this)
.query = httpQueryAdd(httpQueryNewP(), S3_QUERY_UPLOADS_STR, EMPTY_STR)))));
// Store the upload id
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
{
this->uploadId = xmlNodeContent(xmlNodeChild(xmlRoot, S3_XML_TAG_UPLOAD_ID_STR, true));
this->uploadPartList = strLstNew();
@ -143,7 +141,7 @@ storageWriteS3PartAsync(StorageWriteS3 *this)
httpQueryAdd(query, S3_QUERY_UPLOAD_ID_STR, this->uploadId);
httpQueryAdd(query, S3_QUERY_PART_NUMBER_STR, strNewFmt("%u", strLstSize(this->uploadPartList) + 1));
MEM_CONTEXT_BEGIN(this->memContext)
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
{
this->request = storageS3RequestAsyncP(
this->storage, HTTP_VERB_PUT_STR, this->interface.name, .query = query, .content = this->partBuffer);
@ -275,13 +273,12 @@ storageWriteS3New(StorageS3 *storage, const String *name, size_t partSize)
StorageWrite *this = NULL;
MEM_CONTEXT_NEW_BEGIN("StorageWriteS3")
OBJ_NEW_BEGIN(StorageWriteS3)
{
StorageWriteS3 *driver = memNew(sizeof(StorageWriteS3));
StorageWriteS3 *driver = OBJ_NEW_ALLOC();
*driver = (StorageWriteS3)
{
.memContext = MEM_CONTEXT_NEW(),
.storage = storage,
.partSize = partSize,
@ -305,7 +302,7 @@ storageWriteS3New(StorageS3 *storage, const String *name, size_t partSize)
this = storageWriteNew(driver, &driver->interface);
}
MEM_CONTEXT_NEW_END();
OBJ_NEW_END();
FUNCTION_LOG_RETURN(STORAGE_WRITE, this);
}

Some files were not shown because too many files have changed in this diff Show More