Skip to content

Commit

Permalink
Don't include config.h from serverassert.h (#404)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
zuiderkwast committed May 1, 2024
1 parent 44f273d commit 89f72bc
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/serverassert.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 89f72bc

Please sign in to comment.