Don't include config.h from serverassert.h (#404)

Serverassert is a drop-in replacement of assert. We use it even in code
copied from other sources. To make these files usable outside of Valkey,
it should be enough to replace the `serverassert.h` include with
`<assert.h>`. Therefore, this file shouldn't have any dependencies to
the rest of the valkey code.

---------

Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
This commit is contained in:
Viktor Söderqvist 2024-05-01 03:26:59 +02:00 committed by GitHub
parent 44f273d13b
commit 89f72bc3ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -38,7 +38,20 @@
#ifndef VALKEY_ASSERT_H
#define VALKEY_ASSERT_H
#include "config.h"
/* This file shouldn't have any dependencies to any other Valkey code. */
#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
#define valkey_unreachable __builtin_unreachable
#else
#include <stdlib.h>
#define valkey_unreachable abort
#endif
#if __GNUC__ >= 3
#define likely(x) __builtin_expect(!!(x), 1)
#else
#define likely(x) (x)
#endif
#define assert(_e) (likely((_e))?(void)0 : (_serverAssert(#_e,__FILE__,__LINE__),valkey_unreachable()))
#define panic(...) _serverPanic(__FILE__,__LINE__,__VA_ARGS__),valkey_unreachable()