Add jemalloc (#691)

* add jemalloc

* fix jemalloc

* improve jemalloc

* remove bsd
pull/695/head
ruki 3 years ago committed by GitHub
parent 43a494a984
commit e8138ab9a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 74
      packages/j/jemalloc/patches/5.2.1/fix_nothrow_type.patch
  2. 52
      packages/j/jemalloc/xmake.lua

@ -0,0 +1,74 @@
From 3b4a03b92b2e415415a08f0150fdb9eeb659cd52 Mon Sep 17 00:00:00 2001
From: David Goldblatt <davidgoldblatt@fb.com>
Date: Thu, 26 Mar 2020 11:40:49 -0700
Subject: [PATCH] Mac: don't declare system functions as nothrow.
This contradicts the system headers, which can lead to breakages.
---
include/jemalloc/jemalloc_macros.h.in | 6 ++++++
include/jemalloc/jemalloc_protos.h.in | 19 ++++++++++---------
2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/include/jemalloc/jemalloc_macros.h.in b/include/jemalloc/jemalloc_macros.h.in
index b4469d8e9..1ceb7b170 100644
--- a/include/jemalloc/jemalloc_macros.h.in
+++ b/include/jemalloc/jemalloc_macros.h.in
@@ -134,3 +134,9 @@
# define JEMALLOC_RESTRICT_RETURN
# define JEMALLOC_ALLOCATOR
#endif
+
+#if defined(__APPLE__) && !defined(JEMALLOC_NO_RENAME)
+# define JEMALLOC_SYS_NOTHROW
+#else
+# define JEMALLOC_SYS_NOTHROW JEMALLOC_NOTHROW
+#endif
diff --git a/include/jemalloc/jemalloc_protos.h.in b/include/jemalloc/jemalloc_protos.h.in
index a78414b19..d75b2224c 100644
--- a/include/jemalloc/jemalloc_protos.h.in
+++ b/include/jemalloc/jemalloc_protos.h.in
@@ -8,21 +8,22 @@ extern JEMALLOC_EXPORT void (*@je_@malloc_message)(void *cbopaque,
const char *s);
JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN
- void JEMALLOC_NOTHROW *@je_@malloc(size_t size)
+ void JEMALLOC_SYS_NOTHROW *@je_@malloc(size_t size)
JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc) JEMALLOC_ALLOC_SIZE(1);
JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN
- void JEMALLOC_NOTHROW *@je_@calloc(size_t num, size_t size)
+ void JEMALLOC_SYS_NOTHROW *@je_@calloc(size_t num, size_t size)
JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc) JEMALLOC_ALLOC_SIZE2(1, 2);
-JEMALLOC_EXPORT int JEMALLOC_NOTHROW @je_@posix_memalign(void **memptr,
- size_t alignment, size_t size) JEMALLOC_CXX_THROW JEMALLOC_ATTR(nonnull(1));
+JEMALLOC_EXPORT int JEMALLOC_SYS_NOTHROW @je_@posix_memalign(
+ void **memptr, size_t alignment, size_t size) JEMALLOC_CXX_THROW
+ JEMALLOC_ATTR(nonnull(1));
JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN
- void JEMALLOC_NOTHROW *@je_@aligned_alloc(size_t alignment,
+ void JEMALLOC_SYS_NOTHROW *@je_@aligned_alloc(size_t alignment,
size_t size) JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc)
JEMALLOC_ALLOC_SIZE(2);
JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN
- void JEMALLOC_NOTHROW *@je_@realloc(void *ptr, size_t size)
+ void JEMALLOC_SYS_NOTHROW *@je_@realloc(void *ptr, size_t size)
JEMALLOC_CXX_THROW JEMALLOC_ALLOC_SIZE(2);
-JEMALLOC_EXPORT void JEMALLOC_NOTHROW @je_@free(void *ptr)
+JEMALLOC_EXPORT void JEMALLOC_SYS_NOTHROW @je_@free(void *ptr)
JEMALLOC_CXX_THROW;
JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN
@@ -55,12 +56,12 @@ JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW @je_@malloc_usable_size(
#ifdef JEMALLOC_OVERRIDE_MEMALIGN
JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN
- void JEMALLOC_NOTHROW *@je_@memalign(size_t alignment, size_t size)
+ void JEMALLOC_SYS_NOTHROW *@je_@memalign(size_t alignment, size_t size)
JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc);
#endif
#ifdef JEMALLOC_OVERRIDE_VALLOC
JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN
- void JEMALLOC_NOTHROW *@je_@valloc(size_t size) JEMALLOC_CXX_THROW
+ void JEMALLOC_SYS_NOTHROW *@je_@valloc(size_t size) JEMALLOC_CXX_THROW
JEMALLOC_ATTR(malloc);
#endif

@ -0,0 +1,52 @@
package("jemalloc")
set_homepage("http://jemalloc.net/")
set_description([[A general purpose malloc(3) implementation that emphasizes
fragmentation avoidance and scalable concurrency support]])
set_urls("https://github.com/jemalloc/jemalloc/releases/download/$(version)/jemalloc-$(version).tar.bz2",
"https://github.com/jemalloc/jemalloc.git")
add_versions("5.2.1", "34330e5ce276099e2e8950d9335db5a875689a4c6a56751ef3b1d8c537f887f6")
add_patches("5.2.1", path.join(os.scriptdir(), "patches", "5.2.1", "fix_nothrow_type.patch"), "d79f5c8767695059ff541f291db3fbc57c9b67299dc129848dd365c2f51b214a")
if is_plat("linux") then
add_syslinks("pthread", "dl")
end
on_load(function (package)
if package:gitref() then
package:add("deps", "automake", "autoconf")
end
if package:is_plat("linux") and package:config("pic") ~= false then
package:add("links", "jemalloc_pic")
else
package:add("links", "jemalloc")
end
end)
on_install("linux", "macosx", "mingw@macosx", function(package)
local configs = {"--disable-debug",
"--with-jemalloc-prefix="}
table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
if package:is_plat("linux") and package:config("pic") ~= false then
table.insert(configs, "--with-pic")
end
import("package.tools.autoconf").install(package, configs)
end)
on_test(function(package)
assert(package:check_cxxsnippets({
test = [[
#include <stdlib.h>
#include <jemalloc/jemalloc.h>
static void test() {
for (size_t i = 0; i < 1000; i++) {
malloc(i * 100);
}
malloc_stats_print(NULL, NULL, NULL);
}
]]
}, {includes = {"stdlib.h", "jemalloc/jemalloc.h"}}))
end)
Loading…
Cancel
Save