Skip to content

Commit

Permalink
for a working MSVC++ bitcoind.exe version 0.8.6
Browse files Browse the repository at this point in the history
A full bitcoind.exe 0.8.6, with all asserts with side effects duplicated
in release mode.  All STL collection out of range references fixed with
no change to the gcc sources.  Added start up display of Boost and
levelDB versions to complement the existing OpenSSL version info.  BTW
this links and runs with OpenSSL 1.0.1g..

The MSVC++ code has added compile time warning level control to allow
better inspection of "suspect code".  Added  code to allow debug output
to the log file to actually work when DEBUG_LOCKCONTENTION-and
DEBUG_LOCKORDER  are defined..  This would be useful in the gcc compiled
version too.  Many other startup instrumentation parts were added in the
process of sorting out the problems in porting to MSVC, but they are all
only in play on the MS compiler.

Todo: add release mode assert  mirror code to json_spirit_reader and
writer_template.h files, since I missed them!

Ron
  • Loading branch information
bc4-old-c-coder committed Apr 18, 2014
1 parent 0071858 commit f0d221e
Show file tree
Hide file tree
Showing 46 changed files with 2,721 additions and 104 deletions.
14 changes: 14 additions & 0 deletions src/JustInCase.h
@@ -0,0 +1,14 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_JUSTINCASE_H
#define BITCOIN_JUSTINCASE_H

#ifdef _MSC_VER
#define __PRETTY_FUNCTION__ __FUNCTION__
#ifndef _DEBUG
extern void releaseModeAssertionfailure( const char* pFileName, const int nL, const std::string strFunctionName );
#endif
#endif
#endif
20 changes: 20 additions & 0 deletions src/MSVC_warnings.h
@@ -0,0 +1,20 @@
// Copyright (c) 2009-2012 Bitcoin Developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#pragma warning(disable:4503) // decorated name > the compiler limit (4096 characters, yikes!), truncated
#pragma warning( push )
#pragma warning(disable:4101) // local variable is never used
#pragma warning(disable:4146) // unary minus operator applied to unsigned type, result still unsigned
#pragma warning(disable:4244) // floating point type to an integer type. A possible loss of data
#pragma warning(disable:4267) // size_t' to 'type', possible loss of data
#pragma warning(disable:4288) // loop control variable declared in the for-loop is used outside the for-loop scope
#pragma warning(disable:4290) // function is declared using exception specification
#pragma warning(disable:4345) // object of POD type with an initializer of the form () will be default-initialized
//#pragma warning(disable:4503) // decorated name > the compiler limit (4096), truncated
#pragma warning(disable:4717) // recurse function
#pragma warning(disable:4786) // >255 char symbols for debugging
#pragma warning(disable:4800) // forcing value to bool 'true' or 'false' (performance warning)
#pragma warning(disable:4804) // unsafe bool usage, e.g. unary operator (-) or the complement operator (~).
#pragma warning(disable:4805) // comparison operations between unsafe bool and int for example
#pragma warning(disable:4996) // function that was marked with deprecated.
7 changes: 7 additions & 0 deletions src/MSVC_warnings.pop.h
@@ -0,0 +1,7 @@
// Copyright (c) 2009-2012 Bitcoin Developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifdef THE_BLUE_PILL
#pragma warning( pop )
#endif
17 changes: 17 additions & 0 deletions src/MSVC_warnings.push.h
@@ -0,0 +1,17 @@
// Copyright (c) 2009-2012 Bitcoin Developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifdef THE_BLUE_PILL
// You take the blue pill – the story ends, you wake up in your bed and
// believe whatever you want to believe

#ifdef THE_RED_PILL
// You take the red pill – you stay in Wonderland, and I show you how
// deep the rabbit hole goes. Remember, all I'm offering is the truth – nothing more
// [ at Warning level 3! ]
#pragma warning( push )
#else
#include "MSVC_warnings.h"
#endif
#endif
174 changes: 172 additions & 2 deletions src/addrman.cpp
Expand Up @@ -2,6 +2,13 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifdef _MSC_VER
#include <stdint.h> // this gets rid of the
// ...\program files\microsoft visual studio 8\vc\include\stdint.h(244) : warning C4005: 'INTMAX_C' : macro redefinition
// ...\libs\boost_1_53_0\boost\cstdint.hpp(423) : see previous definition of 'INTMAX_C'
#include "msvc_warnings.push.h"
#endif

#include "addrman.h"
#include "hash.h"

Expand Down Expand Up @@ -108,13 +115,43 @@ void CAddrMan::SwapRandom(unsigned int nRndPos1, unsigned int nRndPos2)
if (nRndPos1 == nRndPos2)
return;

#ifdef _MSC_VER
bool
fTest = (
(nRndPos1 < vRandom.size()) &&
(nRndPos2 < vRandom.size())
);
#ifdef _DEBUG
assert(fTest);
#else
if( !fTest )
releaseModeAssertionfailure( __FILE__, __LINE__, __PRETTY_FUNCTION__ );
#endif
#else
assert(nRndPos1 < vRandom.size() && nRndPos2 < vRandom.size());

#endif
int nId1 = vRandom[nRndPos1];
int nId2 = vRandom[nRndPos2];

#ifdef _MSC_VER
fTest = (1 == mapInfo.count(nId1));
#ifdef _DEBUG
assert(fTest);
#else
if( !fTest )
releaseModeAssertionfailure( __FILE__, __LINE__, __PRETTY_FUNCTION__ );
#endif

fTest = (1 == mapInfo.count(nId2));
#ifdef _DEBUG
assert(fTest);
#else
if( !fTest )
releaseModeAssertionfailure( __FILE__, __LINE__, __PRETTY_FUNCTION__ );
#endif
#else
assert(mapInfo.count(nId1) == 1);
assert(mapInfo.count(nId2) == 1);
#endif

mapInfo[nId1].nRandomPos = nRndPos2;
mapInfo[nId2].nRandomPos = nRndPos1;
Expand All @@ -137,7 +174,21 @@ int CAddrMan::SelectTried(int nKBucket)
int nTemp = vTried[nPos];
vTried[nPos] = vTried[i];
vTried[i] = nTemp;
#ifdef _MSC_VER
bool
fTest = (
(-1 == nOldest) ||
(1 == mapInfo.count(nTemp))
);
#ifdef _DEBUG
assert(fTest);
#else
if( !fTest )
releaseModeAssertionfailure( __FILE__, __LINE__, __PRETTY_FUNCTION__ );
#endif
#else
assert(nOldest == -1 || mapInfo.count(nTemp) == 1);
#endif
if (nOldest == -1 || mapInfo[nTemp].nLastSuccess < mapInfo[nOldest].nLastSuccess) {
nOldest = nTemp;
nOldestPos = nPos;
Expand All @@ -149,13 +200,37 @@ int CAddrMan::SelectTried(int nKBucket)

int CAddrMan::ShrinkNew(int nUBucket)
{
#ifdef _MSC_VER
bool
fTest = (
(nUBucket >= 0) &&
((unsigned int)nUBucket < vvNew.size())
);
#ifdef _DEBUG
assert(fTest);
#else
if( !fTest )
releaseModeAssertionfailure( __FILE__, __LINE__, __PRETTY_FUNCTION__ );
#endif
#else
assert(nUBucket >= 0 && (unsigned int)nUBucket < vvNew.size());
#endif
std::set<int> &vNew = vvNew[nUBucket];

// first look for deletable items
for (std::set<int>::iterator it = vNew.begin(); it != vNew.end(); it++)
{
#ifdef _MSC_VER
fTest = mapInfo.count(*it);
#ifdef _DEBUG
assert(fTest);
#else
if( !fTest )
releaseModeAssertionfailure( __FILE__, __LINE__, __PRETTY_FUNCTION__ );
#endif
#else
assert(mapInfo.count(*it));
#endif
CAddrInfo &info = mapInfo[*it];
if (info.IsTerrible())
{
Expand All @@ -180,13 +255,36 @@ int CAddrMan::ShrinkNew(int nUBucket)
{
if (nI == n[0] || nI == n[1] || nI == n[2] || nI == n[3])
{
#ifdef _MSC_VER
fTest = (
(-1 == nOldest) ||
(1 == mapInfo.count(*it))
);
#ifdef _DEBUG
assert(fTest);
#else
if( !fTest )
releaseModeAssertionfailure( __FILE__, __LINE__, __PRETTY_FUNCTION__ );
#endif
#else
assert(nOldest == -1 || mapInfo.count(*it) == 1);
#endif
if (nOldest == -1 || mapInfo[*it].nTime < mapInfo[nOldest].nTime)
nOldest = *it;
}
nI++;
}
#ifdef _MSC_VER
fTest = (1 == mapInfo.count(nOldest));
#ifdef _DEBUG
assert(fTest);
#else
if( !fTest )
releaseModeAssertionfailure( __FILE__, __LINE__, __PRETTY_FUNCTION__ );
#endif
#else
assert(mapInfo.count(nOldest) == 1);
#endif
CAddrInfo &info = mapInfo[nOldest];
if (--info.nRefCount == 0)
{
Expand All @@ -203,7 +301,18 @@ int CAddrMan::ShrinkNew(int nUBucket)

void CAddrMan::MakeTried(CAddrInfo& info, int nId, int nOrigin)
{
#ifdef _MSC_VER
bool
fTest = (1 == vvNew[nOrigin].count(nId));
#ifdef _DEBUG
assert(fTest);
#else
if( !fTest )
releaseModeAssertionfailure( __FILE__, __LINE__, __PRETTY_FUNCTION__ );
#endif
#else
assert(vvNew[nOrigin].count(nId) == 1);
#endif

// remove the entry from all new buckets
for (std::vector<std::set<int> >::iterator it = vvNew.begin(); it != vvNew.end(); it++)
Expand All @@ -213,7 +322,17 @@ void CAddrMan::MakeTried(CAddrInfo& info, int nId, int nOrigin)
}
nNew--;

#ifdef _MSC_VER
fTest = (0 == info.nRefCount);
#ifdef _DEBUG
assert(fTest);
#else
if( !fTest )
releaseModeAssertionfailure( __FILE__, __LINE__, __PRETTY_FUNCTION__ );
#endif
#else
assert(info.nRefCount == 0);
#endif

// what tried bucket to move the entry to
int nKBucket = info.GetTriedBucket(nKey);
Expand All @@ -232,7 +351,17 @@ void CAddrMan::MakeTried(CAddrInfo& info, int nId, int nOrigin)
int nPos = SelectTried(nKBucket);

// find which new bucket it belongs to
#ifdef _MSC_VER
fTest = (1 == mapInfo.count(vTried[nPos]));
#ifdef _DEBUG
assert(fTest);
#else
if( !fTest )
releaseModeAssertionfailure( __FILE__, __LINE__, __PRETTY_FUNCTION__ );
#endif
#else
assert(mapInfo.count(vTried[nPos]) == 1);
#endif
int nUBucket = mapInfo[vTried[nPos]].GetNewBucket(nKey);
std::set<int> &vNew = vvNew[nUBucket];

Expand Down Expand Up @@ -392,8 +521,13 @@ CAddress CAddrMan::Select_(int nUnkBias)
if (size() == 0)
return CAddress();

#ifdef _MSC_VER
double nCorTried = sqrt(double(nTried)) * (100.0 - nUnkBias);
double nCorNew = sqrt(double(nNew)) * nUnkBias;
#else
double nCorTried = sqrt(nTried) * (100.0 - nUnkBias);
double nCorNew = sqrt(nNew) * nUnkBias;
#endif
if ((nCorTried + nCorNew)*GetRandInt(1<<30)/(1<<30) < nCorTried)
{
// use a tried node
Expand All @@ -404,7 +538,18 @@ CAddress CAddrMan::Select_(int nUnkBias)
std::vector<int> &vTried = vvTried[nKBucket];
if (vTried.size() == 0) continue;
int nPos = GetRandInt(vTried.size());
#ifdef _MSC_VER
bool
fTest = (1 == mapInfo.count(vTried[nPos]));
#ifdef _DEBUG
assert(fTest);
#else
if( !fTest )
releaseModeAssertionfailure( __FILE__, __LINE__, __PRETTY_FUNCTION__ );
#endif
#else
assert(mapInfo.count(vTried[nPos]) == 1);
#endif
CAddrInfo &info = mapInfo[vTried[nPos]];
if (GetRandInt(1<<30) < fChanceFactor*info.GetChance()*(1<<30))
return info;
Expand All @@ -422,7 +567,18 @@ CAddress CAddrMan::Select_(int nUnkBias)
std::set<int>::iterator it = vNew.begin();
while (nPos--)
it++;
#ifdef _MSC_VER
bool
fTest = (1 == mapInfo.count(*it));
#ifdef _DEBUG
assert(fTest);
#else
if( !fTest )
releaseModeAssertionfailure( __FILE__, __LINE__, __PRETTY_FUNCTION__ );
#endif
#else
assert(mapInfo.count(*it) == 1);
#endif
CAddrInfo &info = mapInfo[*it];
if (GetRandInt(1<<30) < fChanceFactor*info.GetChance()*(1<<30))
return info;
Expand Down Expand Up @@ -502,7 +658,18 @@ void CAddrMan::GetAddr_(std::vector<CAddress> &vAddr)
{
int nRndPos = GetRandInt(vRandom.size() - n) + n;
SwapRandom(n, nRndPos);
#ifdef _MSC_VER
bool
fTest = (1 == mapInfo.count(vRandom[n]));
#ifdef _DEBUG
assert(fTest);
#else
if( !fTest )
releaseModeAssertionfailure( __FILE__, __LINE__, __PRETTY_FUNCTION__ );
#endif
#else
assert(mapInfo.count(vRandom[n]) == 1);
#endif
vAddr.push_back(mapInfo[vRandom[n]]);
}
}
Expand All @@ -526,3 +693,6 @@ void CAddrMan::Connected_(const CService &addr, int64 nTime)
if (nTime - info.nTime > nUpdateInterval)
info.nTime = nTime;
}
#ifdef _MSC_VER
#include "msvc_warnings.pop.h"
#endif

0 comments on commit f0d221e

Please sign in to comment.