Skip to content

Commit 4426565

Browse files
authored
Merge pull request #1604 from evoskuil/master
Set _CRTDBG_MAP_ALLOC for vc++ debug mode leak tracking.
2 parents 324923d + 2aaa375 commit 4426565

File tree

12 files changed

+30
-31
lines changed

12 files changed

+30
-31
lines changed

builds/msvc/vs2022/libbitcoin-system.import.props

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@
5151
<!-- WIN32_LEAN_AND_MEAN avoids inclusion of certain headers, winsock.h conflicts with boost and protocol use of winsock2.h. -->
5252
<PreprocessorDefinitions>WITH_ICU;WIN32_LEAN_AND_MEAN;NOMINMAX;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
5353
<PreprocessorDefinitions Condition="'$(Linkage-libbitcoin-system)' == 'static' Or '$(Linkage-libbitcoin-system)' == 'ltcg'">BC_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
54-
</ClCompile>
55-
<ClCompile>
54+
<PreprocessorDefinitions Condition="$(Configuration.IndexOf('Debug')) != -1">_CRTDBG_MAP_ALLOC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
5655
<!-- Enable use of CPU intrinsics. -->
5756
<PreprocessorDefinitions Condition="'$(Option-avx512)' == 'true'">WITH_AVX512;%(PreprocessorDefinitions)</PreprocessorDefinitions>
5857
<PreprocessorDefinitions Condition="'$(Option-avx2)' == 'true'">WITH_AVX2;%(PreprocessorDefinitions)</PreprocessorDefinitions>

builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.props

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<PreprocessorDefinitions>WITH_ICU;WIN32_LEAN_AND_MEAN;NOMINMAX;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
2626
<PreprocessorDefinitions Condition="'$(ConfigurationType)' == 'DynamicLibrary'">BC_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
2727
<PreprocessorDefinitions Condition="'$(ConfigurationType)' == 'StaticLibrary'">BC_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
28+
<PreprocessorDefinitions Condition="$(Configuration.IndexOf('Debug')) != -1">_CRTDBG_MAP_ALLOC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
2829
<!-- Enable use of CPU intrinsics. -->
2930
<PreprocessorDefinitions Condition="'$(Option-avx512)' == 'true'">WITH_AVX512;%(PreprocessorDefinitions)</PreprocessorDefinitions>
3031
<PreprocessorDefinitions Condition="'$(Option-avx2)' == 'true'">WITH_AVX2;%(PreprocessorDefinitions)</PreprocessorDefinitions>

include/bitcoin/system/have.hpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@
128128
#define HAVE_ICU
129129
#endif
130130

131-
/// XCPU architecture intrinsics sse41, avx2, avx512f, sha-ni.
131+
/// XCPU architecture intrinsics sse41, avx2, avx512f/bw, sha-ni.
132132
/// This assumes that avx512 implies avx2 and that all imply sse41.
133133
#if defined(HAVE_XCPU)
134-
// TODO: CLANG/GCC compile test and set -msse4 -mavx2 -mavx512f -msha.
134+
// CLANG/GCC compile with -msse4 -mavx2 -mavx512f/-mavx512bw -msha.
135135
#if defined(WITH_SHANI)
136136
#define HAVE_SHANI
137137
#endif
@@ -204,9 +204,6 @@
204204
#endif
205205
#endif
206206

207-
/// C++20: parenthesized initialization of aggregates requires clang16/xcode16.
208-
/// We don't have macro treatment for that, just ad-hoc HAVE_CLANG conditions.
209-
210207
/// None on xcode.
211208
/// Requires link with -ltbb on gcc (v9).
212209
/// Experimental on clang (libcxx.llvm.org/Status/PSTL.html), requires:
@@ -227,7 +224,7 @@
227224
#define HAVE_SUPPRESSION
228225

229226
/// Disable noexcept to capture stack trace.
230-
#define HAVE_NOEXCEPT
227+
////#define HAVE_NOEXCEPT
231228

232229
/// Disable to emit all suppressed warnings.
233230
#define HAVE_WARNINGS

include/bitcoin/system/intrinsics/haves.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ namespace cpu1_0
7474
constexpr auto avx_ecx_bit = 28;
7575
}
7676

77-
// wikichip.org/wiki/x86/avx-512
7877
namespace cpu7_0
7978
{
8079
constexpr auto leaf = 7;

include/bitcoin/system/literals.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace libbitcoin {
3535
/// not be subject to regressions in other code, as a break here causes a large
3636
/// number of test and other failures. See tests for usage and detailed info.
3737
/// ---------------------------------------------------------------------------
38-
/// These should be consteval for safety, but waiting on clang++20 to catch up.
38+
/// These should be consteval for safety, but waiting on clang++ v17.
3939

4040
// Functions are consteval where available (bogus warning).
4141
BC_PUSH_WARNING(USE_CONSTEXPR_FOR_FUNCTION)

include/bitcoin/system/preprocessor.hpp

+16-7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@
3232
/// Debugging.
3333
/// ---------------------------------------------------------------------------
3434

35+
/// Enables ETW tracing for VS memory profiler.
36+
#if defined(HAVE_MSC)
37+
#define ALLOCATOR __declspec(allocator)
38+
#else
39+
#define ALLOCATOR
40+
#endif
41+
42+
/// learn.microsoft.com/en-us/cpp/c-runtime-library/
43+
/// find-memory-leaks-using-the-crt-library
44+
/// _CRTDBG_MAP_ALLOC must be prior to the includes, so defined in props.
45+
#if defined(HAVE_MSC) && defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
46+
#include <stdlib.h>
47+
#include <crtdbg.h>
48+
////_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
49+
#endif
50+
3551
/// NDEBUG (conditional exclusion).
3652
#if defined(NDEBUG)
3753
#define BC_ASSERT(expression)
@@ -44,13 +60,6 @@
4460
#define BC_DEBUG_ONLY(expression) expression
4561
#endif
4662

47-
/// Enables ETW tracing for VS memory profiler.
48-
#if defined(HAVE_MSC)
49-
#define ALLOCATOR __declspec(allocator)
50-
#else
51-
#define ALLOCATOR
52-
#endif
53-
5463
/// Messages.
5564
/// ---------------------------------------------------------------------------
5665

src/arena.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
*/
1919
#include <bitcoin/system/arena.hpp>
2020

21+
#include <cstdlib>
2122
#include <bitcoin/system/constants.hpp>
2223

2324
namespace libbitcoin {
2425

25-
BC_PUSH_WARNING(NO_NEW_OR_DELETE)
26-
2726
bool operator==(const arena& left, const arena& right) NOEXCEPT
2827
{
2928
return &left == &right || left.is_equal(right);
@@ -41,14 +40,18 @@ void* default_arena::do_allocate(size_t bytes, size_t) THROWS
4140
{
4241
////if (align > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
4342
//// return ::operator new(bytes, std::align_val_t{ align });
44-
return ::operator new(bytes);
43+
BC_PUSH_WARNING(NO_MALLOC_OR_FREE)
44+
return std::malloc(bytes);
45+
BC_POP_WARNING()
4546
}
4647

4748
void default_arena::do_deallocate(void* ptr, size_t, size_t) NOEXCEPT
4849
{
4950
////if (align > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
5051
//// ::operator delete(ptr, std::align_val_t{ align });
51-
::operator delete(ptr);
52+
BC_PUSH_WARNING(NO_MALLOC_OR_FREE)
53+
std::free(ptr);
54+
BC_POP_WARNING()
5255
}
5356

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

63+
// null return indicates that this arena is not detachable.
6064
void* default_arena::start(size_t) THROWS
6165
{
6266
return nullptr;
@@ -71,6 +75,4 @@ void default_arena::release(void*) NOEXCEPT
7175
{
7276
}
7377

74-
BC_POP_WARNING()
75-
7678
} // namespace libbitcoin

src/chain/block.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#include <algorithm>
2222
#include <iterator>
23-
#include <memory>
2423
#include <numeric>
2524
#include <ranges>
2625
#include <set>

src/chain/point.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
#include <bitcoin/system/chain/point.hpp>
2020

21-
#include <memory>
2221
#include <utility>
2322
#include <bitcoin/system/chain/enums/magic_numbers.hpp>
2423
#include <bitcoin/system/define.hpp>

src/chain/script.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#include <algorithm>
2222
#include <iterator>
23-
#include <memory>
2423
#include <numeric>
2524
#include <sstream>
2625
#include <utility>

src/chain/transaction.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#include <algorithm>
2222
#include <iterator>
23-
#include <memory>
2423
#include <numeric>
2524
#include <type_traits>
2625
#include <utility>

test/allocator.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ BC_PUSH_WARNING(NO_UNGUARDED_POINTERS)
2626
BC_PUSH_WARNING(NO_DELETE_RAW_POINTER)
2727
BC_PUSH_WARNING(NO_UNCLEARED_OWNER_POINTER)
2828

29-
// Clang is not yet C++20 compliant in terms of aggregate initialization.
30-
// See [reviews.llvm.org/D140327] for details. So vectors provide constructors.
31-
///////////////////////////////////////////////////////////////////////////////
32-
3329
struct simple
3430
{
3531
simple(size_t arg={}) NOEXCEPT

0 commit comments

Comments
 (0)