libGimbal 0.0.0 (PRERELEASE)
Ultimate C17/C++20 Core Utility Library and Cross-Language Runtime Framework
gimbal_call_stack.h File Reference

Go to the source code of this file.

Data Structures

struct  GblSourceLocation
 
struct  GblCallRecord
 
struct  GblStackFrame
 

Functions

static GblThreadGblThread_current (void)
 
GblContextGblThread_context (const GblThread *pSelf)
 
static GblStackFrameGblThread_stackFrameTop (const GblThread *pSelf)
 
static void GBL_CALL_RECORD_CONSTRUCT (GblCallRecord *pRecord, struct GblObject *pObject, GBL_RESULT resultCode, GblSourceLocation source, const char *pFmt,...)
 
GblContextGblObject_findContext (GblObject *pSelf)
 
static GBL_RESULT GBL_CTX_STACK_FRAME_CONSTRUCT (GblStackFrame *pFrame, GblObject *pObject, GBL_RESULT initialResult)
 

Function Documentation

◆ GBL_CALL_RECORD_CONSTRUCT()

static void GBL_CALL_RECORD_CONSTRUCT ( GblCallRecord pRecord,
struct GblObject pObject,
GBL_RESULT  resultCode,
GblSourceLocation  source,
const char *  pFmt,
  ... 
)
inlinestatic

Definition at line 38 of file gimbal_call_stack.h.

38 {
39 va_list varArgs;
40 va_start(varArgs, pFmt);
41 pRecord->result = GBL_RESULT_UNKNOWN;
42 pRecord->message[0] = '\0';
43 pRecord->srcLocation.pFile = pRecord->srcLocation.pFunc = GBL_NULL;
44 if(pFmt) GBL_UNLIKELY vsnprintf(pRecord->message, sizeof(pRecord->message), pFmt, varArgs);
45 va_end(varArgs);
46 pRecord->srcLocation = source;
47 pRecord->result = resultCode;
48}

◆ GBL_CTX_STACK_FRAME_CONSTRUCT()

static GBL_RESULT GBL_CTX_STACK_FRAME_CONSTRUCT ( GblStackFrame pFrame,
GblObject pObject,
GBL_RESULT  initialResult 
)
inlinestatic

Definition at line 63 of file gimbal_call_stack.h.

63 {
64 GBL_RESULT result = GBL_RESULT_SUCCESS;
65 GblContext* pContext = GBL_NULL;
66
67 if(pObject) GBL_UNLIKELY {
68 const GblStackFrame* pPrev = GblThread_stackFrameTop(NULL);
69 if(pPrev && pPrev->pObject == pObject) GBL_LIKELY {
70 pContext = pPrev->pContext;
71 } else GBL_UNLIKELY {
72 pContext = GblObject_findContext(pObject);
73 }
74 }
75
76 if(!pContext) GBL_LIKELY {
77 pContext = GblThread_context(NULL);
78 }
79
80 pFrame->record.srcLocation.pFile = GBL_NULL;
81 pFrame->record.srcLocation.pFunc = GBL_NULL;
82 pFrame->record.result = initialResult;
83 pFrame->stackDepth = 0;
84 pFrame->sourceCurrentCaptureDepth = 0;
85 pFrame->pObject = pObject;
86 pFrame->pContext = pContext;
87 pFrame->pPrevFrame = NULL;
88 return result;
89}