Skip to content

Commit

Permalink
Merge pull request ifdefelse#13 from ethereum-mining/master
Browse files Browse the repository at this point in the history
Merge from ethminer master
  • Loading branch information
AndreaLanfranchi authored Nov 28, 2018
2 parents 5f11c5e + 07ea6f9 commit 67dcbfb
Show file tree
Hide file tree
Showing 20 changed files with 101 additions and 86 deletions.
8 changes: 8 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,modernize-*,bugprone-*,readability-*,-readability-implicit-bool-conversion,performance-*'
WarningsAsErrors: ''
HeaderFilterRegex: 'ethminer/.*'
CheckOptions:
- key: readability-braces-around-statements.ShortStatementLines
value: '3'
...
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ before_install:
- |
if [ "$TRAVIS_OS_NAME" = linux ]; then
echo "Checking format of sourcecode..."
find . -type f -name '*.cpp' -o -name '*.h' -print0 | xargs -r0 clang-format -i
find . -type f \( -name '*.cpp' -o -name '*.h' -o -name '*.cu' -o -name '*.cuh' \) -print0 | xargs -r0 clang-format -i
git diff --color # --exit-code
fi
- |
Expand Down
6 changes: 3 additions & 3 deletions ethminer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class MinerCLI
}

#if ETH_DBUS
dbusint.send(toString(mp).c_str());
dbusint.send(toString(Farm::f().miningProgress()).c_str());
#endif
}
else
Expand Down Expand Up @@ -928,7 +928,7 @@ class MinerCLI
"should "
<< endl
<< " listen on." << endl
<< " --api-port INT [1 .. 65535] Default not set" << endl
<< " --http-port INT [1 .. 65535] Default not set" << endl
<< " Set the http port, the miner should listen on all "
"bound"
<< endl
Expand Down Expand Up @@ -1077,7 +1077,7 @@ class MinerCLI
"exits"
<< endl
<< " Must be combined with -G or -U or -X flags" << endl
<< " -L,--dag-load-mode INT[0 .. 2] Default = 0" << endl
<< " -L,--dag-load-mode INT[0 .. 1] Default = 0" << endl
<< " Set DAG load mode. Can be one of:" << endl
<< " 0 Parallel load mode (each GPU independently)" << endl
<< " 1 Sequential load mode (one GPU after another)" << endl
Expand Down
2 changes: 1 addition & 1 deletion libapicore/ApiServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ApiConnection
m_is_authenticated = false;
}

~ApiConnection() {}
~ApiConnection() = default;

void start();

Expand Down
2 changes: 1 addition & 1 deletion libdevcore/CommonData.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ inline T fromBigEndian(_In const& _bytes)
inline bytes toBigEndian(u256 _val)
{
bytes ret(32);
toBigEndian(_val, ret);
toBigEndian(std::move(_val), ret);
return ret;
}
inline bytes toBigEndian(u160 _val)
Expand Down
9 changes: 7 additions & 2 deletions libdevcore/FixedHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ class FixedHash
}

/// Explicitly construct, copying from a bytes in memory with given pointer.
explicit FixedHash(byte const* _bs, ConstructFromPointerType) { memcpy(m_data.data(), _bs, N); }
explicit FixedHash(byte const* _bs, ConstructFromPointerType /*unused*/)
{
memcpy(m_data.data(), _bs, N);
}

/// Explicitly construct, copying from a string.
explicit FixedHash(std::string const& _s)
Expand All @@ -149,10 +152,12 @@ class FixedHash
bool operator<(FixedHash const& _c) const
{
for (unsigned i = 0; i < N; ++i)
{
if (m_data[i] < _c.m_data[i])
return true;
else if (m_data[i] > _c.m_data[i])
if (m_data[i] > _c.m_data[i])
return false;
}
return false;
}
bool operator>=(FixedHash const& _c) const { return !operator<(_c); }
Expand Down
2 changes: 1 addition & 1 deletion libdevcore/Guards.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ template <class N>
class Notified
{
public:
Notified() {}
Notified() = default;
Notified(N const& _v) : m_value(_v) {}
Notified(Notified const&) = delete;
Notified& operator=(N const& _v)
Expand Down
9 changes: 5 additions & 4 deletions libdevcore/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ void dev::simpleDebugOut(std::string const& _s)
{
try
{
std::ostream& os = g_logStdout ? std::cout : std::clog;
if (!g_logNoColor)
{
(g_logStdout ? std::cout : std::cerr) << _s + '\n';
(g_logStdout ? std::cout : std::cerr).flush();
os << _s + '\n';
os.flush();
return;
}
bool skip = false;
Expand All @@ -123,8 +124,8 @@ void dev::simpleDebugOut(std::string const& _s)
ss << it;
}
ss << '\n';
(g_logStdout ? std::cout : std::cerr) << ss.str();
(g_logStdout ? std::cout : std::cerr).flush();
os << ss.str();
os.flush();
}
catch (...)
{
Expand Down
58 changes: 27 additions & 31 deletions libdevcore/RLP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ size_t RLP::length() const
byte const n = m_data[0];
if (n < c_rlpDataImmLenStart)
return 1;
else if (n <= c_rlpDataIndLenZero)
if (n <= c_rlpDataIndLenZero)
return n - c_rlpDataImmLenStart;
else if (n < c_rlpListStart)
if (n < c_rlpListStart)
{
if (m_data.size() <= size_t(n - c_rlpDataIndLenZero))
BOOST_THROW_EXCEPTION(BadRLP());
Expand Down Expand Up @@ -210,16 +210,16 @@ size_t RLP::items() const
{
bytesConstRef d = payload();
size_t i = 0;
for (; d.size(); ++i)
for (; !d.empty(); ++i)
d = d.cropped(sizeAsEncoded(d));
return i;
}
return 0;
}

RLPStream& RLPStream::appendRaw(bytesConstRef _s, size_t _itemCount)
RLPStream& RLPStream::appendRaw(bytesConstRef _rlp, size_t _itemCount)
{
m_out.insert(m_out.end(), _s.begin(), _s.end());
m_out.insert(m_out.end(), _rlp.begin(), _rlp.end());
noteAppended(_itemCount);
return *this;
}
Expand All @@ -239,32 +239,27 @@ void RLPStream::noteAppended(size_t _itemCount)
m_listStack.back().first -= _itemCount;
if (m_listStack.back().first)
break;
else

auto p = m_listStack.back().second;
m_listStack.pop_back();
size_t s = m_out.size() - p; // list size
auto brs = bytesRequired(s);
unsigned encodeSize = s < c_rlpListImmLenCount ? 1 : (1 + brs);
auto os = m_out.size();
m_out.resize(os + encodeSize);
memmove(m_out.data() + p + encodeSize, m_out.data() + p, os - p);
if (s < c_rlpListImmLenCount)
m_out[p] = (byte)(c_rlpListStart + s);
else if (c_rlpListIndLenZero + brs <= 0xff)
{
auto p = m_listStack.back().second;
m_listStack.pop_back();
size_t s = m_out.size() - p; // list size
auto brs = bytesRequired(s);
unsigned encodeSize = s < c_rlpListImmLenCount ? 1 : (1 + brs);
// cdebug << "s: " << s << ", p: " << p << ", m_out.size(): " << m_out.size()
//<<
//", encodeSize: " << encodeSize << " (br: " << brs << ")";
auto os = m_out.size();
m_out.resize(os + encodeSize);
memmove(m_out.data() + p + encodeSize, m_out.data() + p, os - p);
if (s < c_rlpListImmLenCount)
m_out[p] = (byte)(c_rlpListStart + s);
else if (c_rlpListIndLenZero + brs <= 0xff)
{
m_out[p] = (byte)(c_rlpListIndLenZero + brs);
byte* b = &(m_out[p + brs]);
for (; s; s >>= 8)
*(b--) = (byte)s;
}
else
BOOST_THROW_EXCEPTION(
RLPException() << errinfo_comment("itemCount too large for RLP"));
m_out[p] = (byte)(c_rlpListIndLenZero + brs);
byte* b = &(m_out[p + brs]);
for (; s; s >>= 8)
*(b--) = (byte)s;
}
else
BOOST_THROW_EXCEPTION(RLPException() << errinfo_comment("itemCount too large for RLP"));

_itemCount = 1; // for all following iterations, we've effectively appended a single item
// only since we completed a list.
}
Expand Down Expand Up @@ -295,9 +290,10 @@ RLPStream& RLPStream::append(bytesConstRef _s, bool _compact)
size_t s = _s.size();
byte const* d = _s.data();
if (_compact)
{
for (size_t i = 0; i < _s.size() && !*d; ++i, --s, ++d)
{
}
;
}

if (s == 1 && *d < c_rlpDataImmLenStart)
m_out.push_back(*d);
Expand Down
18 changes: 9 additions & 9 deletions libdevcore/RLP.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class RLP
using Strictness = int;

/// Construct a null node.
RLP() {}
RLP() = default;

/// Construct a node of value given in the bytes.
explicit RLP(bytesConstRef _d, Strictness _s = VeryStrict);
Expand All @@ -118,7 +118,7 @@ class RLP
explicit operator bool() const { return !isNull(); }

/// No value.
bool isNull() const { return m_data.size() == 0; }
bool isNull() const { return m_data.empty(); }

/// String value.
bool isData() const { return !isNull() && m_data[0] < c_rlpListStart; }
Expand Down Expand Up @@ -191,18 +191,18 @@ class RLP
bool operator!=(iterator const& _cmp) const { return !operator==(_cmp); }

private:
iterator() {}
iterator() = default;
iterator(RLP const& _parent, bool _begin);

size_t m_remaining = 0;
bytesConstRef m_currentItem;
};

/// @brief Iterator into beginning of sub-item list (valid only if we are a list).
iterator begin() const { return iterator(*this, true); }
iterator begin() const { return {*this, true}; }

/// @brief Iterator into end of sub-item list (valid only if we are a list).
iterator end() const { return iterator(*this, false); }
iterator end() const { return {*this, false}; }

/// Best-effort conversion operators.
explicit operator std::string() const { return toString(); }
Expand Down Expand Up @@ -404,18 +404,18 @@ class RLPStream
{
public:
/// Initializes empty RLPStream.
RLPStream() {}
RLPStream() = default;

/// Initializes the RLPStream as a list of @a _listItems items.
explicit RLPStream(size_t _listItems) { appendList(_listItems); }

~RLPStream() {}
~RLPStream() = default;

/// Append given datum to the byte stream.
RLPStream& append(unsigned _s) { return append(bigint(_s)); }
RLPStream& append(u160 _s) { return append(bigint(_s)); }
RLPStream& append(u256 _s) { return append(bigint(_s)); }
RLPStream& append(bigint _s);
RLPStream& append(bigint _i);
RLPStream& append(bytesConstRef _s, bool _compact = false);
RLPStream& append(bytes const& _s) { return append(bytesConstRef(&_s)); }
RLPStream& append(std::string const& _s) { return append(bytesConstRef(_s)); }
Expand Down Expand Up @@ -483,7 +483,7 @@ class RLPStream

/// Push the node-type byte (using @a _base) along with the item count @a _count.
/// @arg _count is number of characters for strings, data-bytes for ints, or items for lists.
void pushCount(size_t _count, byte _offset);
void pushCount(size_t _count, byte _base);

/// Push an integer as a raw big-endian byte-stream.
template <class _T>
Expand Down
2 changes: 1 addition & 1 deletion libdevcore/Worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ enum class WorkerState
class Worker
{
public:
Worker(std::string const& _name) : m_name(_name) {}
Worker(std::string _name) : m_name(std::move(_name)) {}

Worker(Worker const&) = delete;
Worker& operator=(Worker const&) = delete;
Expand Down
18 changes: 5 additions & 13 deletions libdevcore/vector_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ class vector_ref
{
if (!m_data || m_count == 0)
return _c.empty();
else
return _c.size() == m_count && !memcmp(_c.data(), m_data, m_count * sizeof(_T));
return _c.size() == m_count && !memcmp(_c.data(), m_data, m_count * sizeof(_T));
}
std::vector<mutable_value_type> toVector() const
{
Expand Down Expand Up @@ -90,8 +89,7 @@ class vector_ref
{
if (!m_data)
return *this;
else
return vector_ref<_T>(m_data + m_count, m_count);
return vector_ref<_T>(m_data + m_count, m_count);
}
/// @returns a new vector_ref which is a shifted and shortened view of the original data.
/// If this goes out of bounds in any way, returns an empty vector_ref.
Expand All @@ -101,17 +99,15 @@ class vector_ref
if (m_data && _begin <= m_count && _count <= m_count && _begin + _count <= m_count)
return vector_ref<_T>(
m_data + _begin, _count == ~size_t(0) ? m_count - _begin : _count);
else
return vector_ref<_T>();
return {};
}
/// @returns a new vector_ref which is a shifted view of the original data (not going beyond
/// it).
vector_ref<_T> cropped(size_t _begin) const
{
if (m_data && _begin <= m_count)
return vector_ref<_T>(m_data + _begin, m_count - _begin);
else
return vector_ref<_T>();
return {};
}
void retarget(_T* _d, size_t _s)
{
Expand Down Expand Up @@ -153,7 +149,7 @@ class vector_ref
void cleanse()
{
static unsigned char s_cleanseCounter = 0;
uint8_t* p = (uint8_t*)begin();
auto* p = (uint8_t*)begin();
size_t const len = (uint8_t*)end() - p;
size_t loop = len;
size_t count = s_cleanseCounter;
Expand Down Expand Up @@ -193,10 +189,6 @@ class vector_ref
}
bool operator!=(vector_ref<_T> const& _cmp) const { return !operator==(_cmp); }

#if DEV_LDB
operator ldb::Slice() const { return ldb::Slice((char const*)m_data, m_count * sizeof(_T)); }
#endif

void reset()
{
m_data = nullptr;
Expand Down
3 changes: 1 addition & 2 deletions libethash-cl/CLMiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,7 @@ bool CLMiner::initEpoch_internal()
// create mining buffers
ETHCL_LOG("Creating mining buffer");
m_searchBuffer.clear();
m_searchBuffer.push_back(
cl::Buffer(m_context[0], CL_MEM_WRITE_ONLY, sizeof(SearchResults)));
m_searchBuffer.emplace_back(m_context[0], CL_MEM_WRITE_ONLY, sizeof(SearchResults));

m_dagKernel.setArg(1, m_light[0]);
m_dagKernel.setArg(2, m_dag[0]);
Expand Down
2 changes: 1 addition & 1 deletion libethcore/Miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class Miner : public Worker
: Worker(_name + std::to_string(_index)), m_index(_index)
{}

virtual ~Miner() = default;
~Miner() override = default;

/**
* @brief Assigns the device descriptor to this instance
Expand Down
Loading

0 comments on commit 67dcbfb

Please sign in to comment.