Skip to content

Commit 6dfbfea

Browse files
committed
Compute flecs C++ type/symbol name at most once
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
1 parent 41a5288 commit 6dfbfea

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

distr/flecs.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26534,7 +26534,8 @@ inline const char* type_name() {
2653426534
static const size_t len = ECS_FUNC_TYPE_LEN(const char*, type_name, ECS_FUNC_NAME);
2653526535
static char result[len + 1] = {};
2653626536
static const size_t front_len = ECS_FUNC_NAME_FRONT(const char*, type_name);
26537-
return ecs_cpp_get_type_name(result, ECS_FUNC_NAME, len, front_len);
26537+
static const char* cppTypeName = ecs_cpp_get_type_name(result, ECS_FUNC_NAME, len, front_len);
26538+
return cppTypeName;
2653826539
}
2653926540
#else
2654026541
#error "implicit component registration not supported"
@@ -26546,7 +26547,8 @@ template <typename T>
2654626547
inline const char* symbol_name() {
2654726548
static const size_t len = ECS_FUNC_TYPE_LEN(const char*, symbol_name, ECS_FUNC_NAME);
2654826549
static char result[len + 1] = {};
26549-
return ecs_cpp_get_symbol_name(result, type_name<T>(), len);
26550+
static const char* cppSymbolName = ecs_cpp_get_symbol_name(result, type_name<T>(), len);
26551+
return cppSymbolName;
2655026552
}
2655126553

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

include/flecs/addons/cpp/component.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ inline const char* type_name() {
3434
static const size_t len = ECS_FUNC_TYPE_LEN(const char*, type_name, ECS_FUNC_NAME);
3535
static char result[len + 1] = {};
3636
static const size_t front_len = ECS_FUNC_NAME_FRONT(const char*, type_name);
37-
return ecs_cpp_get_type_name(result, ECS_FUNC_NAME, len, front_len);
37+
static const char* cppTypeName = ecs_cpp_get_type_name(result, ECS_FUNC_NAME, len, front_len);
38+
return cppTypeName;
3839
}
3940
#else
4041
#error "implicit component registration not supported"
@@ -46,7 +47,8 @@ template <typename T>
4647
inline const char* symbol_name() {
4748
static const size_t len = ECS_FUNC_TYPE_LEN(const char*, symbol_name, ECS_FUNC_NAME);
4849
static char result[len + 1] = {};
49-
return ecs_cpp_get_symbol_name(result, type_name<T>(), len);
50+
static const char* cppSymbolName = ecs_cpp_get_symbol_name(result, type_name<T>(), len);
51+
return cppSymbolName;
5052
}
5153

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

0 commit comments

Comments
 (0)