diff --git a/easy_profiler_core/include/easy/details/arbitrary_value_aux.h b/easy_profiler_core/include/easy/details/arbitrary_value_aux.h index 50ac8a1..6de3c14 100644 --- a/easy_profiler_core/include/easy/details/arbitrary_value_aux.h +++ b/easy_profiler_core/include/easy/details/arbitrary_value_aux.h @@ -54,7 +54,7 @@ namespace profiler class ValueId EASY_FINAL { friend ::ThreadStorage; - vin_t m_id; + const void* m_id; public: @@ -66,14 +66,14 @@ namespace profiler inline EASY_CONSTEXPR_FCN ValueId(ValueId&&) = default; #endif - explicit inline EASY_CONSTEXPR_FCN ValueId() : m_id(0) {} - explicit inline EASY_CONSTEXPR_FCN ValueId(const void* _member) : m_id(reinterpret_cast(_member)) {} + explicit inline EASY_CONSTEXPR_FCN ValueId() : m_id(nullptr) {} + explicit inline EASY_CONSTEXPR_FCN ValueId(const void* _member) : m_id(_member) {} template - explicit inline EASY_CONSTEXPR_FCN ValueId(const T& _member) : m_id(reinterpret_cast(&_member)) {} + explicit inline EASY_CONSTEXPR_FCN ValueId(const T& _member) : m_id(&_member) {} template - explicit inline EASY_CONSTEXPR_FCN ValueId(const T (&_member)[N]) : m_id(reinterpret_cast((void*)_member)) {} + explicit inline EASY_CONSTEXPR_FCN ValueId(const T (&_member)[N]) : m_id(_member) {} ValueId& operator = (const ValueId&) = delete; ValueId& operator = (ValueId&&) = delete; diff --git a/easy_profiler_core/thread_storage.cpp b/easy_profiler_core/thread_storage.cpp index 760f681..7091362 100644 --- a/easy_profiler_core/thread_storage.cpp +++ b/easy_profiler_core/thread_storage.cpp @@ -44,6 +44,17 @@ The Apache License, Version 2.0 (the "License"); #include "current_thread.h" #include "current_time.h" +static profiler::vin_t ptr2vin(const void* ptr) +{ + static_assert(sizeof(uintptr_t) == sizeof(void*), + "Can not cast void* to uintptr_t. Different sizes."); + + static_assert(sizeof(profiler::vin_t) >= sizeof(uintptr_t), + "Can not cast uintptr_t to vin_t. Possible truncation."); + + return static_cast(reinterpret_cast(ptr)); +} + ThreadStorage::ThreadStorage() : nonscopedBlocks(16) , frameStartTime(0) @@ -62,7 +73,7 @@ void ThreadStorage::storeValue(profiler::timestamp_t _timestamp, profiler::block const uint16_t serializedDataSize = _size + static_cast(sizeof(profiler::ArbitraryValue)); void* data = blocks.closedList.allocate(serializedDataSize); - ::new (data) profiler::ArbitraryValue(_timestamp, _vin.m_id, _id, _size, _type, _isArray); + ::new (data) profiler::ArbitraryValue(_timestamp, ptr2vin(_vin.m_id), _id, _size, _type, _isArray); char* cdata = reinterpret_cast(data); memcpy(cdata + sizeof(profiler::ArbitraryValue), _data, _size);