Skip to content

Commit

Permalink
Compute flecs C++ type/symbol name at most once
Browse files Browse the repository at this point in the history
Summary: This diff upstreams a fix that ensures that the C++ type/symbol names are computed at most once, and fixes an issue where the name buffers could be written to simultaneously by different threads.

Differential Revision: D62050989
  • Loading branch information
SanderMertens committed Sep 4, 2024
1 parent 41a5288 commit 6dfbfea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions distr/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -26534,7 +26534,8 @@ inline const char* type_name() {
static const size_t len = ECS_FUNC_TYPE_LEN(const char*, type_name, ECS_FUNC_NAME);
static char result[len + 1] = {};
static const size_t front_len = ECS_FUNC_NAME_FRONT(const char*, type_name);
return ecs_cpp_get_type_name(result, ECS_FUNC_NAME, len, front_len);
static const char* cppTypeName = ecs_cpp_get_type_name(result, ECS_FUNC_NAME, len, front_len);
return cppTypeName;
}
#else
#error "implicit component registration not supported"
Expand All @@ -26546,7 +26547,8 @@ template <typename T>
inline const char* symbol_name() {
static const size_t len = ECS_FUNC_TYPE_LEN(const char*, symbol_name, ECS_FUNC_NAME);
static char result[len + 1] = {};
return ecs_cpp_get_symbol_name(result, type_name<T>(), len);
static const char* cppSymbolName = ecs_cpp_get_symbol_name(result, type_name<T>(), len);
return cppSymbolName;
}

template <> inline const char* symbol_name<uint8_t>() {
Expand Down
6 changes: 4 additions & 2 deletions include/flecs/addons/cpp/component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ inline const char* type_name() {
static const size_t len = ECS_FUNC_TYPE_LEN(const char*, type_name, ECS_FUNC_NAME);
static char result[len + 1] = {};
static const size_t front_len = ECS_FUNC_NAME_FRONT(const char*, type_name);
return ecs_cpp_get_type_name(result, ECS_FUNC_NAME, len, front_len);
static const char* cppTypeName = ecs_cpp_get_type_name(result, ECS_FUNC_NAME, len, front_len);
return cppTypeName;
}
#else
#error "implicit component registration not supported"
Expand All @@ -46,7 +47,8 @@ template <typename T>
inline const char* symbol_name() {
static const size_t len = ECS_FUNC_TYPE_LEN(const char*, symbol_name, ECS_FUNC_NAME);
static char result[len + 1] = {};
return ecs_cpp_get_symbol_name(result, type_name<T>(), len);
static const char* cppSymbolName = ecs_cpp_get_symbol_name(result, type_name<T>(), len);
return cppSymbolName;
}

template <> inline const char* symbol_name<uint8_t>() {
Expand Down

0 comments on commit 6dfbfea

Please sign in to comment.