aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDave Watson <davejwatson@fb.com>2016-10-23 15:56:30 -0700
committerJason Evans <jasone@canonware.com>2016-12-12 18:36:06 -0800
commit2319152d9f5d9b33eebc36a50ccf4239f31c1ad9 (patch)
tree44a848c13219a110dec96d2969f6135f2a3c54f7 /test
parentd4c5aceb7cb5c5cf7a6dfd62e072c7dd12188998 (diff)
downloadplatform_external_jemalloc_new-2319152d9f5d9b33eebc36a50ccf4239f31c1ad9.tar.gz
platform_external_jemalloc_new-2319152d9f5d9b33eebc36a50ccf4239f31c1ad9.tar.bz2
platform_external_jemalloc_new-2319152d9f5d9b33eebc36a50ccf4239f31c1ad9.zip
jemalloc cpp new/delete bindings
Adds cpp bindings for jemalloc, along with necessary autoconf settings. This is mostly to add sized deallocation support, which can't be added from C directly. Sized deallocation is ~10% microbench improvement. * Import ax_cxx_compile_stdcxx.m4 from the autoconf repo, seems like the easiest way to get c++14 detection. * Adds various other changes, like CXXFLAGS, to configure.ac. * Adds new rules to Makefile.in for src/jemalloc-cpp.cpp, and a basic unittest. * Both new and delete are overridden, to ensure jemalloc is used for both. * TODO future enhancement of avoiding extra PLT thunks for new and delete - sdallocx and malloc are publicly exported jemalloc symbols, using an alias would link them directly. Unfortunately, was having trouble getting it to play nice with jemalloc's namespace support. Testing: Tested gcc 4.8, gcc 5, gcc 5.2, clang 4.0. Only gcc >= 5 has sized deallocation support, verified that the rest build correctly. Tested mac osx and Centos. Tested --with-jemalloc-prefix and --without-export. This resolves #202.
Diffstat (limited to 'test')
-rw-r--r--test/include/test/jemalloc_test.h.in11
-rw-r--r--test/include/test/test.h4
-rw-r--r--test/integration/cpp/basic.cpp18
3 files changed, 30 insertions, 3 deletions
diff --git a/test/include/test/jemalloc_test.h.in b/test/include/test/jemalloc_test.h.in
index 1f36e469..66485c0e 100644
--- a/test/include/test/jemalloc_test.h.in
+++ b/test/include/test/jemalloc_test.h.in
@@ -1,3 +1,7 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include <limits.h>
#ifndef SIZE_T_MAX
# define SIZE_T_MAX SIZE_MAX
@@ -47,7 +51,8 @@
* expose the minimum necessary internal utility code (to avoid re-implementing
* essentially identical code within the test infrastructure).
*/
-#elif defined(JEMALLOC_INTEGRATION_TEST)
+#elif defined(JEMALLOC_INTEGRATION_TEST) || \
+ defined(JEMALLOC_INTEGRATION_CPP_TEST)
# define JEMALLOC_MANGLE
# include "jemalloc/jemalloc@install_suffix@.h"
# include "jemalloc/internal/jemalloc_internal_defs.h"
@@ -161,3 +166,7 @@ static const bool config_debug =
if (!(e)) \
not_implemented(); \
} while (0)
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/test/include/test/test.h b/test/include/test/test.h
index c8112eb8..8c69fc2e 100644
--- a/test/include/test/test.h
+++ b/test/include/test/test.h
@@ -8,8 +8,8 @@
char message[ASSERT_BUFSIZE]; \
malloc_snprintf(prefix, sizeof(prefix), \
"%s:%s:%d: Failed assertion: " \
- "(%s) "#cmp" (%s) --> " \
- "%"pri" "#neg_cmp" %"pri": ", \
+ "(%s) " #cmp " (%s) --> " \
+ "%" pri " " #neg_cmp " %" pri ": ", \
__func__, __FILE__, __LINE__, \
#a, #b, a_, b_); \
malloc_snprintf(message, sizeof(message), __VA_ARGS__); \
diff --git a/test/integration/cpp/basic.cpp b/test/integration/cpp/basic.cpp
new file mode 100644
index 00000000..eeb93c47
--- /dev/null
+++ b/test/integration/cpp/basic.cpp
@@ -0,0 +1,18 @@
+#include <memory>
+#include "test/jemalloc_test.h"
+
+TEST_BEGIN(test_basic)
+{
+ auto foo = new long(4);
+ assert_ptr_not_null(foo, "Unexpected new[] failure");
+ delete foo;
+}
+TEST_END
+
+int
+main()
+{
+
+ return (test(
+ test_basic));
+}