Merge #11558: Minimal code changes to allow msvc compilation

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 (#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
This commit is contained in:
Wladimir J. van der Laan 2017-12-13 13:32:00 +01:00 committed by Pasta
parent 3855979343
commit 39a8e20de6
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
8 changed files with 23 additions and 9 deletions

View File

@ -22,7 +22,7 @@ static void Base58Encode(benchmark::State& state)
} }
}; };
while (state.KeepRunning()) { while (state.KeepRunning()) {
EncodeBase58(buff.begin(), buff.end()); EncodeBase58(buff.data(), buff.data() + buff.size());
} }
} }

View File

@ -19,7 +19,7 @@ static const int MIN_CORES = 2;
static const size_t BATCHES = 101; static const size_t BATCHES = 101;
static const size_t BATCH_SIZE = 30; static const size_t BATCH_SIZE = 30;
static const int PREVECTOR_SIZE = 28; 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) static void CCheckQueueSpeed(benchmark::State& state)
{ {
struct FakeJobNoWork { struct FakeJobNoWork {

View File

@ -404,7 +404,7 @@ public:
nMinSporkKeys = 1; nMinSporkKeys = 1;
fBIP9CheckMasternodesUpgraded = true; fBIP9CheckMasternodesUpgraded = true;
checkpointData = (CCheckpointData) { checkpointData = {
{ {
{1500, uint256S("0x000000aaf0300f59f49bc3e970bad15c11f961fe2347accffff19d96ec9778e3")}, {1500, uint256S("0x000000aaf0300f59f49bc3e970bad15c11f961fe2347accffff19d96ec9778e3")},
{4991, uint256S("0x000000003b01809551952460744d5dbb8fcbd6cbae3c220267bf7fa43f837367")}, {4991, uint256S("0x000000003b01809551952460744d5dbb8fcbd6cbae3c220267bf7fa43f837367")},
@ -580,7 +580,7 @@ public:
nMinSporkKeys = 1; nMinSporkKeys = 1;
fBIP9CheckMasternodesUpgraded = true; fBIP9CheckMasternodesUpgraded = true;
checkpointData = (CCheckpointData) { checkpointData = {
{ {
{261, uint256S("0x00000c26026d0815a7e2ce4fa270775f61403c040647ff2c3091f99e894a4618")}, {261, uint256S("0x00000c26026d0815a7e2ce4fa270775f61403c040647ff2c3091f99e894a4618")},
{1999, uint256S("0x00000052e538d27fa53693efe6fb6892a0c1d26c0235f599171c48a3cce553b1")}, {1999, uint256S("0x00000052e538d27fa53693efe6fb6892a0c1d26c0235f599171c48a3cce553b1")},
@ -848,7 +848,7 @@ public:
// regtest usually has no masternodes in most tests, so don't check for upgraged MNs // regtest usually has no masternodes in most tests, so don't check for upgraged MNs
fBIP9CheckMasternodesUpgraded = false; fBIP9CheckMasternodesUpgraded = false;
checkpointData = (CCheckpointData) { checkpointData = {
{ {
{0, uint256S("0x000008ca1832a4baf228eb1553c03d3a2c8e02399550dd6ea8d65cec3ef23d2e")}, {0, uint256S("0x000008ca1832a4baf228eb1553c03d3a2c8e02399550dd6ea8d65cec3ef23d2e")},
} }

View File

@ -41,6 +41,7 @@
#include <mswsock.h> #include <mswsock.h>
#include <windows.h> #include <windows.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#include <stdint.h>
#else #else
#include <fcntl.h> #include <fcntl.h>
#include <sys/mman.h> #include <sys/mman.h>
@ -81,6 +82,15 @@ typedef unsigned int SOCKET;
#else #else
#define MAX_PATH 1024 #define MAX_PATH 1024
#endif #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 #if HAVE_DECL_STRNLEN == 0
size_t strnlen( const char *start, size_t max_len); size_t strnlen( const char *start, size_t max_len);

View File

@ -64,7 +64,7 @@ std::atomic<int64_t> nTimeBestReceived(0); // Used only to inform the wallet of
struct IteratorComparator struct IteratorComparator
{ {
template<typename I> template<typename I>
bool operator()(const I& a, const I& b) bool operator()(const I& a, const I& b) const
{ {
return &(*a) < &(*b); return &(*a) < &(*b);
} }

View File

@ -138,7 +138,7 @@ public:
* sure that the underlying OS APIs for all platforms support the number. * sure that the underlying OS APIs for all platforms support the number.
* (many cap out at 256 bytes). * (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 /** Get 32 bytes of system entropy. Do not use this in application code: use
* GetStrongRandBytes instead. * GetStrongRandBytes instead.

View File

@ -7,6 +7,10 @@
#include <cstring> #include <cstring>
#if defined(_MSC_VER)
#include <Windows.h> // For SecureZeroMemory.
#endif
/* Compilers have a bad habit of removing "superfluous" memset calls that /* Compilers have a bad habit of removing "superfluous" memset calls that
* are trying to zero memory. For example, when memset()ing a buffer and * 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 * then free()ing it, the compiler might decide that the memset is
@ -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 might try to eliminate "superfluous" memsets. If there's an easy way to
detect memset_s, it would be better to use that. */ detect memset_s, it would be better to use that. */
#if defined(_MSC_VER) #if defined(_MSC_VER)
__asm; SecureZeroMemory(ptr, len);
#else #else
__asm__ __volatile__("" : : "r"(ptr) : "memory"); __asm__ __volatile__("" : : "r"(ptr) : "memory");
#endif #endif

View File

@ -24,7 +24,7 @@
// otherwise. // otherwise.
BOOST_FIXTURE_TEST_SUITE(checkqueue_tests, TestingSetup) BOOST_FIXTURE_TEST_SUITE(checkqueue_tests, TestingSetup)
static const int QUEUE_BATCH_SIZE = 128; static const unsigned int QUEUE_BATCH_SIZE = 128;
struct FakeCheck { struct FakeCheck {
bool operator()() bool operator()()