Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
replace memcpy function to avoid compilation error. Some trailing whi…
Browse files Browse the repository at this point in the history
…tespace eliminated too
  • Loading branch information
Phil Mesnier committed Jun 18, 2017
1 parent 875f782 commit 7159ee6
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions libraries/chain/wasm_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace eos { namespace chain {
using namespace IR;
using namespace Runtime;

wasm_interface::wasm_interface() {
}

Expand Down Expand Up @@ -41,7 +41,7 @@ DEFINE_INTRINSIC_FUNCTION4(env,store,store,none,i32,keyptr,i32,keylen,i32,valuep
if( obj ) {
db.modify( *obj, [&]( auto& o ) {
o.value.resize( valuelen );
memcpy( o.value.data(), value, valuelen );
o.value.replace (0, valuelen, value);
});
} else {
db.create<key_value_object>( [&](auto& o) {
Expand All @@ -50,7 +50,7 @@ DEFINE_INTRINSIC_FUNCTION4(env,store,store,none,i32,keyptr,i32,keylen,i32,valuep
o.value.insert( 0, value, valuelen );
});
}
}
}

DEFINE_INTRINSIC_FUNCTION2(env,remove,remove,i32,i32,keyptr,i32,keylen) {
FC_ASSERT( keylen > 0 );
Expand Down Expand Up @@ -172,13 +172,13 @@ DEFINE_INTRINSIC_FUNCTION2(env,assert,assert,none,i32,test,i32,msg) {
std::string message = &Runtime::memoryRef<char>( wasm_interface::get().current_memory, msg );
if( !test ) edump((message));
FC_ASSERT( test, "assertion failed: ${s}", ("s",message)("ptr",msg) );
}
}

DEFINE_INTRINSIC_FUNCTION0(env,messageSize,messageSize,i32) {
return wasm_interface::get().current_validate_context->msg.data.size();
}

DEFINE_INTRINSIC_FUNCTION1(env,malloc,malloc,i32,i32,size) {
DEFINE_INTRINSIC_FUNCTION1(env,malloc,malloc,i32,i32,size) {
FC_ASSERT( size > 0 );
int32_t& end = Runtime::memoryRef<int32_t>( Runtime::getDefaultMemory(wasm_interface::get().current_module), 0);
int32_t old_end = end;
Expand All @@ -202,10 +202,10 @@ DEFINE_INTRINSIC_FUNCTION2(env,print,print,none,i32,charptr,i32,size) {
wlog( std::string( str, size ) );
}

DEFINE_INTRINSIC_FUNCTION1(env,free,free,none,i32,ptr) {
DEFINE_INTRINSIC_FUNCTION1(env,free,free,none,i32,ptr) {
}

DEFINE_INTRINSIC_FUNCTION1(env,toUpper,toUpper,none,i32,charptr) {
DEFINE_INTRINSIC_FUNCTION1(env,toUpper,toUpper,none,i32,charptr) {
std::cerr << "TO UPPER CALLED\n";// << charptr << "\n";
// std::cerr << "moduleInstance: " << moduleInstance << "\n";
// /*U8* base = */Runtime::getMemoryBaseAddress( Runtime::getDefaultMemory(moduleInstance) );
Expand All @@ -219,7 +219,7 @@ DEFINE_INTRINSIC_FUNCTION1(env,toUpper,toUpper,none,i32,charptr) {

wasm_interface& wasm_interface::get() {
static wasm_interface* wasm = nullptr;
if( !wasm )
if( !wasm )
{
wlog( "Runtime::init" );
Runtime::init();
Expand Down Expand Up @@ -273,7 +273,7 @@ DEFINE_INTRINSIC_FUNCTION1(env,toUpper,toUpper,none,i32,charptr) {
return U32(ptr - &memoryRef<char>(current_memory,0));
}

void wasm_interface::vm_apply()
void wasm_interface::vm_apply()
{ try {
try {
std::string mangledapply("onApply_");
Expand All @@ -297,7 +297,7 @@ DEFINE_INTRINSIC_FUNCTION1(env,toUpper,toUpper,none,i32,charptr) {
}
} FC_CAPTURE_AND_RETHROW() }

void wasm_interface::vm_onInit()
void wasm_interface::vm_onInit()
{ try {
try {
wlog( "onInit" );
Expand Down Expand Up @@ -375,7 +375,7 @@ DEFINE_INTRINSIC_FUNCTION1(env,toUpper,toUpper,none,i32,charptr) {
state.init_memory.resize(1<<16); /// TODO: actually get memory size
memcpy( state.init_memory.data(), memstart, state.init_memory.size() );
std::cerr <<"INIT MEMORY: \n";
for( uint32_t i = 0; i < 10000; ++i )
for( uint32_t i = 0; i < 10000; ++i )
if( memstart[i] )
std::cerr << (char)memstart[i];
std::cerr <<"\n";
Expand Down Expand Up @@ -415,15 +415,15 @@ DEFINE_INTRINSIC_FUNCTION1(env,toUpper,toUpper,none,i32,charptr) {
if( module ) {
char* memstart = &memoryRef<char>( current_memory, 0 );
memcpy( memstart, memory_backup.data(), memory_backup.size() );
return;
return;
auto start = fc::time_point::now();
RootResolver rootResolver;
LinkResult linkResult = linkModule(*module,rootResolver);
current_module = instantiateModule( *module, std::move(linkResult.resolvedImports) );
FC_ASSERT( current_module );
current_memory = Runtime::getDefaultMemory(current_module);
auto end = fc::time_point::now();
idump(( 1000000.0 / (end-start).count() ) );
Expand Down

0 comments on commit 7159ee6

Please sign in to comment.