Skip to content

Commit

Permalink
fix: removing use of typeid
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucy committed Sep 25, 2023
1 parent 7985054 commit 40958d1
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions ecsact/wasm/detail/mem_stack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
#include <span>
#include <typeindex>
#include <unordered_map>
#include <map>
#include <vector>
#include <string_view>
#include <cstring>

namespace {
struct call_mem_info_t {
std::span<std::byte> data;
std::size_t data_offset = 0;
#ifndef NDEBUG
std::unordered_map<std::size_t, std::type_index> data_offset_types;
std::map<std::size_t, const char*> data_offset_types;
std::vector<std::string_view> method_trace;
#endif
};
Expand All @@ -24,13 +26,14 @@ thread_local auto call_mem_info = std::optional<call_mem_info_t>{};
} // namespace

#ifndef NDEBUG
# define ASSERT_OFFSET_TYPE(offset, type) \
assert(call_mem_info->data_offset_types.contains(offset)); \
assert(call_mem_info->data_offset_types.at(offset) == type)

# define ASSERT_OFFSET_TYPE(offset, type) { \
auto& types = call_mem_info->data_offset_types;\
assert(types.contains(offset)); \
assert(std::strcmp(types.at(offset), type.name()) == 0); \
} static_assert(true, "macro requires semi-colon")
# define ASSIGN_OFFSET_TYPE(offset, type) \
assert(!call_mem_info->data_offset_types.contains(offset)); \
call_mem_info->data_offset_types.insert({offset, std::type_index{type}})
call_mem_info->data_offset_types.insert({offset, type.name()})
#else
# define ASSERT_OFFSET_TYPE(offset, type) \
static_assert(true, "macro requires semi-colon")
Expand Down

0 comments on commit 40958d1

Please sign in to comment.