Skip to content

Commit

Permalink
Merge pull request #1604 from evoskuil/master
Browse files Browse the repository at this point in the history
Set _CRTDBG_MAP_ALLOC for vc++ debug mode leak tracking.
  • Loading branch information
evoskuil authored Jan 31, 2025
2 parents 324923d + 2aaa375 commit 4426565
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 31 deletions.
3 changes: 1 addition & 2 deletions builds/msvc/vs2022/libbitcoin-system.import.props
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
<!-- WIN32_LEAN_AND_MEAN avoids inclusion of certain headers, winsock.h conflicts with boost and protocol use of winsock2.h. -->
<PreprocessorDefinitions>WITH_ICU;WIN32_LEAN_AND_MEAN;NOMINMAX;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Linkage-libbitcoin-system)' == 'static' Or '$(Linkage-libbitcoin-system)' == 'ltcg'">BC_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile>
<PreprocessorDefinitions Condition="$(Configuration.IndexOf('Debug')) != -1">_CRTDBG_MAP_ALLOC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<!-- Enable use of CPU intrinsics. -->
<PreprocessorDefinitions Condition="'$(Option-avx512)' == 'true'">WITH_AVX512;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Option-avx2)' == 'true'">WITH_AVX2;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<PreprocessorDefinitions>WITH_ICU;WIN32_LEAN_AND_MEAN;NOMINMAX;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(ConfigurationType)' == 'DynamicLibrary'">BC_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(ConfigurationType)' == 'StaticLibrary'">BC_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="$(Configuration.IndexOf('Debug')) != -1">_CRTDBG_MAP_ALLOC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<!-- Enable use of CPU intrinsics. -->
<PreprocessorDefinitions Condition="'$(Option-avx512)' == 'true'">WITH_AVX512;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Option-avx2)' == 'true'">WITH_AVX2;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand Down
9 changes: 3 additions & 6 deletions include/bitcoin/system/have.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@
#define HAVE_ICU
#endif

/// XCPU architecture intrinsics sse41, avx2, avx512f, sha-ni.
/// XCPU architecture intrinsics sse41, avx2, avx512f/bw, sha-ni.
/// This assumes that avx512 implies avx2 and that all imply sse41.
#if defined(HAVE_XCPU)
// TODO: CLANG/GCC compile test and set -msse4 -mavx2 -mavx512f -msha.
// CLANG/GCC compile with -msse4 -mavx2 -mavx512f/-mavx512bw -msha.
#if defined(WITH_SHANI)
#define HAVE_SHANI
#endif
Expand Down Expand Up @@ -204,9 +204,6 @@
#endif
#endif

/// C++20: parenthesized initialization of aggregates requires clang16/xcode16.
/// We don't have macro treatment for that, just ad-hoc HAVE_CLANG conditions.

/// None on xcode.
/// Requires link with -ltbb on gcc (v9).
/// Experimental on clang (libcxx.llvm.org/Status/PSTL.html), requires:
Expand All @@ -227,7 +224,7 @@
#define HAVE_SUPPRESSION

/// Disable noexcept to capture stack trace.
#define HAVE_NOEXCEPT
////#define HAVE_NOEXCEPT

/// Disable to emit all suppressed warnings.
#define HAVE_WARNINGS
Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/system/intrinsics/haves.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ namespace cpu1_0
constexpr auto avx_ecx_bit = 28;
}

// wikichip.org/wiki/x86/avx-512
namespace cpu7_0
{
constexpr auto leaf = 7;
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/system/literals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace libbitcoin {
/// not be subject to regressions in other code, as a break here causes a large
/// number of test and other failures. See tests for usage and detailed info.
/// ---------------------------------------------------------------------------
/// These should be consteval for safety, but waiting on clang++20 to catch up.
/// These should be consteval for safety, but waiting on clang++ v17.

// Functions are consteval where available (bogus warning).
BC_PUSH_WARNING(USE_CONSTEXPR_FOR_FUNCTION)
Expand Down
23 changes: 16 additions & 7 deletions include/bitcoin/system/preprocessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@
/// Debugging.
/// ---------------------------------------------------------------------------

/// Enables ETW tracing for VS memory profiler.
#if defined(HAVE_MSC)
#define ALLOCATOR __declspec(allocator)
#else
#define ALLOCATOR
#endif

/// learn.microsoft.com/en-us/cpp/c-runtime-library/
/// find-memory-leaks-using-the-crt-library
/// _CRTDBG_MAP_ALLOC must be prior to the includes, so defined in props.
#if defined(HAVE_MSC) && defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#include <stdlib.h>
#include <crtdbg.h>
////_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif

/// NDEBUG (conditional exclusion).
#if defined(NDEBUG)
#define BC_ASSERT(expression)
Expand All @@ -44,13 +60,6 @@
#define BC_DEBUG_ONLY(expression) expression
#endif

/// Enables ETW tracing for VS memory profiler.
#if defined(HAVE_MSC)
#define ALLOCATOR __declspec(allocator)
#else
#define ALLOCATOR
#endif

/// Messages.
/// ---------------------------------------------------------------------------

Expand Down
14 changes: 8 additions & 6 deletions src/arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
*/
#include <bitcoin/system/arena.hpp>

#include <cstdlib>
#include <bitcoin/system/constants.hpp>

namespace libbitcoin {

BC_PUSH_WARNING(NO_NEW_OR_DELETE)

bool operator==(const arena& left, const arena& right) NOEXCEPT
{
return &left == &right || left.is_equal(right);
Expand All @@ -41,14 +40,18 @@ void* default_arena::do_allocate(size_t bytes, size_t) THROWS
{
////if (align > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
//// return ::operator new(bytes, std::align_val_t{ align });
return ::operator new(bytes);
BC_PUSH_WARNING(NO_MALLOC_OR_FREE)
return std::malloc(bytes);
BC_POP_WARNING()
}

void default_arena::do_deallocate(void* ptr, size_t, size_t) NOEXCEPT
{
////if (align > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
//// ::operator delete(ptr, std::align_val_t{ align });
::operator delete(ptr);
BC_PUSH_WARNING(NO_MALLOC_OR_FREE)
std::free(ptr);
BC_POP_WARNING()
}

bool default_arena::do_is_equal(const arena& other) const NOEXCEPT
Expand All @@ -57,6 +60,7 @@ bool default_arena::do_is_equal(const arena& other) const NOEXCEPT
return &other == this;
}

// null return indicates that this arena is not detachable.
void* default_arena::start(size_t) THROWS
{
return nullptr;
Expand All @@ -71,6 +75,4 @@ void default_arena::release(void*) NOEXCEPT
{
}

BC_POP_WARNING()

} // namespace libbitcoin
1 change: 0 additions & 1 deletion src/chain/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include <algorithm>
#include <iterator>
#include <memory>
#include <numeric>
#include <ranges>
#include <set>
Expand Down
1 change: 0 additions & 1 deletion src/chain/point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
#include <bitcoin/system/chain/point.hpp>

#include <memory>
#include <utility>
#include <bitcoin/system/chain/enums/magic_numbers.hpp>
#include <bitcoin/system/define.hpp>
Expand Down
1 change: 0 additions & 1 deletion src/chain/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include <algorithm>
#include <iterator>
#include <memory>
#include <numeric>
#include <sstream>
#include <utility>
Expand Down
1 change: 0 additions & 1 deletion src/chain/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include <algorithm>
#include <iterator>
#include <memory>
#include <numeric>
#include <type_traits>
#include <utility>
Expand Down
4 changes: 0 additions & 4 deletions test/allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ BC_PUSH_WARNING(NO_UNGUARDED_POINTERS)
BC_PUSH_WARNING(NO_DELETE_RAW_POINTER)
BC_PUSH_WARNING(NO_UNCLEARED_OWNER_POINTER)

// Clang is not yet C++20 compliant in terms of aggregate initialization.
// See [reviews.llvm.org/D140327] for details. So vectors provide constructors.
///////////////////////////////////////////////////////////////////////////////

struct simple
{
simple(size_t arg={}) NOEXCEPT
Expand Down

0 comments on commit 4426565

Please sign in to comment.