1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-18 04:58:51 +02:00

Replace OBJECT_DEFINE_FREE_RESOURCE_BEGIN() with normal functions.

OBJECT_DEFINE_MOVE() and OBJECT_DEFINE_FREE() will be replaced with inlines so this would be the only macro left that is constructing functions.

It is not a great pattern anyway since it makes it hard to find the function implementation.
This commit is contained in:
David Steele 2021-04-07 16:27:55 -04:00
parent cc85c4f03d
commit 351e7db4c4
24 changed files with 264 additions and 135 deletions

View File

@ -22,9 +22,6 @@ STRING_EXTERN(BZ2_COMPRESS_FILTER_TYPE_STR, BZ2_COMPRESS
/***********************************************************************************************************************************
Object type
***********************************************************************************************************************************/
#define BZ2_COMPRESS_TYPE Bz2Compress
#define BZ2_COMPRESS_PREFIX bz2Compress
typedef struct Bz2Compress
{
MemContext *memContext; // Context to store data
@ -54,11 +51,21 @@ bz2CompressToLog(const Bz2Compress *this)
/***********************************************************************************************************************************
Free compression stream
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(BZ2_COMPRESS, LOG, logLevelTrace)
static void
bz2CompressFreeResource(THIS_VOID)
{
THIS(Bz2Compress);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(BZ2_COMPRESS, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
BZ2_bzCompressEnd(&this->stream);
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/***********************************************************************************************************************************
Compress data

View File

@ -22,9 +22,6 @@ STRING_EXTERN(BZ2_DECOMPRESS_FILTER_TYPE_STR, BZ2_DECOMPR
/***********************************************************************************************************************************
Object type
***********************************************************************************************************************************/
#define BZ2_DECOMPRESS_TYPE Bz2Decompress
#define BZ2_DECOMPRESS_PREFIX bz2Decompress
typedef struct Bz2Decompress
{
MemContext *memContext; // Context to store data
@ -54,11 +51,21 @@ bz2DecompressToLog(const Bz2Decompress *this)
/***********************************************************************************************************************************
Free inflate stream
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(BZ2_DECOMPRESS, LOG, logLevelTrace)
static void
bz2DecompressFreeResource(THIS_VOID)
{
THIS(Bz2Decompress);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(BZ2_DECOMPRESS, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
BZ2_bzDecompressEnd(&this->stream);
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/***********************************************************************************************************************************
Decompress data

View File

@ -22,9 +22,6 @@ STRING_EXTERN(GZ_COMPRESS_FILTER_TYPE_STR, GZ_COMPRESS_
/***********************************************************************************************************************************
Object type
***********************************************************************************************************************************/
#define GZ_COMPRESS_TYPE GzCompress
#define GZ_COMPRESS_PREFIX gzCompress
typedef struct GzCompress
{
MemContext *memContext; // Context to store data
@ -59,11 +56,21 @@ Compression constants
/***********************************************************************************************************************************
Free deflate stream
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(GZ_COMPRESS, LOG, logLevelTrace)
static void
gzCompressFreeResource(THIS_VOID)
{
THIS(GzCompress);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(GZ_COMPRESS, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
deflateEnd(&this->stream);
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/***********************************************************************************************************************************
Compress data

View File

@ -22,9 +22,6 @@ STRING_EXTERN(GZ_DECOMPRESS_FILTER_TYPE_STR, GZ_DECOMPRES
/***********************************************************************************************************************************
Object type
***********************************************************************************************************************************/
#define GZ_DECOMPRESS_TYPE GzDecompress
#define GZ_DECOMPRESS_PREFIX gzDecompress
typedef struct GzDecompress
{
MemContext *memContext; // Context to store data
@ -54,11 +51,21 @@ gzDecompressToLog(const GzDecompress *this)
/***********************************************************************************************************************************
Free inflate stream
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(GZ_DECOMPRESS, LOG, logLevelTrace)
static void
gzDecompressFreeResource(THIS_VOID)
{
THIS(GzDecompress);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(GZ_DECOMPRESS, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
inflateEnd(&this->stream);
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/***********************************************************************************************************************************
Decompress data

View File

@ -34,9 +34,6 @@ STRING_EXTERN(LZ4_COMPRESS_FILTER_TYPE_STR, LZ4_COMPRESS
/***********************************************************************************************************************************
Object type
***********************************************************************************************************************************/
#define LZ4_COMPRESS_TYPE Lz4Compress
#define LZ4_COMPRESS_PREFIX lz4Compress
typedef struct Lz4Compress
{
MemContext *memContext; // Context to store data
@ -69,11 +66,21 @@ lz4CompressToLog(const Lz4Compress *this)
/***********************************************************************************************************************************
Free compression context
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(LZ4_COMPRESS, LOG, logLevelTrace)
static void
lz4CompressFreeResource(THIS_VOID)
{
THIS(Lz4Compress);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(LZ4_COMPRESS, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
LZ4F_freeCompressionContext(this->context);
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/***********************************************************************************************************************************
Compress data

View File

@ -24,9 +24,6 @@ STRING_EXTERN(LZ4_DECOMPRESS_FILTER_TYPE_STR, LZ4_DECOMPRE
/***********************************************************************************************************************************
Object type
***********************************************************************************************************************************/
#define LZ4_DECOMPRESS_TYPE Lz4Decompress
#define LZ4_DECOMPRESS_PREFIX lz4Decompress
typedef struct Lz4Decompress
{
MemContext *memContext; // Context to store data
@ -58,11 +55,21 @@ lz4DecompressToLog(const Lz4Decompress *this)
/***********************************************************************************************************************************
Free decompression context
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(LZ4_DECOMPRESS, LOG, logLevelTrace)
static void
lz4DecompressFreeResource(THIS_VOID)
{
THIS(Lz4Decompress);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(LZ4_DECOMPRESS, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
LZ4F_freeDecompressionContext(this->context);
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/***********************************************************************************************************************************
Decompress data

View File

@ -23,9 +23,6 @@ STRING_EXTERN(ZST_COMPRESS_FILTER_TYPE_STR, ZST_COMPRESS
/***********************************************************************************************************************************
Object type
***********************************************************************************************************************************/
#define ZST_COMPRESS_TYPE ZstCompress
#define ZST_COMPRESS_PREFIX zstCompress
typedef struct ZstCompress
{
MemContext *memContext; // Context to store data
@ -57,11 +54,21 @@ zstCompressToLog(const ZstCompress *this)
/***********************************************************************************************************************************
Free compression context
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(ZST_COMPRESS, LOG, logLevelTrace)
static void
zstCompressFreeResource(THIS_VOID)
{
THIS(ZstCompress);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(ZST_COMPRESS, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
ZSTD_freeCStream(this->context);
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/***********************************************************************************************************************************
Compress data

View File

@ -23,9 +23,6 @@ STRING_EXTERN(ZST_DECOMPRESS_FILTER_TYPE_STR, ZST_DECOMPRE
/***********************************************************************************************************************************
Object type
***********************************************************************************************************************************/
#define ZST_DECOMPRESS_TYPE ZstDecompress
#define ZST_DECOMPRESS_PREFIX zstDecompress
typedef struct ZstDecompress
{
MemContext *memContext; // Context to store data
@ -57,11 +54,21 @@ zstDecompressToLog(const ZstDecompress *this)
/***********************************************************************************************************************************
Free decompression context
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(ZST_DECOMPRESS, LOG, logLevelTrace)
static void
zstDecompressFreeResource(THIS_VOID)
{
THIS(ZstDecompress);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(ZST_DECOMPRESS, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
ZSTD_freeDStream(this->context);
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/***********************************************************************************************************************************
Decompress data

View File

@ -35,9 +35,6 @@ Header constants and sizes
/***********************************************************************************************************************************
Object type
***********************************************************************************************************************************/
#define CIPHER_BLOCK_TYPE CipherBlock
#define CIPHER_BLOCK_PREFIX cipherBlock
typedef struct CipherBlock
{
MemContext *memContext; // Context to store data
@ -75,11 +72,21 @@ cipherBlockToLog(const CipherBlock *this)
/***********************************************************************************************************************************
Free cipher context
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(CIPHER_BLOCK, LOG, logLevelTrace)
static void
cipherBlockFreeResource(THIS_VOID)
{
THIS(CipherBlock);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(CIPHER_BLOCK, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
EVP_CIPHER_CTX_free(this->cipherContext);
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/***********************************************************************************************************************************
Determine how large the destination buffer should be

View File

@ -43,9 +43,6 @@ Include local MD5 code
/***********************************************************************************************************************************
Object type
***********************************************************************************************************************************/
#define CRYPTO_HASH_TYPE CryptoHash
#define CRYPTO_HASH_PREFIX cryptoHash
typedef struct CryptoHash
{
MemContext *memContext; // Context to store data
@ -66,11 +63,21 @@ Macros for function logging
/***********************************************************************************************************************************
Free hash context
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(CRYPTO_HASH, LOG, logLevelTrace)
static void
cryptoHashFreeResource(THIS_VOID)
{
THIS(CryptoHash);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(CRYPTO_HASH, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
EVP_MD_CTX_destroy(this->hashContext);
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/***********************************************************************************************************************************
Add message data to the hash from a Buffer

View File

@ -74,8 +74,17 @@ other code.
/***********************************************************************************************************************************
Free exec file descriptors and ensure process is shut down
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(EXEC, LOG, logLevelTrace)
static void
execFreeResource(THIS_VOID)
{
THIS(Exec);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(EXEC, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
// Close file descriptors
close(this->fdRead);
close(this->fdWrite);
@ -103,8 +112,9 @@ OBJECT_DEFINE_FREE_RESOURCE_BEGIN(EXEC, LOG, logLevelTrace)
}
MEM_CONTEXT_TEMP_END();
}
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/**********************************************************************************************************************************/
Exec *

View File

@ -17,9 +17,6 @@ Socket Session
/***********************************************************************************************************************************
Object type
***********************************************************************************************************************************/
#define SOCKET_SESSION_TYPE SocketSession
#define SOCKET_SESSION_PREFIX sckSession
typedef struct SocketSession
{
MemContext *memContext; // Mem context
@ -52,11 +49,21 @@ sckSessionToLog(const THIS_VOID)
/***********************************************************************************************************************************
Free connection
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(SOCKET_SESSION, LOG, logLevelTrace)
static void
sckSessionFreeResource(THIS_VOID)
{
THIS(SocketSession);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(SOCKET_SESSION, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
close(this->fd);
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/**********************************************************************************************************************************/
static void

View File

@ -35,9 +35,6 @@ STRING_EXTERN(TLS_STAT_SESSION_STR, TLS_STAT_SES
/***********************************************************************************************************************************
Object type
***********************************************************************************************************************************/
#define TLS_CLIENT_TYPE TlsClient
#define TLS_CLIENT_PREFIX tlsClient
typedef struct TlsClient
{
MemContext *memContext; // Mem context
@ -71,11 +68,21 @@ tlsClientToLog(const THIS_VOID)
/***********************************************************************************************************************************
Free connection
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(TLS_CLIENT, LOG, logLevelTrace)
static void
tlsClientFreeResource(THIS_VOID)
{
THIS(TlsClient);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(TLS_CLIENT, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
SSL_CTX_free(this->context);
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/***********************************************************************************************************************************
Convert an ASN1 string used in certificates to a String

View File

@ -20,9 +20,6 @@ TLS Session
/***********************************************************************************************************************************
Object type
***********************************************************************************************************************************/
#define TLS_SESSION_TYPE TlsSession
#define TLS_SESSION_PREFIX tlsSession
typedef struct TlsSession
{
MemContext *memContext; // Mem context
@ -57,11 +54,21 @@ tlsSessionToLog(const THIS_VOID)
/***********************************************************************************************************************************
Free connection
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(TLS_SESSION, LOG, logLevelTrace)
static void
tlsSessionFreeResource(THIS_VOID)
{
THIS(TlsSession);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(TLS_SESSION, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
SSL_free(this->session);
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/**********************************************************************************************************************************/
static void

View File

@ -27,11 +27,21 @@ OBJECT_DEFINE_FREE(REGEXP);
/***********************************************************************************************************************************
Free regular expression
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(REGEXP, TEST, )
static void
regExpFreeResource(THIS_VOID)
{
THIS(RegExp);
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(REGEXP, this);
FUNCTION_TEST_END();
ASSERT(this != NULL);
regfree(&this->regExp);
FUNCTION_TEST_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(TEST);
/***********************************************************************************************************************************
Handle errors

View File

@ -58,33 +58,6 @@ If "this" is NULL then no action is taken.
FUNCTION_TEST_RETURN(this); \
}
/***********************************************************************************************************************************
Free resource associated with an object that was not allocated by a mem context
Create a callback function intended to be use with memContextCallbackSet() that frees a resource that was allocated by, e.g., a
third-party library and not by a mem context. Don't call memFree() or memContextFree() in this function -- that will be handled
when the mem context is freed.
If the object prefix is "object" then the function will be defined as:
static void objectFreeResource(THIS_VOID)
***********************************************************************************************************************************/
#define OBJECT_DEFINE_FREE_RESOURCE_BEGIN(objectMacro, logTypeMacro, logLevelMacro) \
static void \
GLUE(objectMacro##_PREFIX, FreeResource)(THIS_VOID) \
{ \
THIS(objectMacro##_TYPE); \
\
FUNCTION_##logTypeMacro##_BEGIN(logLevelMacro); \
FUNCTION_##logTypeMacro##_PARAM(objectMacro, this); \
FUNCTION_##logTypeMacro##_END(); \
\
ASSERT(this != NULL);
#define OBJECT_DEFINE_FREE_RESOURCE_END(logTypeMacro) \
FUNCTION_##logTypeMacro##_RETURN_VOID(); \
}
/***********************************************************************************************************************************
Define a function used by the caller to dispose of an object that is no longer needed when it would consume significant amounts of
memory, e.g. in a loop. For the most part free does not need to be called explicitly, and in fact should not be since the automatic

View File

@ -360,11 +360,21 @@ xmlNodeFree(XmlNode *this)
/***********************************************************************************************************************************
Free document
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(XML_DOCUMENT, LOG, logLevelTrace)
static void
xmlDocumentFreeResource(THIS_VOID)
{
THIS(XmlDocument);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(XML_DOCUMENT, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
xmlFreeDoc(this->xml);
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/**********************************************************************************************************************************/
XmlDocument *

View File

@ -43,14 +43,24 @@ OBJECT_DEFINE_FREE(DB);
/***********************************************************************************************************************************
Close protocol connection. No need to close a locally created PgClient since it has its own destructor.
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(DB, LOG, logLevelTrace)
static void
dbFreeResource(THIS_VOID)
{
THIS(Db);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(DB, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
ProtocolCommand *command = protocolCommandNew(PROTOCOL_COMMAND_DB_CLOSE_STR);
protocolCommandParamAdd(command, VARUINT(this->remoteIdx));
protocolClientExecute(this->remoteClient, command, false);
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/**********************************************************************************************************************************/
Db *

View File

@ -34,11 +34,21 @@ OBJECT_DEFINE_FREE(PG_CLIENT);
/***********************************************************************************************************************************
Close protocol connection
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(PG_CLIENT, LOG, logLevelTrace)
static void
pgClientFreeResource(THIS_VOID)
{
THIS(PgClient);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(PG_CLIENT, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
PQfinish(this->connection);
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/**********************************************************************************************************************************/
PgClient *

View File

@ -47,16 +47,26 @@ OBJECT_DEFINE_FREE(PROTOCOL_CLIENT);
/***********************************************************************************************************************************
Close protocol connection
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(PROTOCOL_CLIENT, LOG, logLevelTrace)
static void
protocolClientFreeResource(THIS_VOID)
{
THIS(ProtocolClient);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(PROTOCOL_CLIENT, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
// Send an exit command but don't wait to see if it succeeds
MEM_CONTEXT_TEMP_BEGIN()
{
protocolClientWriteCommand(this, protocolCommandNew(PROTOCOL_COMMAND_EXIT_STR));
}
MEM_CONTEXT_TEMP_END();
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/**********************************************************************************************************************************/
ProtocolClient *

View File

@ -18,9 +18,6 @@ Posix Storage Read
/***********************************************************************************************************************************
Object types
***********************************************************************************************************************************/
#define STORAGE_READ_POSIX_TYPE StorageReadPosix
#define STORAGE_READ_POSIX_PREFIX storageReadPosix
typedef struct StorageReadPosix
{
MemContext *memContext; // Object mem context
@ -44,12 +41,22 @@ Macros for function logging
/***********************************************************************************************************************************
Close file descriptor
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(STORAGE_READ_POSIX, LOG, logLevelTrace)
static void
storageReadPosixFreeResource(THIS_VOID)
{
THIS(StorageReadPosix);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(STORAGE_READ_POSIX, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
if (this->fd != -1)
THROW_ON_SYS_ERROR_FMT(close(this->fd) == -1, FileCloseError, STORAGE_ERROR_READ_CLOSE, strZ(this->interface.name));
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/***********************************************************************************************************************************
Open the file

View File

@ -21,9 +21,6 @@ Posix Storage File write
/***********************************************************************************************************************************
Object type
***********************************************************************************************************************************/
#define STORAGE_WRITE_POSIX_TYPE StorageWritePosix
#define STORAGE_WRITE_POSIX_PREFIX storageWritePosix
typedef struct StorageWritePosix
{
MemContext *memContext; // Object mem context
@ -54,11 +51,21 @@ Since open is called more than once use constants to make sure these parameters
/***********************************************************************************************************************************
Close file descriptor
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(STORAGE_WRITE_POSIX, LOG, logLevelTrace)
static void
storageWritePosixFreeResource(THIS_VOID)
{
THIS(StorageWritePosix);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(STORAGE_WRITE_POSIX, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
THROW_ON_SYS_ERROR_FMT(close(this->fd) == -1, FileCloseError, STORAGE_ERROR_WRITE_CLOSE, strZ(this->nameTmp));
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/***********************************************************************************************************************************
Open the file

View File

@ -16,9 +16,6 @@ Remote Storage File write
/***********************************************************************************************************************************
Object type
***********************************************************************************************************************************/
#define STORAGE_WRITE_REMOTE_TYPE StorageWriteRemote
#define STORAGE_WRITE_REMOTE_PREFIX storageWriteRemote
typedef struct StorageWriteRemote
{
MemContext *memContext; // Object mem context
@ -43,13 +40,23 @@ Macros for function logging
/***********************************************************************************************************************************
Close file on the remote
***********************************************************************************************************************************/
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(STORAGE_WRITE_REMOTE, LOG, logLevelTrace)
static void
storageWriteRemoteFreeResource(THIS_VOID)
{
THIS(StorageWriteRemote);
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(STORAGE_WRITE_REMOTE, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
ioWriteLine(protocolClientIoWrite(this->client), BUFSTRDEF(PROTOCOL_BLOCK_HEADER "-1"));
ioWriteFlush(protocolClientIoWrite(this->client));
protocolClientReadOutput(this->client, false);
FUNCTION_LOG_RETURN_VOID();
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/***********************************************************************************************************************************
Open the file

View File

@ -32,19 +32,6 @@ void testObjectFree(TestObject *this);
OBJECT_DEFINE_MOVE(TEST_OBJECT);
OBJECT_DEFINE_FREE(TEST_OBJECT);
/***********************************************************************************************************************************
Free object resource
***********************************************************************************************************************************/
bool testObjectFreeResourceCalled = false;
static void testObjectFreeResource(void *thisVoid);
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(TEST_OBJECT, LOG, logLevelTrace)
{
testObjectFreeResourceCalled = true;
}
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
/**********************************************************************************************************************************/
TestObject *
testObjectNew(void)
@ -61,8 +48,6 @@ testObjectNew(void)
{
.memContext = MEM_CONTEXT_NEW(),
};
memContextCallbackSet(this->memContext, testObjectFreeResource, (void *)1);
}
MEM_CONTEXT_NEW_END();
@ -91,7 +76,6 @@ testRun(void)
MEM_CONTEXT_TEMP_END();
TEST_RESULT_VOID(testObjectFree(testObject), " free object");
TEST_RESULT_BOOL(testObjectFreeResourceCalled, true, " check callback");
}
FUNCTION_HARNESS_RETURN_VOID();