From ccb6c85bfceb341b6cec57cd73469b141d7339dd Mon Sep 17 00:00:00 2001 From: "ocean (they/them)" Date: Wed, 21 Jun 2023 16:02:58 -0400 Subject: [PATCH] Unify debug/non-debug behavior of `ClassDB::get_method_info()` 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). --- core/object/class_db.cpp | 22 ++-------------------- core/object/class_db.h | 4 ++-- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index cc4a29164d09..d158bb46129a 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -462,12 +462,12 @@ void ClassDB::get_method_list(const StringName &p_class, List *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; @@ -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) { @@ -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; @@ -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; @@ -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 *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) { @@ -1511,8 +1495,6 @@ void ClassDB::get_virtual_methods(const StringName &p_class, List *p } check = check->inherits_ptr; } - -#endif } void ClassDB::set_class_enabled(const StringName &p_class, bool p_enable) { diff --git a/core/object/class_db.h b/core/object/class_db.h index ce64336a45c1..6ca8bb6897cb 100644 --- a/core/object/class_db.h +++ b/core/object/class_db.h @@ -116,12 +116,12 @@ class ClassDB { HashMap signal_map; List property_list; HashMap property_map; + List virtual_methods; + HashMap virtual_methods_map; #ifdef DEBUG_METHODS_ENABLED List constant_order; List method_order; HashSet methods_in_properties; - List virtual_methods; - HashMap virtual_methods_map; HashMap> method_error_values; HashMap> linked_properties; #endif