Skip to content

Commit

Permalink
reverting exceptions to jumps
Browse files Browse the repository at this point in the history
  • Loading branch information
dimas1185 committed Feb 11, 2023
1 parent 0a53b4a commit ea20dd0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 24 deletions.
1 change: 0 additions & 1 deletion libraries/native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ target_include_directories( sf PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/softfloat/sou
if (${PARENT_PROJECT_NAME} STREQUAL "cdt_tools")
add_library(${PROJECT_NAME} STATIC ${softfloat_sources} intrinsics.cpp crt_lib.cpp)

target_compile_definitions(${PROJECT_NAME} PUBLIC NATIVELIB_ENABLE_EXCEPTIONS)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/../libraries/eosiolib/core
${CMAKE_SOURCE_DIR}/../libraries/eosiolib/contracts
${CMAKE_SOURCE_DIR}/../libraries/eosiolib/capi
Expand Down
10 changes: 10 additions & 0 deletions libraries/native/crt_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ eosio::cdt::output_stream std_err;
bool ___disable_output = false;
bool ___has_failed = false;
bool ___earlier_unit_test_has_failed = false;
static jmp_buf env;
static jmp_buf test_env;
jmp_buf* ___env_ptr = &env;

void __set_env_test() {
___env_ptr = &test_env;
}
void __reset_env() {
___env_ptr = &env;
}

void _prints_l(const char* cstr, uint32_t len, uint8_t which) {
for (int i=0; i < len; i++) {
Expand Down
18 changes: 3 additions & 15 deletions libraries/native/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,6 @@
#include <softfloat.hpp>
#include <float.h>

#ifdef NATIVELIB_ENABLE_EXCEPTIONS
#define RAISE_ERROR_CHOOSE(_1,_2,NAME,...) NAME
#define RAISE_ERROR1(msg) \
throw eosio::cdt::assert_exception((const char*)msg)
#define RAISE_ERROR2(msg, len) \
throw eosio::cdt::assert_exception(std::string((const char*)msg, (size_t)len))
#define RAISE_ERROR(...) RAISE_ERROR_CHOOSE(__VA_ARGS__, RAISE_ERROR2, RAISE_ERROR1)(__VA_ARGS__)
#else
#define RAISE_ERROR(...) \
longjmp(*___env_ptr, 1)
#endif

// Boilerplate
using namespace eosio::native;
extern "C" {
Expand Down Expand Up @@ -873,15 +861,15 @@ extern "C" {
if (test == 0) {
_prints(msg, eosio::cdt::output_stream_kind::std_err);
_prints_l("\n", 1, eosio::cdt::output_stream_kind::none);
RAISE_ERROR(msg);
longjmp(*___env_ptr, 1);
}
}

void eosio_assert_message(uint32_t test, const char* msg, uint32_t len) {
if (test == 0) {
_prints_l(msg, len, eosio::cdt::output_stream_kind::std_err);
_prints_l("\n", 1, eosio::cdt::output_stream_kind::none);
RAISE_ERROR(msg, len);
longjmp(*___env_ptr, 1);
}
}

Expand All @@ -891,7 +879,7 @@ extern "C" {
snprintf(buff, 32, "%llu", code);
_prints(buff, eosio::cdt::output_stream_kind::std_err);
_prints_l("\n", 1, eosio::cdt::output_stream_kind::none);
RAISE_ERROR(buff);
longjmp(*___env_ptr, 1);
}
}

Expand Down
8 changes: 0 additions & 8 deletions libraries/native/native/eosio/crt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@

#include <string>


#ifdef NATIVELIB_ENABLE_EXCEPTIONS
#include <stdexcept>
namespace eosio { namespace cdt {
using assert_exception = std::runtime_error;
}} //ns eosio::cdt
#endif

namespace eosio { namespace cdt {

enum output_stream_kind {
Expand Down

0 comments on commit ea20dd0

Please sign in to comment.