summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--absl/algorithm/container.h10
-rw-r--r--absl/algorithm/container_test.cc13
-rw-r--r--absl/base/BUILD.bazel1
-rw-r--r--absl/base/CMakeLists.txt1
-rw-r--r--absl/base/internal/log_severity.cc15
-rw-r--r--absl/base/internal/malloc_extension.cc39
-rw-r--r--absl/base/internal/malloc_extension_test.cc23
-rw-r--r--absl/base/internal/malloc_hook.cc161
-rw-r--r--absl/base/internal/malloc_hook.h104
-rw-r--r--absl/base/internal/malloc_hook_c.h87
-rw-r--r--absl/types/span.h8
11 files changed, 104 insertions, 358 deletions
diff --git a/absl/algorithm/container.h b/absl/algorithm/container.h
index 839a6adc..8d0d4035 100644
--- a/absl/algorithm/container.h
+++ b/absl/algorithm/container.h
@@ -499,16 +499,6 @@ OutputIterator c_move(C& src, OutputIterator dest) {
container_algorithm_internal::c_end(src), dest);
}
-// c_move_backward()
-//
-// Container-based version of the <algorithm> `std::move_backward()` function to
-// move a container's elements into an iterator in reverse order.
-template <typename C, typename BidirectionalIterator>
-BidirectionalIterator c_move_backward(C& src, BidirectionalIterator dest) {
- return std::move_backward(container_algorithm_internal::c_begin(src),
- container_algorithm_internal::c_end(src), dest);
-}
-
// c_swap_ranges()
//
// Container-based version of the <algorithm> `std::swap_ranges()` function to
diff --git a/absl/algorithm/container_test.cc b/absl/algorithm/container_test.cc
index 093b2814..de66f146 100644
--- a/absl/algorithm/container_test.cc
+++ b/absl/algorithm/container_test.cc
@@ -636,19 +636,6 @@ TEST(MutatingTest, Move) {
Pointee(5)));
}
-TEST(MutatingTest, MoveBackward) {
- std::vector<std::unique_ptr<int>> actual;
- actual.emplace_back(absl::make_unique<int>(1));
- actual.emplace_back(absl::make_unique<int>(2));
- actual.emplace_back(absl::make_unique<int>(3));
- actual.emplace_back(absl::make_unique<int>(4));
- actual.emplace_back(absl::make_unique<int>(5));
- auto subrange = absl::MakeSpan(actual.data(), 3);
- absl::c_move_backward(subrange, actual.end());
- EXPECT_THAT(actual, ElementsAre(IsNull(), IsNull(), Pointee(1), Pointee(2),
- Pointee(3)));
-}
-
TEST(MutatingTest, SwapRanges) {
std::vector<int> odds = {2, 4, 6};
std::vector<int> evens = {1, 3, 5};
diff --git a/absl/base/BUILD.bazel b/absl/base/BUILD.bazel
index 743add7e..f6d6c3d2 100644
--- a/absl/base/BUILD.bazel
+++ b/absl/base/BUILD.bazel
@@ -82,7 +82,6 @@ cc_library(
srcs = ["internal/malloc_extension.cc"],
hdrs = [
"internal/malloc_extension.h",
- "internal/malloc_extension_c.h",
],
copts = ABSL_DEFAULT_COPTS,
visibility = [
diff --git a/absl/base/CMakeLists.txt b/absl/base/CMakeLists.txt
index 3e94d51f..1b24fd1b 100644
--- a/absl/base/CMakeLists.txt
+++ b/absl/base/CMakeLists.txt
@@ -38,7 +38,6 @@ list(APPEND BASE_INTERNAL_HEADERS
"internal/log_severity.h"
"internal/low_level_alloc.h"
"internal/low_level_scheduling.h"
- "internal/malloc_extension_c.h"
"internal/malloc_extension.h"
"internal/malloc_hook_c.h"
"internal/malloc_hook.h"
diff --git a/absl/base/internal/log_severity.cc b/absl/base/internal/log_severity.cc
deleted file mode 100644
index 430ac458..00000000
--- a/absl/base/internal/log_severity.cc
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2017 The Abseil Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "absl/base/internal/log_severity.h"
diff --git a/absl/base/internal/malloc_extension.cc b/absl/base/internal/malloc_extension.cc
index d48ec5bc..5b906533 100644
--- a/absl/base/internal/malloc_extension.cc
+++ b/absl/base/internal/malloc_extension.cc
@@ -20,7 +20,6 @@
#include <string>
#include "absl/base/dynamic_annotations.h"
-#include "absl/base/internal/malloc_extension_c.h"
namespace absl {
namespace base_internal {
@@ -155,44 +154,6 @@ void MallocExtension::GetFragmentationProfile(MallocExtensionWriter*) {}
} // namespace base_internal
} // namespace absl
-// These are C shims that work on the current instance.
-
-#define C_SHIM(fn, retval, paramlist, arglist) \
- extern "C" retval MallocExtension_##fn paramlist { \
- return absl::base_internal::MallocExtension::instance()->fn arglist; \
- }
-
-C_SHIM(VerifyAllMemory, int, (void), ());
-C_SHIM(VerifyNewMemory, int, (const void* p), (p));
-C_SHIM(VerifyArrayNewMemory, int, (const void* p), (p));
-C_SHIM(VerifyMallocMemory, int, (const void* p), (p));
-C_SHIM(
- MallocMemoryStats, int,
- (int* blocks, size_t* total,
- int histogram[absl::base_internal::MallocExtension::kMallocHistogramSize]),
- (blocks, total, histogram));
-
-C_SHIM(GetStats, void,
- (char* buffer, int buffer_length), (buffer, buffer_length));
-C_SHIM(GetNumericProperty, int,
- (const char* property, size_t* value), (property, value));
-C_SHIM(SetNumericProperty, int,
- (const char* property, size_t value), (property, value));
-
-C_SHIM(MarkThreadIdle, void, (void), ());
-C_SHIM(MarkThreadBusy, void, (void), ());
-C_SHIM(ReleaseFreeMemory, void, (void), ());
-C_SHIM(ReleaseToSystem, void, (size_t num_bytes), (num_bytes));
-C_SHIM(GetEstimatedAllocatedSize, size_t, (size_t size), (size));
-C_SHIM(GetAllocatedSize, size_t, (const void* p), (p));
-
-// Can't use the shim here because of the need to translate the enums.
-extern "C"
-MallocExtension_Ownership MallocExtension_GetOwnership(const void* p) {
- return static_cast<MallocExtension_Ownership>(
- absl::base_internal::MallocExtension::instance()->GetOwnership(p));
-}
-
// Default implementation just returns size. The expectation is that
// the linked-in malloc implementation might provide an override of
// this weak function with a better implementation.
diff --git a/absl/base/internal/malloc_extension_test.cc b/absl/base/internal/malloc_extension_test.cc
index 246875a0..76605eb1 100644
--- a/absl/base/internal/malloc_extension_test.cc
+++ b/absl/base/internal/malloc_extension_test.cc
@@ -19,7 +19,6 @@
#include "gtest/gtest.h"
#include "absl/base/internal/malloc_extension.h"
-#include "absl/base/internal/malloc_extension_c.h"
namespace absl {
namespace base_internal {
@@ -35,15 +34,12 @@ TEST(MallocExtension, MallocExtension) {
} else {
ASSERT_TRUE(MallocExtension::instance()->GetNumericProperty(
"generic.current_allocated_bytes", &cxx_bytes_used));
- ASSERT_TRUE(MallocExtension_GetNumericProperty(
- "generic.current_allocated_bytes", &c_bytes_used));
#ifndef MEMORY_SANITIZER
EXPECT_GT(cxx_bytes_used, 1000);
EXPECT_GT(c_bytes_used, 1000);
#endif
EXPECT_TRUE(MallocExtension::instance()->VerifyAllMemory());
- EXPECT_TRUE(MallocExtension_VerifyAllMemory());
EXPECT_EQ(MallocExtension::kOwned,
MallocExtension::instance()->GetOwnership(a));
@@ -65,30 +61,11 @@ TEST(MallocExtension, MallocExtension) {
MallocExtension::instance()->GetEstimatedAllocatedSize(i));
free(p);
}
-
- // Check the c-shim version too.
- EXPECT_EQ(MallocExtension_kOwned, MallocExtension_GetOwnership(a));
- EXPECT_EQ(MallocExtension_kNotOwned,
- MallocExtension_GetOwnership(&cxx_bytes_used));
- EXPECT_EQ(MallocExtension_kNotOwned, MallocExtension_GetOwnership(nullptr));
- EXPECT_GE(MallocExtension_GetAllocatedSize(a), 1000);
- EXPECT_LE(MallocExtension_GetAllocatedSize(a), 5000);
- EXPECT_GE(MallocExtension_GetEstimatedAllocatedSize(1000), 1000);
}
free(a);
}
-// Verify that the .cc file and .h file have the same enum values.
-TEST(GetOwnership, EnumValuesEqualForCAndCXX) {
- EXPECT_EQ(static_cast<int>(MallocExtension::kUnknownOwnership),
- static_cast<int>(MallocExtension_kUnknownOwnership));
- EXPECT_EQ(static_cast<int>(MallocExtension::kOwned),
- static_cast<int>(MallocExtension_kOwned));
- EXPECT_EQ(static_cast<int>(MallocExtension::kNotOwned),
- static_cast<int>(MallocExtension_kNotOwned));
-}
-
TEST(nallocx, SaneBehavior) {
for (size_t size = 0; size < 64 * 1024; ++size) {
size_t alloc_size = nallocx(size, 0);
diff --git a/absl/base/internal/malloc_hook.cc b/absl/base/internal/malloc_hook.cc
index 52531c68..780e8fe3 100644
--- a/absl/base/internal/malloc_hook.cc
+++ b/absl/base/internal/malloc_hook.cc
@@ -215,139 +215,101 @@ HookList<MallocHook::MunmapReplacement> munmap_replacement_ = INIT_HOOK_LIST;
#undef INIT_HOOK_LIST_WITH_VALUE
#undef INIT_HOOK_LIST
-} // namespace base_internal
-} // namespace absl
+bool MallocHook::AddNewHook(NewHook hook) { return new_hooks_.Add(hook); }
-// These are available as C bindings as well as C++, hence their
-// definition outside the MallocHook class.
-extern "C"
-int MallocHook_AddNewHook(MallocHook_NewHook hook) {
- return absl::base_internal::new_hooks_.Add(hook);
-}
-
-extern "C"
-int MallocHook_RemoveNewHook(MallocHook_NewHook hook) {
- return absl::base_internal::new_hooks_.Remove(hook);
-}
+bool MallocHook::RemoveNewHook(NewHook hook) { return new_hooks_.Remove(hook); }
-extern "C"
-int MallocHook_AddDeleteHook(MallocHook_DeleteHook hook) {
- return absl::base_internal::delete_hooks_.Add(hook);
+bool MallocHook::AddDeleteHook(DeleteHook hook) {
+ return delete_hooks_.Add(hook);
}
-extern "C"
-int MallocHook_RemoveDeleteHook(MallocHook_DeleteHook hook) {
- return absl::base_internal::delete_hooks_.Remove(hook);
+bool MallocHook::RemoveDeleteHook(DeleteHook hook) {
+ return delete_hooks_.Remove(hook);
}
-extern "C" int MallocHook_AddSampledNewHook(MallocHook_SampledNewHook hook) {
- return absl::base_internal::sampled_new_hooks_.Add(hook);
+bool MallocHook::AddSampledNewHook(SampledNewHook hook) {
+ return sampled_new_hooks_.Add(hook);
}
-extern "C" int MallocHook_RemoveSampledNewHook(MallocHook_SampledNewHook hook) {
- return absl::base_internal::sampled_new_hooks_.Remove(hook);
+bool MallocHook::RemoveSampledNewHook(SampledNewHook hook) {
+ return sampled_new_hooks_.Remove(hook);
}
-extern "C" int MallocHook_AddSampledDeleteHook(
- MallocHook_SampledDeleteHook hook) {
- return absl::base_internal::sampled_delete_hooks_.Add(hook);
+bool MallocHook::AddSampledDeleteHook(SampledDeleteHook hook) {
+ return sampled_delete_hooks_.Add(hook);
}
-extern "C" int MallocHook_RemoveSampledDeleteHook(
- MallocHook_SampledDeleteHook hook) {
- return absl::base_internal::sampled_delete_hooks_.Remove(hook);
+bool MallocHook::RemoveSampledDeleteHook(SampledDeleteHook hook) {
+ return sampled_delete_hooks_.Remove(hook);
}
-extern "C"
-int MallocHook_AddPreMmapHook(MallocHook_PreMmapHook hook) {
- return absl::base_internal::premmap_hooks_.Add(hook);
+bool MallocHook::AddPreMmapHook(PreMmapHook hook) {
+ return premmap_hooks_.Add(hook);
}
-extern "C"
-int MallocHook_RemovePreMmapHook(MallocHook_PreMmapHook hook) {
- return absl::base_internal::premmap_hooks_.Remove(hook);
+bool MallocHook::RemovePreMmapHook(PreMmapHook hook) {
+ return premmap_hooks_.Remove(hook);
}
-extern "C"
-int MallocHook_SetMmapReplacement(MallocHook_MmapReplacement hook) {
+bool MallocHook::SetMmapReplacement(MmapReplacement hook) {
// NOTE this is a best effort CHECK. Concurrent sets could succeed since
// this test is outside of the Add spin lock.
- ABSL_RAW_CHECK(absl::base_internal::mmap_replacement_.empty(),
+ ABSL_RAW_CHECK(mmap_replacement_.empty(),
"Only one MMapReplacement is allowed.");
- return absl::base_internal::mmap_replacement_.Add(hook);
-}
-
-extern "C"
-int MallocHook_RemoveMmapReplacement(MallocHook_MmapReplacement hook) {
- return absl::base_internal::mmap_replacement_.Remove(hook);
-}
-
-extern "C"
-int MallocHook_AddMmapHook(MallocHook_MmapHook hook) {
- return absl::base_internal::mmap_hooks_.Add(hook);
+ return mmap_replacement_.Add(hook);
}
-extern "C"
-int MallocHook_RemoveMmapHook(MallocHook_MmapHook hook) {
- return absl::base_internal::mmap_hooks_.Remove(hook);
+bool MallocHook::RemoveMmapReplacement(MmapReplacement hook) {
+ return mmap_replacement_.Remove(hook);
}
-extern "C"
-int MallocHook_AddMunmapHook(MallocHook_MunmapHook hook) {
- return absl::base_internal::munmap_hooks_.Add(hook);
-}
+bool MallocHook::AddMmapHook(MmapHook hook) { return mmap_hooks_.Add(hook); }
-extern "C"
-int MallocHook_RemoveMunmapHook(MallocHook_MunmapHook hook) {
- return absl::base_internal::munmap_hooks_.Remove(hook);
+bool MallocHook::RemoveMmapHook(MmapHook hook) {
+ return mmap_hooks_.Remove(hook);
}
-extern "C"
-int MallocHook_SetMunmapReplacement(MallocHook_MunmapReplacement hook) {
+bool MallocHook::SetMunmapReplacement(MunmapReplacement hook) {
// NOTE this is a best effort CHECK. Concurrent sets could succeed since
// this test is outside of the Add spin lock.
- ABSL_RAW_CHECK(absl::base_internal::munmap_replacement_.empty(),
+ ABSL_RAW_CHECK(munmap_replacement_.empty(),
"Only one MunmapReplacement is allowed.");
- return absl::base_internal::munmap_replacement_.Add(hook);
+ return munmap_replacement_.Add(hook);
}
-extern "C"
-int MallocHook_RemoveMunmapReplacement(MallocHook_MunmapReplacement hook) {
- return absl::base_internal::munmap_replacement_.Remove(hook);
+bool MallocHook::RemoveMunmapReplacement(MunmapReplacement hook) {
+ return munmap_replacement_.Remove(hook);
}
-extern "C"
-int MallocHook_AddMremapHook(MallocHook_MremapHook hook) {
- return absl::base_internal::mremap_hooks_.Add(hook);
+bool MallocHook::AddMunmapHook(MunmapHook hook) {
+ return munmap_hooks_.Add(hook);
}
-extern "C"
-int MallocHook_RemoveMremapHook(MallocHook_MremapHook hook) {
- return absl::base_internal::mremap_hooks_.Remove(hook);
+bool MallocHook::RemoveMunmapHook(MunmapHook hook) {
+ return munmap_hooks_.Remove(hook);
}
-extern "C"
-int MallocHook_AddPreSbrkHook(MallocHook_PreSbrkHook hook) {
- return absl::base_internal::presbrk_hooks_.Add(hook);
+bool MallocHook::AddMremapHook(MremapHook hook) {
+ return mremap_hooks_.Add(hook);
}
-extern "C"
-int MallocHook_RemovePreSbrkHook(MallocHook_PreSbrkHook hook) {
- return absl::base_internal::presbrk_hooks_.Remove(hook);
+bool MallocHook::RemoveMremapHook(MremapHook hook) {
+ return mremap_hooks_.Remove(hook);
}
-extern "C"
-int MallocHook_AddSbrkHook(MallocHook_SbrkHook hook) {
- return absl::base_internal::sbrk_hooks_.Add(hook);
+bool MallocHook::AddPreSbrkHook(PreSbrkHook hook) {
+ return presbrk_hooks_.Add(hook);
}
-extern "C"
-int MallocHook_RemoveSbrkHook(MallocHook_SbrkHook hook) {
- return absl::base_internal::sbrk_hooks_.Remove(hook);
+bool MallocHook::RemovePreSbrkHook(PreSbrkHook hook) {
+ return presbrk_hooks_.Remove(hook);
}
-namespace absl {
-namespace base_internal {
+bool MallocHook::AddSbrkHook(SbrkHook hook) { return sbrk_hooks_.Add(hook); }
+
+bool MallocHook::RemoveSbrkHook(SbrkHook hook) {
+ return sbrk_hooks_.Remove(hook);
+}
// Note: embedding the function calls inside the traversal of HookList would be
// very confusing, as it is legal for a hook to remove itself and add other
@@ -501,12 +463,11 @@ static void InitializeInHookCaller() {
ABSL_INIT_ATTRIBUTE_SECTION_VARS(blink_malloc);
}
-// We can improve behavior/compactness of this function
-// if we pass a generic test function (with a generic arg)
-// into the implementations for get_stack_trace_fn instead of the skip_count.
-extern "C" int MallocHook_GetCallerStackTrace(
- void** result, int max_depth, int skip_count,
- MallocHook_GetStackTraceFn get_stack_trace_fn) {
+namespace absl {
+namespace base_internal {
+int MallocHook::GetCallerStackTrace(void** result, int max_depth,
+ int skip_count,
+ GetStackTraceFn get_stack_trace_fn) {
if (!ABSL_HAVE_ATTRIBUTE_SECTION) {
// Fall back to get_stack_trace_fn and good old but fragile frame skip
// counts.
@@ -524,11 +485,11 @@ extern "C" int MallocHook_GetCallerStackTrace(
absl::call_once(in_hook_caller_once, InitializeInHookCaller);
// MallocHook caller determination via InHookCaller works, use it:
static const int kMaxSkip = 32 + 6 + 3;
- // Constant tuned to do just one get_stack_trace_fn call below in practice
- // and not get many frames that we don't actually need:
- // currently max passed max_depth is 32,
- // max passed/needed skip_count is 6
- // and 3 is to account for some hook daisy chaining.
+ // Constant tuned to do just one get_stack_trace_fn call below in practice
+ // and not get many frames that we don't actually need:
+ // currently max passed max_depth is 32,
+ // max passed/needed skip_count is 6
+ // and 3 is to account for some hook daisy chaining.
static const int kStackSize = kMaxSkip + 1;
void* stack[kStackSize];
int depth =
@@ -538,11 +499,11 @@ extern "C" int MallocHook_GetCallerStackTrace(
return 0;
for (int i = depth - 1; i >= 0; --i) { // stack[0] is our immediate caller
if (InHookCaller(stack[i])) {
- i += 1; // skip hook caller frame
+ i += 1; // skip hook caller frame
depth -= i; // correct depth
if (depth > max_depth) depth = max_depth;
std::copy(stack + i, stack + i + depth, result);
- if (depth < max_depth && depth + i == kStackSize) {
+ if (depth < max_depth && depth + i == kStackSize) {
// get frames for the missing depth
depth += get_stack_trace_fn(result + depth, max_depth - depth,
1 + kStackSize);
@@ -558,6 +519,8 @@ extern "C" int MallocHook_GetCallerStackTrace(
// all functions in that section must be inside the same library.
return 0;
}
+} // namespace base_internal
+} // namespace absl
// On systems where we know how, we override mmap/munmap/mremap/sbrk
// to provide support for calling the related hooks (in addition,
diff --git a/absl/base/internal/malloc_hook.h b/absl/base/internal/malloc_hook.h
index ed5cf2e6..7c1eaddb 100644
--- a/absl/base/internal/malloc_hook.h
+++ b/absl/base/internal/malloc_hook.h
@@ -74,24 +74,16 @@ class MallocHook {
// Object pointer and size are passed in.
// It may be passed null pointer if the allocator returned null.
typedef MallocHook_NewHook NewHook;
- inline static bool AddNewHook(NewHook hook) {
- return MallocHook_AddNewHook(hook);
- }
- inline static bool RemoveNewHook(NewHook hook) {
- return MallocHook_RemoveNewHook(hook);
- }
+ static bool AddNewHook(NewHook hook);
+ static bool RemoveNewHook(NewHook hook);
inline static void InvokeNewHook(const void* ptr, size_t size);
// The DeleteHook is invoked whenever an object is being deallocated.
// Object pointer is passed in.
// It may be passed null pointer if the caller is trying to delete null.
typedef MallocHook_DeleteHook DeleteHook;
- inline static bool AddDeleteHook(DeleteHook hook) {
- return MallocHook_AddDeleteHook(hook);
- }
- inline static bool RemoveDeleteHook(DeleteHook hook) {
- return MallocHook_RemoveDeleteHook(hook);
- }
+ static bool AddDeleteHook(DeleteHook hook);
+ static bool RemoveDeleteHook(DeleteHook hook);
inline static void InvokeDeleteHook(const void* ptr);
// The SampledNewHook is invoked for some subset of object allocations
@@ -107,12 +99,8 @@ class MallocHook {
// call InvokeSampledDeleteHook() with that value.
typedef MallocHook_SampledNewHook SampledNewHook;
typedef MallocHook_SampledAlloc SampledAlloc;
- inline static bool AddSampledNewHook(SampledNewHook hook) {
- return MallocHook_AddSampledNewHook(hook);
- }
- inline static bool RemoveSampledNewHook(SampledNewHook hook) {
- return MallocHook_RemoveSampledNewHook(hook);
- }
+ static bool AddSampledNewHook(SampledNewHook hook);
+ static bool RemoveSampledNewHook(SampledNewHook hook);
inline static void InvokeSampledNewHook(const SampledAlloc* sampled_alloc);
// The SampledDeleteHook is invoked whenever an object previously chosen
@@ -121,12 +109,8 @@ class MallocHook {
// InvokeSampledNewHook()-- is passed in.
typedef MallocHook_SampledDeleteHook SampledDeleteHook;
typedef MallocHook_AllocHandle AllocHandle;
- inline static bool AddSampledDeleteHook(SampledDeleteHook hook) {
- return MallocHook_AddSampledDeleteHook(hook);
- }
- inline static bool RemoveSampledDeleteHook(SampledDeleteHook hook) {
- return MallocHook_RemoveSampledDeleteHook(hook);
- }
+ static bool AddSampledDeleteHook(SampledDeleteHook hook);
+ static bool RemoveSampledDeleteHook(SampledDeleteHook hook);
inline static void InvokeSampledDeleteHook(AllocHandle handle);
// The PreMmapHook is invoked with mmap's or mmap64's arguments just
@@ -134,12 +118,8 @@ class MallocHook {
// in memory limited contexts, to catch allocations that will exceed
// a memory limit, and take outside actions to increase that limit.
typedef MallocHook_PreMmapHook PreMmapHook;
- inline static bool AddPreMmapHook(PreMmapHook hook) {
- return MallocHook_AddPreMmapHook(hook);
- }
- inline static bool RemovePreMmapHook(PreMmapHook hook) {
- return MallocHook_RemovePreMmapHook(hook);
- }
+ static bool AddPreMmapHook(PreMmapHook hook);
+ static bool RemovePreMmapHook(PreMmapHook hook);
inline static void InvokePreMmapHook(const void* start,
size_t size,
int protection,
@@ -159,12 +139,8 @@ class MallocHook {
// you must call RemoveMmapReplacement before calling SetMmapReplacement
// again.
typedef MallocHook_MmapReplacement MmapReplacement;
- inline static bool SetMmapReplacement(MmapReplacement hook) {
- return MallocHook_SetMmapReplacement(hook);
- }
- inline static bool RemoveMmapReplacement(MmapReplacement hook) {
- return MallocHook_RemoveMmapReplacement(hook);
- }
+ static bool SetMmapReplacement(MmapReplacement hook);
+ static bool RemoveMmapReplacement(MmapReplacement hook);
inline static bool InvokeMmapReplacement(const void* start,
size_t size,
int protection,
@@ -178,12 +154,8 @@ class MallocHook {
// a region of memory has been just mapped.
// It may be passed MAP_FAILED if the mmap failed.
typedef MallocHook_MmapHook MmapHook;
- inline static bool AddMmapHook(MmapHook hook) {
- return MallocHook_AddMmapHook(hook);
- }
- inline static bool RemoveMmapHook(MmapHook hook) {
- return MallocHook_RemoveMmapHook(hook);
- }
+ static bool AddMmapHook(MmapHook hook);
+ static bool RemoveMmapHook(MmapHook hook);
inline static void InvokeMmapHook(const void* result,
const void* start,
size_t size,
@@ -202,12 +174,8 @@ class MallocHook {
// MunmapReplacement you must call RemoveMunmapReplacement before
// calling SetMunmapReplacement again.
typedef MallocHook_MunmapReplacement MunmapReplacement;
- inline static bool SetMunmapReplacement(MunmapReplacement hook) {
- return MallocHook_SetMunmapReplacement(hook);
- }
- inline static bool RemoveMunmapReplacement(MunmapReplacement hook) {
- return MallocHook_RemoveMunmapReplacement(hook);
- }
+ static bool SetMunmapReplacement(MunmapReplacement hook);
+ static bool RemoveMunmapReplacement(MunmapReplacement hook);
inline static bool InvokeMunmapReplacement(const void* start,
size_t size,
int* result);
@@ -217,23 +185,15 @@ class MallocHook {
// TODO(maxim): Rename this to PreMunmapHook for consistency with PreMmapHook
// and PreSbrkHook.
typedef MallocHook_MunmapHook MunmapHook;
- inline static bool AddMunmapHook(MunmapHook hook) {
- return MallocHook_AddMunmapHook(hook);
- }
- inline static bool RemoveMunmapHook(MunmapHook hook) {
- return MallocHook_RemoveMunmapHook(hook);
- }
+ static bool AddMunmapHook(MunmapHook hook);
+ static bool RemoveMunmapHook(MunmapHook hook);
inline static void InvokeMunmapHook(const void* start, size_t size);
// The MremapHook is invoked with mremap's return value and arguments
// whenever a region of memory has been just remapped.
typedef MallocHook_MremapHook MremapHook;
- inline static bool AddMremapHook(MremapHook hook) {
- return MallocHook_AddMremapHook(hook);
- }
- inline static bool RemoveMremapHook(MremapHook hook) {
- return MallocHook_RemoveMremapHook(hook);
- }
+ static bool AddMremapHook(MremapHook hook);
+ static bool RemoveMremapHook(MremapHook hook);
inline static void InvokeMremapHook(const void* result,
const void* old_addr,
size_t old_size,
@@ -248,12 +208,8 @@ class MallocHook {
// to catch allocations that will exceed the limit and take outside
// actions to increase such a limit.
typedef MallocHook_PreSbrkHook PreSbrkHook;
- inline static bool AddPreSbrkHook(PreSbrkHook hook) {
- return MallocHook_AddPreSbrkHook(hook);
- }
- inline static bool RemovePreSbrkHook(PreSbrkHook hook) {
- return MallocHook_RemovePreSbrkHook(hook);
- }
+ static bool AddPreSbrkHook(PreSbrkHook hook);
+ static bool RemovePreSbrkHook(PreSbrkHook hook);
inline static void InvokePreSbrkHook(ptrdiff_t increment);
// The SbrkHook is invoked with sbrk's result and argument whenever sbrk
@@ -261,12 +217,8 @@ class MallocHook {
// This is because sbrk(0) is often called to get the top of the memory stack,
// and is not actually a memory-allocation call.
typedef MallocHook_SbrkHook SbrkHook;
- inline static bool AddSbrkHook(SbrkHook hook) {
- return MallocHook_AddSbrkHook(hook);
- }
- inline static bool RemoveSbrkHook(SbrkHook hook) {
- return MallocHook_RemoveSbrkHook(hook);
- }
+ static bool AddSbrkHook(SbrkHook hook);
+ static bool RemoveSbrkHook(SbrkHook hook);
inline static void InvokeSbrkHook(const void* result, ptrdiff_t increment);
// Pointer to a absl::GetStackTrace implementation, following the API in
@@ -280,12 +232,8 @@ class MallocHook {
// is not available.
// Stack trace is filled into *result up to the size of max_depth.
// The actual number of stack frames filled is returned.
- inline static int GetCallerStackTrace(void** result, int max_depth,
- int skip_count,
- GetStackTraceFn get_stack_trace_fn) {
- return MallocHook_GetCallerStackTrace(result, max_depth, skip_count,
- get_stack_trace_fn);
- }
+ static int GetCallerStackTrace(void** result, int max_depth, int skip_count,
+ GetStackTraceFn get_stack_trace_fn);
#if ABSL_HAVE_MMAP
// Unhooked versions of mmap() and munmap(). These should be used
diff --git a/absl/base/internal/malloc_hook_c.h b/absl/base/internal/malloc_hook_c.h
index 03b84ca6..ed41143a 100644
--- a/absl/base/internal/malloc_hook_c.h
+++ b/absl/base/internal/malloc_hook_c.h
@@ -29,28 +29,9 @@
extern "C" {
#endif /* __cplusplus */
-/* Get the current stack trace. Try to skip all routines up to and
- * including the caller of MallocHook::Invoke*.
- * Use "skip_count" (similarly to absl::GetStackTrace from stacktrace.h)
- * as a hint about how many routines to skip if better information
- * is not available.
- */
typedef int (*MallocHook_GetStackTraceFn)(void**, int, int);
-int MallocHook_GetCallerStackTrace(void** result, int max_depth, int skip_count,
- MallocHook_GetStackTraceFn fn);
-
-/* All the MallocHook_{Add,Remove}*Hook functions below return 1 on success
- * and 0 on failure.
- */
-
typedef void (*MallocHook_NewHook)(const void* ptr, size_t size);
-int MallocHook_AddNewHook(MallocHook_NewHook hook);
-int MallocHook_RemoveNewHook(MallocHook_NewHook hook);
-
typedef void (*MallocHook_DeleteHook)(const void* ptr);
-int MallocHook_AddDeleteHook(MallocHook_DeleteHook hook);
-int MallocHook_RemoveDeleteHook(MallocHook_DeleteHook hook);
-
typedef int64_t MallocHook_AllocHandle;
typedef struct {
/* See malloc_hook.h for documentation for this struct. */
@@ -61,68 +42,24 @@ typedef struct {
} MallocHook_SampledAlloc;
typedef void (*MallocHook_SampledNewHook)(
const MallocHook_SampledAlloc* sampled_alloc);
-int MallocHook_AddSampledNewHook(MallocHook_SampledNewHook hook);
-int MallocHook_RemoveSampledNewHook(MallocHook_SampledNewHook hook);
-
typedef void (*MallocHook_SampledDeleteHook)(MallocHook_AllocHandle handle);
-int MallocHook_AddSampledDeleteHook(MallocHook_SampledDeleteHook hook);
-int MallocHook_RemoveSampledDeleteHook(MallocHook_SampledDeleteHook hook);
-
-typedef void (*MallocHook_PreMmapHook)(const void *start,
- size_t size,
- int protection,
- int flags,
- int fd,
+typedef void (*MallocHook_PreMmapHook)(const void* start, size_t size,
+ int protection, int flags, int fd,
off_t offset);
-int MallocHook_AddPreMmapHook(MallocHook_PreMmapHook hook);
-int MallocHook_RemovePreMmapHook(MallocHook_PreMmapHook hook);
-
-typedef void (*MallocHook_MmapHook)(const void* result,
- const void* start,
- size_t size,
- int protection,
- int flags,
- int fd,
- off_t offset);
-int MallocHook_AddMmapHook(MallocHook_MmapHook hook);
-int MallocHook_RemoveMmapHook(MallocHook_MmapHook hook);
-
-typedef int (*MallocHook_MmapReplacement)(const void* start,
- size_t size,
- int protection,
- int flags,
- int fd,
- off_t offset,
- void** result);
-int MallocHook_SetMmapReplacement(MallocHook_MmapReplacement hook);
-int MallocHook_RemoveMmapReplacement(MallocHook_MmapReplacement hook);
-
+typedef void (*MallocHook_MmapHook)(const void* result, const void* start,
+ size_t size, int protection, int flags,
+ int fd, off_t offset);
+typedef int (*MallocHook_MmapReplacement)(const void* start, size_t size,
+ int protection, int flags, int fd,
+ off_t offset, void** result);
typedef void (*MallocHook_MunmapHook)(const void* start, size_t size);
-int MallocHook_AddMunmapHook(MallocHook_MunmapHook hook);
-int MallocHook_RemoveMunmapHook(MallocHook_MunmapHook hook);
-
-typedef int (*MallocHook_MunmapReplacement)(const void* start,
- size_t size,
+typedef int (*MallocHook_MunmapReplacement)(const void* start, size_t size,
int* result);
-int MallocHook_SetMunmapReplacement(MallocHook_MunmapReplacement hook);
-int MallocHook_RemoveMunmapReplacement(MallocHook_MunmapReplacement hook);
-
-typedef void (*MallocHook_MremapHook)(const void* result,
- const void* old_addr,
- size_t old_size,
- size_t new_size,
- int flags,
- const void* new_addr);
-int MallocHook_AddMremapHook(MallocHook_MremapHook hook);
-int MallocHook_RemoveMremapHook(MallocHook_MremapHook hook);
-
+typedef void (*MallocHook_MremapHook)(const void* result, const void* old_addr,
+ size_t old_size, size_t new_size,
+ int flags, const void* new_addr);
typedef void (*MallocHook_PreSbrkHook)(ptrdiff_t increment);
-int MallocHook_AddPreSbrkHook(MallocHook_PreSbrkHook hook);
-int MallocHook_RemovePreSbrkHook(MallocHook_PreSbrkHook hook);
-
typedef void (*MallocHook_SbrkHook)(const void* result, ptrdiff_t increment);
-int MallocHook_AddSbrkHook(MallocHook_SbrkHook hook);
-int MallocHook_RemoveSbrkHook(MallocHook_SbrkHook hook);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/absl/types/span.h b/absl/types/span.h
index e2abe780..d1ef97a2 100644
--- a/absl/types/span.h
+++ b/absl/types/span.h
@@ -152,11 +152,11 @@ bool LessThanImpl(Span<T> a, Span<T> b) {
template <typename From, typename To>
struct IsConvertibleHelper {
private:
- static std::true_type test(To);
- static std::false_type test(...);
+ static std::true_type testval(To);
+ static std::false_type testval(...);
public:
- using type = decltype(test(std::declval<From>()));
+ using type = decltype(testval(std::declval<From>()));
};
template <typename From, typename To>
@@ -660,7 +660,7 @@ bool operator>=(Span<T> a, const U& b) {
// MyRoutine(my_vector); // error, type mismatch
//
// // Explicitly constructing the Span is verbose
-// MyRoutine(absl::Span<MyComplicatedType>(my_vector);
+// MyRoutine(absl::Span<MyComplicatedType>(my_vector));
//
// // Use MakeSpan() to make an absl::Span<T>
// MyRoutine(absl::MakeSpan(my_vector));