mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-01-30 05:39:12 +02:00
Replace OBJECT_DEFINE_MOVE() and OBJECT_DEFINE_FREE() with inlines.
Inline functions are more efficient and if they are not used are automatically omitted from the binary. This also makes the implementation of these functions easier to find and removes the need for a declaration. That is, the complete implementation is located in the header rather than being spread between the header and C file.
This commit is contained in:
parent
351e7db4c4
commit
d30ec9c9ae
@ -108,6 +108,7 @@ SRCS = \
|
||||
common/type/keyValue.c \
|
||||
common/type/list.c \
|
||||
common/type/mcv.c \
|
||||
common/type/object.c \
|
||||
common/type/pack.c \
|
||||
common/type/string.c \
|
||||
common/type/stringList.c \
|
||||
|
@ -7,6 +7,7 @@ Page Checksum Filter
|
||||
#include "common/io/filter/filter.intern.h"
|
||||
#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"
|
||||
|
@ -11,6 +11,7 @@ BZ2 Compress
|
||||
#include "common/debug.h"
|
||||
#include "common/io/filter/filter.intern.h"
|
||||
#include "common/log.h"
|
||||
#include "common/macro.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
|
@ -11,6 +11,7 @@ BZ2 Decompress
|
||||
#include "common/debug.h"
|
||||
#include "common/io/filter/filter.intern.h"
|
||||
#include "common/log.h"
|
||||
#include "common/macro.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
|
@ -11,6 +11,7 @@ Gz Compress
|
||||
#include "common/debug.h"
|
||||
#include "common/io/filter/filter.intern.h"
|
||||
#include "common/log.h"
|
||||
#include "common/macro.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
|
@ -11,6 +11,7 @@ Gz Decompress
|
||||
#include "common/debug.h"
|
||||
#include "common/io/filter/filter.intern.h"
|
||||
#include "common/log.h"
|
||||
#include "common/macro.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
|
@ -19,7 +19,6 @@ Execute Process
|
||||
#include "common/io/io.h"
|
||||
#include "common/io/read.intern.h"
|
||||
#include "common/io/write.intern.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/wait.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -46,8 +45,6 @@ struct Exec
|
||||
IoWrite *ioWriteExec; // Wrapper for file descriptor write interface
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_FREE(EXEC);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macro to close file descriptors after dup2() in the child process
|
||||
|
||||
|
@ -12,14 +12,12 @@ execution.
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define EXEC_TYPE Exec
|
||||
#define EXEC_PREFIX exec
|
||||
|
||||
typedef struct Exec Exec;
|
||||
|
||||
#include "common/io/read.h"
|
||||
#include "common/io/write.h"
|
||||
#include "common/time.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Constructors
|
||||
@ -47,7 +45,11 @@ MemContext *execMemContext(const Exec *this);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void execFree(Exec *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
execFree(Exec *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -13,7 +13,6 @@ Ini Handler
|
||||
#include "common/ini.h"
|
||||
#include "common/type/json.h"
|
||||
#include "common/type/keyValue.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
@ -24,9 +23,6 @@ struct Ini
|
||||
KeyValue *store; // Key value store that contains the ini data
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(INI);
|
||||
OBJECT_DEFINE_FREE(INI);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
Ini *
|
||||
iniNew(void)
|
||||
|
@ -7,13 +7,11 @@ Ini Handler
|
||||
/***********************************************************************************************************************************
|
||||
Ini object
|
||||
***********************************************************************************************************************************/
|
||||
#define INI_TYPE Ini
|
||||
#define INI_PREFIX ini
|
||||
|
||||
typedef struct Ini Ini;
|
||||
|
||||
#include "common/io/read.h"
|
||||
#include "common/io/write.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/variant.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -25,7 +23,11 @@ Ini *iniNew(void);
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
// Move to a new parent mem context
|
||||
Ini *iniMove(Ini *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline Ini *
|
||||
iniMove(Ini *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
// Parse ini from a string. Comments are ignored and additional whitespace around sections, keys, and values is trimmed. Should be
|
||||
// used *only* to read user-generated config files, for code-generated info files see iniLoad().
|
||||
@ -58,7 +60,11 @@ StringList *iniSectionList(const Ini *this);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void iniFree(Ini *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
iniFree(Ini *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Helper Functions
|
||||
|
@ -7,7 +7,6 @@ Io Client Interface
|
||||
#include "common/io/client.intern.h"
|
||||
#include "common/log.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
@ -19,9 +18,6 @@ struct IoClient
|
||||
const IoClientInterface *interface; // Driver interface
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(IO_CLIENT);
|
||||
OBJECT_DEFINE_FREE(IO_CLIENT);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
IoClient *
|
||||
ioClientNew(void *driver, const IoClientInterface *interface)
|
||||
|
@ -10,18 +10,20 @@ opened with ioClientOpen().
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define IO_CLIENT_TYPE IoClient
|
||||
#define IO_CLIENT_PREFIX ioClient
|
||||
|
||||
typedef struct IoClient IoClient;
|
||||
|
||||
#include "common/io/session.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
// Move to a new parent mem context
|
||||
IoClient *ioClientMove(IoClient *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline IoClient *
|
||||
ioClientMove(IoClient *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
// Open session
|
||||
IoSession *ioClientOpen(IoClient *this);
|
||||
@ -35,7 +37,11 @@ const String *ioClientName(IoClient *this);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void ioClientFree(IoClient *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
ioClientFree(IoClient *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -7,7 +7,6 @@ IO Filter Interface
|
||||
#include "common/io/filter/filter.intern.h"
|
||||
#include "common/log.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
@ -23,9 +22,6 @@ struct IoFilter
|
||||
bool flushing; // Has the filter started flushing?
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(IO_FILTER);
|
||||
OBJECT_DEFINE_FREE(IO_FILTER);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Allocations will be in the memory context of the caller.
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -14,11 +14,9 @@ Information on implementing a filter is in filter.internal.h.
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define IO_FILTER_TYPE IoFilter
|
||||
#define IO_FILTER_PREFIX ioFilter
|
||||
|
||||
typedef struct IoFilter IoFilter;
|
||||
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/string.h"
|
||||
#include "common/type/variant.h"
|
||||
|
||||
@ -34,7 +32,11 @@ const String *ioFilterType(const IoFilter *this);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void ioFilterFree(IoFilter *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
ioFilterFree(IoFilter *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -64,7 +64,11 @@ void ioFilterProcessIn(IoFilter *this, const Buffer *input);
|
||||
void ioFilterProcessInOut(IoFilter *this, const Buffer *input, Buffer *output);
|
||||
|
||||
// Move filter to a new parent mem context
|
||||
IoFilter *ioFilterMove(IoFilter *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline IoFilter *
|
||||
ioFilterMove(IoFilter *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Getters/Setters
|
||||
|
@ -13,7 +13,6 @@ IO Filter Group
|
||||
#include "common/log.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/list.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Filter and buffer structure
|
||||
@ -53,8 +52,6 @@ struct IoFilterGroup
|
||||
#endif
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_FREE(IO_FILTER_GROUP);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
IoFilterGroup *
|
||||
ioFilterGroupNew(void)
|
||||
|
@ -13,12 +13,10 @@ only call ioFilterGroupNew(), ioFilterGroupAdd(), and ioFilterGroupResult().
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define IO_FILTER_GROUP_TYPE IoFilterGroup
|
||||
#define IO_FILTER_GROUP_PREFIX ioFilterGroup
|
||||
|
||||
typedef struct IoFilterGroup IoFilterGroup;
|
||||
|
||||
#include "common/io/filter/filter.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/string.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -75,7 +73,11 @@ unsigned int ioFilterGroupSize(const IoFilterGroup *this);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void ioFilterGroupFree(IoFilterGroup *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
ioFilterGroupFree(IoFilterGroup *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -7,7 +7,6 @@ HTTP Header
|
||||
#include "common/io/http/header.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/keyValue.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
@ -19,9 +18,6 @@ struct HttpHeader
|
||||
KeyValue *kv; // KeyValue store
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(HTTP_HEADER);
|
||||
OBJECT_DEFINE_FREE(HTTP_HEADER);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
HttpHeader *
|
||||
httpHeaderNew(const StringList *redactList)
|
||||
|
@ -9,11 +9,9 @@ Object to track HTTP headers. Headers can be marked as redacted so they are not
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define HTTP_HEADER_TYPE HttpHeader
|
||||
#define HTTP_HEADER_PREFIX httpHeader
|
||||
|
||||
typedef struct HttpHeader HttpHeader;
|
||||
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/stringList.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -35,7 +33,11 @@ const String *httpHeaderGet(const HttpHeader *this, const String *key);
|
||||
StringList *httpHeaderList(const HttpHeader *this);
|
||||
|
||||
// Move to a new parent mem context
|
||||
HttpHeader *httpHeaderMove(HttpHeader *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline HttpHeader *
|
||||
httpHeaderMove(HttpHeader *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
// Put a header
|
||||
HttpHeader *httpHeaderPut(HttpHeader *this, const String *header, const String *value);
|
||||
@ -46,7 +48,11 @@ bool httpHeaderRedact(const HttpHeader *this, const String *key);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void httpHeaderFree(HttpHeader *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
httpHeaderFree(HttpHeader *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -8,7 +8,6 @@ HTTP Query
|
||||
#include "common/io/http/query.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/keyValue.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
@ -20,9 +19,6 @@ struct HttpQuery
|
||||
const StringList *redactList; // List of keys to redact values for
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(HTTP_QUERY);
|
||||
OBJECT_DEFINE_FREE(HTTP_QUERY);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
HttpQuery *
|
||||
httpQueryNew(HttpQueryNewParam param)
|
||||
|
@ -9,11 +9,9 @@ Object to track HTTP queries and output them with proper escaping.
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define HTTP_QUERY_TYPE HttpQuery
|
||||
#define HTTP_QUERY_PREFIX httpQuery
|
||||
|
||||
typedef struct HttpQuery HttpQuery;
|
||||
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/stringList.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -61,7 +59,11 @@ StringList *httpQueryList(const HttpQuery *this);
|
||||
HttpQuery *httpQueryMerge(HttpQuery *this, const HttpQuery *query);
|
||||
|
||||
// Move to a new parent mem context
|
||||
HttpQuery *httpQueryMove(HttpQuery *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline HttpQuery *
|
||||
httpQueryMove(HttpQuery *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
// Put a query item
|
||||
HttpQuery *httpQueryPut(HttpQuery *this, const String *header, const String *value);
|
||||
@ -84,7 +86,11 @@ String *httpQueryRender(const HttpQuery *this, HttpQueryRenderParam param);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void httpQueryFree(HttpQuery *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
httpQueryFree(HttpQuery *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -8,7 +8,6 @@ HTTP Request
|
||||
#include "common/io/http/request.h"
|
||||
#include "common/log.h"
|
||||
#include "common/stat.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/wait.h"
|
||||
#include "version.h"
|
||||
|
||||
@ -45,16 +44,12 @@ Object type
|
||||
struct HttpRequest
|
||||
{
|
||||
HttpRequestPub pub; // Publicly accessible variables
|
||||
MemContext *memContext; // Mem context
|
||||
HttpClient *client; // HTTP client
|
||||
const Buffer *content; // HTTP content
|
||||
|
||||
HttpSession *session; // Session for async requests
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(HTTP_REQUEST);
|
||||
OBJECT_DEFINE_FREE(HTTP_REQUEST);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Process the request
|
||||
***********************************************************************************************************************************/
|
||||
@ -131,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->memContext);
|
||||
this->session = httpSessionMove(session, this->pub.memContext);
|
||||
}
|
||||
|
||||
// Wait for response
|
||||
@ -202,12 +197,12 @@ httpRequestNew(HttpClient *client, const String *verb, const String *path, HttpR
|
||||
{
|
||||
.pub =
|
||||
{
|
||||
.memContext = MEM_CONTEXT_NEW(),
|
||||
.verb = strDup(verb),
|
||||
.path = strDup(path),
|
||||
.query = httpQueryDupP(param.query),
|
||||
.header = param.header == NULL ? httpHeaderNew(NULL) : httpHeaderDup(param.header, NULL),
|
||||
},
|
||||
.memContext = MEM_CONTEXT_NEW(),
|
||||
.client = client,
|
||||
.content = param.content == NULL ? NULL : bufDup(param.content),
|
||||
};
|
||||
|
@ -11,14 +11,12 @@ behavior.
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define HTTP_REQUEST_TYPE HttpRequest
|
||||
#define HTTP_REQUEST_PREFIX httpRequest
|
||||
|
||||
typedef struct HttpRequest HttpRequest;
|
||||
|
||||
#include "common/io/http/header.h"
|
||||
#include "common/io/http/query.h"
|
||||
#include "common/io/http/response.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
HTTP Constants
|
||||
@ -82,6 +80,7 @@ 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
|
||||
@ -130,12 +129,20 @@ HttpResponse *httpRequestResponse(HttpRequest *this, bool contentCache);
|
||||
void httpRequestError(const HttpRequest *this, HttpResponse *response) __attribute__((__noreturn__));
|
||||
|
||||
// Move to a new parent mem context
|
||||
HttpRequest *httpRequestMove(HttpRequest *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline HttpRequest *
|
||||
httpRequestMove(HttpRequest *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void httpRequestFree(HttpRequest *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
httpRequestFree(HttpRequest *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -12,7 +12,6 @@ HTTP Response
|
||||
#include "common/io/read.intern.h"
|
||||
#include "common/log.h"
|
||||
#include "common/stat.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/wait.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -34,10 +33,7 @@ Object type
|
||||
struct HttpResponse
|
||||
{
|
||||
HttpResponsePub pub; // Publicly accessible variables
|
||||
MemContext *memContext; // Mem context
|
||||
|
||||
HttpSession *session; // HTTP session
|
||||
|
||||
bool contentChunked; // Is the response content chunked?
|
||||
uint64_t contentSize; // Content size (ignored for chunked)
|
||||
uint64_t contentRemaining; // Content remaining (per chunk if chunked)
|
||||
@ -47,9 +43,6 @@ struct HttpResponse
|
||||
Buffer *content; // Caches content once requested
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(HTTP_RESPONSE);
|
||||
OBJECT_DEFINE_FREE(HTTP_RESPONSE);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
When response is done close/reuse the connection
|
||||
***********************************************************************************************************************************/
|
||||
@ -217,9 +210,9 @@ httpResponseNew(HttpSession *session, const String *verb, bool contentCache)
|
||||
{
|
||||
.pub =
|
||||
{
|
||||
.memContext = MEM_CONTEXT_NEW(),
|
||||
.header = httpHeaderNew(NULL),
|
||||
},
|
||||
.memContext = MEM_CONTEXT_NEW(),
|
||||
.session = httpSessionMove(session, memContextCurrent()),
|
||||
};
|
||||
|
||||
@ -258,7 +251,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->memContext)
|
||||
MEM_CONTEXT_BEGIN(this->pub.memContext)
|
||||
{
|
||||
this->pub.reason = strSub(status, (size_t)spacePos + 1);
|
||||
}
|
||||
@ -328,7 +321,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->memContext)
|
||||
MEM_CONTEXT_BEGIN(this->pub.memContext)
|
||||
{
|
||||
this->pub.contentRead = ioReadNewP(this, .eof = httpResponseEof, .read = httpResponseRead);
|
||||
ioReadOpen(httpResponseIoRead(this));
|
||||
@ -343,7 +336,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->memContext)
|
||||
MEM_CONTEXT_BEGIN(this->pub.memContext)
|
||||
{
|
||||
httpResponseContent(this);
|
||||
}
|
||||
|
@ -10,14 +10,12 @@ cached content, etc. will still be available for the lifetime of the object.
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define HTTP_RESPONSE_TYPE HttpResponse
|
||||
#define HTTP_RESPONSE_PREFIX httpResponse
|
||||
|
||||
typedef struct HttpResponse HttpResponse;
|
||||
|
||||
#include "common/io/http/header.h"
|
||||
#include "common/io/http/session.h"
|
||||
#include "common/io/read.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
HTTP Response Constants
|
||||
@ -36,6 +34,7 @@ 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
|
||||
@ -89,12 +88,20 @@ httpResponseCodeOk(const HttpResponse *this)
|
||||
const Buffer *httpResponseContent(HttpResponse *this);
|
||||
|
||||
// Move to a new parent mem context
|
||||
HttpResponse *httpResponseMove(HttpResponse *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline HttpResponse *
|
||||
httpResponseMove(HttpResponse *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void httpResponseFree(HttpResponse *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
httpResponseFree(HttpResponse *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -8,7 +8,6 @@ HTTP Session
|
||||
#include "common/io/io.h"
|
||||
#include "common/log.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
@ -20,9 +19,6 @@ struct HttpSession
|
||||
IoSession *ioSession; // IO session
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(HTTP_SESSION);
|
||||
OBJECT_DEFINE_FREE(HTTP_SESSION);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
HttpSession *
|
||||
httpSessionNew(HttpClient *httpClient, IoSession *ioSession)
|
||||
|
@ -9,15 +9,13 @@ HTTP sessions are created by calling httpClientOpen(), which is currently done e
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define HTTP_SESSION_TYPE HttpSession
|
||||
#define HTTP_SESSION_PREFIX httpSession
|
||||
|
||||
typedef struct HttpSession HttpSession;
|
||||
|
||||
#include "common/io/read.h"
|
||||
#include "common/io/http/client.h"
|
||||
#include "common/io/session.h"
|
||||
#include "common/io/write.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Constructors
|
||||
@ -28,7 +26,11 @@ HttpSession *httpSessionNew(HttpClient *client, IoSession *session);
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
// Move to a new parent mem context
|
||||
HttpSession *httpSessionMove(HttpSession *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline HttpSession *
|
||||
httpSessionMove(HttpSession *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
// Work with the session has finished cleanly and it can be reused
|
||||
void httpSessionDone(HttpSession *this);
|
||||
@ -45,7 +47,11 @@ IoWrite *httpSessionIoWrite(HttpSession *this);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void httpSessionFree(HttpSession *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
httpSessionFree(HttpSession *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -6,7 +6,6 @@ HTTP URL
|
||||
#include "common/debug.h"
|
||||
#include "common/io/http/url.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/stringList.h"
|
||||
#include "common/regExp.h"
|
||||
|
||||
@ -27,11 +26,8 @@ Object type
|
||||
struct HttpUrl
|
||||
{
|
||||
HttpUrlPub pub;
|
||||
MemContext *memContext; // Mem context
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_FREE(HTTP_URL);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Convert protocol type to a string
|
||||
***********************************************************************************************************************************/
|
||||
@ -74,9 +70,9 @@ httpUrlNewParse(const String *const url, HttpUrlNewParseParam param)
|
||||
|
||||
*this = (HttpUrl)
|
||||
{
|
||||
.memContext = MEM_CONTEXT_NEW(),
|
||||
.pub =
|
||||
{
|
||||
.memContext = MEM_CONTEXT_NEW(),
|
||||
.url = strDup(url),
|
||||
},
|
||||
};
|
||||
|
@ -9,12 +9,10 @@ Parse a URL into component parts.
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define HTTP_URL_TYPE HttpUrl
|
||||
#define HTTP_URL_PREFIX httpUrl
|
||||
|
||||
typedef struct HttpUrl HttpUrl;
|
||||
|
||||
#include "common/type/param.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/string.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -46,6 +44,7 @@ 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
|
||||
@ -96,7 +95,11 @@ httpUrl(const HttpUrl *this)
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void httpUrlFree(HttpUrl *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
httpUrlFree(HttpUrl *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -10,7 +10,6 @@ IO Read Interface
|
||||
#include "common/io/read.intern.h"
|
||||
#include "common/log.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
@ -33,8 +32,6 @@ struct IoRead
|
||||
#endif
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_FREE(IO_READ);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
IoRead *
|
||||
ioReadNew(void *driver, IoReadInterface interface)
|
||||
|
@ -12,13 +12,11 @@ example of an IoRead object is IoBufferRead.
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define IO_READ_TYPE IoRead
|
||||
#define IO_READ_PREFIX ioRead
|
||||
|
||||
typedef struct IoRead IoRead;
|
||||
|
||||
#include "common/io/filter/group.h"
|
||||
#include "common/type/buffer.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Functions
|
||||
@ -72,7 +70,11 @@ int ioReadFd(const IoRead *this);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void ioReadFree(IoRead *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
ioReadFree(IoRead *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -7,7 +7,6 @@ Io Session Interface
|
||||
#include "common/io/session.intern.h"
|
||||
#include "common/log.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
@ -19,9 +18,6 @@ struct IoSession
|
||||
const IoSessionInterface *interface; // Driver interface
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(IO_SESSION);
|
||||
OBJECT_DEFINE_FREE(IO_SESSION);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
IoSession *
|
||||
ioSessionNew(void *driver, const IoSessionInterface *interface)
|
||||
|
@ -10,13 +10,11 @@ be closed when work with them is done but they also contain destructors to do cl
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define IO_SESSION_TYPE IoSession
|
||||
#define IO_SESSION_PREFIX ioSession
|
||||
|
||||
typedef struct IoSession IoSession;
|
||||
|
||||
#include "common/io/read.h"
|
||||
#include "common/io/write.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Session roles
|
||||
@ -34,7 +32,11 @@ Functions
|
||||
void ioSessionClose(IoSession *this);
|
||||
|
||||
// Move to a new parent mem context
|
||||
IoSession *ioSessionMove(IoSession *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline IoSession *
|
||||
ioSessionMove(IoSession *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Getters/Setters
|
||||
@ -54,7 +56,11 @@ IoSessionRole ioSessionRole(const IoSession *this);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void ioSessionFree(IoSession *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
ioSessionFree(IoSession *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -34,9 +34,6 @@ STRING_EXTERN(SOCKET_STAT_SESSION_STR, SOCKET_STAT_
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define SOCKET_CLIENT_TYPE SocketClient
|
||||
#define SOCKET_CLIENT_PREFIX sckClient
|
||||
|
||||
typedef struct SocketClient
|
||||
{
|
||||
MemContext *memContext; // Mem context
|
||||
|
@ -10,7 +10,6 @@ IO Write Interface
|
||||
#include "common/io/write.intern.h"
|
||||
#include "common/log.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
@ -30,8 +29,6 @@ struct IoWrite
|
||||
#endif
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_FREE(IO_WRITE);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
IoWrite *
|
||||
ioWriteNew(void *driver, IoWriteInterface interface)
|
||||
|
@ -11,13 +11,11 @@ allocate/open or deallocate/free resources. An example of an IoWrite object is
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define IO_WRITE_TYPE IoWrite
|
||||
#define IO_WRITE_PREFIX ioWrite
|
||||
|
||||
typedef struct IoWrite IoWrite;
|
||||
|
||||
#include "common/io/filter/group.h"
|
||||
#include "common/type/buffer.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Functions
|
||||
@ -67,7 +65,11 @@ int ioWriteFd(const IoWrite *this);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void ioWriteFree(IoWrite *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
ioWriteFree(IoWrite *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -8,7 +8,6 @@ Regular Expression Handler
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/regExp.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -22,8 +21,6 @@ struct RegExp
|
||||
size_t matchSize;
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_FREE(REGEXP);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Free regular expression
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -7,11 +7,9 @@ Regular Expression Handler
|
||||
/***********************************************************************************************************************************
|
||||
RegExp object
|
||||
***********************************************************************************************************************************/
|
||||
#define REGEXP_TYPE RegExp
|
||||
#define REGEXP_PREFIX regExp
|
||||
|
||||
typedef struct RegExp RegExp;
|
||||
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/string.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -51,7 +49,11 @@ String *regExpPrefix(const String *expression);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void regExpFree(RegExp *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
regExpFree(RegExp *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -8,7 +8,6 @@ Buffer Handler
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "common/type/buffer.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Constant buffers that are generally useful
|
||||
@ -31,12 +30,8 @@ struct Buffer
|
||||
{
|
||||
BUFFER_COMMON // Variables that are common to static and dynamic buffers
|
||||
unsigned char *buffer; // Internal buffer
|
||||
MemContext *memContext; // Mem context for dynamic buffers
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(BUFFER);
|
||||
OBJECT_DEFINE_FREE(BUFFER);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
Buffer *
|
||||
bufNew(size_t size)
|
||||
|
@ -7,12 +7,10 @@ Buffer Handler
|
||||
/***********************************************************************************************************************************
|
||||
Buffer object
|
||||
***********************************************************************************************************************************/
|
||||
#define BUFFER_TYPE Buffer
|
||||
#define BUFFER_PREFIX buf
|
||||
|
||||
typedef struct Buffer Buffer;
|
||||
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/string.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -22,6 +20,7 @@ There is nothing user-accessible here but this construct allows constant buffers
|
||||
functions that process dynamically allocated buffers.
|
||||
***********************************************************************************************************************************/
|
||||
#define BUFFER_COMMON \
|
||||
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? */ \
|
||||
@ -68,7 +67,11 @@ bool bufEq(const Buffer *this, const Buffer *compare);
|
||||
String *bufHex(const Buffer *this);
|
||||
|
||||
// Move to a new parent mem context
|
||||
Buffer *bufMove(Buffer *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline Buffer *
|
||||
bufMove(Buffer *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
// Resize the buffer
|
||||
Buffer *bufResize(Buffer *this, size_t size);
|
||||
@ -156,7 +159,11 @@ bufRemainsPtr(Buffer *this)
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void bufFree(Buffer *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
bufFree(Buffer *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for constant buffers
|
||||
|
@ -9,7 +9,6 @@ Key Value Handler
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/keyValue.h"
|
||||
#include "common/type/list.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/variantList.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -27,9 +26,6 @@ struct KeyValue
|
||||
VariantList *keyList; // List of keys
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(KEY_VALUE);
|
||||
OBJECT_DEFINE_FREE(KEY_VALUE);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Contains information about an individual key/value pair
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -7,11 +7,9 @@ Key Value Handler
|
||||
/***********************************************************************************************************************************
|
||||
KeyValue object
|
||||
***********************************************************************************************************************************/
|
||||
#define KEY_VALUE_TYPE KeyValue
|
||||
#define KEY_VALUE_PREFIX kv
|
||||
|
||||
typedef struct KeyValue KeyValue;
|
||||
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/variantList.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -29,7 +27,12 @@ KeyValue *kvAdd(KeyValue *this, const Variant *key, const Variant *value);
|
||||
// List of keys
|
||||
const VariantList *kvKeyList(const KeyValue *this);
|
||||
|
||||
KeyValue *kvMove(KeyValue *this, MemContext *parentNew);
|
||||
// Move to a new parent mem context
|
||||
__attribute__((always_inline)) static inline KeyValue *
|
||||
kvMove(KeyValue *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
// Put key/value pair
|
||||
KeyValue *kvPut(KeyValue *this, const Variant *key, const Variant *value);
|
||||
@ -53,7 +56,11 @@ VariantList *kvGetList(const KeyValue *this, const Variant *key);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void kvFree(KeyValue *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
kvFree(KeyValue *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -10,7 +10,6 @@ List Handler
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "common/type/list.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
@ -18,7 +17,6 @@ Object type
|
||||
struct List
|
||||
{
|
||||
ListPub pub; // Publicly accessible variables
|
||||
MemContext *memContext;
|
||||
size_t itemSize;
|
||||
unsigned int listSizeMax;
|
||||
SortOrder sortOrder;
|
||||
@ -27,9 +25,6 @@ struct List
|
||||
ListComparator *comparator;
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(LIST);
|
||||
OBJECT_DEFINE_FREE(LIST);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
List *
|
||||
lstNew(size_t itemSize, ListParam param)
|
||||
@ -47,8 +42,11 @@ lstNew(size_t itemSize, ListParam param)
|
||||
this = memNew(sizeof(List));
|
||||
|
||||
*this = (List)
|
||||
{
|
||||
.pub =
|
||||
{
|
||||
.memContext = MEM_CONTEXT_NEW(),
|
||||
},
|
||||
.itemSize = itemSize,
|
||||
.sortOrder = param.sortOrder,
|
||||
.comparator = param.comparator,
|
||||
@ -71,7 +69,7 @@ lstClear(List *this)
|
||||
|
||||
if (this->list != NULL)
|
||||
{
|
||||
MEM_CONTEXT_BEGIN(this->memContext)
|
||||
MEM_CONTEXT_BEGIN(lstMemContext(this))
|
||||
{
|
||||
memFree(this->list);
|
||||
}
|
||||
@ -251,7 +249,7 @@ lstInsert(List *this, unsigned int listIdx, const void *item)
|
||||
// If list size = max then allocate more space
|
||||
if (lstSize(this) == this->listSizeMax)
|
||||
{
|
||||
MEM_CONTEXT_BEGIN(this->memContext)
|
||||
MEM_CONTEXT_BEGIN(lstMemContext(this))
|
||||
{
|
||||
// If nothing has been allocated yet
|
||||
if (this->listSizeMax == 0)
|
||||
@ -362,19 +360,6 @@ lstRemoveLast(List *this)
|
||||
FUNCTION_TEST_RETURN(lstRemoveIdx(this, lstSize(this) - 1));
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
MemContext *
|
||||
lstMemContext(const List *this)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(LIST, this);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(this != NULL);
|
||||
|
||||
FUNCTION_TEST_RETURN(this->memContext);
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
List *
|
||||
lstSort(List *this, SortOrder sortOrder)
|
||||
|
@ -9,12 +9,10 @@ List Handler
|
||||
/***********************************************************************************************************************************
|
||||
List object
|
||||
***********************************************************************************************************************************/
|
||||
#define LIST_TYPE List
|
||||
#define LIST_PREFIX lst
|
||||
|
||||
typedef struct List List;
|
||||
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/param.h"
|
||||
#include "common/type/string.h"
|
||||
|
||||
@ -68,12 +66,21 @@ Getters/Setters
|
||||
***********************************************************************************************************************************/
|
||||
typedef struct ListPub
|
||||
{
|
||||
MemContext *memContext; // Mem context
|
||||
unsigned int listSize; // List size
|
||||
} ListPub;
|
||||
|
||||
// Set a new comparator
|
||||
List *lstComparatorSet(List *this, ListComparator *comparator);
|
||||
|
||||
// Memory context for this list
|
||||
__attribute__((always_inline)) static inline MemContext *
|
||||
lstMemContext(const List *this)
|
||||
{
|
||||
ASSERT_INLINE(this != NULL);
|
||||
return ((const ListPub *)this)->memContext;
|
||||
}
|
||||
|
||||
// List size
|
||||
__attribute__((always_inline)) static inline unsigned int
|
||||
lstSize(const List *this)
|
||||
@ -124,11 +131,12 @@ lstAdd(List *this, const void *item)
|
||||
return lstInsert(this, lstSize(this), item);
|
||||
}
|
||||
|
||||
// Memory context for this list
|
||||
MemContext *lstMemContext(const List *this);
|
||||
|
||||
// Move to a new parent mem context
|
||||
List *lstMove(List *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline List *
|
||||
lstMove(List *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
// Remove an item from the list
|
||||
bool lstRemove(List *this, const void *item);
|
||||
@ -141,7 +149,11 @@ List *lstSort(List *this, SortOrder sortOrder);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void lstFree(List *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
lstFree(List *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -6,7 +6,6 @@ Calculate Most Common Value
|
||||
#include "common/debug.h"
|
||||
#include "common/type/list.h"
|
||||
#include "common/type/mcv.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/variant.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -24,8 +23,6 @@ typedef struct MostCommonValueEntry
|
||||
uint64_t total; // Total count for the value
|
||||
} MostCommonValueEntry;
|
||||
|
||||
OBJECT_DEFINE_FREE(MOST_COMMON_VALUE);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
MostCommonValue *
|
||||
mcvNew(void)
|
||||
|
@ -12,11 +12,9 @@ since it is not stored.
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define MOST_COMMON_VALUE_TYPE MostCommonValue
|
||||
#define MOST_COMMON_VALUE_PREFIX mcv
|
||||
|
||||
typedef struct MostCommonValue MostCommonValue;
|
||||
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/stringList.h"
|
||||
#include "common/type/variant.h"
|
||||
|
||||
@ -37,7 +35,11 @@ const Variant *mcvResult(const MostCommonValue *this);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void mcvFree(MostCommonValue *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
mcvFree(MostCommonValue *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
24
src/common/type/object.c
Normal file
24
src/common/type/object.c
Normal file
@ -0,0 +1,24 @@
|
||||
/***********************************************************************************************************************************
|
||||
Object Helper Macros and Functions
|
||||
***********************************************************************************************************************************/
|
||||
#include "build.auto.h"
|
||||
|
||||
#include "common/type/object.h"
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void *
|
||||
objMove(THIS_VOID, MemContext *parentNew)
|
||||
{
|
||||
if (thisVoid != NULL)
|
||||
memContextMove(*(MemContext **)thisVoid, parentNew);
|
||||
|
||||
return thisVoid;
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
objFree(THIS_VOID)
|
||||
{
|
||||
if (thisVoid != NULL)
|
||||
memContextFree(*(MemContext **)thisVoid);
|
||||
}
|
@ -1,31 +1,19 @@
|
||||
/***********************************************************************************************************************************
|
||||
Object Helper Macros
|
||||
Object Helper Macros and Functions
|
||||
|
||||
Macros to automate definitions of various boilerplate functions and log macros.
|
||||
|
||||
Each object should have at least two macros defined it its header file, <OBJECT_NAME>_TYPE and <OBJECT_NAME>_PREFIX. So if the
|
||||
object type is "Object" the macros would be:
|
||||
|
||||
#define OBJECT_TYPE Object
|
||||
#define OBJECT_PREFIX object
|
||||
|
||||
In most cases _PREFIX will be identical to _TYPE except that the first letter is lower-cased. For commonly used objects (e.g.
|
||||
String) a shorter prefix may be used.
|
||||
|
||||
When a macro exists to create a function definition in a C file there is no equivalent macro to create the prototype in the header.
|
||||
The prototype is not repetitious enough to justify a macro and it would only serve to obfuscate the header file.
|
||||
These macros and functions implement common object functionality.
|
||||
***********************************************************************************************************************************/
|
||||
#ifndef COMMON_TYPE_OBJECT_H
|
||||
#define COMMON_TYPE_OBJECT_H
|
||||
|
||||
#include "common/macro.h"
|
||||
#include "common/memContext.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Used in interface function parameter lists to discourage use of the untyped thisVoid parameter, e.g.:
|
||||
|
||||
size_t bufferRead(THIS_VOID, Buffer *buffer)
|
||||
|
||||
This macro should not be used unless the function is assigned to an interface.
|
||||
This macro should not be used unless the function is assigned to an interface or passed as a parameter.
|
||||
***********************************************************************************************************************************/
|
||||
#define THIS_VOID void *thisVoid
|
||||
|
||||
@ -35,53 +23,20 @@ Create a local "this" variable of the correct type from a THIS_VOID parameter
|
||||
#define THIS(type) type *this = thisVoid
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Define a function used by the caller to move an object from one context to another
|
||||
Functions
|
||||
|
||||
The object type is expected to have a memmber named "memContext" and the object must allocate *all* memory in that context.
|
||||
To ensure proper type checking, these functions are meant to be called from inline functions created specifically for each object:
|
||||
|
||||
If "this" is NULL then no action is taken.
|
||||
__attribute__((always_inline)) static inline void
|
||||
storageFree(Storage *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
***********************************************************************************************************************************/
|
||||
#define OBJECT_DEFINE_MOVE(objectMacro) \
|
||||
objectMacro##_TYPE * \
|
||||
GLUE(objectMacro##_PREFIX, Move)(objectMacro##_TYPE *this, MemContext *parentNew) \
|
||||
{ \
|
||||
FUNCTION_TEST_BEGIN(); \
|
||||
FUNCTION_TEST_PARAM(objectMacro, this); \
|
||||
FUNCTION_TEST_PARAM(MEM_CONTEXT, parentNew); \
|
||||
FUNCTION_TEST_END(); \
|
||||
\
|
||||
ASSERT(parentNew != NULL); \
|
||||
\
|
||||
if (this != NULL) \
|
||||
memContextMove(this->memContext, parentNew); \
|
||||
\
|
||||
FUNCTION_TEST_RETURN(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.
|
||||
void *objMove(THIS_VOID, MemContext *parentNew);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
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
|
||||
cleanup is much more efficient.
|
||||
|
||||
If the object type/prefix is "Object"/"object" then the function will be defined as:
|
||||
|
||||
static void objectFree(Object *this)
|
||||
|
||||
Note that this function is externed as there no need for a static free function since the context will be cleaned up automatically
|
||||
by the parent context.
|
||||
***********************************************************************************************************************************/
|
||||
#define OBJECT_DEFINE_FREE(objectMacro) \
|
||||
void \
|
||||
GLUE(objectMacro##_PREFIX, Free)(objectMacro##_TYPE *this) \
|
||||
{ \
|
||||
FUNCTION_TEST_BEGIN(); \
|
||||
FUNCTION_TEST_PARAM(objectMacro, this); \
|
||||
FUNCTION_TEST_END(); \
|
||||
\
|
||||
if (this != NULL) \
|
||||
memContextFree(this->memContext); \
|
||||
\
|
||||
FUNCTION_TEST_RETURN_VOID(); \
|
||||
}
|
||||
// Free the object mem context if this != NULL. The mem context to be freed must be the first member of the object struct.
|
||||
void objFree(THIS_VOID);
|
||||
|
||||
#endif
|
||||
|
@ -101,7 +101,6 @@ Array and object types:
|
||||
#include "common/io/read.h"
|
||||
#include "common/io/write.h"
|
||||
#include "common/type/convert.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/pack.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -211,8 +210,6 @@ struct PackRead
|
||||
PackTagStack *tagStackTop; // Top tag on the stack
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_FREE(PACK_READ);
|
||||
|
||||
struct PackWrite
|
||||
{
|
||||
MemContext *memContext; // Mem context
|
||||
@ -223,8 +220,6 @@ struct PackWrite
|
||||
PackTagStack *tagStackTop; // Top tag on the stack
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_FREE(PACK_WRITE);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
// Helper to create common data
|
||||
static PackRead *
|
||||
@ -958,7 +953,7 @@ pckReadToLog(const PackRead *this)
|
||||
{
|
||||
return strNewFmt(
|
||||
"{depth: %u, idLast: %u, tagNextId: %u, tagNextType: %u, tagNextValue %" PRIu64 "}", lstSize(this->tagStack),
|
||||
this->tagStackTop != NULL ? this->tagStackTop->idLast : 0, this->tagNextId, this->tagNextType, this->tagNextValue);
|
||||
this->tagStackTop->idLast, this->tagNextId, this->tagNextType, this->tagNextValue);
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
@ -1576,7 +1571,7 @@ pckWriteEnd(PackWrite *this)
|
||||
String *
|
||||
pckWriteToLog(const PackWrite *this)
|
||||
{
|
||||
return strNewFmt("{depth: %u, idLast: %u}", lstSize(this->tagStack), this->tagStackTop == NULL ? 0 : this->tagStackTop->idLast);
|
||||
return strNewFmt("{depth: %u, idLast: %u}", lstSize(this->tagStack), this->tagStackTop->idLast);
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
|
@ -92,18 +92,12 @@ Minimum number of extra bytes to allocate for packs that are growing or are like
|
||||
/***********************************************************************************************************************************
|
||||
Object types
|
||||
***********************************************************************************************************************************/
|
||||
#define PACK_READ_TYPE PackRead
|
||||
#define PACK_READ_PREFIX pckRead
|
||||
|
||||
typedef struct PackRead PackRead;
|
||||
|
||||
#define PACK_WRITE_TYPE PackWrite
|
||||
#define PACK_WRITE_PREFIX pckWrite
|
||||
|
||||
typedef struct PackWrite PackWrite;
|
||||
|
||||
#include "common/io/read.h"
|
||||
#include "common/io/write.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/string.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -303,7 +297,11 @@ void pckReadEnd(PackRead *this);
|
||||
/***********************************************************************************************************************************
|
||||
Read Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void pckReadFree(PackRead *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
pckReadFree(PackRead *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Write Constructors
|
||||
@ -474,7 +472,11 @@ PackWrite *pckWriteEnd(PackWrite *this);
|
||||
/***********************************************************************************************************************************
|
||||
Write Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void pckWriteFree(PackWrite *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
pckWriteFree(PackWrite *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Helper Functions
|
||||
|
@ -12,7 +12,6 @@ Xml Handler
|
||||
#include "common/log.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/list.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/xml.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -38,8 +37,6 @@ struct XmlDocument
|
||||
XmlNode *root;
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_FREE(XML_DOCUMENT);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Error handler
|
||||
|
||||
|
@ -11,14 +11,12 @@ There are many capabilities of libxml2 that are not exposed here and may need to
|
||||
/***********************************************************************************************************************************
|
||||
Objects
|
||||
***********************************************************************************************************************************/
|
||||
#define XML_DOCUMENT_TYPE XmlDocument
|
||||
#define XML_DOCUMENT_PREFIX xmlDocument
|
||||
|
||||
typedef struct XmlDocument XmlDocument;
|
||||
typedef struct XmlNode XmlNode;
|
||||
typedef struct XmlNodeList XmlNodeList;
|
||||
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/string.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -48,7 +46,11 @@ XmlNode *xmlDocumentRoot(const XmlDocument *this);
|
||||
/***********************************************************************************************************************************
|
||||
Document Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void xmlDocumentFree(XmlDocument *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
xmlDocumentFree(XmlDocument *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Node Functions
|
||||
|
@ -6,7 +6,6 @@ Wait Handler
|
||||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/wait.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -15,15 +14,12 @@ Object type
|
||||
struct Wait
|
||||
{
|
||||
WaitPub pub; // Publicly accessible variables
|
||||
MemContext *memContext; // Context that contains the wait handler
|
||||
TimeMSec waitTime; // Total time to wait (in usec)
|
||||
TimeMSec sleepTime; // Next sleep time (in usec)
|
||||
TimeMSec sleepPrevTime; // Previous time slept (in usec)
|
||||
TimeMSec beginTime; // Time the wait began (in epoch usec)
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_FREE(WAIT);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
Wait *
|
||||
waitNew(TimeMSec waitTime)
|
||||
@ -46,9 +42,9 @@ waitNew(TimeMSec waitTime)
|
||||
{
|
||||
.pub =
|
||||
{
|
||||
.memContext = MEM_CONTEXT_NEW(),
|
||||
.remainTime = waitTime,
|
||||
},
|
||||
.memContext = MEM_CONTEXT_NEW(),
|
||||
.waitTime = waitTime,
|
||||
};
|
||||
|
||||
|
@ -7,12 +7,10 @@ Wait Handler
|
||||
/***********************************************************************************************************************************
|
||||
Wait object
|
||||
***********************************************************************************************************************************/
|
||||
#define WAIT_TYPE Wait
|
||||
#define WAIT_PREFIX wait
|
||||
|
||||
typedef struct Wait Wait;
|
||||
|
||||
#include "common/time.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Constructors
|
||||
@ -24,6 +22,7 @@ Getters/Setters
|
||||
***********************************************************************************************************************************/
|
||||
typedef struct WaitPub
|
||||
{
|
||||
MemContext *memContext; // Mem context
|
||||
TimeMSec remainTime; // Wait time remaining (in usec)
|
||||
} WaitPub;
|
||||
|
||||
@ -44,7 +43,11 @@ bool waitMore(Wait *this);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void waitFree(Wait *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
waitFree(Wait *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -6,7 +6,6 @@ Database Client
|
||||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/wait.h"
|
||||
#include "db/db.h"
|
||||
#include "db/protocol.h"
|
||||
@ -37,9 +36,6 @@ struct Db
|
||||
const String *archiveCommand; // The archive_command reported by the database
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(DB);
|
||||
OBJECT_DEFINE_FREE(DB);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Close protocol connection. No need to close a locally created PgClient since it has its own destructor.
|
||||
***********************************************************************************************************************************/
|
||||
|
16
src/db/db.h
16
src/db/db.h
@ -7,15 +7,13 @@ expected to be embedded in this object.
|
||||
#ifndef DB_DB_H
|
||||
#define DB_DB_H
|
||||
|
||||
#include "common/type/object.h"
|
||||
#include "postgres/client.h"
|
||||
#include "protocol/client.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define DB_TYPE Db
|
||||
#define DB_PREFIX db
|
||||
|
||||
typedef struct Db Db;
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -69,7 +67,11 @@ String *dbWalSwitch(Db *this);
|
||||
void dbClose(Db *this);
|
||||
|
||||
// Move to a new parent mem context
|
||||
Db *dbMove(Db *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline Db *
|
||||
dbMove(Db *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Getters/Setters
|
||||
@ -89,7 +91,11 @@ const String *dbArchiveCommand(const Db *this);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void dbFree(Db *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
dbFree(Db *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -7,9 +7,6 @@ Info Handler
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define INFO_TYPE Info
|
||||
#define INFO_PREFIX info
|
||||
|
||||
typedef struct Info Info;
|
||||
typedef struct InfoSave InfoSave;
|
||||
|
||||
|
@ -15,7 +15,6 @@ Archive Info Handler
|
||||
#include "common/io/bufferWrite.h"
|
||||
#include "common/io/io.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
#include "info/infoArchive.h"
|
||||
#include "info/infoPg.h"
|
||||
#include "postgres/interface.h"
|
||||
@ -37,9 +36,6 @@ struct InfoArchive
|
||||
InfoPg *infoPg; // Contents of the DB data
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(INFO_ARCHIVE);
|
||||
OBJECT_DEFINE_FREE(INFO_ARCHIVE);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Internal constructor
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -7,12 +7,10 @@ Archive Info Handler
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define INFO_ARCHIVE_TYPE InfoArchive
|
||||
#define INFO_ARCHIVE_PREFIX infoArchive
|
||||
|
||||
typedef struct InfoArchive InfoArchive;
|
||||
|
||||
#include "common/crypto/common.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/string.h"
|
||||
#include "info/infoPg.h"
|
||||
#include "storage/storage.h"
|
||||
@ -44,7 +42,11 @@ const String *infoArchiveIdHistoryMatch(
|
||||
const InfoArchive *this, const unsigned int historyId, const unsigned int pgVersion, const uint64_t pgSystemId);
|
||||
|
||||
// Move to a new parent mem context
|
||||
InfoArchive *infoArchiveMove(InfoArchive *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline InfoArchive *
|
||||
infoArchiveMove(InfoArchive *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Getters/Setters
|
||||
@ -62,7 +64,11 @@ InfoArchive *infoArchivePgSet(InfoArchive *this, unsigned int pgVersion, uint64_
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void infoArchiveFree(InfoArchive *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
infoArchiveFree(InfoArchive *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Helper functions
|
||||
|
@ -19,7 +19,6 @@ Backup Info Handler
|
||||
#include "common/regExp.h"
|
||||
#include "common/type/json.h"
|
||||
#include "common/type/list.h"
|
||||
#include "common/type/object.h"
|
||||
#include "info/infoBackup.h"
|
||||
#include "info/manifest.h"
|
||||
#include "postgres/interface.h"
|
||||
@ -66,9 +65,6 @@ struct InfoBackup
|
||||
List *backup; // List of current backups and their associated data
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(INFO_BACKUP);
|
||||
OBJECT_DEFINE_FREE(INFO_BACKUP);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Internal constructor
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -7,11 +7,9 @@ Backup Info Handler
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define INFO_BACKUP_TYPE InfoBackup
|
||||
#define INFO_BACKUP_PREFIX infoBackup
|
||||
|
||||
typedef struct InfoBackup InfoBackup;
|
||||
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/string.h"
|
||||
#include "common/type/stringList.h"
|
||||
#include "info/infoPg.h"
|
||||
@ -75,7 +73,11 @@ void infoBackupDataAdd(const InfoBackup *this, const Manifest *manifest);
|
||||
void infoBackupDataDelete(const InfoBackup *this, const String *backupDeleteLabel);
|
||||
|
||||
// Move to a new parent mem context
|
||||
InfoBackup *infoBackupMove(InfoBackup *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline InfoBackup *
|
||||
infoBackupMove(InfoBackup *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Getters/Setters
|
||||
@ -105,7 +107,11 @@ const String *infoBackupCipherPass(const InfoBackup *this);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void infoBackupFree(InfoBackup *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
infoBackupFree(InfoBackup *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Helper functions
|
||||
|
@ -9,9 +9,6 @@ PostgreSQL Info Handler
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define INFO_PG_TYPE InfoPg
|
||||
#define INFO_PG_PREFIX infoPg
|
||||
|
||||
typedef struct InfoPg InfoPg;
|
||||
|
||||
#include "common/crypto/common.h"
|
||||
|
@ -14,7 +14,6 @@ Backup Manifest Handler
|
||||
#include "common/type/json.h"
|
||||
#include "common/type/list.h"
|
||||
#include "common/type/mcv.h"
|
||||
#include "common/type/object.h"
|
||||
#include "info/info.h"
|
||||
#include "info/manifest.h"
|
||||
#include "postgres/interface.h"
|
||||
@ -165,9 +164,6 @@ struct Manifest
|
||||
List *dbList; // List of databases
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(MANIFEST);
|
||||
OBJECT_DEFINE_FREE(MANIFEST);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Internal functions to add types to their lists
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -29,12 +29,10 @@ Constants
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define MANIFEST_TYPE Manifest
|
||||
#define MANIFEST_PREFIX manifest
|
||||
|
||||
typedef struct Manifest Manifest;
|
||||
|
||||
#include "common/crypto/hash.h"
|
||||
#include "common/type/object.h"
|
||||
#include "storage/storage.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -182,7 +180,11 @@ Functions
|
||||
void manifestLinkCheck(const Manifest *this);
|
||||
|
||||
// Move to a new parent mem context
|
||||
Manifest *manifestMove(Manifest *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline Manifest *
|
||||
manifestMove(Manifest *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
// Manifest save
|
||||
void manifestSave(Manifest *this, IoWrite *write);
|
||||
@ -268,7 +270,11 @@ void manifestBackupLabelSet(Manifest *this, const String *backupLabel);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void manifestFree(Manifest *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
manifestFree(Manifest *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Helper functions
|
||||
|
@ -9,7 +9,6 @@ Postgres Client
|
||||
#include "common/log.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/list.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/wait.h"
|
||||
#include "postgres/client.h"
|
||||
|
||||
@ -28,9 +27,6 @@ struct PgClient
|
||||
PGconn *connection;
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(PG_CLIENT);
|
||||
OBJECT_DEFINE_FREE(PG_CLIENT);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Close protocol connection
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -8,6 +8,7 @@ casts to queries to output one of these types.
|
||||
#ifndef POSTGRES_QUERY_H
|
||||
#define POSTGRES_QUERY_H
|
||||
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/string.h"
|
||||
#include "common/type/variantList.h"
|
||||
#include "common/time.h"
|
||||
@ -15,9 +16,6 @@ casts to queries to output one of these types.
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define PG_CLIENT_TYPE PgClient
|
||||
#define PG_CLIENT_PREFIX pgClient
|
||||
|
||||
typedef struct PgClient PgClient;
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -33,7 +31,11 @@ Functions
|
||||
PgClient *pgClientOpen(PgClient *this);
|
||||
|
||||
// Move to a new parent mem context
|
||||
PgClient *pgClientMove(PgClient *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline PgClient *
|
||||
pgClientMove(PgClient *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
// Execute a query and return results
|
||||
VariantList *pgClientQuery(PgClient *this, const String *query);
|
||||
@ -44,7 +46,11 @@ void pgClientClose(PgClient *this);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void pgClientFree(PgClient *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
pgClientFree(PgClient *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -9,7 +9,6 @@ Protocol Client
|
||||
#include "common/time.h"
|
||||
#include "common/type/json.h"
|
||||
#include "common/type/keyValue.h"
|
||||
#include "common/type/object.h"
|
||||
#include "protocol/client.h"
|
||||
#include "version.h"
|
||||
|
||||
@ -41,9 +40,6 @@ struct ProtocolClient
|
||||
TimeMSec keepAliveTime;
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(PROTOCOL_CLIENT);
|
||||
OBJECT_DEFINE_FREE(PROTOCOL_CLIENT);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Close protocol connection
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -7,13 +7,11 @@ Protocol Client
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define PROTOCOL_CLIENT_TYPE ProtocolClient
|
||||
#define PROTOCOL_CLIENT_PREFIX protocolClient
|
||||
|
||||
typedef struct ProtocolClient ProtocolClient;
|
||||
|
||||
#include "common/io/read.h"
|
||||
#include "common/io/write.h"
|
||||
#include "common/type/object.h"
|
||||
#include "protocol/command.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -49,7 +47,13 @@ Functions
|
||||
***********************************************************************************************************************************/
|
||||
// Execute a protocol command and get the output
|
||||
const Variant *protocolClientExecute(ProtocolClient *this, const ProtocolCommand *command, bool outputRequired);
|
||||
ProtocolClient *protocolClientMove(ProtocolClient *this, MemContext *parentNew);
|
||||
|
||||
// Move to a new parent mem context
|
||||
__attribute__((always_inline)) static inline ProtocolClient *
|
||||
protocolClientMove(ProtocolClient *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
// Send noop to test connection or keep it alive
|
||||
void protocolClientNoOp(ProtocolClient *this);
|
||||
@ -75,7 +79,11 @@ IoWrite *protocolClientIoWrite(const ProtocolClient *this);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void protocolClientFree(ProtocolClient *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
protocolClientFree(ProtocolClient *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -8,7 +8,6 @@ Protocol Command
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/json.h"
|
||||
#include "common/type/keyValue.h"
|
||||
#include "common/type/object.h"
|
||||
#include "protocol/command.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -27,9 +26,6 @@ struct ProtocolCommand
|
||||
Variant *parameterList;
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(PROTOCOL_COMMAND);
|
||||
OBJECT_DEFINE_FREE(PROTOCOL_COMMAND);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
ProtocolCommand *
|
||||
protocolCommandNew(const String *command)
|
||||
|
@ -7,11 +7,9 @@ Protocol Command
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define PROTOCOL_COMMAND_TYPE ProtocolCommand
|
||||
#define PROTOCOL_COMMAND_PREFIX protocolCommand
|
||||
|
||||
typedef struct ProtocolCommand ProtocolCommand;
|
||||
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/variant.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -31,7 +29,12 @@ ProtocolCommand *protocolCommandNew(const String *command);
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
// Move to a new parent mem context
|
||||
ProtocolCommand *protocolCommandMove(ProtocolCommand *this, MemContext *parentNew);
|
||||
// Move to a new parent mem context
|
||||
__attribute__((always_inline)) static inline ProtocolCommand *
|
||||
protocolCommandMove(ProtocolCommand *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
// Read the command output
|
||||
ProtocolCommand *protocolCommandParamAdd(ProtocolCommand *this, const Variant *param);
|
||||
@ -45,7 +48,11 @@ String *protocolCommandJson(const ProtocolCommand *this);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void protocolCommandFree(ProtocolCommand *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
protocolCommandFree(ProtocolCommand *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -8,11 +8,11 @@ Protocol Parallel Executor
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
#include "common/macro.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/json.h"
|
||||
#include "common/type/keyValue.h"
|
||||
#include "common/type/list.h"
|
||||
#include "common/type/object.h"
|
||||
#include "protocol/command.h"
|
||||
#include "protocol/helper.h"
|
||||
#include "protocol/parallel.h"
|
||||
@ -35,8 +35,6 @@ struct ProtocolParallel
|
||||
ProtocolParallelJobState state; // Overall state of job processing
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_FREE(PROTOCOL_PARALLEL);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
ProtocolParallel *
|
||||
protocolParallelNew(TimeMSec timeout, ParallelJobCallback *callbackFunction, void *callbackData)
|
||||
|
@ -7,12 +7,10 @@ Protocol Parallel Executor
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define PROTOCOL_PARALLEL_TYPE ProtocolParallel
|
||||
#define PROTOCOL_PARALLEL_PREFIX protocolParallel
|
||||
|
||||
typedef struct ProtocolParallel ProtocolParallel;
|
||||
|
||||
#include "common/time.h"
|
||||
#include "common/type/object.h"
|
||||
#include "protocol/client.h"
|
||||
#include "protocol/parallelJob.h"
|
||||
|
||||
@ -50,7 +48,11 @@ ProtocolParallelJob *protocolParallelResult(ProtocolParallel *this);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void protocolParallelFree(ProtocolParallel *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
protocolParallelFree(ProtocolParallel *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -6,7 +6,6 @@ Protocol Parallel Job
|
||||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
#include "protocol/command.h"
|
||||
#include "protocol/parallelJob.h"
|
||||
|
||||
@ -27,9 +26,6 @@ struct ProtocolParallelJob
|
||||
const Variant *result; // Result if job was successful
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(PROTOCOL_PARALLEL_JOB);
|
||||
OBJECT_DEFINE_FREE(PROTOCOL_PARALLEL_JOB);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
ProtocolParallelJob *
|
||||
protocolParallelJobNew(const Variant *key, ProtocolCommand *command)
|
||||
|
@ -7,9 +7,6 @@ Protocol Parallel Job
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define PROTOCOL_PARALLEL_JOB_TYPE ProtocolParallelJob
|
||||
#define PROTOCOL_PARALLEL_JOB_PREFIX protocolParallelJob
|
||||
|
||||
typedef struct ProtocolParallelJob ProtocolParallelJob;
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -23,6 +20,7 @@ typedef enum
|
||||
} ProtocolParallelJobState;
|
||||
|
||||
#include "common/time.h"
|
||||
#include "common/type/object.h"
|
||||
#include "protocol/client.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -34,7 +32,11 @@ ProtocolParallelJob *protocolParallelJobNew(const Variant *key, ProtocolCommand
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
// Move to new parent mem context
|
||||
ProtocolParallelJob *protocolParallelJobMove(ProtocolParallelJob *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline ProtocolParallelJob *
|
||||
protocolParallelJobMove(ProtocolParallelJob *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Getters/Setters
|
||||
@ -65,7 +67,11 @@ void protocolParallelJobStateSet(ProtocolParallelJob *this, ProtocolParallelJobS
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void protocolParallelJobFree(ProtocolParallelJob *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
protocolParallelJobFree(ProtocolParallelJob *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -12,7 +12,6 @@ Protocol Server
|
||||
#include "common/type/json.h"
|
||||
#include "common/type/keyValue.h"
|
||||
#include "common/type/list.h"
|
||||
#include "common/type/object.h"
|
||||
#include "protocol/client.h"
|
||||
#include "protocol/helper.h"
|
||||
#include "protocol/server.h"
|
||||
@ -29,9 +28,6 @@ struct ProtocolServer
|
||||
IoWrite *write;
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(PROTOCOL_SERVER);
|
||||
OBJECT_DEFINE_FREE(PROTOCOL_SERVER);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
ProtocolServer *
|
||||
protocolServerNew(const String *name, const String *service, IoRead *read, IoWrite *write)
|
||||
|
@ -7,13 +7,11 @@ Protocol Server
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define PROTOCOL_SERVER_TYPE ProtocolServer
|
||||
#define PROTOCOL_SERVER_PREFIX protocolServer
|
||||
|
||||
typedef struct ProtocolServer ProtocolServer;
|
||||
|
||||
#include "common/io/read.h"
|
||||
#include "common/io/write.h"
|
||||
#include "common/type/object.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Protocol command handler type and structure
|
||||
@ -51,7 +49,11 @@ void protocolServerProcess(
|
||||
void protocolServerResponse(ProtocolServer *this, const Variant *output);
|
||||
|
||||
// Move to a new parent mem context
|
||||
ProtocolServer *protocolServerMove(ProtocolServer *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline ProtocolServer *
|
||||
protocolServerMove(ProtocolServer *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
// Write a line
|
||||
void protocolServerWriteLine(const ProtocolServer *this, const String *line);
|
||||
@ -68,7 +70,11 @@ IoWrite *protocolServerIoWrite(const ProtocolServer *this);
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void protocolServerFree(ProtocolServer *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
protocolServerFree(ProtocolServer *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -14,9 +14,6 @@ Azure Storage Read
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define STORAGE_READ_AZURE_TYPE StorageReadAzure
|
||||
#define STORAGE_READ_AZURE_PREFIX storageReadAzure
|
||||
|
||||
typedef struct StorageReadAzure
|
||||
{
|
||||
MemContext *memContext; // Object mem context
|
||||
|
@ -20,9 +20,6 @@ STRING_STATIC(GCS_QUERY_ALT_STR, "alt");
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define STORAGE_READ_GCS_TYPE StorageReadGcs
|
||||
#define STORAGE_READ_GCS_PREFIX storageReadGcs
|
||||
|
||||
typedef struct StorageReadGcs
|
||||
{
|
||||
MemContext *memContext; // Object mem context
|
||||
|
@ -6,7 +6,6 @@ Storage Read Interface
|
||||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
#include "storage/read.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -15,13 +14,9 @@ Object type
|
||||
struct StorageRead
|
||||
{
|
||||
StorageReadPub pub; // Publicly accessible variables
|
||||
MemContext *memContext; // Object mem context
|
||||
void *driver;
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(STORAGE_READ);
|
||||
OBJECT_DEFINE_FREE(STORAGE_READ);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
***********************************************************************************************************************************/
|
||||
@ -50,10 +45,10 @@ storageReadNew(void *driver, const StorageReadInterface *interface)
|
||||
{
|
||||
.pub =
|
||||
{
|
||||
.memContext = memContextCurrent(),
|
||||
.interface = interface,
|
||||
.io = ioReadNew(driver, interface->ioInterface),
|
||||
},
|
||||
.memContext = memContextCurrent(),
|
||||
.driver = driver,
|
||||
};
|
||||
|
||||
|
@ -7,24 +7,27 @@ Storage Read Interface
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define STORAGE_READ_TYPE StorageRead
|
||||
#define STORAGE_READ_PREFIX storageRead
|
||||
|
||||
typedef struct StorageRead StorageRead;
|
||||
|
||||
#include "common/io/read.h"
|
||||
#include "common/type/object.h"
|
||||
#include "storage/read.intern.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
StorageRead *storageReadMove(StorageRead *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline StorageRead *
|
||||
storageReadMove(StorageRead *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Getters/Setters
|
||||
***********************************************************************************************************************************/
|
||||
typedef struct StorageReadPub
|
||||
{
|
||||
MemContext *memContext; // Mem context
|
||||
const StorageReadInterface *interface; // File data (name, driver type, etc.)
|
||||
IoRead *io; // Read interface
|
||||
} StorageReadPub;
|
||||
@ -72,7 +75,11 @@ storageReadType(const StorageRead *this)
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void storageReadFree(StorageRead *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
storageReadFree(StorageRead *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -11,7 +11,6 @@ Storage Interface
|
||||
#include "common/type/list.h"
|
||||
#include "common/log.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/regExp.h"
|
||||
#include "common/wait.h"
|
||||
#include "storage/storage.h"
|
||||
@ -30,8 +29,6 @@ struct Storage
|
||||
StoragePathExpressionCallback *pathExpressionFunction;
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_FREE(STORAGE);
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
Storage *
|
||||
storageNew(
|
||||
|
@ -9,9 +9,6 @@ Storage Interface
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define STORAGE_TYPE Storage
|
||||
#define STORAGE_PREFIX storage
|
||||
|
||||
typedef struct Storage Storage;
|
||||
|
||||
#include "common/type/buffer.h"
|
||||
|
@ -6,7 +6,6 @@ Storage Write Interface
|
||||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type/object.h"
|
||||
#include "storage/write.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -15,13 +14,9 @@ Object type
|
||||
struct StorageWrite
|
||||
{
|
||||
StorageWritePub pub; // Publicly accessible variables
|
||||
MemContext *memContext; // Object mem context
|
||||
void *driver;
|
||||
};
|
||||
|
||||
OBJECT_DEFINE_MOVE(STORAGE_WRITE);
|
||||
OBJECT_DEFINE_FREE(STORAGE_WRITE);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
***********************************************************************************************************************************/
|
||||
@ -51,10 +46,10 @@ storageWriteNew(void *driver, const StorageWriteInterface *interface)
|
||||
{
|
||||
.pub =
|
||||
{
|
||||
.memContext = memContextCurrent(),
|
||||
.interface = interface,
|
||||
.io = ioWriteNew(driver, interface->ioInterface),
|
||||
},
|
||||
.memContext = memContextCurrent(),
|
||||
.driver = driver,
|
||||
};
|
||||
|
||||
|
@ -7,13 +7,11 @@ Storage Write Interface
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
#define STORAGE_WRITE_TYPE StorageWrite
|
||||
#define STORAGE_WRITE_PREFIX storageWrite
|
||||
|
||||
typedef struct StorageWrite StorageWrite;
|
||||
|
||||
#include "common/io/write.h"
|
||||
#include "common/type/buffer.h"
|
||||
#include "common/type/object.h"
|
||||
#include "common/type/string.h"
|
||||
#include "storage/write.intern.h"
|
||||
|
||||
@ -21,13 +19,18 @@ typedef struct StorageWrite StorageWrite;
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
// Move to a new parent mem context
|
||||
StorageWrite *storageWriteMove(StorageWrite *this, MemContext *parentNew);
|
||||
__attribute__((always_inline)) static inline StorageWrite *
|
||||
storageWriteMove(StorageWrite *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Getters/Setters
|
||||
***********************************************************************************************************************************/
|
||||
typedef struct StorageWritePub
|
||||
{
|
||||
MemContext *memContext; // Mem context
|
||||
const StorageWriteInterface *interface; // File data (name, driver type, etc.)
|
||||
IoWrite *io; // Write interface
|
||||
} StorageWritePub;
|
||||
@ -108,7 +111,11 @@ storageWriteType(const StorageWrite *this)
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
***********************************************************************************************************************************/
|
||||
void storageWriteFree(StorageWrite *this);
|
||||
__attribute__((always_inline)) static inline void
|
||||
storageWriteFree(StorageWrite *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
|
@ -120,6 +120,13 @@ unit:
|
||||
coverage:
|
||||
- common/encode
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------------
|
||||
- name: type-object
|
||||
total: 1
|
||||
|
||||
coverage:
|
||||
- common/type/object
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------------
|
||||
- name: type-string
|
||||
total: 25
|
||||
@ -196,13 +203,6 @@ unit:
|
||||
coverage:
|
||||
- common/wait
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------------
|
||||
- name: type-object
|
||||
total: 1
|
||||
|
||||
coverage:
|
||||
- common/type/object: noCode
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------------
|
||||
- name: type-mcv
|
||||
total: 1
|
||||
|
@ -37,7 +37,7 @@ testRun(void)
|
||||
TEST_RESULT_UINT(list->itemSize, sizeof(void *), "item size");
|
||||
TEST_RESULT_UINT(list->pub.listSize, 0, "list size");
|
||||
TEST_RESULT_UINT(list->listSizeMax, 0, "list size max");
|
||||
TEST_RESULT_PTR(lstMemContext(list), list->memContext, "list mem context");
|
||||
TEST_RESULT_PTR(lstMemContext(list), list->pub.memContext, "list mem context");
|
||||
TEST_RESULT_VOID(lstClear(list), "clear list");
|
||||
|
||||
void *ptr = NULL;
|
||||
|
@ -1,43 +1,35 @@
|
||||
/***********************************************************************************************************************************
|
||||
Test Object Helper Macros
|
||||
***********************************************************************************************************************************/
|
||||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/macro.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
TestObject Type
|
||||
***********************************************************************************************************************************/
|
||||
#define TEST_OBJECT_TYPE TestObject
|
||||
#define TEST_OBJECT_PREFIX testObject
|
||||
|
||||
typedef struct TestObject
|
||||
{
|
||||
MemContext *memContext; // Mem context
|
||||
} TestObject;
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
Standard object methods
|
||||
***********************************************************************************************************************************/
|
||||
#define FUNCTION_LOG_TEST_OBJECT_TYPE \
|
||||
TestObject *
|
||||
#define FUNCTION_LOG_TEST_OBJECT_FORMAT(value, buffer, bufferSize) \
|
||||
objToLog(value, STRINGIFY(TestObject), buffer, bufferSize)
|
||||
TestObject *
|
||||
testObjectMove(TestObject *this, MemContext *parentNew)
|
||||
{
|
||||
return objMove(this, parentNew);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Free object
|
||||
***********************************************************************************************************************************/
|
||||
void testObjectFree(TestObject *this);
|
||||
|
||||
OBJECT_DEFINE_MOVE(TEST_OBJECT);
|
||||
OBJECT_DEFINE_FREE(TEST_OBJECT);
|
||||
void
|
||||
testObjectFree(TestObject *this)
|
||||
{
|
||||
objFree(this);
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
TestObject *
|
||||
testObjectNew(void)
|
||||
{
|
||||
FUNCTION_LOG_VOID(logLevelTrace);
|
||||
|
||||
TestObject *this = NULL;
|
||||
|
||||
MEM_CONTEXT_NEW_BEGIN(STRINGIFY(TestObject))
|
||||
@ -51,7 +43,7 @@ testObjectNew(void)
|
||||
}
|
||||
MEM_CONTEXT_NEW_END();
|
||||
|
||||
FUNCTION_LOG_RETURN(TEST_OBJECT, this);
|
||||
return this;
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -76,6 +68,7 @@ testRun(void)
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
TEST_RESULT_VOID(testObjectFree(testObject), " free object");
|
||||
TEST_RESULT_VOID(testObjectFree(NULL), " free null object");
|
||||
}
|
||||
|
||||
FUNCTION_HARNESS_RETURN_VOID();
|
||||
|
@ -80,7 +80,7 @@ testRun(void)
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("storageNew() and storageFree()"))
|
||||
if (testBegin("storageNew()"))
|
||||
{
|
||||
Storage *storageTest = NULL;
|
||||
TEST_ASSIGN(storageTest, storagePosixNewP(strNew("/")), "new storage (defaults)");
|
||||
@ -107,8 +107,6 @@ testRun(void)
|
||||
TEST_RESULT_STR(storageType(storageTest), storageType(storageTest), " check type");
|
||||
TEST_RESULT_BOOL(storageFeature(storageTest, storageFeaturePath), true, " check path feature");
|
||||
TEST_RESULT_BOOL(storageFeature(storageTest, storageFeatureCompress), true, " check compress feature");
|
||||
|
||||
TEST_RESULT_VOID(storageFree(storageTest), "free storage");
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
|
Loading…
x
Reference in New Issue
Block a user