Browse Source

Use safe pointers in Executive

cl-refactor
Paweł Bylica 10 years ago
parent
commit
160aa47288
  1. 15
      libethereum/Executive.cpp
  2. 17
      libethereum/Executive.h
  3. 1
      libethereum/State.cpp
  4. 1
      libethereum/State.h
  5. 1
      test/vm.cpp

15
libethereum/Executive.cpp

@ -32,13 +32,6 @@ using namespace dev::eth;
#define ETH_VMTRACE 1 #define ETH_VMTRACE 1
Executive::~Executive()
{
// TODO: Make safe.
delete m_ext;
delete m_vm;
}
u256 Executive::gasUsed() const u256 Executive::gasUsed() const
{ {
return m_t.gas() - m_endGas; return m_t.gas() - m_endGas;
@ -112,9 +105,9 @@ bool Executive::call(Address _receiveAddress, Address _senderAddress, u256 _valu
if (m_s.addressHasCode(_receiveAddress)) if (m_s.addressHasCode(_receiveAddress))
{ {
m_vm = new VM(_gas); m_vm.reset(new VM(_gas));
bytes const& c = m_s.code(_receiveAddress); bytes const& c = m_s.code(_receiveAddress);
m_ext = new ExtVM(m_s, _receiveAddress, _senderAddress, _originAddress, _value, _gasPrice, _data, &c, m_ms); m_ext.reset(new ExtVM(m_s, _receiveAddress, _senderAddress, _originAddress, _value, _gasPrice, _data, &c, m_ms));
} }
else else
m_endGas = _gas; m_endGas = _gas;
@ -131,8 +124,8 @@ bool Executive::create(Address _sender, u256 _endowment, u256 _gasPrice, u256 _g
m_s.m_cache[m_newAddress] = Account(m_s.balance(m_newAddress) + _endowment, Account::ContractConception); m_s.m_cache[m_newAddress] = Account(m_s.balance(m_newAddress) + _endowment, Account::ContractConception);
// Execute _init. // Execute _init.
m_vm = new VM(_gas); m_vm.reset(new VM(_gas));
m_ext = new ExtVM(m_s, m_newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _init, m_ms); m_ext.reset(new ExtVM(m_s, m_newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _init, m_ms));
return _init.empty(); return _init.empty();
} }

17
libethereum/Executive.h

@ -25,18 +25,17 @@
#include <libdevcore/Log.h> #include <libdevcore/Log.h>
#include <libevmcore/Instruction.h> #include <libevmcore/Instruction.h>
#include <libethcore/CommonEth.h> #include <libethcore/CommonEth.h>
#include <libevm/ExtVMFace.h> #include <libevm/VMFace.h>
#include "Transaction.h" #include "Transaction.h"
#include "Manifest.h" #include "ExtVM.h"
namespace dev namespace dev
{ {
namespace eth namespace eth
{ {
class VM;
class ExtVM;
class State; class State;
struct Manifest;
struct VMTraceChannel: public LogChannel { static const char* name() { return "EVM"; } static const int verbosity = 11; }; struct VMTraceChannel: public LogChannel { static const char* name() { return "EVM"; } static const int verbosity = 11; };
@ -44,7 +43,9 @@ class Executive
{ {
public: public:
Executive(State& _s, Manifest* o_ms = nullptr): m_s(_s), m_ms(o_ms) {} Executive(State& _s, Manifest* o_ms = nullptr): m_s(_s), m_ms(o_ms) {}
~Executive(); ~Executive() = default;
Executive(Executive const&) = delete;
void operator=(Executive) = delete;
bool setup(bytesConstRef _transaction); bool setup(bytesConstRef _transaction);
bool create(Address _txSender, u256 _endowment, u256 _gasPrice, u256 _gas, bytesConstRef _code, Address _originAddress); bool create(Address _txSender, u256 _endowment, u256 _gasPrice, u256 _gas, bytesConstRef _code, Address _originAddress);
@ -63,14 +64,14 @@ public:
h160 newAddress() const { return m_newAddress; } h160 newAddress() const { return m_newAddress; }
LogEntries const& logs() const { return m_logs; } LogEntries const& logs() const { return m_logs; }
VM const& vm() const { return *m_vm; } VMFace const& vm() const { return *m_vm; }
State const& state() const { return m_s; } State const& state() const { return m_s; }
ExtVM const& ext() const { return *m_ext; } ExtVM const& ext() const { return *m_ext; }
private: private:
State& m_s; State& m_s;
ExtVM* m_ext = nullptr; // TODO: make safe. std::unique_ptr<ExtVM> m_ext;
VM* m_vm = nullptr; std::unique_ptr<VMFace> m_vm;
Manifest* m_ms = nullptr; Manifest* m_ms = nullptr;
bytesConstRef m_out; bytesConstRef m_out;
Address m_newAddress; Address m_newAddress;

1
libethereum/State.cpp

@ -33,6 +33,7 @@
#include "BlockChain.h" #include "BlockChain.h"
#include "Defaults.h" #include "Defaults.h"
#include "ExtVM.h" #include "ExtVM.h"
#include "Executive.h"
using namespace std; using namespace std;
using namespace dev; using namespace dev;
using namespace dev::eth; using namespace dev::eth;

1
libethereum/State.h

@ -36,7 +36,6 @@
#include "Account.h" #include "Account.h"
#include "Transaction.h" #include "Transaction.h"
#include "TransactionReceipt.h" #include "TransactionReceipt.h"
#include "Executive.h"
#include "AccountDiff.h" #include "AccountDiff.h"
namespace dev namespace dev

1
test/vm.cpp

@ -21,6 +21,7 @@
*/ */
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <libethereum/Executive.h>
#include "vm.h" #include "vm.h"
using namespace std; using namespace std;

Loading…
Cancel
Save