t = (kherr_thread *) TlsGetValue(tls_error);
if (t) {
- if (t->n_ctx > 0)
- return t->ctx[t->n_ctx - 1];
- else
+ if (t->n_ctx > 0) {
+ kherr_context * c;
+
+ c = t->ctx[t->n_ctx - 1];
+
+ assert(c == NULL || IS_KHERR_CTX(c));
+
+ return c;
+ } else {
return NULL;
+ }
} else
return NULL;
}
if (t) {
if (t->n_ctx > 0) {
c = t->ctx[--(t->n_ctx)];
+ assert(IS_KHERR_CTX(c));
return c;
} else
return NULL;
}
void free_event_params(kherr_event * e) {
+ assert(IS_KHERR_EVENT(e));
if(parm_type(e->p1) == KEPT_STRINGT) {
assert((void *) parm_data(e->p1));
PFREE((void*) parm_data(e->p1));
EnterCriticalSection(&cs_error);
- assert(e->magic == KHERR_EVENT_MAGIC);
+ assert(IS_KHERR_EVENT(e));
#ifdef DEBUG_CONTEXT
kherr_debug_printf(L"Freeing event 0x%x\n", e);
kherr_context * ch;
kherr_event * e;
- assert(c->magic == KHERR_CONTEXT_MAGIC);
+ assert(IS_KHERR_CTX(c));
+
#ifdef DEBUG_CONTEXT
kherr_debug_printf(L"Freeing context 0x%x\n", c);
#endif
{
kherr_event * te;
+ assert(IS_KHERR_CTX(c));
+ assert(IS_KHERR_EVENT(e));
+
EnterCriticalSection(&cs_error);
te = QBOTTOM(c);
if (te && !(te->flags & KHERR_RF_COMMIT)) {
KHMEXP void KHMAPI kherr_evaluate_event(kherr_event * e) {
- if (!e)
+ if (!IS_KHERR_EVENT(e))
return;
EnterCriticalSection(&cs_error);
DWORD tid;
c = peek_context();
- if(!c)
+ if(!IS_KHERR_CTX(c))
return;
tid = GetCurrentThreadId();
while (e != NULL && e->thread_id != tid)
e = QPREV(e);
- if(!e)
+ if(!IS_KHERR_EVENT(e))
goto _exit;
resolve_event_strings(e);
,NULL
#endif
);
- if (e) {
+ if (IS_KHERR_EVENT(e)) {
kherr_evaluate_event(e);
}
,hModule
#endif
);
- if (e) {
+ if (IS_KHERR_EVENT(e)) {
kherr_evaluate_event(e);
}
return;
c = peek_context();
- if(!c)
+ if(!IS_KHERR_CTX(c))
return;
tid = GetCurrentThreadId();
while (e != NULL && e->thread_id != tid)
e = QPREV(e);
- if(!e)
+ if(!IS_KHERR_EVENT(e))
goto _exit;
/* if strings have already been resolved in this event, we cant
DWORD tid;
c = peek_context();
- if(!c)
+ if(!IS_KHERR_CTX(c))
return;
tid = GetCurrentThreadId();
while (e != NULL && e->thread_id != tid)
e = QPREV(e);
- if(!e)
+ if(!IS_KHERR_EVENT(e))
goto _exit;
e->location = location;
_exit:
DWORD tid;
c = peek_context();
- if(!c)
+ if(!IS_KHERR_CTX(c))
return;
tid = GetCurrentThreadId();
EnterCriticalSection(&cs_error);
while (e != NULL && e->thread_id != tid)
e = QPREV(e);
- if(!e)
+ if(!IS_KHERR_EVENT(e))
goto _exit;
e->facility = facility;
e->facility_id = facility_id;
DWORD tid;
c = peek_context();
- if(!c)
+ if(!IS_KHERR_CTX(c))
return;
tid = GetCurrentThreadId();
while (e != NULL && e->thread_id != tid)
e = QPREV(e);
- if(!e || c->desc_event)
+ if(!IS_KHERR_EVENT(e) || c->desc_event)
goto _exit;
QDEL(c,e);
c = peek_context();
- if(!c)
+ if(!IS_KHERR_CTX(c))
return;
tid = GetCurrentThreadId();
while (e != NULL && e->thread_id != tid)
e = QPREV(e);
- if(e) {
+ if(IS_KHERR_EVENT(e)) {
QDEL(c, e);
if(c->err_event == e) {
pick_err_event(c);
KHMEXP void KHMAPI kherr_push_context(kherr_context * c)
{
- kherr_context * p;
+ kherr_context * p = NULL;
int new_context = FALSE;
+ if (!IS_KHERR_CTX(c))
+ return;
+
EnterCriticalSection(&cs_error);
p = peek_context();
- if(p && (c->flags & KHERR_CF_UNBOUND)) {
+ if(IS_KHERR_CTX(p) && (c->flags & KHERR_CF_UNBOUND)) {
LDELETE(&ctx_root_list, c);
TADDCHILD(p,c);
c->flags &= ~KHERR_CF_UNBOUND;
}
push_context(c);
- if (new_context)
+ if (new_context && IS_KHERR_CTX(p)) {
notify_ctx_event(KHERR_CTX_BEGIN, c);
+ }
LeaveCriticalSection(&cs_error);
}
KHMEXP void KHMAPI kherr_push_new_context(khm_int32 flags)
{
- kherr_context * p;
+ kherr_context * p = NULL;
kherr_context * c;
flags &= KHERR_CFMASK_INITIAL;
EnterCriticalSection(&cs_error);
p = peek_context();
c = get_empty_context();
- if(p) {
+ if(IS_KHERR_CTX(p)) {
LDELETE(&ctx_root_list, c);
TADDCHILD(p,c);
c->flags &= ~KHERR_CF_UNBOUND;
push_context(c);
notify_ctx_event(KHERR_CTX_BEGIN, c);
+ if (IS_KHERR_CTX(p)) {
+ notify_ctx_event(KHERR_CTX_NEWCHILD, p);
+ }
LeaveCriticalSection(&cs_error);
}
kherr_event * e;
kherr_event * g;
- if (!c)
+ if (!IS_KHERR_CTX(c))
return NULL;
EnterCriticalSection(&cs_error);
c->desc_event = NULL;
}
- if (e)
+ if (IS_KHERR_EVENT(e))
e->flags |= KHERR_RF_CONTEXT_FOLD;
LeaveCriticalSection(&cs_error);
}
KHMEXP void KHMAPI kherr_hold_context(kherr_context * c) {
- assert(c && c->magic == KHERR_CONTEXT_MAGIC);
+
+ if(!IS_KHERR_CTX(c))
+ return;
EnterCriticalSection(&cs_error);
c->refcount++;
LeaveCriticalSection(&cs_error);
}
KHMEXP void KHMAPI kherr_release_context(kherr_context * c) {
- assert(c && c->magic == KHERR_CONTEXT_MAGIC);
+ if (!IS_KHERR_CTX(c))
+ return;
+
EnterCriticalSection(&cs_error);
c->refcount--;
if (c->refcount == 0) {
kherr_context * p;
e = QBOTTOM(c);
- if (e && !(e->flags & KHERR_RF_COMMIT)) {
+ if (IS_KHERR_EVENT(e) && !(e->flags & KHERR_RF_COMMIT)) {
notify_ctx_event(KHERR_CTX_EVTCOMMIT, c);
e->flags |= KHERR_RF_COMMIT;
}
notify_ctx_event(KHERR_CTX_END, c);
p = TPARENT(c);
- if (p) {
+ if (IS_KHERR_CTX(p)) {
e = fold_context(c);
if (e)
add_event(p, e);
EnterCriticalSection(&cs_error);
c = pop_context();
- if(c) {
+ if(IS_KHERR_CTX(c)) {
kherr_release_context(c);
}
LeaveCriticalSection(&cs_error);
kherr_context * c;
c = peek_context();
- if (c)
+ if (IS_KHERR_CTX(c))
kherr_hold_context(c);
return c;
}
KHMEXP khm_boolean KHMAPI kherr_is_error_i(kherr_context * c) {
- if(c && c->severity <= KHERR_ERROR)
+ if(IS_KHERR_CTX(c) && c->severity <= KHERR_ERROR)
return TRUE;
else
return FALSE;
KHMEXP void KHMAPI kherr_clear_error(void) {
kherr_context * c = peek_context();
- if (c)
+ if (IS_KHERR_CTX(c))
kherr_clear_error_i(c);
}
KHMEXP void KHMAPI kherr_clear_error_i(kherr_context * c) {
kherr_event * e;
- if (c) {
+ if (IS_KHERR_CTX(c)) {
EnterCriticalSection(&cs_error);
e = QTOP(c);
while(e) {
+ assert(IS_KHERR_EVENT(e));
+
e->flags |= KHERR_RF_INERT;
e = QNEXT(e);
}
kherr_set_progress(khm_ui_4 num, khm_ui_4 denom)
{
kherr_context * c = peek_context();
- if(c) {
+ if(IS_KHERR_CTX(c)) {
EnterCriticalSection(&cs_error);
if (num > denom)
notify_ctx_event(KHERR_CTX_PROGRESS, c);
for (p = TPARENT(c);
- p && !CTX_USES_OWN_PROGRESS(p);
+ IS_KHERR_CTX(p) && !CTX_USES_OWN_PROGRESS(p);
p = TPARENT(p)) {
notify_ctx_event(KHERR_CTX_PROGRESS, p);
khm_ui_4 cnum, cdenom;
- assert(cc);
+ assert(IS_KHERR_CTX(cc));
get_progress(cc, &cnum, &cdenom);
KHMEXP kherr_event * KHMAPI kherr_get_first_event(kherr_context * c)
{
kherr_event * e;
+
+ if (!IS_KHERR_CTX(c))
+ return NULL;
+
EnterCriticalSection(&cs_error);
e = QTOP(c);
LeaveCriticalSection(&cs_error);
+ assert(e == NULL || IS_KHERR_EVENT(e));
return e;
}
{
kherr_event * ee;
+ if (!IS_KHERR_EVENT(e))
+ return NULL;
+
EnterCriticalSection(&cs_error);
ee = QNEXT(e);
LeaveCriticalSection(&cs_error);
+ assert(ee == NULL || IS_KHERR_EVENT(ee));
return ee;
}
{
kherr_event * ee;
+ if (!IS_KHERR_EVENT(e))
+ return NULL;
+
EnterCriticalSection(&cs_error);
ee = QPREV(e);
LeaveCriticalSection(&cs_error);
-
+ assert(ee == NULL || IS_KHERR_EVENT(ee));
return ee;
}
KHMEXP kherr_event * KHMAPI kherr_get_last_event(kherr_context * c)
{
kherr_event * e;
+
+ if (!IS_KHERR_CTX(c))
+ return NULL;
+
EnterCriticalSection(&cs_error);
e = QBOTTOM(c);
LeaveCriticalSection(&cs_error);
+ assert(e == NULL || IS_KHERR_EVENT(e));
return e;
}
{
kherr_context * cc;
+ if (c != NULL && !IS_KHERR_CTX(c))
+ return NULL;
+
EnterCriticalSection(&cs_error);
- if (c) {
+ if (IS_KHERR_CTX(c)) {
cc = TFIRSTCHILD(c);
if (cc)
kherr_hold_context(cc);
kherr_hold_context(cc);
}
LeaveCriticalSection(&cs_error);
+ assert(cc == NULL || IS_KHERR_CTX(cc));
return cc;
}
KHMEXP kherr_context * KHMAPI kherr_get_next_context(kherr_context * c)
{
kherr_context * cc;
+
+ if (!IS_KHERR_CTX(c))
+ return NULL;
+
EnterCriticalSection(&cs_error);
cc = LNEXT(c);
if (cc)
kherr_hold_context(cc);
LeaveCriticalSection(&cs_error);
+ assert(cc == NULL || IS_KHERR_CTX(cc));
return cc;
}
KHMEXP kherr_event * KHMAPI kherr_get_err_event(kherr_context * c)
{
kherr_event * e;
+
+ if (!IS_KHERR_CTX(c))
+ return NULL;
+
EnterCriticalSection(&cs_error);
if(!c->err_event) {
pick_err_event(c);
}
e = c->err_event;
LeaveCriticalSection(&cs_error);
+ assert(e == NULL || IS_KHERR_EVENT(e));
return e;
}
{
kherr_event * e;
+ if (!IS_KHERR_CTX(c))
+ return NULL;
+
EnterCriticalSection(&cs_error);
e = c->desc_event;
LeaveCriticalSection(&cs_error);
+ assert(e == NULL || IS_KHERR_EVENT(e));
return e;
}