Skip to content

Commit

Permalink
Adding macros to enchance return and failure checks. (#1871)
Browse files Browse the repository at this point in the history
  • Loading branch information
msft-Jeyaram authored Jan 28, 2017
1 parent 1ed5a15 commit 794fbfd
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions Frameworks/include/wil/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,22 @@ typedef _Return_type_success_(return >= 0) LONG NTSTATUS;
return false; \
} \
} while (0, 0)
#define RETURN_IF(condition) \
do { \
if (condition) { \
return; \
} \
} while (0, 0)
#define RETURN_RESULT_IF(condition, result) \
do { \
if (condition) { \
return result; \
} \
} while (0, 0)

#define RETURN_FALSE_IF_FAILED(hr) RETURN_FALSE_IF(FAILED(hr));
#define RETURN_RESULT_IF_NULL(ptr, result) RETURN_RESULT_IF((ptr == nullptr), result);
#define RETURN_RESULT_IF_FAILED(hr, result) RETURN_RESULT_IF(FAILED(hr), result)

//*****************************************************************************
// Macros for logging failures (ignore or pass-through)
Expand Down Expand Up @@ -1932,8 +1948,7 @@ class shared_object {
}

template <typename param_t>
RefAndObject(param_t&& param1)
: m_refCount(1), m_object(wistd::forward<param_t>(param1)) {
RefAndObject(param_t&& param1) : m_refCount(1), m_object(wistd::forward<param_t>(param1)) {
}
};

Expand Down Expand Up @@ -5082,14 +5097,13 @@ void _rethrowNormalizedCaughtExceptionObjC(__R_FN_PARAMS_FULL, _In_opt_ PCWSTR m
}

// Misspelling is intentional
WI_HEADER_INITITALIZATION_FUNCTION(InitializeObjCExceptions,
[] {
g_resultFromUncaughtExceptionObjC = _resultFromUncaughtExceptionObjC;
g_rethrowAsNSException = _rethrowAsNSException;
g_objcThrowFailureInfo = _objcThrowFailureInfo;
g_rethrowNormalizedCaughtExceptionObjC = _rethrowNormalizedCaughtExceptionObjC;
return 1;
});
WI_HEADER_INITITALIZATION_FUNCTION(InitializeObjCExceptions, [] {
g_resultFromUncaughtExceptionObjC = _resultFromUncaughtExceptionObjC;
g_rethrowAsNSException = _rethrowAsNSException;
g_objcThrowFailureInfo = _objcThrowFailureInfo;
g_rethrowNormalizedCaughtExceptionObjC = _rethrowNormalizedCaughtExceptionObjC;
return 1;
});

#endif

Expand Down

0 comments on commit 794fbfd

Please sign in to comment.