Skip to content

Commit 723878b

Browse files
committed
StringName: Use inline static field definitions
Before this change StringName used regular static field definitions for its mutex, _table, configured and debug_stringname fields. Since in the general case the ordering of the static variable and field initialization and destruction is undefined, it was possible that the destruction of StringName's static fields happened prior to the destruction of statically allocated StringName instances. By changing the static field definitions to inline in string_name.h, the C++17 standard guarantees the correct initialization and destruction ordering.
1 parent 8e36f98 commit 723878b

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

core/string/string_name.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,10 @@ StaticCString StaticCString::create(const char *p_ptr) {
3939
return scs;
4040
}
4141

42-
StringName::_Data *StringName::_table[STRING_TABLE_LEN];
43-
4442
StringName _scs_create(const char *p_chr, bool p_static) {
4543
return (p_chr[0] ? StringName(StaticCString::create(p_chr), p_static) : StringName());
4644
}
4745

48-
bool StringName::configured = false;
49-
Mutex StringName::mutex;
50-
51-
#ifdef DEBUG_ENABLED
52-
bool StringName::debug_stringname = false;
53-
#endif
54-
5546
void StringName::setup() {
5647
ERR_FAIL_COND(configured);
5748
for (int i = 0; i < STRING_TABLE_LEN; i++) {

core/string/string_name.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,26 @@ class StringName {
6767
_Data() {}
6868
};
6969

70-
static _Data *_table[STRING_TABLE_LEN];
70+
static inline _Data *_table[STRING_TABLE_LEN];
7171

7272
_Data *_data = nullptr;
7373

7474
void unref();
7575
friend void register_core_types();
7676
friend void unregister_core_types();
7777
friend class Main;
78-
static Mutex mutex;
78+
static inline Mutex mutex;
7979
static void setup();
8080
static void cleanup();
81-
static bool configured;
81+
static inline bool configured = false;
8282
#ifdef DEBUG_ENABLED
8383
struct DebugSortReferences {
8484
bool operator()(const _Data *p_left, const _Data *p_right) const {
8585
return p_left->debug_references > p_right->debug_references;
8686
}
8787
};
8888

89-
static bool debug_stringname;
89+
static inline bool debug_stringname = false;
9090
#endif
9191

9292
StringName(_Data *p_data) { _data = p_data; }

0 commit comments

Comments
 (0)