Browse Source

Get rid of C99 PRI?64 usage in source files

Amend to d5f1e72. It turns out that BerkelyDB was including inttypes.h
indirectly, so we cannot fix this with just macros.

Trivial commit: apply the following script to all .cpp and .h files:

    # Middle
    sed -i 's/"PRIx64"/x/g' "$1"
    sed -i 's/"PRIu64"/u/g' "$1"
    sed -i 's/"PRId64"/d/g' "$1"
    # Initial
    sed -i 's/PRIx64"/"x/g' "$1"
    sed -i 's/PRIu64"/"u/g' "$1"
    sed -i 's/PRId64"/"d/g' "$1"
    # Trailing
    sed -i 's/"PRIx64/x"/g' "$1"
    sed -i 's/"PRIu64/u"/g' "$1"
    sed -i 's/"PRId64/d"/g' "$1"

After this commit, `git grep` for PRI.64 should turn up nothing except
the defines in util.h.
0.10
Wladimir J. van der Laan 11 years ago
parent
commit
f48742c2bf
  1. 4
      src/alert.cpp
  2. 2
      src/core.cpp
  3. 2
      src/db.cpp
  4. 10
      src/init.cpp
  5. 14
      src/main.cpp
  6. 2
      src/miner.cpp
  7. 2
      src/net.cpp
  8. 2
      src/net.h
  9. 2
      src/rpcnet.cpp
  10. 6
      src/test/util_tests.cpp
  11. 8
      src/util.cpp
  12. 2
      src/util.h
  13. 10
      src/wallet.cpp
  14. 6
      src/walletdb.cpp

4
src/alert.cpp

@ -51,8 +51,8 @@ std::string CUnsignedAlert::ToString() const
return strprintf( return strprintf(
"CAlert(\n" "CAlert(\n"
" nVersion = %d\n" " nVersion = %d\n"
" nRelayUntil = %"PRId64"\n" " nRelayUntil = %d\n"
" nExpiration = %"PRId64"\n" " nExpiration = %d\n"
" nID = %d\n" " nID = %d\n"
" nCancel = %d\n" " nCancel = %d\n"
" setCancel = %s\n" " setCancel = %s\n"

2
src/core.cpp

@ -64,7 +64,7 @@ uint256 CTxOut::GetHash() const
std::string CTxOut::ToString() const std::string CTxOut::ToString() const
{ {
return strprintf("CTxOut(nValue=%"PRId64".%08"PRId64", scriptPubKey=%s)", nValue / COIN, nValue % COIN, scriptPubKey.ToString().substr(0,30)); return strprintf("CTxOut(nValue=%d.%08d, scriptPubKey=%s)", nValue / COIN, nValue % COIN, scriptPubKey.ToString().substr(0,30));
} }
void CTxOut::print() const void CTxOut::print() const

2
src/db.cpp

@ -463,7 +463,7 @@ void CDBEnv::Flush(bool fShutdown)
else else
mi++; mi++;
} }
LogPrint("db", "DBFlush(%s)%s ended %15"PRId64"ms\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started", GetTimeMillis() - nStart); LogPrint("db", "DBFlush(%s)%s ended %15dms\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started", GetTimeMillis() - nStart);
if (fShutdown) if (fShutdown)
{ {
char** listp; char** listp;

10
src/init.cpp

@ -599,7 +599,7 @@ bool AppInit2(boost::thread_group& threadGroup)
{ {
// try moving the database env out of the way // try moving the database env out of the way
boost::filesystem::path pathDatabase = GetDataDir() / "database"; boost::filesystem::path pathDatabase = GetDataDir() / "database";
boost::filesystem::path pathDatabaseBak = GetDataDir() / strprintf("database.%"PRId64".bak", GetTime()); boost::filesystem::path pathDatabaseBak = GetDataDir() / strprintf("database.%d.bak", GetTime());
try { try {
boost::filesystem::rename(pathDatabase, pathDatabaseBak); boost::filesystem::rename(pathDatabase, pathDatabaseBak);
LogPrintf("Moved old %s to %s. Retrying.\n", pathDatabase.string(), pathDatabaseBak.string()); LogPrintf("Moved old %s to %s. Retrying.\n", pathDatabase.string(), pathDatabaseBak.string());
@ -874,7 +874,7 @@ bool AppInit2(boost::thread_group& threadGroup)
LogPrintf("Shutdown requested. Exiting.\n"); LogPrintf("Shutdown requested. Exiting.\n");
return false; return false;
} }
LogPrintf(" block index %15"PRId64"ms\n", GetTimeMillis() - nStart); LogPrintf(" block index %15dms\n", GetTimeMillis() - nStart);
if (GetBoolArg("-printblockindex", false) || GetBoolArg("-printblocktree", false)) if (GetBoolArg("-printblockindex", false) || GetBoolArg("-printblocktree", false))
{ {
@ -985,7 +985,7 @@ bool AppInit2(boost::thread_group& threadGroup)
} }
LogPrintf("%s", strErrors.str()); LogPrintf("%s", strErrors.str());
LogPrintf(" wallet %15"PRId64"ms\n", GetTimeMillis() - nStart); LogPrintf(" wallet %15dms\n", GetTimeMillis() - nStart);
RegisterWallet(pwalletMain); RegisterWallet(pwalletMain);
@ -1007,7 +1007,7 @@ bool AppInit2(boost::thread_group& threadGroup)
LogPrintf("Rescanning last %i blocks (from block %i)...\n", chainActive.Height() - pindexRescan->nHeight, pindexRescan->nHeight); LogPrintf("Rescanning last %i blocks (from block %i)...\n", chainActive.Height() - pindexRescan->nHeight, pindexRescan->nHeight);
nStart = GetTimeMillis(); nStart = GetTimeMillis();
pwalletMain->ScanForWalletTransactions(pindexRescan, true); pwalletMain->ScanForWalletTransactions(pindexRescan, true);
LogPrintf(" rescan %15"PRId64"ms\n", GetTimeMillis() - nStart); LogPrintf(" rescan %15dms\n", GetTimeMillis() - nStart);
pwalletMain->SetBestChain(chainActive.GetLocator()); pwalletMain->SetBestChain(chainActive.GetLocator());
nWalletDBUpdated++; nWalletDBUpdated++;
} }
@ -1042,7 +1042,7 @@ bool AppInit2(boost::thread_group& threadGroup)
LogPrintf("Invalid or missing peers.dat; recreating\n"); LogPrintf("Invalid or missing peers.dat; recreating\n");
} }
LogPrintf("Loaded %i addresses from peers.dat %"PRId64"ms\n", LogPrintf("Loaded %i addresses from peers.dat %dms\n",
addrman.size(), GetTimeMillis() - nStart); addrman.size(), GetTimeMillis() - nStart);
// ********************************************************* Step 11: start node // ********************************************************* Step 11: start node

14
src/main.cpp

@ -822,7 +822,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
// Don't accept it if it can't get into a block // Don't accept it if it can't get into a block
int64_t txMinFee = GetMinFee(tx, nSize, true, GMF_RELAY); int64_t txMinFee = GetMinFee(tx, nSize, true, GMF_RELAY);
if (fLimitFree && nFees < txMinFee) if (fLimitFree && nFees < txMinFee)
return state.DoS(0, error("AcceptToMemoryPool : not enough fees %s, %"PRId64" < %"PRId64, return state.DoS(0, error("AcceptToMemoryPool : not enough fees %s, %d < %d",
hash.ToString(), nFees, txMinFee), hash.ToString(), nFees, txMinFee),
REJECT_INSUFFICIENTFEE, "insufficient fee"); REJECT_INSUFFICIENTFEE, "insufficient fee");
@ -851,7 +851,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
} }
if (fRejectInsaneFee && nFees > CTransaction::nMinRelayTxFee * 10000) if (fRejectInsaneFee && nFees > CTransaction::nMinRelayTxFee * 10000)
return error("AcceptToMemoryPool: : insane fees %s, %"PRId64" > %"PRId64, return error("AcceptToMemoryPool: : insane fees %s, %d > %d",
hash.ToString(), hash.ToString(),
nFees, CTransaction::nMinRelayTxFee * 10000); nFees, CTransaction::nMinRelayTxFee * 10000);
@ -1168,7 +1168,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
// Limit adjustment step // Limit adjustment step
int64_t nActualTimespan = pindexLast->GetBlockTime() - pindexFirst->GetBlockTime(); int64_t nActualTimespan = pindexLast->GetBlockTime() - pindexFirst->GetBlockTime();
LogPrintf(" nActualTimespan = %"PRId64" before bounds\n", nActualTimespan); LogPrintf(" nActualTimespan = %d before bounds\n", nActualTimespan);
if (nActualTimespan < nTargetTimespan/4) if (nActualTimespan < nTargetTimespan/4)
nActualTimespan = nTargetTimespan/4; nActualTimespan = nTargetTimespan/4;
if (nActualTimespan > nTargetTimespan*4) if (nActualTimespan > nTargetTimespan*4)
@ -1185,7 +1185,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
/// debug print /// debug print
LogPrintf("GetNextWorkRequired RETARGET\n"); LogPrintf("GetNextWorkRequired RETARGET\n");
LogPrintf("nTargetTimespan = %"PRId64" nActualTimespan = %"PRId64"\n", nTargetTimespan, nActualTimespan); LogPrintf("nTargetTimespan = %d nActualTimespan = %d\n", nTargetTimespan, nActualTimespan);
LogPrintf("Before: %08x %s\n", pindexLast->nBits, CBigNum().SetCompact(pindexLast->nBits).getuint256().ToString()); LogPrintf("Before: %08x %s\n", pindexLast->nBits, CBigNum().SetCompact(pindexLast->nBits).getuint256().ToString());
LogPrintf("After: %08x %s\n", bnNew.GetCompact(), bnNew.getuint256().ToString()); LogPrintf("After: %08x %s\n", bnNew.GetCompact(), bnNew.getuint256().ToString());
@ -1737,7 +1737,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
if (block.vtx[0].GetValueOut() > GetBlockValue(pindex->nHeight, nFees)) if (block.vtx[0].GetValueOut() > GetBlockValue(pindex->nHeight, nFees))
return state.DoS(100, return state.DoS(100,
error("ConnectBlock() : coinbase pays too much (actual=%"PRId64" vs limit=%"PRId64")", error("ConnectBlock() : coinbase pays too much (actual=%d vs limit=%d)",
block.vtx[0].GetValueOut(), GetBlockValue(pindex->nHeight, nFees)), block.vtx[0].GetValueOut(), GetBlockValue(pindex->nHeight, nFees)),
REJECT_INVALID, "bad-cb-amount"); REJECT_INVALID, "bad-cb-amount");
@ -3014,7 +3014,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
AbortNode(_("Error: system error: ") + e.what()); AbortNode(_("Error: system error: ") + e.what());
} }
if (nLoaded > 0) if (nLoaded > 0)
LogPrintf("Loaded %i blocks from external file in %"PRId64"ms\n", nLoaded, GetTimeMillis() - nStart); LogPrintf("Loaded %i blocks from external file in %dms\n", nLoaded, GetTimeMillis() - nStart);
return nLoaded > 0; return nLoaded > 0;
} }
@ -3804,7 +3804,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
} }
if (!(sProblem.empty())) { if (!(sProblem.empty())) {
LogPrint("net", "pong %s %s: %s, %"PRIx64" expected, %"PRIx64" received, %"PRIszu" bytes\n", LogPrint("net", "pong %s %s: %s, %x expected, %x received, %"PRIszu" bytes\n",
pfrom->addr.ToString(), pfrom->addr.ToString(),
pfrom->cleanSubVer, pfrom->cleanSubVer,
sProblem, sProblem,

2
src/miner.cpp

@ -319,7 +319,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
nLastBlockTx = nBlockTx; nLastBlockTx = nBlockTx;
nLastBlockSize = nBlockSize; nLastBlockSize = nBlockSize;
LogPrintf("CreateNewBlock(): total size %"PRIu64"\n", nBlockSize); LogPrintf("CreateNewBlock(): total size %u\n", nBlockSize);
pblock->vtx[0].vout[0].nValue = GetBlockValue(pindexPrev->nHeight+1, nFees); pblock->vtx[0].vout[0].nValue = GetBlockValue(pindexPrev->nHeight+1, nFees);
pblocktemplate->vTxFees[0] = -nFees; pblocktemplate->vTxFees[0] = -nFees;

2
src/net.cpp

@ -1243,7 +1243,7 @@ void DumpAddresses()
CAddrDB adb; CAddrDB adb;
adb.Write(addrman); adb.Write(addrman);
LogPrint("net", "Flushed %d addresses to peers.dat %"PRId64"ms\n", LogPrint("net", "Flushed %d addresses to peers.dat %dms\n",
addrman.size(), GetTimeMillis() - nStart); addrman.size(), GetTimeMillis() - nStart);
} }

2
src/net.h

@ -423,7 +423,7 @@ public:
nRequestTime = it->second; nRequestTime = it->second;
else else
nRequestTime = 0; nRequestTime = 0;
LogPrint("net", "askfor %s %"PRId64" (%s)\n", inv.ToString().c_str(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000).c_str()); LogPrint("net", "askfor %s %d (%s)\n", inv.ToString().c_str(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000).c_str());
// Make sure not to reuse time indexes to keep things in the same order // Make sure not to reuse time indexes to keep things in the same order
int64_t nNow = (GetTime() - 1) * 1000000; int64_t nNow = (GetTime() - 1) * 1000000;

2
src/rpcnet.cpp

@ -119,7 +119,7 @@ Value getpeerinfo(const Array& params, bool fHelp)
obj.push_back(Pair("addr", stats.addrName)); obj.push_back(Pair("addr", stats.addrName));
if (!(stats.addrLocal.empty())) if (!(stats.addrLocal.empty()))
obj.push_back(Pair("addrlocal", stats.addrLocal)); obj.push_back(Pair("addrlocal", stats.addrLocal));
obj.push_back(Pair("services", strprintf("%08"PRIx64, stats.nServices))); obj.push_back(Pair("services", strprintf("%08x", stats.nServices)));
obj.push_back(Pair("lastsend", (boost::int64_t)stats.nLastSend)); obj.push_back(Pair("lastsend", (boost::int64_t)stats.nLastSend));
obj.push_back(Pair("lastrecv", (boost::int64_t)stats.nLastRecv)); obj.push_back(Pair("lastrecv", (boost::int64_t)stats.nLastRecv));
obj.push_back(Pair("bytessent", (boost::int64_t)stats.nSendBytes)); obj.push_back(Pair("bytessent", (boost::int64_t)stats.nSendBytes));

6
src/test/util_tests.cpp

@ -311,9 +311,9 @@ BOOST_AUTO_TEST_CASE(strprintf_numbers)
{ {
int64_t s64t = -9223372036854775807LL; /* signed 64 bit test value */ int64_t s64t = -9223372036854775807LL; /* signed 64 bit test value */
uint64_t u64t = 18446744073709551615ULL; /* unsigned 64 bit test value */ uint64_t u64t = 18446744073709551615ULL; /* unsigned 64 bit test value */
BOOST_CHECK(strprintf("%s %"PRId64" %s", B, s64t, E) == B" -9223372036854775807 "E); BOOST_CHECK(strprintf("%s %d %s", B, s64t, E) == B" -9223372036854775807 "E);
BOOST_CHECK(strprintf("%s %"PRIu64" %s", B, u64t, E) == B" 18446744073709551615 "E); BOOST_CHECK(strprintf("%s %u %s", B, u64t, E) == B" 18446744073709551615 "E);
BOOST_CHECK(strprintf("%s %"PRIx64" %s", B, u64t, E) == B" ffffffffffffffff "E); BOOST_CHECK(strprintf("%s %x %s", B, u64t, E) == B" ffffffffffffffff "E);
size_t st = 12345678; /* unsigned size_t test value */ size_t st = 12345678; /* unsigned size_t test value */
ssize_t sst = -12345678; /* signed size_t test value */ ssize_t sst = -12345678; /* signed size_t test value */

8
src/util.cpp

@ -330,7 +330,7 @@ string FormatMoney(int64_t n, bool fPlus)
int64_t n_abs = (n > 0 ? n : -n); int64_t n_abs = (n > 0 ? n : -n);
int64_t quotient = n_abs/COIN; int64_t quotient = n_abs/COIN;
int64_t remainder = n_abs%COIN; int64_t remainder = n_abs%COIN;
string str = strprintf("%"PRId64".%08"PRId64, quotient, remainder); string str = strprintf("%d.%08d", quotient, remainder);
// Right-trim excess zeros before the decimal point: // Right-trim excess zeros before the decimal point:
int nTrim = 0; int nTrim = 0;
@ -1278,7 +1278,7 @@ void AddTimeData(const CNetAddr& ip, int64_t nTime)
// Add data // Add data
static CMedianFilter<int64_t> vTimeOffsets(200,0); static CMedianFilter<int64_t> vTimeOffsets(200,0);
vTimeOffsets.input(nOffsetSample); vTimeOffsets.input(nOffsetSample);
LogPrintf("Added time data, samples %d, offset %+"PRId64" (%+"PRId64" minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60); LogPrintf("Added time data, samples %d, offset %+d (%+d minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60);
if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1) if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1)
{ {
int64_t nMedian = vTimeOffsets.median(); int64_t nMedian = vTimeOffsets.median();
@ -1313,10 +1313,10 @@ void AddTimeData(const CNetAddr& ip, int64_t nTime)
} }
if (fDebug) { if (fDebug) {
BOOST_FOREACH(int64_t n, vSorted) BOOST_FOREACH(int64_t n, vSorted)
LogPrintf("%+"PRId64" ", n); LogPrintf("%+d ", n);
LogPrintf("| "); LogPrintf("| ");
} }
LogPrintf("nTimeOffset = %+"PRId64" (%+"PRId64" minutes)\n", nTimeOffset, nTimeOffset/60); LogPrintf("nTimeOffset = %+d (%+d minutes)\n", nTimeOffset, nTimeOffset/60);
} }
} }

2
src/util.h

@ -234,7 +234,7 @@ void runCommand(std::string strCommand);
inline std::string i64tostr(int64_t n) inline std::string i64tostr(int64_t n)
{ {
return strprintf("%"PRId64, n); return strprintf("%d", n);
} }
inline std::string itostr(int n) inline std::string itostr(int n)

10
src/wallet.cpp

@ -1693,7 +1693,7 @@ bool CWallet::NewKeyPool()
walletdb.WritePool(nIndex, CKeyPool(GenerateNewKey())); walletdb.WritePool(nIndex, CKeyPool(GenerateNewKey()));
setKeyPool.insert(nIndex); setKeyPool.insert(nIndex);
} }
LogPrintf("CWallet::NewKeyPool wrote %"PRId64" new keys\n", nKeys); LogPrintf("CWallet::NewKeyPool wrote %d new keys\n", nKeys);
} }
return true; return true;
} }
@ -1723,7 +1723,7 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
if (!walletdb.WritePool(nEnd, CKeyPool(GenerateNewKey()))) if (!walletdb.WritePool(nEnd, CKeyPool(GenerateNewKey())))
throw runtime_error("TopUpKeyPool() : writing generated key failed"); throw runtime_error("TopUpKeyPool() : writing generated key failed");
setKeyPool.insert(nEnd); setKeyPool.insert(nEnd);
LogPrintf("keypool added key %"PRId64", size=%"PRIszu"\n", nEnd, setKeyPool.size()); LogPrintf("keypool added key %d, size=%"PRIszu"\n", nEnd, setKeyPool.size());
} }
} }
return true; return true;
@ -1752,7 +1752,7 @@ void CWallet::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool)
if (!HaveKey(keypool.vchPubKey.GetID())) if (!HaveKey(keypool.vchPubKey.GetID()))
throw runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool"); throw runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool");
assert(keypool.vchPubKey.IsValid()); assert(keypool.vchPubKey.IsValid());
LogPrintf("keypool reserve %"PRId64"\n", nIndex); LogPrintf("keypool reserve %d\n", nIndex);
} }
} }
@ -1779,7 +1779,7 @@ void CWallet::KeepKey(int64_t nIndex)
CWalletDB walletdb(strWalletFile); CWalletDB walletdb(strWalletFile);
walletdb.ErasePool(nIndex); walletdb.ErasePool(nIndex);
} }
LogPrintf("keypool keep %"PRId64"\n", nIndex); LogPrintf("keypool keep %d\n", nIndex);
} }
void CWallet::ReturnKey(int64_t nIndex) void CWallet::ReturnKey(int64_t nIndex)
@ -1789,7 +1789,7 @@ void CWallet::ReturnKey(int64_t nIndex)
LOCK(cs_wallet); LOCK(cs_wallet);
setKeyPool.insert(nIndex); setKeyPool.insert(nIndex);
} }
LogPrintf("keypool return %"PRId64"\n", nIndex); LogPrintf("keypool return %d\n", nIndex);
} }
bool CWallet::GetKeyFromPool(CPubKey& result) bool CWallet::GetKeyFromPool(CPubKey& result)

6
src/walletdb.cpp

@ -383,7 +383,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
pwallet->AddToWallet(wtx, true); pwallet->AddToWallet(wtx, true);
//// debug print //// debug print
//LogPrintf("LoadWallet %s\n", wtx.GetHash().ToString()); //LogPrintf("LoadWallet %s\n", wtx.GetHash().ToString());
//LogPrintf(" %12"PRId64" %s %s %s\n", //LogPrintf(" %12d %s %s %s\n",
// wtx.vout[0].nValue, // wtx.vout[0].nValue,
// DateTimeStrFormat("%Y-%m-%d %H:%M:%S", wtx.GetBlockTime()), // DateTimeStrFormat("%Y-%m-%d %H:%M:%S", wtx.GetBlockTime()),
// wtx.hashBlock.ToString(), // wtx.hashBlock.ToString(),
@ -816,7 +816,7 @@ void ThreadFlushWalletDB(const string& strFile)
bitdb.CheckpointLSN(strFile); bitdb.CheckpointLSN(strFile);
bitdb.mapFileUseCount.erase(mi++); bitdb.mapFileUseCount.erase(mi++);
LogPrint("db", "Flushed wallet.dat %"PRId64"ms\n", GetTimeMillis() - nStart); LogPrint("db", "Flushed wallet.dat %dms\n", GetTimeMillis() - nStart);
} }
} }
} }
@ -877,7 +877,7 @@ bool CWalletDB::Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys)
// Set -rescan so any missing transactions will be // Set -rescan so any missing transactions will be
// found. // found.
int64_t now = GetTime(); int64_t now = GetTime();
std::string newFilename = strprintf("wallet.%"PRId64".bak", now); std::string newFilename = strprintf("wallet.%d.bak", now);
int result = dbenv.dbenv.dbrename(NULL, filename.c_str(), NULL, int result = dbenv.dbenv.dbrename(NULL, filename.c_str(), NULL,
newFilename.c_str(), DB_AUTO_COMMIT); newFilename.c_str(), DB_AUTO_COMMIT);

Loading…
Cancel
Save