From f15f79bdccb32b5c63d4dab975d84987896fa8c6 Mon Sep 17 00:00:00 2001 From: vng Date: Sun, 3 Jul 2011 12:53:14 +0300 Subject: [PATCH] Add SetAssertFunction. --- android/jni/logging.cpp | 2 +- base/assert.hpp | 7 ++++++- base/base.cpp | 8 +++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/android/jni/logging.cpp b/android/jni/logging.cpp index 715fbb4046..d5fc4a74a1 100644 --- a/android/jni/logging.cpp +++ b/android/jni/logging.cpp @@ -35,7 +35,7 @@ void InitSystemLog() void InitAssertLog() { - OnAssertFailed = &AndroidAssertMessage; + SetAssertFunction(&AndroidAssertMessage); } } diff --git a/base/assert.hpp b/base/assert.hpp index d5afe4b6c6..18fd915cbf 100644 --- a/base/assert.hpp +++ b/base/assert.hpp @@ -8,8 +8,13 @@ namespace my { // Called when ASSERT, CHECK or VERIFY failed. - extern void (*OnAssertFailed)(SrcPoint const &, string const &); + typedef void (*AssertFailedFn)(SrcPoint const &, string const &); + extern AssertFailedFn OnAssertFailed; + + /// @return Pointer to previous message function. + AssertFailedFn SetAssertFunction(AssertFailedFn fn); } + // TODO: Evaluate X only once in CHECK(). #define CHECK(X, msg) if (X) {} else { \ ::my::OnAssertFailed(SRC(), ::my::impl::MergeMsg("CHECK("#X")", ::my::impl::Message msg));} diff --git a/base/base.cpp b/base/base.cpp index 7649d272bd..fbb306bf89 100644 --- a/base/base.cpp +++ b/base/base.cpp @@ -32,5 +32,11 @@ namespace my #endif } - void (*OnAssertFailed)(SrcPoint const &, string const &) = &OnAssertFailedDefault; + AssertFailedFn OnAssertFailed = &OnAssertFailedDefault; + + AssertFailedFn SetAssertFunction(AssertFailedFn fn) + { + std::swap(OnAssertFailed, fn); + return fn; + } }