From 3c4635c81df99829a74655111ad237dc62059a08 Mon Sep 17 00:00:00 2001 From: Tim Hughes Date: Tue, 14 Jan 2014 11:55:41 +0000 Subject: [PATCH] Compile and warning fixes for Visual Studio 2013 and x64 --- libethereum/Common.h | 5 ++--- libethereum/Dagger.cpp | 6 +++++- libethereum/vector_ref.h | 20 ++++++++++++-------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/libethereum/Common.h b/libethereum/Common.h index 01918dea0..e543e5f6b 100644 --- a/libethereum/Common.h +++ b/libethereum/Common.h @@ -190,9 +190,8 @@ bytes toHex(std::string const& _s); template inline void toBigEndian(_T _val, _Out& o_out) { - auto s = o_out.size(); - for (uint i = 0; i < s; ++i, _val >>= 8) - o_out[s - 1 - i] = (typename _Out::value_type)(uint8_t)_val; + for (auto i = o_out.size(); i-- != 0; _val >>= 8) + o_out[i] = (typename _Out::value_type)(uint8_t)_val; } /// Converts a big-endian byte-stream represented on a templated collection to a templated integer value. diff --git a/libethereum/Dagger.cpp b/libethereum/Dagger.cpp index 171c3a261..17bbc4ffc 100644 --- a/libethereum/Dagger.cpp +++ b/libethereum/Dagger.cpp @@ -7,7 +7,9 @@ #include "Dagger.h" using namespace std; using namespace std::chrono; -using namespace eth; + +namespace eth +{ Dagger::Dagger(h256 _hash): m_hash(_hash) { @@ -93,3 +95,5 @@ u256 Dagger::eval(u256 _N) } return get(bsha); } + +} diff --git a/libethereum/vector_ref.h b/libethereum/vector_ref.h index facc5621e..7996f57d0 100644 --- a/libethereum/vector_ref.h +++ b/libethereum/vector_ref.h @@ -4,7 +4,11 @@ #include #include #include + +#pragma warning(push) +#pragma warning(disable: 4267) #include +#pragma warning(pop) namespace eth { @@ -17,7 +21,7 @@ public: typedef _T element_type; vector_ref(): m_data(nullptr), m_count(0) {} - vector_ref(_T* _data, unsigned _count): m_data(_data), m_count(_count) {} + vector_ref(_T* _data, size_t _count): m_data(_data), m_count(_count) {} vector_ref(std::string* _data): m_data((_T*)_data->data()), m_count(_data->size() / sizeof(_T)) {} vector_ref(typename std::conditional::value, std::vector::type> const*, std::vector<_T>*>::type _data): m_data(_data->data()), m_count(_data->size()) {} vector_ref(typename std::conditional::value, std::string const&, std::string&>::type _data): m_data((_T*)_data.data()), m_count(_data.size() / sizeof(_T)) {} @@ -31,11 +35,11 @@ public: template operator vector_ref<_T2>() const { assert(m_count * sizeof(_T) / sizeof(_T2) * sizeof(_T2) / sizeof(_T) == m_count); return vector_ref<_T2>((_T2*)m_data, m_count * sizeof(_T) / sizeof(_T2)); } _T* data() const { return m_data; } - unsigned count() const { return m_count; } - unsigned size() const { return m_count; } - unsigned empty() const { return !m_count; } + size_t count() const { return m_count; } + size_t size() const { return m_count; } + bool empty() const { return !m_count; } vector_ref<_T> next() const { return vector_ref<_T>(m_data + m_count, m_count); } - vector_ref<_T> cropped(unsigned _begin, int _count = -1) const { if (m_data && _begin + std::max(0, _count) <= m_count) return vector_ref<_T>(m_data + _begin, _count < 0 ? m_count - _begin : _count); else return vector_ref<_T>(); } + vector_ref<_T> cropped(size_t _begin, int _count = -1) const { if (m_data && _begin + std::max(0, _count) <= m_count) return vector_ref<_T>(m_data + _begin, _count < 0 ? m_count - _begin : _count); else return vector_ref<_T>(); } void retarget(_T const* _d, size_t _s) { m_data = _d; m_count = _s; } void retarget(std::vector<_T> const& _t) { m_data = _t.data(); m_count = _t.size(); } @@ -44,8 +48,8 @@ public: _T const* begin() const { return m_data; } _T const* end() const { return m_data + m_count; } - _T& operator[](unsigned _i) { assert(m_data); assert(_i < m_count); return m_data[_i]; } - _T const& operator[](unsigned _i) const { assert(m_data); assert(_i < m_count); return m_data[_i]; } + _T& operator[](size_t _i) { assert(m_data); assert(_i < m_count); return m_data[_i]; } + _T const& operator[](size_t _i) const { assert(m_data); assert(_i < m_count); return m_data[_i]; } bool operator==(vector_ref<_T> const& _cmp) const { return m_data == _cmp.m_data && m_count == _cmp.m_count; } bool operator!=(vector_ref<_T> const& _cmp) const { return !operator==(); } @@ -56,7 +60,7 @@ public: private: _T* m_data; - unsigned m_count; + size_t m_count; }; template vector_ref<_T const> ref(_T const& _t) { return vector_ref<_T const>(&_t, 1); }