File: 0003-Add-support-for-USE_SYSTEM_JEMALLOC-flag.patch

package info (click to toggle)
redict 7.3.2%2Bds-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 14,896 kB
  • sloc: ansic: 129,309; tcl: 46,053; makefile: 930; python: 815; ruby: 572; sh: 482; javascript: 30
file content (128 lines) | stat: -rw-r--r-- 3,946 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
From: Chris Lamb <lamby@debian.org>
From: Maytham Alsudany <maytha8thedev@gmail.com>
Subject: Add support for USE_SYSTEM_JEMALLOC flag.
Forwarded: https://codeberg.org/redict/redict/pulls/40
Applied-Upstream: https://codeberg.org/redict/redict/commit/5defea5b98

---
 deps/Makefile |  2 ++
 src/Makefile  |  8 +++++++-
 src/debug.c   | 12 ++++++++----
 src/object.c  |  7 ++++++-
 src/sds.c     |  4 ++++
 src/zmalloc.c | 10 ++++++++++
 src/zmalloc.h |  4 ++++
 7 files changed, 41 insertions(+), 6 deletions(-)

--- a/deps/Makefile
+++ b/deps/Makefile
@@ -39,7 +39,9 @@
 	-(cd hiredict && $(MAKE) clean) > /dev/null || true
 	-(cd linenoise && $(MAKE) clean) > /dev/null || true
 	-(cd lua && $(MAKE) clean) > /dev/null || true
+ifneq ($(USE_SYSTEM_JEMALLOC),yes)
 	-(cd jemalloc && [ -f Makefile ] && $(MAKE) distclean) > /dev/null || true
+endif
 	-(cd hdr_histogram && $(MAKE) clean) > /dev/null || true
 	-(cd fpconv && $(MAKE) clean) > /dev/null || true
 	-(rm -f .make-*)
--- a/src/Makefile
+++ b/src/Makefile
@@ -266,10 +266,16 @@
 endif

 ifeq ($(MALLOC),jemalloc)
+	FINAL_CFLAGS+= -DUSE_JEMALLOC
+ifeq ($(USE_SYSTEM_JEMALLOC),yes)
+	FINAL_CFLAGS+= -DUSE_SYSTEM_JEMALLOC -I/usr/include/jemalloc/include
+	FINAL_LIBS := -ljemalloc $(FINAL_LIBS)
+else
 	DEPENDENCY_TARGETS+= jemalloc
-	FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include
+	FINAL_CFLAGS+= -I../deps/jemalloc/include
 	FINAL_LIBS := ../deps/jemalloc/lib/libjemalloc.a $(FINAL_LIBS)
 endif
+endif

 # LIBSSL & LIBCRYPTO
 LIBSSL_LIBS=
--- a/src/debug.c
+++ b/src/debug.c
@@ -56,6 +56,10 @@
 void logStackTrace(void *eip, int uplevel, int current_thread);
 void sigalrmSignalHandler(int sig, siginfo_t *info, void *secret);

+#if defined(USE_JEMALLOC) && defined(USE_SYSTEM_JEMALLOC)
+#define je_mallctl mallctl
+#endif
+
 /* ================================= Debugging ============================== */

 /* Compute the sha1 of string at 's' with 'len' bytes long.
--- a/src/object.c
+++ b/src/object.c
@@ -15,6 +15,11 @@
 #define strtold(a,b) ((long double)strtod((a),(b)))
 #endif

+#if defined(USE_JEMALLOC) && defined(USE_SYSTEM_JEMALLOC)
+#define je_mallctl mallctl
+#define je_malloc_stats_print malloc_stats_print
+#endif
+
 /* ===================== Creation and parsing of objects ==================== */

 robj *createObject(int type, void *ptr) {
--- a/src/sds.c
+++ b/src/sds.c
@@ -24,6 +24,10 @@
 #include "sds.h"
 #include "sdsalloc.h"

+#if defined(USE_JEMALLOC) && defined(USE_SYSTEM_JEMALLOC)
+#define je_nallocx nallocx
+#endif
+
 const char *SDS_NOINIT = "SDS_NOINIT";

 static inline int sdsHdrSize(char type) {
--- a/src/zmalloc.c
+++ b/src/zmalloc.c
@@ -56,6 +56,15 @@
 #define free(ptr) tc_free(ptr)
 /* Explicitly override malloc/free etc when using jemalloc. */
 #elif defined(USE_JEMALLOC)
+#if defined(USE_SYSTEM_JEMALLOC)
+#define malloc(size) malloc(size)
+#define calloc(count,size) calloc(count,size)
+#define realloc(ptr,size) realloc(ptr,size)
+#define free(ptr) free(ptr)
+#define mallocx(size,flags) mallocx(size,flags)
+#define dallocx(ptr,flags) dallocx(ptr,flags)
+#define je_mallctl mallctl
+#else
 #define malloc(size) je_malloc(size)
 #define calloc(count,size) je_calloc(count,size)
 #define realloc(ptr,size) je_realloc(ptr,size)
@@ -63,6 +72,7 @@
 #define mallocx(size,flags) je_mallocx(size,flags)
 #define dallocx(ptr,flags) je_dallocx(ptr,flags)
 #endif
+#endif

 #define update_zmalloc_stat_alloc(__n) atomicIncr(used_memory,(__n))
 #define update_zmalloc_stat_free(__n) atomicDecr(used_memory,(__n))
--- a/src/zmalloc.h
+++ b/src/zmalloc.h
@@ -27,7 +27,11 @@
 #include <jemalloc/jemalloc.h>
 #if (JEMALLOC_VERSION_MAJOR == 2 && JEMALLOC_VERSION_MINOR >= 1) || (JEMALLOC_VERSION_MAJOR > 2)
 #define HAVE_MALLOC_SIZE 1
+#if defined(USE_SYSTEM_JEMALLOC)
+#define zmalloc_size(p) malloc_usable_size(p)
+#else
 #define zmalloc_size(p) je_malloc_usable_size(p)
+#endif
 #else
 #error "Newer version of jemalloc required"
 #endif