xref: /redis-3.2.3/src/redisassert.h (revision 2d9e3eb1)
1ca294c6bSantirez /* redisassert.h -- Drop in replacemnet assert.h that prints the stack trace
2ca294c6bSantirez  *                  in the Redis logs.
3ca294c6bSantirez  *
4ca294c6bSantirez  * This file should be included instead of "assert.h" inside libraries used by
5ca294c6bSantirez  * Redis that are using assertions, so instead of Redis disappearing with
6ca294c6bSantirez  * SIGABORT, we get the details and stack trace inside the log file.
7ca294c6bSantirez  *
8ca294c6bSantirez  * ----------------------------------------------------------------------------
9ca294c6bSantirez  *
10ca294c6bSantirez  * Copyright (c) 2006-2012, Salvatore Sanfilippo <antirez at gmail dot com>
11ca294c6bSantirez  * All rights reserved.
12ca294c6bSantirez  *
13ca294c6bSantirez  * Redistribution and use in source and binary forms, with or without
14ca294c6bSantirez  * modification, are permitted provided that the following conditions are met:
15ca294c6bSantirez  *
16ca294c6bSantirez  *   * Redistributions of source code must retain the above copyright notice,
17ca294c6bSantirez  *     this list of conditions and the following disclaimer.
18ca294c6bSantirez  *   * Redistributions in binary form must reproduce the above copyright
19ca294c6bSantirez  *     notice, this list of conditions and the following disclaimer in the
20ca294c6bSantirez  *     documentation and/or other materials provided with the distribution.
21ca294c6bSantirez  *   * Neither the name of Redis nor the names of its contributors may be used
22ca294c6bSantirez  *     to endorse or promote products derived from this software without
23ca294c6bSantirez  *     specific prior written permission.
24ca294c6bSantirez  *
25ca294c6bSantirez  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26ca294c6bSantirez  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27ca294c6bSantirez  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28ca294c6bSantirez  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29ca294c6bSantirez  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30ca294c6bSantirez  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31ca294c6bSantirez  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32ca294c6bSantirez  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33ca294c6bSantirez  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34ca294c6bSantirez  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35ca294c6bSantirez  * POSSIBILITY OF SUCH DAMAGE.
36ca294c6bSantirez  */
37ca294c6bSantirez 
38ca294c6bSantirez #ifndef __REDIS_ASSERT_H__
39ca294c6bSantirez #define __REDIS_ASSERT_H__
40ca294c6bSantirez 
411c754084Santirez #include <unistd.h> /* for _exit() */
421c754084Santirez 
43*2d9e3eb1Santirez #define assert(_e) ((_e)?(void)0 : (_serverAssert(#_e,__FILE__,__LINE__),_exit(1)))
44ca294c6bSantirez 
45*2d9e3eb1Santirez void _serverAssert(char *estr, char *file, int line);
46ca294c6bSantirez 
47ca294c6bSantirez #endif
48