2
3
4
5
6
7
8
12#include "../algorithms/gimbal_numeric.h"
13#include "../meta/ifaces/gimbal_ilogger.h"
23#define GBL_CTX_FRAME_DECLARE GblStackFrame* GBL_CTX_FRAME_NAME
24#define GBL_CTX_FRAME() (GblThd_current()->pStackFrameTop)
27#define GBL_CTX_RECORD() (GBL_CTX_FRAME_NAME)->record
28#define GBL_CTX_RESULT() (GBL_CTX_FRAME_NAME)->record.result
29#define GBL_CTX_SOURCE() (GBL_CTX_FRAME_NAME)->record.srcLocation
30#define GBL_CTX_LAST_RECORD() (GblThd_current()->callRecord)
35#define GBL_SRC_FILE __FILE__
36#define GBL_SRC_FN __func__
37#define GBL_SRC_LN __LINE__
39#define GblSrcLoc GblSourceLocation
41#define GBL_SOURCE_LOCATION(FILE, FUNCTION, LINE) GBL_STRUCT_INIT(GblSourceLocation, FILE, FUNCTION, LINE)
43#define GBL_CTX_STACK_FRAME_SOURCE_PUSH(pStackFrame, current)
44 if(++pStackFrame->sourceCurrentCaptureDepth == 1
) GBL_CTX_SOURCE() = current;
46#define GBL_CTX_STACK_FRAME_SOURCE_POP(pStackFrame)
48 GBL_ASSERT(pStackFrame->sourceCurrentCaptureDepth);
49 --pStackFrame->sourceCurrentCaptureDepth;
52#define GBL_CTX_SOURCE_LOC_PUSH(srcLoc)
55#define GBL_CTX_SOURCE_PUSH(FILE, FUNCTION, LINE)
58#define GBL_CTX_SOURCE_POP()
61#define GBL_CTX_SOURCE_SCOPED(CALL, loc, ...)
70#define GBL_CTX_RECORD_SET_JMP_CND_(expr, result, label, srcLoc, ...)
82#define GBL_CTX_RECORD_SET_JMP_CND(expr, result, label, ...)
87#define GBL_CTX_VERIFY_(expr, result, srcLoc, ...)
90 goto GBL_CTX_END_LABEL,
93#define GBL_CTX_VERIFY_N(srcLoc, expr, result, ...)
96#define GBL_CTX_VERIFY_3(srcLoc, expr, result)
99#define GBL_CTX_VERIFY(...)
107#define GBL_CTX_VERIFY_EXPRESSION_N(srcLoc, expr, ...)
108 GBL_CTX_VERIFY_(expr, GBL_RESULT_ERROR_INVALID_EXPRESSION, srcLoc, __VA_ARGS__)
110#define GBL_CTX_VERIFY_EXPRESSION_2(src, expr)
113#define GBL_CTX_VERIFY_EXPRESSION(...)
120#define GBL_CTX_VERIFY_POINTER_N(srcLoc, expr, ...)
121 GBL_CTX_VERIFY_(expr, GBL_RESULT_ERROR_INVALID_POINTER, srcLoc, __VA_ARGS__)
123#define GBL_CTX_VERIFY_POINTER_2(src, expr)
126#define GBL_CTX_VERIFY_POINTER(...)
133#define GBL_CTX_VERIFY_ARG_N(srcLoc, expr, ...)
134 GBL_CTX_VERIFY_(expr, GBL_RESULT_ERROR_INVALID_ARG, srcLoc, __VA_ARGS__)
136#define GBL_CTX_VERIFY_ARG_2(src, expr)
139#define GBL_CTX_VERIFY_ARG(...)
146#define GBL_CTX_VERIFY_TYPE_N(srcLoc, actualType, expectedType, ...)
147 GBL_CTX_VERIFY_(GblType_check(actualType, expectedType), GBL_RESULT_ERROR_TYPE_MISMATCH, srcLoc, __VA_ARGS__)
149#define GBL_CTX_VERIFY_TYPE_3(srcLoc, actualType, expectedType)
150 GBL_CTX_VERIFY_TYPE_N(srcLoc, actualType, expectedType, "Type mismatch [Actual: %s, Expected: %s]", GblType_name(actualType), GblType_name(expectedType))
152#define GBL_CTX_VERIFY_TYPE_2(srcLoc, actualType)
155#define GBL_CTX_VERIFY_TYPE(...)
162#define GBL_CTX_VERIFY_LAST_RECORD()
164 const GblCallRecord* pRecord =
165 GblThd_callRecord(NULL
);
172#define GBL_CTX_CLEAR_LAST_RECORD()
173 GblThd_setCallRecord(NULL
, NULL
)
177#ifdef GBL_CONFIG_ERRNO_CHECKS
178#define GBL_CTX_ERRNO_CLEAR() errno = 0
180#define GBL_CTX_ERRNO_CLEAR()
183#ifdef GBL_CONFIG_ERRNO_CHECKS
184# define GBL_CTX_PERROR(...)
186 if GBL_UNLIKELY(errno) {
187 const GBL_RESULT code =
188 GBL_ERRNO_RESULT(errno);
190 GBL_RESULT_SUCCESS(code),
192 "ERRNO: %s", strerror(errno));
196# define GBL_CTX_PERROR(...)
201 case 0:
return GBL_RESULT_SUCCESS;
202 default:
return GBL_RESULT_ERROR;
207#define GBL_CTX_INLINE_RETVAL() GBL_CTX_INLINE_RETURN_VALUE_NAME
209#define GBL_CTX_INLINE(MethodPrefix, ReturnType, ...)
211 ReturnType GBL_CTX_INLINE_RETURN_VALUE_NAME;
213#define GBL_CTX_INLINE_BEGIN(InitialRetValue)
217#define GBL_CTX_INLINE_END()
218 goto GBL_CTX_END_LABEL;
222#define GBL_CTX_INLINE_RETURN()
226#define GBL_CTX_INLINE_CALL_(MethodPrefix, srcLoc, ...)
229#define GBL_CTX_INLINE_CALL(MethodPrefix, ...)
234#define GBL_CTX_EXT(prefix, ...)
239 GBL_ASSERT(!(GBL_CONFIG_ASSERT_ERROR_ENABLED &&
241 "Ext["#prefix"]: ERROR");
242 GBL_ASSERT(!(GBL_CONFIG_ASSERT_PARTIAL_ENABLED &&
244 "Ext["#prefix"]: ERROR");
253 size = gblAlignedAllocSizeDefault(size);
256 GBL_CTX_EXT(memAlloc_, size, align, pDebugStr, &GBL_CTX_INLINE_RETVAL());
262#define GBL_CTX_MALLOC_4(src, size, align, dbgStr)
265#define GBL_CTX_MALLOC_3(src, size, align)
268#define GBL_CTX_MALLOC_2(src, size)
271#define GBL_CTX_MALLOC(...)
274#define GBL_CTX_NEW_4(src, type, count, dbgStr)
275 (type*)GBL_CTX_INLINE_CALL_(MALLOC, src, gblAlignedAllocSizeDefault(sizeof(type)*count), 0
, dbgStr)
277#define GBL_CTX_NEW_3(src, type, count)
280#define GBL_CTX_NEW_2(src, type)
283#define GBL_CTX_NEW(...)
289 GBL_CTX_EXT(memRealloc_, pData, newSize, newAlign, &GBL_CTX_INLINE_RETVAL());
295#define GBL_CTX_REALLOC_4(src, pData, newSize, newAlign)
298#define GBL_CTX_REALLOC_3(src, pData, newSize)
301#define GBL_CTX_REALLOC(...)
304#define GBL_CTX_RENEW_5(src, ptr, type, count, dbgStr)
307#define GBL_CTX_RENEW_4(src, ptr, type, count)
310#define GBL_CTX_RENEW_3(src, ptr, type)
313#define GBL_CTX_RENEW(...)
316#define GBL_CTX_FREE(pData)
319#define GBL_CTX_PUSH_(srcLoc, ...)
322 GblThd_logPush(NULL
);
328#define GBL_CTX_PUSH()
334#define GBL_CTX_PUSH_VERBOSE_N(srcLoc, pFmt, ...)
340#define GBL_CTX_PUSH_VERBOSE(...)
346#define GBL_CTX_POP_2(srcLoc, count)
347 GblThd_logPop(NULL
, count);
351#define GBL_CTX_POP_1(srcLoc)
354#define GBL_CTX_POP(...)
363 va_start(varArgs, pFmt);
371#define GBL_CTX_LOG_(src, level, pFmt, ...)
373#define GBL_CTX_LOG(level, pFmt, ...)
376#define GBL_CTX_DEBUG(pFmt, ...)
379#define GBL_CTX_VERBOSE(pFmt, ...)
382#define GBL_CTX_INFO(pFmt, ...)
385#define GBL_CTX_WARN(pFmt, ...)
388#define GBL_CTX_ERROR(pFmt, ...)
391#define GBL_CTX_EVENT(event)
402#define GBL_CTX_RECORD_ASSERT_(record, test)
404 GBL_ASSERT(!test(record->result), record->message);
408#define GBL_CTX_RECORD_ASSERT_CONDITIONAL_(enabled, record, test)
412#define GBL_CTX_RECORD_ASSERT_PARTIAL(record)
416#define GBL_CTX_RECORD_ASSERT_ERROR(record)
421#define GBL_CTX_RECORD_ASSERT_UNKNOWN(record)
425#define GBL_CTX_RECORD_ASSERT(record)
436#define GBL_CTX_RECORD_LOG_(prefix, record)
441 gblResultString(record->result), record->message);
447#define GBL_CTX_RECORD_LOG_CONDITIONAL_(prefix, record)
452#define GBL_CTX_RECORD_LOG_PARTIAL(record)
456#define GBL_CTX_RECORD_LOG_ERROR(record)
460#define GBL_CTX_RECORD_LOG_UNKNOWN(record)
464#define GBL_CTX_RECORD_LOG(record)
473#define GBL_CTX_RECORD_LAST_RECORD_(prefix, record)
475 if(GBL_RESULT_##prefix(record->result)) {
476 GblContext_callRecordSet_(GBL_CTX_CONTEXT(), GBL_CTX_FRAME_NAME, record);
477 GblThd_setCallRecord(NULL
, record);
481#define GBL_CTX_RECORD_LAST_RECORD_PARTIAL(record)
484#define GBL_CTX_RECORD_LAST_RECORD_ERROR(record)
487#define GBL_CTX_RECORD_LAST_RECORD_UNKNOWN(record)
490#define GBL_CTX_RECORD_LAST_RECORD(record)
498#define GBL_CTX_RECORD_HANDLER(record)
505#define GBL_CTX_RECORD_SET_N(file, func, line, result, ...)
513#define GBL_CTX_RECORD_SET_5(file, func, line, result, pFmt)
516#define GBL_CTX_RECORD_SET_4(file, func, line, result)
519#define GBL_CTX_RECORD_SET(...)
522#define GBL_CTX_CALL_N(src, funcCall, ...)
532#define GBL_CTX_CALL_2(src, funcCall)
535#define GBL_CTX_CALL(...)
541#define GBL_CTX_VERIFY_CALL(...)
551#define GBL_CTX_BEGIN_FRAME(file, func, line, pObject, frame)
554 GblThd_stackFramePush(NULL
, GBL_CTX_FRAME_NAME)
556#define GBL_CTX_BEGIN_LOG_4(file, func, line, hHandle)
559#define GBL_CTX_BEGIN_LOG_N(file, func, line, hHandle, ...)
560 GBL_CTX_BEGIN_LOG_5(file, func, line, hHandle);
563#define GBL_CTX_BEGIN(...)
566#define GBL_CTX_DONE()
567 goto GBL_CTX_END_LABEL
569#define GBL_CTX_END_BLOCK()
570 goto GBL_CTX_END_LABEL;
572 if(GBL_CTX_FRAME_NAME->stackDepth)
574 GblThd_stackFramePop(NULL
)
578 return GBL_CTX_FRAME_NAME->record.result
580#define GBL_CTX_END_EMPTY()
583#define GBL_CTX_BLOCK_6(file, func, line, hHandle, frame, block)
588#define GBL_CTX_BLOCK_5(file, func, line, hHandle, block)
589 GBL_CTX_BLOCK_7(file, func, line, hHandle, ((GblStackFrame*)GBL_ALLOCA(sizeof(GblStackFrame))), block)
591#define GBL_CTX_BLOCK_4(file, func, line, block)
594#define GBL_CTX_BLOCK(...)
#define GBL_UNLIKELY(exp)
#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.