2
3
4
5
6
10#include "../algorithms/gimbal_numeric.h"
11#include "../meta/ifaces/gimbal_ilogger.h"
21#define GBL_CTX_FRAME_DECLARE GblStackFrame* GBL_CTX_FRAME_NAME
22#define GBL_CTX_FRAME() (GblThd_current()->pStackFrameTop)
25#define GBL_CTX_RECORD() (GBL_CTX_FRAME_NAME)->record
26#define GBL_CTX_RESULT() (GBL_CTX_FRAME_NAME)->record.result
27#define GBL_CTX_SOURCE() (GBL_CTX_FRAME_NAME)->record.srcLocation
28#define GBL_CTX_LAST_RECORD() (GblThd_current()->callRecord)
33#define GBL_SRC_FILE __FILE__
34#define GBL_SRC_FN __func__
35#define GBL_SRC_LN __LINE__
37#define GblSrcLoc GblSourceLocation
39#define GBL_SOURCE_LOCATION(FILE, FUNCTION, LINE) GBL_STRUCT_INIT(GblSourceLocation, FILE, FUNCTION, LINE)
41#define GBL_CTX_STACK_FRAME_SOURCE_PUSH(pStackFrame, current)
42 if(++pStackFrame->sourceCurrentCaptureDepth == 1
) GBL_CTX_SOURCE() = current;
44#define GBL_CTX_STACK_FRAME_SOURCE_POP(pStackFrame)
46 GBL_ASSERT(pStackFrame->sourceCurrentCaptureDepth);
47 --pStackFrame->sourceCurrentCaptureDepth;
50#define GBL_CTX_SOURCE_LOC_PUSH(srcLoc)
53#define GBL_CTX_SOURCE_PUSH(FILE, FUNCTION, LINE)
56#define GBL_CTX_SOURCE_POP()
59#define GBL_CTX_SOURCE_SCOPED(CALL, loc, ...)
68#define GBL_CTX_RECORD_SET_JMP_CND_(expr, result, label, srcLoc, ...)
80#define GBL_CTX_RECORD_SET_JMP_CND(expr, result, label, ...)
85#define GBL_CTX_VERIFY_(expr, result, srcLoc, ...)
88 goto GBL_CTX_END_LABEL,
91#define GBL_CTX_VERIFY_N(srcLoc, expr, result, ...)
94#define GBL_CTX_VERIFY_3(srcLoc, expr, result)
97#define GBL_CTX_VERIFY(...)
105#define GBL_CTX_VERIFY_EXPRESSION_N(srcLoc, expr, ...)
106 GBL_CTX_VERIFY_(expr, GBL_RESULT_ERROR_INVALID_EXPRESSION, srcLoc, __VA_ARGS__)
108#define GBL_CTX_VERIFY_EXPRESSION_2(src, expr)
111#define GBL_CTX_VERIFY_EXPRESSION(...)
118#define GBL_CTX_VERIFY_POINTER_N(srcLoc, expr, ...)
119 GBL_CTX_VERIFY_(expr, GBL_RESULT_ERROR_INVALID_POINTER, srcLoc, __VA_ARGS__)
121#define GBL_CTX_VERIFY_POINTER_2(src, expr)
124#define GBL_CTX_VERIFY_POINTER(...)
131#define GBL_CTX_VERIFY_ARG_N(srcLoc, expr, ...)
132 GBL_CTX_VERIFY_(expr, GBL_RESULT_ERROR_INVALID_ARG, srcLoc, __VA_ARGS__)
134#define GBL_CTX_VERIFY_ARG_2(src, expr)
137#define GBL_CTX_VERIFY_ARG(...)
144#define GBL_CTX_VERIFY_TYPE_N(srcLoc, actualType, expectedType, ...)
145 GBL_CTX_VERIFY_(GblType_check(actualType, expectedType), GBL_RESULT_ERROR_TYPE_MISMATCH, srcLoc, __VA_ARGS__)
147#define GBL_CTX_VERIFY_TYPE_3(srcLoc, actualType, expectedType)
148 GBL_CTX_VERIFY_TYPE_N(srcLoc, actualType, expectedType, "Type mismatch [Actual: %s, Expected: %s]", GblType_name(actualType), GblType_name(expectedType))
150#define GBL_CTX_VERIFY_TYPE_2(srcLoc, actualType)
153#define GBL_CTX_VERIFY_TYPE(...)
160#define GBL_CTX_VERIFY_LAST_RECORD()
162 const GblCallRecord* pRecord =
163 GblThd_callRecord(NULL
);
170#define GBL_CTX_CLEAR_LAST_RECORD()
171 GblThd_setCallRecord(NULL
, NULL
)
175#ifdef GBL_CONFIG_ERRNO_CHECKS
176#define GBL_CTX_ERRNO_CLEAR() errno = 0
178#define GBL_CTX_ERRNO_CLEAR()
181#ifdef GBL_CONFIG_ERRNO_CHECKS
182# define GBL_CTX_PERROR(...)
184 if(errno) GBL_UNLIKELY {
185 const GBL_RESULT code =
186 GBL_ERRNO_RESULT(errno);
188 GBL_RESULT_SUCCESS(code),
190 "ERRNO: %s", strerror(errno));
194# define GBL_CTX_PERROR(...)
199 case 0:
return GBL_RESULT_SUCCESS;
200 default:
return GBL_RESULT_ERROR;
205#define GBL_CTX_INLINE_RETVAL() GBL_CTX_INLINE_RETURN_VALUE_NAME
207#define GBL_CTX_INLINE(MethodPrefix, ReturnType, ...)
209 ReturnType GBL_CTX_INLINE_RETURN_VALUE_NAME;
211#define GBL_CTX_INLINE_BEGIN(InitialRetValue)
215#define GBL_CTX_INLINE_END()
216 goto GBL_CTX_END_LABEL;
220#define GBL_CTX_INLINE_RETURN()
224#define GBL_CTX_INLINE_CALL_(MethodPrefix, srcLoc, ...)
227#define GBL_CTX_INLINE_CALL(MethodPrefix, ...)
232#define GBL_CTX_EXT(prefix, ...)
237 GBL_ASSERT(!(GBL_CONFIG_ASSERT_ERROR_ENABLED &&
239 "Ext["#prefix"]: ERROR");
240 GBL_ASSERT(!(GBL_CONFIG_ASSERT_PARTIAL_ENABLED &&
242 "Ext["#prefix"]: ERROR");
251 size = gblAlignedAllocSizeDefault(size);
254 GBL_CTX_EXT(memAlloc_, size, align, pDebugStr, &GBL_CTX_INLINE_RETVAL());
260#define GBL_CTX_MALLOC_4(src, size, align, dbgStr)
263#define GBL_CTX_MALLOC_3(src, size, align)
266#define GBL_CTX_MALLOC_2(src, size)
269#define GBL_CTX_MALLOC(...)
272#define GBL_CTX_NEW_4(src, type, count, dbgStr)
273 (type*)GBL_CTX_INLINE_CALL_(MALLOC, src, gblAlignedAllocSizeDefault(sizeof(type)*count), 0
, dbgStr)
275#define GBL_CTX_NEW_3(src, type, count)
278#define GBL_CTX_NEW_2(src, type)
281#define GBL_CTX_NEW(...)
287 GBL_CTX_EXT(memRealloc_, pData, newSize, newAlign, &GBL_CTX_INLINE_RETVAL());
293#define GBL_CTX_REALLOC_4(src, pData, newSize, newAlign)
296#define GBL_CTX_REALLOC_3(src, pData, newSize)
299#define GBL_CTX_REALLOC(...)
302#define GBL_CTX_RENEW_5(src, ptr, type, count, dbgStr)
305#define GBL_CTX_RENEW_4(src, ptr, type, count)
308#define GBL_CTX_RENEW_3(src, ptr, type)
311#define GBL_CTX_RENEW(...)
314#define GBL_CTX_FREE(pData)
317#define GBL_CTX_PUSH_(srcLoc, ...)
320 GblThd_logPush(NULL
);
326#define GBL_CTX_PUSH()
332#define GBL_CTX_PUSH_VERBOSE_N(srcLoc, pFmt, ...)
338#define GBL_CTX_PUSH_VERBOSE(...)
344#define GBL_CTX_POP_2(srcLoc, count)
345 GblThd_logPop(NULL
, count);
349#define GBL_CTX_POP_1(srcLoc)
352#define GBL_CTX_POP(...)
361 va_start(varArgs, pFmt);
369#define GBL_CTX_LOG_(src, level, pFmt, ...)
371#define GBL_CTX_LOG(level, pFmt, ...)
374#define GBL_CTX_DEBUG(pFmt, ...)
377#define GBL_CTX_VERBOSE(pFmt, ...)
380#define GBL_CTX_INFO(pFmt, ...)
383#define GBL_CTX_WARN(pFmt, ...)
386#define GBL_CTX_ERROR(pFmt, ...)
389#define GBL_CTX_EVENT(event)
400#define GBL_CTX_RECORD_ASSERT_(record, test)
402 GBL_ASSERT(!test(record->result), record->message);
406#define GBL_CTX_RECORD_ASSERT_CONDITIONAL_(enabled, record, test)
410#define GBL_CTX_RECORD_ASSERT_PARTIAL(record)
414#define GBL_CTX_RECORD_ASSERT_ERROR(record)
419#define GBL_CTX_RECORD_ASSERT_UNKNOWN(record)
423#define GBL_CTX_RECORD_ASSERT(record)
434#define GBL_CTX_RECORD_LOG_(prefix, record)
439 gblResultString(record->result), record->message);
445#define GBL_CTX_RECORD_LOG_CONDITIONAL_(prefix, record)
450#define GBL_CTX_RECORD_LOG_PARTIAL(record)
454#define GBL_CTX_RECORD_LOG_ERROR(record)
458#define GBL_CTX_RECORD_LOG_UNKNOWN(record)
462#define GBL_CTX_RECORD_LOG(record)
471#define GBL_CTX_RECORD_LAST_RECORD_(prefix, record)
473 if(GBL_RESULT_##prefix(record->result)) {
474 GblContext_callRecordSet_(GBL_CTX_CONTEXT(), GBL_CTX_FRAME_NAME, record);
475 GblThd_setCallRecord(NULL
, record);
479#define GBL_CTX_RECORD_LAST_RECORD_PARTIAL(record)
482#define GBL_CTX_RECORD_LAST_RECORD_ERROR(record)
485#define GBL_CTX_RECORD_LAST_RECORD_UNKNOWN(record)
488#define GBL_CTX_RECORD_LAST_RECORD(record)
496#define GBL_CTX_RECORD_HANDLER(record)
503#define GBL_CTX_RECORD_SET_N(file, func, line, result, ...)
511#define GBL_CTX_RECORD_SET_5(file, func, line, result, pFmt)
514#define GBL_CTX_RECORD_SET_4(file, func, line, result)
517#define GBL_CTX_RECORD_SET(...)
520#define GBL_CTX_CALL_N(src, funcCall, ...)
530#define GBL_CTX_CALL_2(src, funcCall)
533#define GBL_CTX_CALL(...)
539#define GBL_CTX_VERIFY_CALL(...)
549#define GBL_CTX_BEGIN_FRAME(file, func, line, pObject, frame)
552 GblThd_stackFramePush(NULL
, GBL_CTX_FRAME_NAME)
554#define GBL_CTX_BEGIN_LOG_4(file, func, line, hHandle)
557#define GBL_CTX_BEGIN_LOG_N(file, func, line, hHandle, ...)
558 GBL_CTX_BEGIN_LOG_5(file, func, line, hHandle);
561#define GBL_CTX_BEGIN(...)
564#define GBL_CTX_DONE()
565 goto GBL_CTX_END_LABEL
567#define GBL_CTX_END_BLOCK()
568 goto GBL_CTX_END_LABEL;
570 if(GBL_CTX_FRAME_NAME->stackDepth)
572 GblThd_stackFramePop(NULL
)
576 return GBL_CTX_FRAME_NAME->record.result
578#define GBL_CTX_END_EMPTY()
581#define GBL_CTX_BLOCK_6(file, func, line, hHandle, frame, block)
586#define GBL_CTX_BLOCK_5(file, func, line, hHandle, block)
587 GBL_CTX_BLOCK_7(file, func, line, hHandle, ((GblStackFrame*)GBL_ALLOCA(sizeof(GblStackFrame))), block)
589#define GBL_CTX_BLOCK_4(file, func, line, block)
592#define GBL_CTX_BLOCK(...)
#define GBL_STRUCT_INIT(type,...)
#define GBL_CTX_RECORD_LAST_RECORD_(prefix, record)
#define GBL_CTX_INLINE_RETURN()
#define GBL_CTX_RECORD_LOG_CONDITIONAL_(prefix, record)
#define GBL_CTX_BLOCK_6(file, func, line, hHandle, frame, block)
#define GBL_CTX_INLINE_CALL(MethodPrefix,...)
#define GBL_CTX_VERIFY_ARG(...)
#define GBL_CTX_VERIFY_POINTER(...)
#define GBL_CTX_RENEW_4(src, ptr, type, count)
#define GBL_CTX_VERIFY_(expr, result, srcLoc,...)
#define GBL_CTX_RECORD_ASSERT_PARTIAL(record)
#define GBL_CTX_RECORD_SET_JMP_CND_(expr, result, label, srcLoc,...)
#define GBL_CTX_VERIFY_POINTER_N(srcLoc, expr,...)
#define GBL_CTX_SOURCE_LOC_PUSH(srcLoc)
#define GBL_CTX_END_BLOCK()
#define GBL_CTX_SOURCE_POP()
#define GBL_CTX_LAST_RECORD()
#define GBL_CTX_BEGIN_FRAME(file, func, line, pObject, frame)
#define GBL_CTX_PUSH_VERBOSE(...)
#define GBL_CTX_RECORD_ASSERT_UNKNOWN(record)
#define GBL_CTX_SOURCE_SCOPED(CALL, loc,...)
#define GBL_CTX_RECORD_LOG_(prefix, record)
#define GBL_CTX_STACK_FRAME_SOURCE_PUSH(pStackFrame, current)
#define GBL_CTX_CALL(...)
#define GBL_CTX_RECORD_ASSERT(record)
#define GBL_CTX_RECORD_SET_N(file, func, line, result,...)
#define GBL_CTX_FRAME_DECLARE
#define GBL_CTX_INLINE(MethodPrefix, ReturnType,...)
#define GBL_CTX_RECORD_LOG(record)
#define GBL_CTX_RECORD_ASSERT_(record, test)
#define GBL_CTX_RECORD_LAST_RECORD_UNKNOWN(record)
#define GBL_CTX_RECORD_LAST_RECORD_ERROR(record)
#define GBL_CTX_VERIFY_TYPE(...)
#define GBL_CTX_POP_2(srcLoc, count)
#define GBL_CTX_VERBOSE(pFmt,...)
#define GBL_CTX_VERIFY_ARG_N(srcLoc, expr,...)
#define GBL_CTX_VERIFY_N(srcLoc, expr, result,...)
#define GBL_SOURCE_LOCATION(FILE, FUNCTION, LINE)
#define GBL_CTX_EXT(prefix,...)
#define GBL_CTX_VERIFY_TYPE_N(srcLoc, actualType, expectedType,...)
#define GBL_CTX_INLINE_END()
#define GBL_CTX_RECORD_LAST_RECORD_PARTIAL(record)
#define GBL_CTX_RECORD_LAST_RECORD(record)
#define GBL_CTX_STACK_FRAME_SOURCE_POP(pStackFrame)
#define GBL_CTX_REALLOC_4(src, pData, newSize, newAlign)
#define GBL_CTX_NEW_4(src, type, count, dbgStr)
#define GBL_CTX_BLOCK(...)
#define GBL_CTX_RECORD_HANDLER(record)
#define GBL_CTX_RECORD_LOG_PARTIAL(record)
#define GBL_CTX_PUSH_(srcLoc,...)
#define GBL_CTX_RECORD_SET(...)
#define GBL_CTX_CALL_N(src, funcCall,...)
#define GBL_CTX_INLINE_BEGIN(InitialRetValue)
#define GBL_CTX_RECORD_ASSERT_ERROR(record)
#define GBL_CTX_VERIFY_EXPRESSION(...)
#define GBL_CTX_RECORD_LOG_ERROR(record)
#define GBL_CTX_MALLOC_3(src, size, align)
#define GBL_CTX_INLINE_CALL_(MethodPrefix, srcLoc,...)
#define GBL_CTX_LOG_(src, level, pFmt,...)
#define GBL_CTX_MALLOC_4(src, size, align, dbgStr)
#define GBL_CTX_VERIFY(...)
#define GBL_CTX_NEW_3(src, type, count)
#define GBL_CTX_MALLOC(...)
#define GBL_CTX_REALLOC(...)
#define GBL_CTX_VERIFY_EXPRESSION_N(srcLoc, expr,...)
#define GBL_CTX_RENEW_5(src, ptr, type, count, dbgStr)
#define GBL_CTX_LOG(level, pFmt,...)
#define GBL_CTX_CONTEXT()
#define GBL_CTX_INLINE_RETVAL()
#define GBL_CTX_RECORD_ASSERT_CONDITIONAL_(enabled, record, test)
#define GBL_CTX_RECORD_SET_5(file, func, line, result, pFmt)
#define GBL_CTX_RECORD_LOG_UNKNOWN(record)
#define GBL_VA_OVERLOAD_CALL(BASE, SUFFIXER,...)
#define GBL_VA_OVERLOAD_SELECT(BASE, SUFFIXER,...)
#define GBL_VA_OVERLOAD_SUFFIXER_5_N(...)
#define GBL_MACRO_CONDITIONAL_CALL(enabled,...)
#define GBL_VA_OVERLOAD_SUFFIXER_3_N(...)
#define GBL_VA_OVERLOAD_SUFFIXER_4_N(...)
#define GBL_VA_OVERLOAD_SUFFIXER_1_N(...)
#define GBL_VA_OVERLOAD_SUFFIXER_2_N(...)
#define GBL_VA_OVERLOAD_SUFFIXER_ARGC(...)
#define GBL_LABEL_EMPTY(name)
#define GBL_RESULT_PARTIAL(value)
#define GBL_RESULT_ERROR(value)
#define GBL_RESULT_SUCCESS(value)
#define GBL_RESULT_UNKNOWN(value)
#define GBL_INVALID_TYPE
GblType UUID of the invalid type.
uint32_t GblFlags
Standard-sized flags type, 32-bits across platforms.