| 1 |
/* |
| 2 |
* libmowgli: A collection of useful routines for programming. |
| 3 |
* assert.h: Assertions. |
| 4 |
* |
| 5 |
* Copyright (c) 2007 William Pitcock <nenolod -at- sacredspiral.co.uk> |
| 6 |
* |
| 7 |
* Permission to use, copy, modify, and/or distribute this software for any |
| 8 |
* purpose with or without fee is hereby granted, provided that the above |
| 9 |
* copyright notice and this permission notice is present in all copies. |
| 10 |
* |
| 11 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 12 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 13 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 14 |
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
| 15 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 16 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 17 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 18 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 19 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 20 |
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 21 |
* POSSIBILITY OF SUCH DAMAGE. |
| 22 |
*/ |
| 23 |
|
| 24 |
#ifndef MOWGLI_SRC_LIBMOWGLI_CORE_ASSERT_H_INCLUDE_GUARD |
| 25 |
#define MOWGLI_SRC_LIBMOWGLI_CORE_ASSERT_H_INCLUDE_GUARD 1 |
| 26 |
|
| 27 |
#include "core/logger.h" |
| 28 |
|
| 29 |
#define _assert_msg(exp) "assertion '" #exp "' failed." |
| 30 |
|
| 31 |
#define soft_assert(exp) \ |
| 32 |
do \ |
| 33 |
{ \ |
| 34 |
if (!(exp)) \ |
| 35 |
{ \ |
| 36 |
mowgli_log_warning(_assert_msg(exp)); \ |
| 37 |
} \ |
| 38 |
} while (0) |
| 39 |
|
| 40 |
#define return_if_fail(exp) \ |
| 41 |
do \ |
| 42 |
{ \ |
| 43 |
if (!(exp)) \ |
| 44 |
{ \ |
| 45 |
mowgli_log_warning(_assert_msg(exp)); \ |
| 46 |
return; \ |
| 47 |
} \ |
| 48 |
} while (0) |
| 49 |
|
| 50 |
#define return_val_if_fail(exp, val) \ |
| 51 |
do \ |
| 52 |
{ \ |
| 53 |
if (!(exp)) \ |
| 54 |
{ \ |
| 55 |
mowgli_log_warning(_assert_msg(exp)); \ |
| 56 |
return (val); \ |
| 57 |
} \ |
| 58 |
} while (0) |
| 59 |
|
| 60 |
#define return_null_if_fail(exp) return_val_if_fail(exp, NULL) |
| 61 |
|
| 62 |
#endif /* MOWGLI_SRC_LIBMOWGLI_CORE_ASSERT_H_INCLUDE_GUARD */ |