Gunnar Dalsnes wrote:
In win32k i use macros for flow control in the NtUser syscalls (functionally like a try/finally block) where its very important that some cleanup (release a lock) is always done:
BOOL NtFunc() { DECLARE_RETURN(BOOL);
Lock(); if (Stuff) RETURN(FALSE); .... RETURN(TRUE);
CLEANUP: Unlock(Stuff); DPRINT1("NtFunc returned %i\n", _ret_); END_CLEANUP; }
Patterns like this can be done without macros. I've always been partial to the following style:
BOOL NtFunc() { BOOL bResult; void *pPointer = NULL;
Lock();
if (Stuff) { bResult = FALSE; goto cleanup; } ....
bResult = TRUE;
cleanup: if (pPointer) free(pPointer); Unlock(stuff); DPRINT1("NtFunc returned %i\n", bResult); return bResult; }
I know that many find goto's to be a crime against humanity, but I've always favored them for this sort of pattern.
-N