Browse Source

Fix MLOAD case to set stack.back() to zero and ifdef the clang workarounds for map::operator[].

cl-refactor
Daniel Hams 11 years ago
parent
commit
c898272228
  1. 4
      libethereum/AddressState.h
  2. 22
      libethereum/State.cpp
  3. 8
      libethereum/State.h

4
libethereum/AddressState.h

@ -43,6 +43,7 @@ public:
AddressState(u256 _balance, u256 _nonce, u256s _memory): m_type(AddressType::Contract), m_balance(_balance), m_nonce(_nonce), m_haveMemory(true)
{
for (unsigned i = 0; i < _memory.size(); ++i)
#ifdef __clang__
{
auto mFinder = m_memory.find((u256)i);
if (mFinder == m_memory.end())
@ -50,6 +51,9 @@ public:
else
mFinder->second = _memory[i];
}
#else
m_memory[(u256)i] = _memory[i];
#endif
}
void incNonce() { m_nonce++; }

22
libethereum/State.cpp

@ -179,10 +179,14 @@ void State::ensureCached(Address _a, bool _requireMemory, bool _forceCreate) con
TrieDB<h256, Overlay> memdb(const_cast<Overlay*>(&m_db), it->second.oldRoot()); // promise we won't alter the overlay! :)
map<u256, u256>& mem = it->second.setHaveMemory();
for (auto const& i: memdb)
#ifdef __clang__
if (mem.find(i.first) == mem.end())
mem.insert(make_pair(i.first, RLP(i.second).toInt<u256>()));
else
mem.at(i.first) = RLP(i.second).toInt<u256>();
#else
mem[i.first] = RLP(i.second).toInt<u256>();
#endif
}
}
@ -707,10 +711,14 @@ void State::executeBare(Transaction const& _t, Address _sender)
m_cache[newAddress] = AddressState(0, 0, AddressType::Contract);
auto& mem = m_cache[newAddress].memory();
for (uint i = 0; i < _t.data.size(); ++i)
#ifdef __clang__
if (mem.find(i) == mem.end())
mem.insert(make_pair(i, _t.data[i]));
else
mem.at(i) = _t.data[i];
#else
mem[i] = _t.data[i];
#endif
#if ETH_SENDER_PAYS_SETUP
subBalance(_sender, _t.value + fee);
@ -752,11 +760,15 @@ void State::execute(Address _myAddress, Address _txSender, u256 _txValue, u256s
{
if (_v)
{
#ifdef __clang__
auto it = myStore.find(_n);
if (it == myStore.end())
myStore.insert(make_pair(_n, _v));
else
myStore.at(_n) = _v;
#else
myStore[_n] = _v;
#endif
}
else
myStore.erase(_n);
@ -1160,21 +1172,29 @@ void State::execute(Address _myAddress, Address _txSender, u256 _txValue, u256s
case Instruction::MLOAD:
{
require(1);
#ifdef __clang__
auto mFinder = tempMem.find(stack.back());
if (mFinder != tempMem.end())
stack.back() = mFinder->second;
else
throw BadInstruction();
stack.back() = 0;
#else
stack.back() = tempMem[stack.back()];
#endif
break;
}
case Instruction::MSTORE:
{
require(2);
#ifdef __clang__
auto mFinder = tempMem.find(stack.back());
if (mFinder == tempMem.end())
tempMem.insert(std::pair<u256,u256>(stack.back(), stack[stack.size() - 2]));
else
mFinder->second = stack[stack.size() - 2];
#else
tempMem[stack.back()] = stack[stack.size() - 2];
#endif
stack.pop_back();
stack.pop_back();
break;

8
libethereum/State.h

@ -272,11 +272,15 @@ inline std::ostream& operator<<(std::ostream& _out, State const& _s)
for (auto const& j: memdb)
{
_out << std::endl << " [" << j.first << ":" << asHex(j.second) << "]";
#ifdef __clang__
auto mFinder = mem.find(j.first);
if (mFinder == mem.end())
mem.insert(std::pair<u256,u256>(j.first, RLP(j.second).toInt<u256>()));
else
mFinder->second = RLP(j.second).toInt<u256>();
#else
mem[j.first] = RLP(j.second).toInt<u256>();
#endif
}
_out << std::endl << mem;
}
@ -305,11 +309,15 @@ inline std::ostream& operator<<(std::ostream& _out, State const& _s)
for (auto const& j: memdb)
{
_out << std::endl << " [" << j.first << ":" << asHex(j.second) << "]";
#ifdef __clang__
auto mFinder = mem.find(j.first);
if (mFinder == mem.end())
mem.insert(std::pair<u256,u256>(j.first, RLP(j.second).toInt<u256>()));
else
mFinder->second = RLP(j.second).toInt<u256>();
#else
mem[j.first] = RLP(j.second).toInt<u256>();
#endif
}
_out << std::endl << mem;
}

Loading…
Cancel
Save