aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/fstring.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-06-16 12:22:19 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-06-16 12:22:19 +0100
commit1a001969a95249b50bd92bf7ea5374159e583ec6 (patch)
treeced8db6f35c93440bb0d7d87581e7d49af90d843 /src/libutil/fstring.c
parent9affb3d2b3d63de12dcb775c675f3a1f48486df8 (diff)
downloadrspamd-1a001969a95249b50bd92bf7ea5374159e583ec6.tar.gz
rspamd-1a001969a95249b50bd92bf7ea5374159e583ec6.zip
[Minor] Support old jemalloc and osx system allocator
Diffstat (limited to 'src/libutil/fstring.c')
-rw-r--r--src/libutil/fstring.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/libutil/fstring.c b/src/libutil/fstring.c
index 65f24dccc..6c51ad62e 100644
--- a/src/libutil/fstring.c
+++ b/src/libutil/fstring.c
@@ -16,8 +16,17 @@
#include "fstring.h"
#include "str_util.h"
+
#ifdef WITH_JEMALLOC
#include <jemalloc/jemalloc.h>
+#if (JEMALLOC_VERSION_MAJOR == 3 && JEMALLOC_VERSION_MINOR >= 6) || (JEMALLOC_VERSION_MAJOR > 3)
+#define HAVE_MALLOC_SIZE 1
+#define sys_alloc_size(sz) nallocx(sz, 0)
+#endif
+#elif defined(__APPLE__)
+#include <malloc/malloc.h>
+#define HAVE_MALLOC_SIZE 1
+#define sys_alloc_size(sz) malloc_good_size(sz)
#endif
static const gsize default_initial_size = 16;
@@ -70,7 +79,7 @@ rspamd_fstring_new_init (const gchar *init, gsize len)
g_error ("%s: failed to allocate %"G_GSIZE_FORMAT" bytes",
G_STRLOC, real_size + sizeof (*s));
- return NULL;
+ abort ();
}
s->len = len;
@@ -113,15 +122,15 @@ rspamd_fstring_free (rspamd_fstring_t *str)
inline gsize
rspamd_fstring_suggest_size (gsize len, gsize allocated, gsize needed_len)
{
- gsize newlen;
+ gsize newlen, optlen = 0;
newlen = MAX (len + needed_len, 1 + allocated * 3 / 2);
-#ifdef WITH_JEMALLOC
- newlen = nallocx (newlen + sizeof (rspamd_fstring_t), 0);
+#ifdef HAVE_MALLOC_SIZE
+ optlen = sys_alloc_size (newlen + sizeof (rspamd_fstring_t));
#endif
- return newlen;
+ return MAX (newlen, optlen);
}
rspamd_fstring_t *
@@ -139,8 +148,7 @@ rspamd_fstring_grow (rspamd_fstring_t *str, gsize needed_len)
free (str);
g_error ("%s: failed to re-allocate %"G_GSIZE_FORMAT" bytes",
G_STRLOC, newlen + sizeof (*str));
-
- return NULL;
+ abort ();
}
str = nptr;