提交 1b8dcab4 编写于 作者: B Bart Wyatt

switch to using unique_ptrs for intrinsic functions, the internal class for...

switch to using unique_ptrs for intrinsic functions, the internal class for that library has copy and move constructors but if they are used then the classes will segfault on destruction due to the use of a singleton mapping that breaks semantics necessary for copies and moves to work
上级 fd15199b
......@@ -48,5 +48,5 @@ INSTALL( TARGETS
)
INSTALL( FILES ${HEADERS} DESTINATION "include/eosio/chain" )
#add_executable( test test.cpp )
#target_link_libraries( test eos_chain ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ${Intl_LIBRARIES} )
add_executable( test test.cpp )
target_link_libraries( test eos_chain ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ${Intl_LIBRARIES} )
......@@ -305,18 +305,16 @@ struct intrinsic_function_invoker<Ret (Cls::*)(Params...)> {
}
};
#define _REGISTER_INTRINSIC(R, CLS, METHOD)\
{\
std::piecewise_construct,\
std::forward_as_tuple(#METHOD),\
std::forward_as_tuple(\
#define _REGISTER_INTRINSIC(R, DATA, METHOD)\
BOOST_PP_TUPLE_ELEM(2, 0, DATA).emplace( #METHOD, \
std::make_unique<Intrinsics::Function>(\
#METHOD,\
eosio::chain::intrinsic_function_invoker<decltype(&CLS::METHOD)>::wasm_function_type(),\
(void *)eosio::chain::intrinsic_function_invoker<decltype(&CLS::METHOD)>::fn<&CLS::METHOD>()\
eosio::chain::intrinsic_function_invoker<decltype(&BOOST_PP_TUPLE_ELEM(2, 1, DATA)::METHOD)>::wasm_function_type(),\
(void *)eosio::chain::intrinsic_function_invoker<decltype(&BOOST_PP_TUPLE_ELEM(2, 1, DATA)::METHOD)>::fn<&BOOST_PP_TUPLE_ELEM(2, 1, DATA)::METHOD>()\
)\
},
);
#define REGISTER_INTRINSICS(CLS, MEMBERS)\
BOOST_PP_SEQ_FOR_EACH(_REGISTER_INTRINSIC, CLS, MEMBERS)
#define REGISTER_INTRINSICS(DATA, MEMBERS)\
BOOST_PP_SEQ_FOR_EACH(_REGISTER_INTRINSIC, DATA, MEMBERS)
} };
\ No newline at end of file
......@@ -348,14 +348,20 @@ class intrinsics {
apply_context& context;
};
map<string, Intrinsics::Function> intrinsic_registry = {
REGISTER_INTRINSICS(intrinsics, (read_action)(assert))
static map<string, unique_ptr<Intrinsics::Function>> intrinsic_registry;
static void lazy_register_intrinsics()
{
if (intrinsic_registry.size() !=0 ) {
return;
}
REGISTER_INTRINSICS((intrinsic_registry, intrinsics), (read_action)(assert));
};
FunctionInstance *resolve_intrinsic(const string& name) {
lazy_register_intrinsics();
auto iter = intrinsic_registry.find(name);
if (iter != intrinsic_registry.end()) {
return (iter->second).function;
return (iter->second)->function;
}
return nullptr;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册