X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fserialize.h;h=44eb4f580341a95fc1a00639899732511cebccd1;hb=265dcc7e227581180487d4a34aaca2c9a82d0db0;hp=12ea1ec695f0f0068f3aa3fe67fd48a574c9f0c6;hpb=6b6aaa1698838278a547f16a15e635bd58ec867d;p=novacoin.git diff --git a/src/serialize.h b/src/serialize.h index 12ea1ec..44eb4f5 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -1,7 +1,7 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying -// file license.txt or http://www.opensource.org/licenses/mit-license.php. +// file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_SERIALIZE_H #define BITCOIN_SERIALIZE_H @@ -154,9 +154,14 @@ template inline void Serialize(Stream& s, bool a, int, int=0) template inline void Unserialize(Stream& s, bool& a, int, int=0) { char f; READDATA(s, f); a=f; } - - - +#ifndef THROW_WITH_STACKTRACE +#define THROW_WITH_STACKTRACE(exception) \ +{ \ + LogStackTrace(); \ + throw (exception); \ +} +void LogStackTrace(); +#endif // // Compact size @@ -234,7 +239,7 @@ uint64 ReadCompactSize(Stream& is) nSizeRet = xSize; } if (nSizeRet > (uint64)MAX_SIZE) - throw std::ios_base::failure("ReadCompactSize() : size too large"); + THROW_WITH_STACKTRACE(std::ios_base::failure("ReadCompactSize() : size too large")); return nSizeRet; } @@ -243,7 +248,6 @@ uint64 ReadCompactSize(Stream& is) #define FLATDATA(obj) REF(CFlatData((char*)&(obj), (char*)&(obj) + sizeof(obj))) /** Wrapper for serializing arrays and POD. - * There's a clever template way to make arrays serialize normally, but MSVC6 doesn't support it. */ class CFlatData { @@ -809,7 +813,8 @@ public: void insert(iterator it, const_iterator first, const_iterator last) { - if (it == vch.begin() + nReadPos && last - first <= nReadPos) + assert(last - first >= 0); + if (it == vch.begin() + nReadPos && (unsigned int)(last - first) <= nReadPos) { // special case for inserting at the front when there's room nReadPos -= (last - first); @@ -819,22 +824,12 @@ public: vch.insert(it, first, last); } - void insert(iterator it, std::vector::const_iterator first, std::vector::const_iterator last) - { - if (it == vch.begin() + nReadPos && last - first <= nReadPos) - { - // special case for inserting at the front when there's room - nReadPos -= (last - first); - memcpy(&vch[nReadPos], &first[0], last - first); - } - else - vch.insert(it, first, last); - } #if !defined(_MSC_VER) || _MSC_VER >= 1300 void insert(iterator it, const char* first, const char* last) { - if (it == vch.begin() + nReadPos && last - first <= nReadPos) + assert(last - first >= 0); + if (it == vch.begin() + nReadPos && (unsigned int)(last - first) <= nReadPos) { // special case for inserting at the front when there's room nReadPos -= (last - first); @@ -905,7 +900,7 @@ public: { state |= bits; if (state & exceptmask) - throw std::ios_base::failure(psz); + THROW_WITH_STACKTRACE(std::ios_base::failure(psz)); } bool eof() const { return size() == 0; } @@ -1007,57 +1002,6 @@ public: } }; -#ifdef TESTCDATASTREAM -// VC6sp6 -// CDataStream: -// n=1000 0 seconds -// n=2000 0 seconds -// n=4000 0 seconds -// n=8000 0 seconds -// n=16000 0 seconds -// n=32000 0 seconds -// n=64000 1 seconds -// n=128000 1 seconds -// n=256000 2 seconds -// n=512000 4 seconds -// n=1024000 8 seconds -// n=2048000 16 seconds -// n=4096000 32 seconds -// stringstream: -// n=1000 1 seconds -// n=2000 1 seconds -// n=4000 13 seconds -// n=8000 87 seconds -// n=16000 400 seconds -// n=32000 1660 seconds -// n=64000 6749 seconds -// n=128000 27241 seconds -// n=256000 109804 seconds -#include -int main(int argc, char *argv[]) -{ - vector vch(0xcc, 250); - printf("CDataStream:\n"); - for (int n = 1000; n <= 4500000; n *= 2) - { - CDataStream ss; - time_t nStart = time(NULL); - for (int i = 0; i < n; i++) - ss.write((char*)&vch[0], vch.size()); - printf("n=%-10d %d seconds\n", n, time(NULL) - nStart); - } - printf("stringstream:\n"); - for (int n = 1000; n <= 4500000; n *= 2) - { - stringstream ss; - time_t nStart = time(NULL); - for (int i = 0; i < n; i++) - ss.write((char*)&vch[0], vch.size()); - printf("n=%-10d %d seconds\n", n, time(NULL) - nStart); - } -} -#endif - @@ -1083,8 +1027,6 @@ public: int nType; int nVersion; - typedef FILE element_type; - CAutoFile(FILE* filenew, int nTypeIn, int nVersionIn) { file = filenew; @@ -1122,7 +1064,7 @@ public: { state |= bits; if (state & exceptmask) - throw std::ios_base::failure(psz); + THROW_WITH_STACKTRACE(std::ios_base::failure(psz)); } bool fail() const { return state & (std::ios::badbit | std::ios::failbit); }