Skip to content

Commit

Permalink
Unify debug/non-debug behavior of ClassDB::get_method_info()
Browse files Browse the repository at this point in the history
Currently only debug builds allow `ClassDB::get_method_info()` to check
for virtual methods. As a result, debug builds will not generate errors
when e.g. calling virtual methods (meant to act as a no-op). Non-debug
builds, however, will complain that those methods do not exist, when
they should also behave as a no-op.

Fixes #76938 (again).
  • Loading branch information
anvilfolk committed Jul 7, 2023
1 parent 4438206 commit ccb6c85
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
22 changes: 2 additions & 20 deletions core/object/class_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,12 @@ void ClassDB::get_method_list(const StringName &p_class, List<MethodInfo> *p_met
continue;
}

#ifdef DEBUG_METHODS_ENABLED

for (const MethodInfo &E : type->virtual_methods) {
p_methods->push_back(E);
}

#ifdef DEBUG_METHODS_ENABLED

for (const StringName &E : type->method_order) {
if (p_exclude_from_properties && type->methods_in_properties.has(E)) {
continue;
Expand Down Expand Up @@ -512,7 +512,6 @@ bool ClassDB::get_method_info(const StringName &p_class, const StringName &p_met
continue;
}

#ifdef DEBUG_METHODS_ENABLED
MethodBind **method = type->method_map.getptr(p_method);
if (method && *method) {
if (r_info != nullptr) {
Expand All @@ -526,16 +525,6 @@ bool ClassDB::get_method_info(const StringName &p_class, const StringName &p_met
}
return true;
}
#else
if (type->method_map.has(p_method)) {
if (r_info) {
MethodBind *m = type->method_map[p_method];
MethodInfo minfo = info_from_bind(m);
*r_info = minfo;
}
return true;
}
#endif

if (p_no_inheritance) {
break;
Expand Down Expand Up @@ -1465,7 +1454,6 @@ void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_

OBJTYPE_WLOCK;

#ifdef DEBUG_METHODS_ENABLED
MethodInfo mi = p_method;
if (p_virtual) {
mi.flags |= METHOD_FLAG_VIRTUAL;
Expand All @@ -1490,15 +1478,11 @@ void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_
}
classes[p_class].virtual_methods.push_back(mi);
classes[p_class].virtual_methods_map[p_method.name] = mi;

#endif
}

void ClassDB::get_virtual_methods(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance) {
ERR_FAIL_COND_MSG(!classes.has(p_class), "Request for nonexistent class '" + p_class + "'.");

#ifdef DEBUG_METHODS_ENABLED

ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
Expand All @@ -1511,8 +1495,6 @@ void ClassDB::get_virtual_methods(const StringName &p_class, List<MethodInfo> *p
}
check = check->inherits_ptr;
}

#endif
}

void ClassDB::set_class_enabled(const StringName &p_class, bool p_enable) {
Expand Down
4 changes: 2 additions & 2 deletions core/object/class_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ class ClassDB {
HashMap<StringName, MethodInfo> signal_map;
List<PropertyInfo> property_list;
HashMap<StringName, PropertyInfo> property_map;
List<MethodInfo> virtual_methods;
HashMap<StringName, MethodInfo> virtual_methods_map;
#ifdef DEBUG_METHODS_ENABLED
List<StringName> constant_order;
List<StringName> method_order;
HashSet<StringName> methods_in_properties;
List<MethodInfo> virtual_methods;
HashMap<StringName, MethodInfo> virtual_methods_map;
HashMap<StringName, Vector<Error>> method_error_values;
HashMap<StringName, List<StringName>> linked_properties;
#endif
Expand Down

0 comments on commit ccb6c85

Please sign in to comment.