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