Skip to content

Commit

Permalink
Merge pull request #43259 from lyuma/get_parent_class_reentrancy_3.2
Browse files Browse the repository at this point in the history
3.2: Backport Avoid reentrant OBJTYPE_RLOCK in ClassDB
  • Loading branch information
akien-mga authored Nov 1, 2020
2 parents 5423675 + d3be847 commit f7d99c9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
29 changes: 20 additions & 9 deletions core/class_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,21 +270,27 @@ ClassDB::ClassInfo::ClassInfo() {
ClassDB::ClassInfo::~ClassInfo() {
}

bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) {

OBJTYPE_RLOCK;
bool ClassDB::_is_parent_class(const StringName &p_class, const StringName &p_inherits) {

StringName inherits = p_class;

while (inherits.operator String().length()) {

if (inherits == p_inherits)
return true;
inherits = get_parent_class(inherits);
inherits = _get_parent_class(inherits);
}

return false;
}

bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) {

OBJTYPE_RLOCK;

return _is_parent_class(p_class, p_inherits);
}

void ClassDB::get_class_list(List<StringName> *p_classes) {

OBJTYPE_RLOCK;
Expand All @@ -307,7 +313,7 @@ void ClassDB::get_inheriters_from_class(const StringName &p_class, List<StringNa

while ((k = classes.next(k))) {

if (*k != p_class && is_parent_class(*k, p_class))
if (*k != p_class && _is_parent_class(*k, p_class))
p_classes->push_back(*k);
}
}
Expand All @@ -320,7 +326,7 @@ void ClassDB::get_direct_inheriters_from_class(const StringName &p_class, List<S

while ((k = classes.next(k))) {

if (*k != p_class && get_parent_class(*k) == p_class)
if (*k != p_class && _get_parent_class(*k) == p_class)
p_classes->push_back(*k);
}
}
Expand All @@ -335,15 +341,20 @@ StringName ClassDB::get_parent_class_nocheck(const StringName &p_class) {
return ti->inherits;
}

StringName ClassDB::get_parent_class(const StringName &p_class) {

OBJTYPE_RLOCK;
StringName ClassDB::_get_parent_class(const StringName &p_class) {

ClassInfo *ti = classes.getptr(p_class);
ERR_FAIL_COND_V_MSG(!ti, StringName(), "Cannot get class '" + String(p_class) + "'.");
return ti->inherits;
}

StringName ClassDB::get_parent_class(const StringName &p_class) {

OBJTYPE_RLOCK;

return _get_parent_class(p_class);
}

ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) {

OBJTYPE_RLOCK;
Expand Down
5 changes: 5 additions & 0 deletions core/class_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ class ClassDB {
static HashMap<StringName, HashMap<StringName, Variant> > default_values;
static Set<StringName> default_values_cached;

private:
// Non-locking variants of get_parent_class and is_parent_class.
static StringName _get_parent_class(const StringName &p_class);
static bool _is_parent_class(const StringName &p_class, const StringName &p_inherits);

public:
// DO NOT USE THIS!!!!!! NEEDS TO BE PUBLIC BUT DO NOT USE NO MATTER WHAT!!!
template <class T>
Expand Down

0 comments on commit f7d99c9

Please sign in to comment.