mirror of https://github.com/valkey-io/valkey
Merge d971037ff1 into 8ab0152bef
This commit is contained in:
commit
d95b2a7557
|
|
@ -19,7 +19,9 @@ option(BUILD_EXAMPLE_MODULES "Build example modules" OFF)
|
|||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
|
||||
project("valkey")
|
||||
add_compile_options(-Wundef)
|
||||
if (NOT WIN32)
|
||||
add_compile_options(-Wundef)
|
||||
endif (NOT WIN32)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
|
|
|
|||
|
|
@ -99,7 +99,9 @@ macro (valkey_build_and_install_bin target sources ld_flags libs link_name)
|
|||
endif ()
|
||||
|
||||
# Enable all warnings + fail on warning
|
||||
target_compile_options(${target} PRIVATE -Werror -Wall)
|
||||
if (NOT WIN32)
|
||||
target_compile_options(${target} PRIVATE -Werror -Wall)
|
||||
endif (NOT WIN32)
|
||||
|
||||
# Install cli tool and create a redis symbolic link
|
||||
valkey_install_bin(${target})
|
||||
|
|
@ -245,14 +247,15 @@ elseif (UNIX)
|
|||
add_valkey_server_linker_option("-lm")
|
||||
endif ()
|
||||
|
||||
if (VALKEY_DEBUG_BUILD)
|
||||
if (VALKEY_DEBUG_BUILD AND NOT WIN32)
|
||||
# Debug build, use enable "-fno-omit-frame-pointer"
|
||||
add_valkey_server_compiler_options("-fno-omit-frame-pointer")
|
||||
endif ()
|
||||
|
||||
# Check for Atomic
|
||||
check_include_files(stdatomic.h HAVE_C11_ATOMIC)
|
||||
if (HAVE_C11_ATOMIC)
|
||||
if (WIN32)
|
||||
elseif (HAVE_C11_ATOMIC)
|
||||
add_valkey_server_compiler_options("-std=gnu11")
|
||||
else ()
|
||||
add_valkey_server_compiler_options("-std=c99")
|
||||
|
|
@ -291,7 +294,9 @@ if (USE_JEMALLOC)
|
|||
endif ()
|
||||
|
||||
# Common compiler flags
|
||||
add_valkey_server_compiler_options("-pedantic")
|
||||
if (NOT WIN32)
|
||||
add_valkey_server_compiler_options("-pedantic")
|
||||
endif ()
|
||||
|
||||
# ----------------------------------------------------
|
||||
# Build options (allocator, tls, rdma et al) - end
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
cmake_minimum_required(VERSION 3.7.0)
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
macro(getDefinedVersion name)
|
||||
set(VERSION_REGEX "^#define LIBVALKEY_${name} (.+)$")
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
cmake_minimum_required(VERSION 3.7.0)
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(examples LANGUAGES C)
|
||||
|
||||
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
|
||||
|
|
|
|||
|
|
@ -47,6 +47,12 @@ typedef SSIZE_T ssize_t;
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop))
|
||||
#else
|
||||
#define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__))
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
|
@ -55,34 +61,34 @@ typedef char *sds;
|
|||
|
||||
/* Note: sdshdr5 is never used, we just access the flags byte directly.
|
||||
* However is here to document the layout of type 5 SDS strings. */
|
||||
struct __attribute__((__packed__)) sdshdr5 {
|
||||
PACK(struct sdshdr5 {
|
||||
unsigned char flags; /* 3 lsb of type, and 5 msb of string length */
|
||||
char buf[];
|
||||
};
|
||||
struct __attribute__((__packed__)) sdshdr8 {
|
||||
});
|
||||
PACK(struct sdshdr8 {
|
||||
uint8_t len; /* used */
|
||||
uint8_t alloc; /* excluding the header and null terminator */
|
||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||
char buf[];
|
||||
};
|
||||
struct __attribute__((__packed__)) sdshdr16 {
|
||||
});
|
||||
PACK(struct sdshdr16 {
|
||||
uint16_t len; /* used */
|
||||
uint16_t alloc; /* excluding the header and null terminator */
|
||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||
char buf[];
|
||||
};
|
||||
struct __attribute__((__packed__)) sdshdr32 {
|
||||
});
|
||||
PACK(struct sdshdr32 {
|
||||
uint32_t len; /* used */
|
||||
uint32_t alloc; /* excluding the header and null terminator */
|
||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||
char buf[];
|
||||
};
|
||||
struct __attribute__((__packed__)) sdshdr64 {
|
||||
});
|
||||
PACK(struct sdshdr64 {
|
||||
uint64_t len; /* used */
|
||||
uint64_t alloc; /* excluding the header and null terminator */
|
||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||
char buf[];
|
||||
};
|
||||
});
|
||||
|
||||
#define SDS_TYPE_5 0
|
||||
#define SDS_TYPE_8 1
|
||||
|
|
|
|||
|
|
@ -96,6 +96,10 @@ __inline int c99_snprintf(char *str, size_t size, const char *format, ...) {
|
|||
#define random rand
|
||||
#endif
|
||||
|
||||
#ifndef SSIZE_MAX
|
||||
#define SSIZE_MAX MAXSSIZE_T
|
||||
#endif /* !SSIZE_MAX */
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#endif /* VALKEY_WIN32_H */
|
||||
|
|
|
|||
|
|
@ -105,8 +105,11 @@
|
|||
|
||||
#define _DEFAULT_SOURCE /* For fchmod() */
|
||||
#define _BSD_SOURCE /* For fchmod() */
|
||||
#ifdef _MSC_VER
|
||||
#else
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@
|
|||
#define LUA_BITOP_VERSION "1.0.2"
|
||||
|
||||
#define LUA_LIB
|
||||
#include <stdint.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,34 @@ valkey_build_and_install_bin(valkey-server "${VALKEY_SERVER_SRCS}" "${VALKEY_SER
|
|||
"redis-server")
|
||||
add_dependencies(valkey-server generate_commands_def)
|
||||
add_dependencies(valkey-server generate_fmtargs_h)
|
||||
add_dependencies(valkey-server release_header)
|
||||
if (WIN32)
|
||||
execute_process(COMMAND git log -1 --format=%H
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||
OUTPUT_VARIABLE GIT_SHA1
|
||||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
execute_process(COMMAND git status --porcelain
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||
OUTPUT_VARIABLE GIT_PORCELAIN
|
||||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if (GIT_PORCELAIN)
|
||||
set(GIT_DIRTY 0)
|
||||
else ()
|
||||
set(GIT_DIRTY 1)
|
||||
endif ()
|
||||
if (NOT DEFINED CMAKE_SYSTEM_NAME)
|
||||
set(CMAKE_SYSTEM_NAME "${CMAKE_HOST_SYSTEM_NAME}")
|
||||
endif (NOT DEFINED CMAKE_SYSTEM_NAME)
|
||||
string(TIMESTAMP now "%s" UTC)
|
||||
set(BUILD_ID "${CMAKE_SYSTEM_NAME}_${now}")
|
||||
set(BUILD_ID_RAW "${BUILD_ID}") # is this right?
|
||||
configure_file(
|
||||
"${CMAKE_SOURCE_DIR}/src/release.h.in"
|
||||
"${CMAKE_SOURCE_DIR}/src/release.h" @ONLY
|
||||
)
|
||||
else ()
|
||||
add_dependencies(valkey-server release_header)
|
||||
endif ()
|
||||
|
||||
if (VALKEY_RELEASE_BUILD)
|
||||
# Enable LTO for Release build
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@
|
|||
#include "fmacros.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifdef _MSC_VER
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/un.h>
|
||||
|
|
@ -39,13 +41,14 @@
|
|||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
#include <netdb.h>
|
||||
#include <grp.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <grp.h>
|
||||
|
||||
#include "anet.h"
|
||||
#include "config.h"
|
||||
|
|
|
|||
|
|
@ -51,6 +51,11 @@
|
|||
#undef ip_len
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <basetsd.h>
|
||||
typedef SSIZE_T ssize_t;
|
||||
#endif
|
||||
|
||||
int anetTcpNonBlockConnect(char *err, const char *addr, int port);
|
||||
int anetTcpNonBlockBestEffortBindConnect(char *err, const char *addr, int port, const char *source_addr, int mptcp);
|
||||
int anetResolve(char *err, char *host, char *ipbuf, size_t ipbuf_len, int flags);
|
||||
|
|
|
|||
|
|
@ -38,9 +38,15 @@
|
|||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include "sds.h"
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef USE_OPENSSL
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
|
|
|
|||
17
src/config.h
17
src/config.h
|
|
@ -30,7 +30,10 @@
|
|||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#else
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <fcntl.h> // for fcntl(fd, F_FULLFSYNC)
|
||||
|
|
@ -216,7 +219,18 @@ void setproctitle(const char *fmt, ...);
|
|||
#include <sys/types.h> /* This will likely define BYTE_ORDER */
|
||||
|
||||
#ifndef BYTE_ORDER
|
||||
#if (BSD >= 199103)
|
||||
#if defined(MSC_VER)
|
||||
/*#include <winsock2.h>
|
||||
#include <sys/param.h>*/
|
||||
#define IS_BIG_ENDIAN (*(uint16_t *)"\0\x1" == 0x1)
|
||||
#ifdef IS_BIG_ENDIAN
|
||||
#define BIG_ENDIAN
|
||||
#define BYTE_ORDER BIG_ENDIAN
|
||||
#else
|
||||
#define LITTLE_ENDIAN
|
||||
#define BYTE_ORDER LITTLE_ENDIAN
|
||||
#endif
|
||||
#elif (BSD >= 199103)
|
||||
#include <machine/endian.h>
|
||||
#else
|
||||
#if defined(linux) || defined(__linux__)
|
||||
|
|
@ -238,7 +252,6 @@ void setproctitle(const char *fmt, ...);
|
|||
defined(__hp9000s300) || defined(__hp9000s700) || defined(BIT_ZERO_ON_LEFT) || defined(m68k) || \
|
||||
defined(__sparc) || (defined(__APPLE__) && defined(__POWERPC__))
|
||||
#define BYTE_ORDER BIG_ENDIAN
|
||||
#endif
|
||||
#endif /* linux */
|
||||
#endif /* BSD */
|
||||
#endif /* BYTE_ORDER */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#ifndef _MSC_VER
|
||||
#include <strings.h>
|
||||
#endif
|
||||
#if defined(__i386__) || defined(__X86_64__)
|
||||
#include <immintrin.h>
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -13,7 +13,10 @@
|
|||
|
||||
#include "fmacros.h"
|
||||
#include <stdint.h>
|
||||
#ifdef _MSC_VER
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
/* A counter in micro-seconds. The 'monotime' type is provided for variables
|
||||
* holding a monotonic time. This will help distinguish & document that the
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Valkey authors
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Redis nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef VALKEY_RELEASE_H
|
||||
#define VALKEY_RELEASE_H
|
||||
|
||||
#include "version.h"
|
||||
|
||||
#define REDIS_GIT_SHA1 "@GIT_SHA1@"
|
||||
#define REDIS_GIT_DIRTY @GIT_DIRTY@
|
||||
#define REDIS_BUILD_ID "@BUILD_ID@"
|
||||
#define REDIS_BUILD_ID_RAW "@BUILD_ID_RAW@"
|
||||
|
||||
#endif /* !VALKEY_RELEASE_H */
|
||||
32
src/sds.h
32
src/sds.h
|
|
@ -32,6 +32,12 @@
|
|||
#ifndef __SDS_H
|
||||
#define __SDS_H
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop))
|
||||
#else
|
||||
#define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__))
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
#define SDS_MAX_PREALLOC (1024 * 1024)
|
||||
extern const char *SDS_NOINIT;
|
||||
|
||||
|
|
@ -50,34 +56,34 @@ typedef const char *const_sds;
|
|||
|
||||
/* Note: sdshdr5 is never used, we just access the flags byte directly.
|
||||
* However is here to document the layout of type 5 SDS strings. */
|
||||
struct __attribute__((__packed__)) sdshdr5 {
|
||||
PACK(struct sdshdr5 {
|
||||
unsigned char flags; /* 3 lsb of type, and 5 msb of string length */
|
||||
char buf[];
|
||||
};
|
||||
struct __attribute__((__packed__)) sdshdr8 {
|
||||
});
|
||||
PACK(struct sdshdr8 {
|
||||
uint8_t len; /* used */
|
||||
uint8_t alloc; /* excluding the header and null terminator */
|
||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||
char buf[];
|
||||
};
|
||||
struct __attribute__((__packed__)) sdshdr16 {
|
||||
});
|
||||
PACK(struct sdshdr16 {
|
||||
uint16_t len; /* used */
|
||||
uint16_t alloc; /* excluding the header and null terminator */
|
||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||
char buf[];
|
||||
};
|
||||
struct __attribute__((__packed__)) sdshdr32 {
|
||||
});
|
||||
PACK(struct sdshdr32 {
|
||||
uint32_t len; /* used */
|
||||
uint32_t alloc; /* excluding the header and null terminator */
|
||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||
char buf[];
|
||||
};
|
||||
struct __attribute__((__packed__)) sdshdr64 {
|
||||
});
|
||||
PACK(struct sdshdr64 {
|
||||
uint64_t len; /* used */
|
||||
uint64_t alloc; /* excluding the header and null terminator */
|
||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||
char buf[];
|
||||
};
|
||||
});
|
||||
|
||||
#define SDS_TYPE_5 0
|
||||
#define SDS_TYPE_8 1
|
||||
|
|
@ -234,11 +240,11 @@ sds sdscatprintf(sds s, const char *fmt, ...);
|
|||
sds sdscatfmt(sds s, char const *fmt, ...);
|
||||
sds sdstrim(sds s, const char *cset);
|
||||
void sdssubstr(sds s, size_t start, size_t len);
|
||||
void sdsrange(sds s, ssize_t start, ssize_t end);
|
||||
void sdsrange(sds s, ptrdiff_t start, ptrdiff_t end);
|
||||
void sdsupdatelen(sds s);
|
||||
void sdsclear(sds s);
|
||||
int sdscmp(const_sds s1, const_sds s2);
|
||||
sds *sdssplitlen(const char *s, ssize_t len, const char *sep, int seplen, int *count);
|
||||
sds *sdssplitlen(const char *s, ptrdiff_t len, const char *sep, int seplen, int *count);
|
||||
void sdsfreesplitres(sds *tokens, int count);
|
||||
void sdstolower(sds s);
|
||||
void sdstoupper(sds s);
|
||||
|
|
@ -263,7 +269,7 @@ int sdsHdrSize(char type);
|
|||
char sdsReqType(size_t string_size);
|
||||
sds sdsMakeRoomFor(sds s, size_t addlen);
|
||||
sds sdsMakeRoomForNonGreedy(sds s, size_t addlen);
|
||||
void sdsIncrLen(sds s, ssize_t incr);
|
||||
void sdsIncrLen(sds s, ptrdiff_t incr);
|
||||
sds sdsRemoveFreeSpace(sds s, int would_regrow);
|
||||
sds sdsResize(sds s, size_t size, int would_regrow);
|
||||
size_t sdsAllocSize(const_sds s);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,9 @@
|
|||
#include "fmacros.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifndef _MSC_VER
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
/** This is an API to invoke callback on a list of threads using a user defined signal handler.
|
||||
* NOTE: This is API is only supported only in linux systems.
|
||||
|
|
|
|||
|
|
@ -1,33 +1,3 @@
|
|||
/* zmalloc - total amount of allocated memory aware version of malloc()
|
||||
*
|
||||
* Copyright (c) 2009-2010, Redis Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Redis nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __ZMALLOC_H
|
||||
#define __ZMALLOC_H
|
||||
|
||||
|
|
@ -65,12 +35,12 @@
|
|||
#endif
|
||||
|
||||
/* On native libc implementations, we should still do our best to provide a
|
||||
* HAVE_MALLOC_SIZE capability. This can be set explicitly as well:
|
||||
* HAVE_MALLOC_SIZE capability.
|
||||
*
|
||||
* NO_MALLOC_USABLE_SIZE disables it on all platforms, even if they are
|
||||
* known to support it.
|
||||
* known to support it.
|
||||
* USE_MALLOC_USABLE_SIZE forces use of malloc_usable_size() regardless
|
||||
* of platform.
|
||||
* of platform.
|
||||
*/
|
||||
#ifndef ZMALLOC_LIB
|
||||
#define ZMALLOC_LIB "libc"
|
||||
|
|
@ -103,15 +73,24 @@
|
|||
/* The zcalloc symbol is a symbol name already used by zlib, which is defining
|
||||
* other names using the "z" prefix specific to zlib. In practice, linking
|
||||
* valkey with a static openssl, which itself might depend on a static libz
|
||||
* will result in link time error rejecting multiple symbol definitions. */
|
||||
#define zmalloc valkey_malloc
|
||||
#define zcalloc valkey_calloc
|
||||
#define zrealloc valkey_realloc
|
||||
#define zfree valkey_free
|
||||
* will result in a link time error rejecting multiple symbol definitions.
|
||||
*/
|
||||
#define zmalloc valkey_malloc
|
||||
#define zcalloc valkey_calloc
|
||||
#define zrealloc valkey_realloc
|
||||
#define zfree valkey_free
|
||||
|
||||
/* On MSVC, the GNU __attribute__ syntax is not supported.
|
||||
* We define it as a variadic macro that discards its arguments.
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
#define __attribute__(...) /* nothing */
|
||||
#endif
|
||||
|
||||
/* 'noinline' attribute is intended to prevent the `-Wstringop-overread` warning
|
||||
* when using gcc-12 later with LTO enabled. It may be removed once the
|
||||
* bug[https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96503] is fixed. */
|
||||
* when using gcc-12 later with LTO enabled. It may be removed once the bug
|
||||
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96503 is fixed.
|
||||
*/
|
||||
__attribute__((malloc, alloc_size(1), noinline)) void *zmalloc(size_t size);
|
||||
__attribute__((malloc, alloc_size(1), noinline)) void *zcalloc(size_t size);
|
||||
__attribute__((malloc, alloc_size(1, 2), noinline)) void *zcalloc_num(size_t num, size_t size);
|
||||
|
|
@ -151,15 +130,13 @@ size_t zmalloc_usable_size(void *ptr);
|
|||
* obtained from z[*]_usable() family functions, there is no need for this step. */
|
||||
#define zmalloc_usable_size(p) zmalloc_size(p)
|
||||
|
||||
/* derived from https://github.com/systemd/systemd/pull/25688
|
||||
* We use zmalloc_usable_size() everywhere to use memory blocks, but that is an abuse since the
|
||||
* malloc_usable_size() isn't meant for this kind of use, it is for diagnostics only. That is also why the
|
||||
* behavior is flaky when built with _FORTIFY_SOURCE, the compiler can sense that we reach outside
|
||||
* the allocated block and SIGABRT.
|
||||
* We use a dummy allocator function to tell the compiler that the new size of ptr is newsize.
|
||||
* The implementation returns the pointer as is; the only reason for its existence is as a conduit for the
|
||||
* alloc_size attribute. This cannot be a static inline because gcc then loses the attributes on the function.
|
||||
* See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96503 */
|
||||
/* Derived from https://github.com/systemd/systemd/pull/25688
|
||||
* We use zmalloc_usable_size() everywhere to use memory blocks, but that is an
|
||||
* abuse of malloc_usable_size(). The extend_to_usable function is a dummy
|
||||
* allocator function that notifies the compiler of updated pointer size.
|
||||
* The function simply returns the pointer as is; its sole purpose is to carry
|
||||
* the alloc_size attribute.
|
||||
*/
|
||||
__attribute__((alloc_size(2), noinline)) void *extend_to_usable(void *ptr, size_t size);
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue