Skip to content

Commit 4395b7f

Browse files
committed
Merge bitcoin/bitcoin#26814: refactor: remove windows-only compat.h usage in random
621cfb7 random: consolidate WIN32 #ifdefs (fanquake) 75ec627 random: remove compat.h include (fanquake) 4dc1281 random: use int for MAX_TRIES (fanquake) Pull request description: This change is related to removing the use of `compat.h` as a miscellaneous catch-all for unclear/platform specific includes. Somewhat prompted by IWYU-related discussion here: https://github.com/bitcoin/bitcoin/pull/26763/files#r1058861693. The only reason `compat.h` is required in random.cpp for Windows (note the `#ifdef WIN32`), is for `ssize_t` and an "indirect" inclusion of `windows.h`. I say indirect, because `windows.h` isn't actually included in compat.h either, it's dragged in as a side-effect of other windows includes there, i.e `winsock2.h`. Remove this coupling by replacing `ssize_t` with int, just including `windows.h` and removing compat.h. ACKs for top commit: hebasto: re-ACK 621cfb7, rebased only since my [recent](bitcoin/bitcoin#26814 (review)) review. Verified with: john-moffett: ACK 621cfb7 Tree-SHA512: 31e1ed2e7ff7daf6c3ee72e6a908def52f7addf8305ba371c5032f1927cbb8ef5d302785e8de42b5c04a123052f04688cc9fd80decceb04738b5d9153f3d32d7
2 parents a245429 + 621cfb7 commit 4395b7f

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/random.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,22 @@
88
#include <compat/cpuid.h>
99
#include <crypto/sha256.h>
1010
#include <crypto/sha512.h>
11-
#include <support/cleanse.h>
12-
#ifdef WIN32
13-
#include <compat/compat.h>
14-
#include <wincrypt.h>
15-
#endif
1611
#include <logging.h>
1712
#include <randomenv.h>
18-
#include <support/allocators/secure.h>
1913
#include <span.h>
20-
#include <sync.h> // for Mutex
21-
#include <util/time.h> // for GetTimeMicros()
14+
#include <support/allocators/secure.h>
15+
#include <support/cleanse.h>
16+
#include <sync.h>
17+
#include <util/time.h>
2218

2319
#include <cmath>
2420
#include <cstdlib>
2521
#include <thread>
2622

27-
#ifndef WIN32
23+
#ifdef WIN32
24+
#include <windows.h>
25+
#include <wincrypt.h>
26+
#else
2827
#include <fcntl.h>
2928
#include <sys/time.h>
3029
#endif
@@ -634,7 +633,7 @@ bool Random_SanityCheck()
634633
* GetOSRand() overwrites all 32 bytes of the output given a maximum
635634
* number of tries.
636635
*/
637-
static const ssize_t MAX_TRIES = 1024;
636+
static constexpr int MAX_TRIES{1024};
638637
uint8_t data[NUM_OS_RANDOM_BYTES];
639638
bool overwritten[NUM_OS_RANDOM_BYTES] = {}; /* Tracks which bytes have been overwritten at least once */
640639
int num_overwritten;

0 commit comments

Comments
 (0)