Skip to content

Commit

Permalink
Merge bitcoin#11558: Minimal code changes to allow msvc compilation
Browse files Browse the repository at this point in the history
fbf327b Minimal code changes to allow msvc compilation. (Aaron Clauson)

Pull request description:

  These changes are required to allow the Bitcoin source to build with Microsoft's C++ compiler (bitcoin#11562 is also required).

  I looked around for a better place for the typedef of ssize_t which is in random.h. The best candidate looks like src/compat.h but I figured including that header in random.h is a bigger change than the typedef. Note that the same typedef is in at least two other places including the OpenSSL and Berkeley DB headers so some of the Bitcoin code already picks it up.

Tree-SHA512: aa6cc6283015e08ab074641f9abdc116c4dc58574dc90f75e7a5af4cc82946d3052370e5cbe855fb6180c00f8dc66997d3724ff0412e4b7417e51b6602154825
  • Loading branch information
laanwj authored and gades committed Jun 30, 2021
1 parent ecb5193 commit ad3bab0
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/bench/base58.cpp
Expand Up @@ -22,7 +22,7 @@ static void Base58Encode(benchmark::State& state)
}
};
while (state.KeepRunning()) {
EncodeBase58(buff.begin(), buff.end());
EncodeBase58(buff.data(), buff.data() + buff.size());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/bench/checkqueue.cpp
Expand Up @@ -19,7 +19,7 @@ static const int MIN_CORES = 2;
static const size_t BATCHES = 101;
static const size_t BATCH_SIZE = 30;
static const int PREVECTOR_SIZE = 28;
static const int QUEUE_BATCH_SIZE = 128;
static const unsigned int QUEUE_BATCH_SIZE = 128;
static void CCheckQueueSpeed(benchmark::State& state)
{
struct FakeJobNoWork {
Expand Down
14 changes: 7 additions & 7 deletions src/chainparams.cpp
Expand Up @@ -429,9 +429,9 @@ class CMainParams : public CChainParams {

nStakeMinAge = 24 * 60 * 60; // 24 hours

checkpointData = (CCheckpointData) {
checkpointData = {
{
{0, uint256S("0x000006cf010a54f22305095939df01cc5d7a2ecd208e1e353259a75cd99f58b4")},
{0, uint256S("0x00000ce07df018e65e003f4d097cf026db99bcd493d6c4d07f0b47edf6534a26")},
}
};

Expand Down Expand Up @@ -594,9 +594,9 @@ class CTestNetParams : public CChainParams {

nStakeMinAge = 24 * 60 * 60; // 24 hours

checkpointData = (CCheckpointData) {
checkpointData = {
{
{0, uint256S("0x00000d08a9828c9e2c4c95996e1a3895e24de49d0b62ef595486a428d727cede")},
{0, uint256S("0x0000030f02c1f2473c1b3d7988b7d83a5e2cde4b2b69fe1612befdcbcb8eb70f")},
}
};

Expand Down Expand Up @@ -758,7 +758,7 @@ class CDevNetParams : public CChainParams {

nStakeMinAge = 24 * 60 * 60; // 24 hours

checkpointData = (CCheckpointData) {
checkpointData = {
{
{ 1, devnetGenesis.GetHash() },
}
Expand Down Expand Up @@ -879,9 +879,9 @@ class CRegTestParams : public CChainParams {

nStakeMinAge = 24 * 60 * 60; // 24 hours

checkpointData = (CCheckpointData) {
checkpointData = {
{
{0, uint256S("0x00000d204dc7f3c855835549afbf59d8002502ae2b56bc46826ca41b7bfc5651")},
{0, uint256S("0x02fc1e7262651eb1027ef489dae355c0ca063bc4832ca4b6d41d18216268835c")},
}
};

Expand Down
10 changes: 10 additions & 0 deletions src/compat.h
Expand Up @@ -41,6 +41,7 @@
#include <mswsock.h>
#include <windows.h>
#include <ws2tcpip.h>
#include <stdint.h>
#else
#include <sys/fcntl.h>
#include <sys/mman.h>
Expand Down Expand Up @@ -81,6 +82,15 @@ typedef unsigned int SOCKET;
#else
#define MAX_PATH 1024
#endif
#ifdef _MSC_VER
#if !defined(ssize_t)
#ifdef _WIN64
typedef int64_t ssize_t;
#else
typedef int32_t ssize_t;
#endif
#endif
#endif

#if HAVE_DECL_STRNLEN == 0
size_t strnlen( const char *start, size_t max_len);
Expand Down
2 changes: 1 addition & 1 deletion src/net_processing.cpp
Expand Up @@ -63,7 +63,7 @@ std::atomic<int64_t> nTimeBestReceived(0); // Used only to inform the wallet of
struct IteratorComparator
{
template<typename I>
bool operator()(const I& a, const I& b)
bool operator()(const I& a, const I& b) const
{
return &(*a) < &(*b);
}
Expand Down
2 changes: 1 addition & 1 deletion src/random.h
Expand Up @@ -138,7 +138,7 @@ class FastRandomContext {
* sure that the underlying OS APIs for all platforms support the number.
* (many cap out at 256 bytes).
*/
static const ssize_t NUM_OS_RANDOM_BYTES = 32;
static const int NUM_OS_RANDOM_BYTES = 32;

/** Get 32 bytes of system entropy. Do not use this in application code: use
* GetStrongRandBytes instead.
Expand Down
6 changes: 5 additions & 1 deletion src/support/cleanse.cpp
Expand Up @@ -7,6 +7,10 @@

#include <cstring>

#if defined(_MSC_VER)
#include <Windows.h> // For SecureZeroMemory.
#endif

/* Compilers have a bad habit of removing "superfluous" memset calls that
* are trying to zero memory. For example, when memset()ing a buffer and
* then free()ing it, the compiler might decide that the memset is
Expand All @@ -32,7 +36,7 @@ void memory_cleanse(void *ptr, size_t len)
might try to eliminate "superfluous" memsets. If there's an easy way to
detect memset_s, it would be better to use that. */
#if defined(_MSC_VER)
__asm;
SecureZeroMemory(ptr, len);
#else
__asm__ __volatile__("" : : "r"(ptr) : "memory");
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/test/checkqueue_tests.cpp
Expand Up @@ -24,7 +24,7 @@
// otherwise.
BOOST_FIXTURE_TEST_SUITE(checkqueue_tests, TestingSetup)

static const int QUEUE_BATCH_SIZE = 128;
static const unsigned int QUEUE_BATCH_SIZE = 128;

struct FakeCheck {
bool operator()()
Expand Down

0 comments on commit ad3bab0

Please sign in to comment.