summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/core_bind.cpp4
-rw-r--r--core/extension/gdextension.cpp40
-rw-r--r--core/extension/gdextension.h3
-rw-r--r--core/extension/gdextension_interface.cpp319
-rw-r--r--core/object/ref_counted.h10
-rw-r--r--core/object/script_language.cpp47
-rw-r--r--core/object/script_language.h14
-rw-r--r--core/variant/method_ptrcall.h10
-rw-r--r--core/variant/variant_internal.h2
9 files changed, 98 insertions, 351 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index bb42b272d7..2d0d24406c 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -1188,7 +1188,11 @@ void Thread::_start_func(void *ud) {
ERR_FAIL_MSG(vformat("Could not call function '%s' on previously freed instance to start thread %s.", t->target_callable.get_method(), t->get_id()));
}
+ // Finding out a suitable name for the thread can involve querying a node, if the target is one.
+ // We know this is safe (unless the user is causing life cycle race conditions, which would be a bug on their part).
+ set_current_thread_safe_for_nodes(true);
String func_name = t->target_callable.is_custom() ? t->target_callable.get_custom()->get_as_text() : String(t->target_callable.get_method());
+ set_current_thread_safe_for_nodes(false);
::Thread::set_name(func_name);
// To avoid a circular reference between the thread and the script which can possibly contain a reference
diff --git a/core/extension/gdextension.cpp b/core/extension/gdextension.cpp
index 8bdea01ae6..73526fae3e 100644
--- a/core/extension/gdextension.cpp
+++ b/core/extension/gdextension.cpp
@@ -37,7 +37,6 @@
#include "core/version.h"
extern void gdextension_setup_interface();
-extern void *gdextension_get_legacy_interface();
extern GDExtensionInterfaceFunctionPtr gdextension_get_proc_address(const char *p_name);
typedef GDExtensionBool (*GDExtensionLegacyInitializationFunction)(void *p_interface, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization);
@@ -450,7 +449,7 @@ GDExtensionInterfaceFunctionPtr GDExtension::get_interface_function(StringName p
return *function;
}
-Error GDExtension::open_library(const String &p_path, const String &p_entry_symbol, bool p_use_legacy_interface) {
+Error GDExtension::open_library(const String &p_path, const String &p_entry_symbol) {
Error err = OS::get_singleton()->open_dynamic_library(p_path, library, true, &library_path);
if (err != OK) {
ERR_PRINT("GDExtension dynamic library not found: " + p_path);
@@ -467,15 +466,8 @@ Error GDExtension::open_library(const String &p_path, const String &p_entry_symb
return err;
}
- GDExtensionBool ret = 0;
- if (p_use_legacy_interface) {
- GDExtensionLegacyInitializationFunction initialization_function = (GDExtensionLegacyInitializationFunction)entry_funcptr;
- ret = initialization_function(gdextension_get_legacy_interface(), this, &initialization);
-
- } else {
- GDExtensionInitializationFunction initialization_function = (GDExtensionInitializationFunction)entry_funcptr;
- ret = initialization_function(&gdextension_get_proc_address, this, &initialization);
- }
+ GDExtensionInitializationFunction initialization_function = (GDExtensionInitializationFunction)entry_funcptr;
+ GDExtensionBool ret = initialization_function(&gdextension_get_proc_address, this, &initialization);
if (ret) {
level_initialized = -1;
@@ -486,10 +478,6 @@ Error GDExtension::open_library(const String &p_path, const String &p_entry_symb
}
}
-Error GDExtension::open_library_compat_76406(const String &p_path, const String &p_entry_symbol) {
- return open_library(p_path, p_entry_symbol, true);
-}
-
void GDExtension::close_library() {
ERR_FAIL_COND(library == nullptr);
OS::get_singleton()->close_dynamic_library(library);
@@ -525,8 +513,7 @@ void GDExtension::deinitialize_library(InitializationLevel p_level) {
}
void GDExtension::_bind_methods() {
- ClassDB::bind_method(D_METHOD("open_library", "path", "entry_symbol", "use_legacy_interface"), &GDExtension::open_library, DEFVAL(false));
- ClassDB::bind_compatibility_method(D_METHOD("open_library", "path", "entry_symbol"), &GDExtension::open_library_compat_76406);
+ ClassDB::bind_method(D_METHOD("open_library", "path", "entry_symbol"), &GDExtension::open_library);
ClassDB::bind_method(D_METHOD("close_library"), &GDExtension::close_library);
ClassDB::bind_method(D_METHOD("is_library_open"), &GDExtension::is_library_open);
@@ -599,9 +586,20 @@ Ref<Resource> GDExtensionResourceLoader::load(const String &p_path, const String
compatibility_minimum[i] = parts[i];
}
}
+ } else {
+ if (r_error) {
+ *r_error = ERR_INVALID_DATA;
+ }
+ ERR_PRINT("GDExtension configuration file must contain a \"configuration/compatibility_minimum\" key: " + p_path);
+ return Ref<Resource>();
}
- if (compatibility_minimum[0] < 4) {
- compatibility_minimum[0] = 4;
+
+ if (compatibility_minimum[0] < 4 || (compatibility_minimum[0] == 4 && compatibility_minimum[1] == 0)) {
+ if (r_error) {
+ *r_error = ERR_INVALID_DATA;
+ }
+ ERR_PRINT(vformat("GDExtension's compatibility_minimum (%d.%d.%d) must be at least 4.1.0: %s", compatibility_minimum[0], compatibility_minimum[1], compatibility_minimum[2], p_path));
+ return Ref<Resource>();
}
bool compatible = true;
@@ -635,12 +633,10 @@ Ref<Resource> GDExtensionResourceLoader::load(const String &p_path, const String
library_path = p_path.get_base_dir().path_join(library_path);
}
- bool use_legacy_interface = compatibility_minimum[0] == 4 && compatibility_minimum[1] == 0;
-
Ref<GDExtension> lib;
lib.instantiate();
String abs_path = ProjectSettings::get_singleton()->globalize_path(library_path);
- err = lib->open_library(abs_path, entry_symbol, use_legacy_interface);
+ err = lib->open_library(abs_path, entry_symbol);
if (r_error) {
*r_error = err;
diff --git a/core/extension/gdextension.h b/core/extension/gdextension.h
index 49f1cf1d8e..77ec458d30 100644
--- a/core/extension/gdextension.h
+++ b/core/extension/gdextension.h
@@ -72,8 +72,7 @@ public:
static String get_extension_list_config_file();
static String find_extension_library(const String &p_path, Ref<ConfigFile> p_config, std::function<bool(String)> p_has_feature, PackedStringArray *r_tags = nullptr);
- Error open_library(const String &p_path, const String &p_entry_symbol, bool p_use_legacy_interface = false);
- Error open_library_compat_76406(const String &p_path, const String &p_entry_symbol);
+ Error open_library(const String &p_path, const String &p_entry_symbol);
void close_library();
enum InitializationLevel {
diff --git a/core/extension/gdextension_interface.cpp b/core/extension/gdextension_interface.cpp
index 21d34b6e0c..7fbf2d00a1 100644
--- a/core/extension/gdextension_interface.cpp
+++ b/core/extension/gdextension_interface.cpp
@@ -1218,322 +1218,3 @@ void gdextension_setup_interface() {
}
#undef REGISTER_INTERFACE_FUNCTION
-
-/*
- * Handle legacy GDExtension interface from Godot 4.0.
- */
-
-typedef struct {
- uint32_t version_major;
- uint32_t version_minor;
- uint32_t version_patch;
- const char *version_string;
-
- GDExtensionInterfaceMemAlloc mem_alloc;
- GDExtensionInterfaceMemRealloc mem_realloc;
- GDExtensionInterfaceMemFree mem_free;
-
- GDExtensionInterfacePrintError print_error;
- GDExtensionInterfacePrintErrorWithMessage print_error_with_message;
- GDExtensionInterfacePrintWarning print_warning;
- GDExtensionInterfacePrintWarningWithMessage print_warning_with_message;
- GDExtensionInterfacePrintScriptError print_script_error;
- GDExtensionInterfacePrintScriptErrorWithMessage print_script_error_with_message;
-
- GDExtensionInterfaceGetNativeStructSize get_native_struct_size;
-
- GDExtensionInterfaceVariantNewCopy variant_new_copy;
- GDExtensionInterfaceVariantNewNil variant_new_nil;
- GDExtensionInterfaceVariantDestroy variant_destroy;
-
- GDExtensionInterfaceVariantCall variant_call;
- GDExtensionInterfaceVariantCallStatic variant_call_static;
- GDExtensionInterfaceVariantEvaluate variant_evaluate;
- GDExtensionInterfaceVariantSet variant_set;
- GDExtensionInterfaceVariantSetNamed variant_set_named;
- GDExtensionInterfaceVariantSetKeyed variant_set_keyed;
- GDExtensionInterfaceVariantSetIndexed variant_set_indexed;
- GDExtensionInterfaceVariantGet variant_get;
- GDExtensionInterfaceVariantGetNamed variant_get_named;
- GDExtensionInterfaceVariantGetKeyed variant_get_keyed;
- GDExtensionInterfaceVariantGetIndexed variant_get_indexed;
- GDExtensionInterfaceVariantIterInit variant_iter_init;
- GDExtensionInterfaceVariantIterNext variant_iter_next;
- GDExtensionInterfaceVariantIterGet variant_iter_get;
- GDExtensionInterfaceVariantHash variant_hash;
- GDExtensionInterfaceVariantRecursiveHash variant_recursive_hash;
- GDExtensionInterfaceVariantHashCompare variant_hash_compare;
- GDExtensionInterfaceVariantBooleanize variant_booleanize;
- GDExtensionInterfaceVariantDuplicate variant_duplicate;
- GDExtensionInterfaceVariantStringify variant_stringify;
-
- GDExtensionInterfaceVariantGetType variant_get_type;
- GDExtensionInterfaceVariantHasMethod variant_has_method;
- GDExtensionInterfaceVariantHasMember variant_has_member;
- GDExtensionInterfaceVariantHasKey variant_has_key;
- GDExtensionInterfaceVariantGetTypeName variant_get_type_name;
- GDExtensionInterfaceVariantCanConvert variant_can_convert;
- GDExtensionInterfaceVariantCanConvertStrict variant_can_convert_strict;
-
- GDExtensionInterfaceGetVariantFromTypeConstructor get_variant_from_type_constructor;
- GDExtensionInterfaceGetVariantToTypeConstructor get_variant_to_type_constructor;
- GDExtensionInterfaceVariantGetPtrOperatorEvaluator variant_get_ptr_operator_evaluator;
- GDExtensionInterfaceVariantGetPtrBuiltinMethod variant_get_ptr_builtin_method;
- GDExtensionInterfaceVariantGetPtrConstructor variant_get_ptr_constructor;
- GDExtensionInterfaceVariantGetPtrDestructor variant_get_ptr_destructor;
- GDExtensionInterfaceVariantConstruct variant_construct;
- GDExtensionInterfaceVariantGetPtrSetter variant_get_ptr_setter;
- GDExtensionInterfaceVariantGetPtrGetter variant_get_ptr_getter;
- GDExtensionInterfaceVariantGetPtrIndexedSetter variant_get_ptr_indexed_setter;
- GDExtensionInterfaceVariantGetPtrIndexedGetter variant_get_ptr_indexed_getter;
- GDExtensionInterfaceVariantGetPtrKeyedSetter variant_get_ptr_keyed_setter;
- GDExtensionInterfaceVariantGetPtrKeyedGetter variant_get_ptr_keyed_getter;
- GDExtensionInterfaceVariantGetPtrKeyedChecker variant_get_ptr_keyed_checker;
- GDExtensionInterfaceVariantGetConstantValue variant_get_constant_value;
- GDExtensionInterfaceVariantGetPtrUtilityFunction variant_get_ptr_utility_function;
-
- GDExtensionInterfaceStringNewWithLatin1Chars string_new_with_latin1_chars;
- GDExtensionInterfaceStringNewWithUtf8Chars string_new_with_utf8_chars;
- GDExtensionInterfaceStringNewWithUtf16Chars string_new_with_utf16_chars;
- GDExtensionInterfaceStringNewWithUtf32Chars string_new_with_utf32_chars;
- GDExtensionInterfaceStringNewWithWideChars string_new_with_wide_chars;
- GDExtensionInterfaceStringNewWithLatin1CharsAndLen string_new_with_latin1_chars_and_len;
- GDExtensionInterfaceStringNewWithUtf8CharsAndLen string_new_with_utf8_chars_and_len;
- GDExtensionInterfaceStringNewWithUtf16CharsAndLen string_new_with_utf16_chars_and_len;
- GDExtensionInterfaceStringNewWithUtf32CharsAndLen string_new_with_utf32_chars_and_len;
- GDExtensionInterfaceStringNewWithWideCharsAndLen string_new_with_wide_chars_and_len;
- GDExtensionInterfaceStringToLatin1Chars string_to_latin1_chars;
- GDExtensionInterfaceStringToUtf8Chars string_to_utf8_chars;
- GDExtensionInterfaceStringToUtf16Chars string_to_utf16_chars;
- GDExtensionInterfaceStringToUtf32Chars string_to_utf32_chars;
- GDExtensionInterfaceStringToWideChars string_to_wide_chars;
- GDExtensionInterfaceStringOperatorIndex string_operator_index;
- GDExtensionInterfaceStringOperatorIndexConst string_operator_index_const;
-
- GDExtensionInterfaceStringOperatorPlusEqString string_operator_plus_eq_string;
- GDExtensionInterfaceStringOperatorPlusEqChar string_operator_plus_eq_char;
- GDExtensionInterfaceStringOperatorPlusEqCstr string_operator_plus_eq_cstr;
- GDExtensionInterfaceStringOperatorPlusEqWcstr string_operator_plus_eq_wcstr;
- GDExtensionInterfaceStringOperatorPlusEqC32str string_operator_plus_eq_c32str;
-
- GDExtensionInterfaceXmlParserOpenBuffer xml_parser_open_buffer;
-
- GDExtensionInterfaceFileAccessStoreBuffer file_access_store_buffer;
- GDExtensionInterfaceFileAccessGetBuffer file_access_get_buffer;
-
- GDExtensionInterfaceWorkerThreadPoolAddNativeGroupTask worker_thread_pool_add_native_group_task;
- GDExtensionInterfaceWorkerThreadPoolAddNativeTask worker_thread_pool_add_native_task;
-
- GDExtensionInterfacePackedByteArrayOperatorIndex packed_byte_array_operator_index;
- GDExtensionInterfacePackedByteArrayOperatorIndexConst packed_byte_array_operator_index_const;
- GDExtensionInterfacePackedColorArrayOperatorIndex packed_color_array_operator_index;
- GDExtensionInterfacePackedColorArrayOperatorIndexConst packed_color_array_operator_index_const;
- GDExtensionInterfacePackedFloat32ArrayOperatorIndex packed_float32_array_operator_index;
- GDExtensionInterfacePackedFloat32ArrayOperatorIndexConst packed_float32_array_operator_index_const;
- GDExtensionInterfacePackedFloat64ArrayOperatorIndex packed_float64_array_operator_index;
- GDExtensionInterfacePackedFloat64ArrayOperatorIndexConst packed_float64_array_operator_index_const;
- GDExtensionInterfacePackedInt32ArrayOperatorIndex packed_int32_array_operator_index;
- GDExtensionInterfacePackedInt32ArrayOperatorIndexConst packed_int32_array_operator_index_const;
- GDExtensionInterfacePackedInt64ArrayOperatorIndex packed_int64_array_operator_index;
- GDExtensionInterfacePackedInt64ArrayOperatorIndexConst packed_int64_array_operator_index_const;
- GDExtensionInterfacePackedStringArrayOperatorIndex packed_string_array_operator_index;
- GDExtensionInterfacePackedStringArrayOperatorIndexConst packed_string_array_operator_index_const;
- GDExtensionInterfacePackedVector2ArrayOperatorIndex packed_vector2_array_operator_index;
- GDExtensionInterfacePackedVector2ArrayOperatorIndexConst packed_vector2_array_operator_index_const;
- GDExtensionInterfacePackedVector3ArrayOperatorIndex packed_vector3_array_operator_index;
- GDExtensionInterfacePackedVector3ArrayOperatorIndexConst packed_vector3_array_operator_index_const;
- GDExtensionInterfaceArrayOperatorIndex array_operator_index;
- GDExtensionInterfaceArrayOperatorIndexConst array_operator_index_const;
- GDExtensionInterfaceArrayRef array_ref;
- GDExtensionInterfaceArraySetTyped array_set_typed;
-
- GDExtensionInterfaceDictionaryOperatorIndex dictionary_operator_index;
- GDExtensionInterfaceDictionaryOperatorIndexConst dictionary_operator_index_const;
-
- GDExtensionInterfaceObjectMethodBindCall object_method_bind_call;
- GDExtensionInterfaceObjectMethodBindPtrcall object_method_bind_ptrcall;
- GDExtensionInterfaceObjectDestroy object_destroy;
- GDExtensionInterfaceGlobalGetSingleton global_get_singleton;
- GDExtensionInterfaceObjectGetInstanceBinding object_get_instance_binding;
- GDExtensionInterfaceObjectSetInstanceBinding object_set_instance_binding;
- GDExtensionInterfaceObjectSetInstance object_set_instance;
- GDExtensionInterfaceObjectCastTo object_cast_to;
- GDExtensionInterfaceObjectGetInstanceFromId object_get_instance_from_id;
- GDExtensionInterfaceObjectGetInstanceId object_get_instance_id;
-
- GDExtensionInterfaceRefGetObject ref_get_object;
- GDExtensionInterfaceRefSetObject ref_set_object;
-
- GDExtensionInterfaceScriptInstanceCreate script_instance_create;
-
- GDExtensionInterfaceClassdbConstructObject classdb_construct_object;
- GDExtensionInterfaceClassdbGetMethodBind classdb_get_method_bind;
- GDExtensionInterfaceClassdbGetClassTag classdb_get_class_tag;
-
- GDExtensionInterfaceClassdbRegisterExtensionClass classdb_register_extension_class;
- GDExtensionInterfaceClassdbRegisterExtensionClassMethod classdb_register_extension_class_method;
- GDExtensionInterfaceClassdbRegisterExtensionClassIntegerConstant classdb_register_extension_class_integer_constant;
- GDExtensionInterfaceClassdbRegisterExtensionClassProperty classdb_register_extension_class_property;
- GDExtensionInterfaceClassdbRegisterExtensionClassPropertyGroup classdb_register_extension_class_property_group;
- GDExtensionInterfaceClassdbRegisterExtensionClassPropertySubgroup classdb_register_extension_class_property_subgroup;
- GDExtensionInterfaceClassdbRegisterExtensionClassSignal classdb_register_extension_class_signal;
- GDExtensionInterfaceClassdbUnregisterExtensionClass classdb_unregister_extension_class;
-
- GDExtensionInterfaceGetLibraryPath get_library_path;
-
-} LegacyGDExtensionInterface;
-
-static LegacyGDExtensionInterface *legacy_gdextension_interface = nullptr;
-
-#define SETUP_LEGACY_FUNC(m_name, m_type) legacy_gdextension_interface->m_name = (m_type)GDExtension::get_interface_function(#m_name)
-
-void *gdextension_get_legacy_interface() {
- if (legacy_gdextension_interface != nullptr) {
- return legacy_gdextension_interface;
- }
-
- legacy_gdextension_interface = memnew(LegacyGDExtensionInterface);
-
- // Force to 4.0.999 to make it easier to detect this structure.
- legacy_gdextension_interface->version_major = 4;
- legacy_gdextension_interface->version_minor = 0;
- legacy_gdextension_interface->version_patch = 999;
- legacy_gdextension_interface->version_string = "Godot Engine v4.0.999.stable.official [000000000]";
-
- SETUP_LEGACY_FUNC(mem_alloc, GDExtensionInterfaceMemAlloc);
- SETUP_LEGACY_FUNC(mem_realloc, GDExtensionInterfaceMemRealloc);
- SETUP_LEGACY_FUNC(mem_free, GDExtensionInterfaceMemFree);
- SETUP_LEGACY_FUNC(print_error, GDExtensionInterfacePrintError);
- SETUP_LEGACY_FUNC(print_error_with_message, GDExtensionInterfacePrintErrorWithMessage);
- SETUP_LEGACY_FUNC(print_warning, GDExtensionInterfacePrintWarning);
- SETUP_LEGACY_FUNC(print_warning_with_message, GDExtensionInterfacePrintWarningWithMessage);
- SETUP_LEGACY_FUNC(print_script_error, GDExtensionInterfacePrintScriptError);
- SETUP_LEGACY_FUNC(print_script_error_with_message, GDExtensionInterfacePrintScriptErrorWithMessage);
- SETUP_LEGACY_FUNC(get_native_struct_size, GDExtensionInterfaceGetNativeStructSize);
- SETUP_LEGACY_FUNC(variant_new_copy, GDExtensionInterfaceVariantNewCopy);
- SETUP_LEGACY_FUNC(variant_new_nil, GDExtensionInterfaceVariantNewNil);
- SETUP_LEGACY_FUNC(variant_destroy, GDExtensionInterfaceVariantDestroy);
- SETUP_LEGACY_FUNC(variant_call, GDExtensionInterfaceVariantCall);
- SETUP_LEGACY_FUNC(variant_call_static, GDExtensionInterfaceVariantCallStatic);
- SETUP_LEGACY_FUNC(variant_evaluate, GDExtensionInterfaceVariantEvaluate);
- SETUP_LEGACY_FUNC(variant_set, GDExtensionInterfaceVariantSet);
- SETUP_LEGACY_FUNC(variant_set_named, GDExtensionInterfaceVariantSetNamed);
- SETUP_LEGACY_FUNC(variant_set_keyed, GDExtensionInterfaceVariantSetKeyed);
- SETUP_LEGACY_FUNC(variant_set_indexed, GDExtensionInterfaceVariantSetIndexed);
- SETUP_LEGACY_FUNC(variant_get, GDExtensionInterfaceVariantGet);
- SETUP_LEGACY_FUNC(variant_get_named, GDExtensionInterfaceVariantGetNamed);
- SETUP_LEGACY_FUNC(variant_get_keyed, GDExtensionInterfaceVariantGetKeyed);
- SETUP_LEGACY_FUNC(variant_get_indexed, GDExtensionInterfaceVariantGetIndexed);
- SETUP_LEGACY_FUNC(variant_iter_init, GDExtensionInterfaceVariantIterInit);
- SETUP_LEGACY_FUNC(variant_iter_next, GDExtensionInterfaceVariantIterNext);
- SETUP_LEGACY_FUNC(variant_iter_get, GDExtensionInterfaceVariantIterGet);
- SETUP_LEGACY_FUNC(variant_hash, GDExtensionInterfaceVariantHash);
- SETUP_LEGACY_FUNC(variant_recursive_hash, GDExtensionInterfaceVariantRecursiveHash);
- SETUP_LEGACY_FUNC(variant_hash_compare, GDExtensionInterfaceVariantHashCompare);
- SETUP_LEGACY_FUNC(variant_booleanize, GDExtensionInterfaceVariantBooleanize);
- SETUP_LEGACY_FUNC(variant_duplicate, GDExtensionInterfaceVariantDuplicate);
- SETUP_LEGACY_FUNC(variant_stringify, GDExtensionInterfaceVariantStringify);
- SETUP_LEGACY_FUNC(variant_get_type, GDExtensionInterfaceVariantGetType);
- SETUP_LEGACY_FUNC(variant_has_method, GDExtensionInterfaceVariantHasMethod);
- SETUP_LEGACY_FUNC(variant_has_member, GDExtensionInterfaceVariantHasMember);
- SETUP_LEGACY_FUNC(variant_has_key, GDExtensionInterfaceVariantHasKey);
- SETUP_LEGACY_FUNC(variant_get_type_name, GDExtensionInterfaceVariantGetTypeName);
- SETUP_LEGACY_FUNC(variant_can_convert, GDExtensionInterfaceVariantCanConvert);
- SETUP_LEGACY_FUNC(variant_can_convert_strict, GDExtensionInterfaceVariantCanConvertStrict);
- SETUP_LEGACY_FUNC(get_variant_from_type_constructor, GDExtensionInterfaceGetVariantFromTypeConstructor);
- SETUP_LEGACY_FUNC(get_variant_to_type_constructor, GDExtensionInterfaceGetVariantToTypeConstructor);
- SETUP_LEGACY_FUNC(variant_get_ptr_operator_evaluator, GDExtensionInterfaceVariantGetPtrOperatorEvaluator);
- SETUP_LEGACY_FUNC(variant_get_ptr_builtin_method, GDExtensionInterfaceVariantGetPtrBuiltinMethod);
- SETUP_LEGACY_FUNC(variant_get_ptr_constructor, GDExtensionInterfaceVariantGetPtrConstructor);
- SETUP_LEGACY_FUNC(variant_get_ptr_destructor, GDExtensionInterfaceVariantGetPtrDestructor);
- SETUP_LEGACY_FUNC(variant_construct, GDExtensionInterfaceVariantConstruct);
- SETUP_LEGACY_FUNC(variant_get_ptr_setter, GDExtensionInterfaceVariantGetPtrSetter);
- SETUP_LEGACY_FUNC(variant_get_ptr_getter, GDExtensionInterfaceVariantGetPtrGetter);
- SETUP_LEGACY_FUNC(variant_get_ptr_indexed_setter, GDExtensionInterfaceVariantGetPtrIndexedSetter);
- SETUP_LEGACY_FUNC(variant_get_ptr_indexed_getter, GDExtensionInterfaceVariantGetPtrIndexedGetter);
- SETUP_LEGACY_FUNC(variant_get_ptr_keyed_setter, GDExtensionInterfaceVariantGetPtrKeyedSetter);
- SETUP_LEGACY_FUNC(variant_get_ptr_keyed_getter, GDExtensionInterfaceVariantGetPtrKeyedGetter);
- SETUP_LEGACY_FUNC(variant_get_ptr_keyed_checker, GDExtensionInterfaceVariantGetPtrKeyedChecker);
- SETUP_LEGACY_FUNC(variant_get_constant_value, GDExtensionInterfaceVariantGetConstantValue);
- SETUP_LEGACY_FUNC(variant_get_ptr_utility_function, GDExtensionInterfaceVariantGetPtrUtilityFunction);
- SETUP_LEGACY_FUNC(string_new_with_latin1_chars, GDExtensionInterfaceStringNewWithLatin1Chars);
- SETUP_LEGACY_FUNC(string_new_with_utf8_chars, GDExtensionInterfaceStringNewWithUtf8Chars);
- SETUP_LEGACY_FUNC(string_new_with_utf16_chars, GDExtensionInterfaceStringNewWithUtf16Chars);
- SETUP_LEGACY_FUNC(string_new_with_utf32_chars, GDExtensionInterfaceStringNewWithUtf32Chars);
- SETUP_LEGACY_FUNC(string_new_with_wide_chars, GDExtensionInterfaceStringNewWithWideChars);
- SETUP_LEGACY_FUNC(string_new_with_latin1_chars_and_len, GDExtensionInterfaceStringNewWithLatin1CharsAndLen);
- SETUP_LEGACY_FUNC(string_new_with_utf8_chars_and_len, GDExtensionInterfaceStringNewWithUtf8CharsAndLen);
- SETUP_LEGACY_FUNC(string_new_with_utf16_chars_and_len, GDExtensionInterfaceStringNewWithUtf16CharsAndLen);
- SETUP_LEGACY_FUNC(string_new_with_utf32_chars_and_len, GDExtensionInterfaceStringNewWithUtf32CharsAndLen);
- SETUP_LEGACY_FUNC(string_new_with_wide_chars_and_len, GDExtensionInterfaceStringNewWithWideCharsAndLen);
- SETUP_LEGACY_FUNC(string_to_latin1_chars, GDExtensionInterfaceStringToLatin1Chars);
- SETUP_LEGACY_FUNC(string_to_utf8_chars, GDExtensionInterfaceStringToUtf8Chars);
- SETUP_LEGACY_FUNC(string_to_utf16_chars, GDExtensionInterfaceStringToUtf16Chars);
- SETUP_LEGACY_FUNC(string_to_utf32_chars, GDExtensionInterfaceStringToUtf32Chars);
- SETUP_LEGACY_FUNC(string_to_wide_chars, GDExtensionInterfaceStringToWideChars);
- SETUP_LEGACY_FUNC(string_operator_index, GDExtensionInterfaceStringOperatorIndex);
- SETUP_LEGACY_FUNC(string_operator_index_const, GDExtensionInterfaceStringOperatorIndexConst);
- SETUP_LEGACY_FUNC(string_operator_plus_eq_string, GDExtensionInterfaceStringOperatorPlusEqString);
- SETUP_LEGACY_FUNC(string_operator_plus_eq_char, GDExtensionInterfaceStringOperatorPlusEqChar);
- SETUP_LEGACY_FUNC(string_operator_plus_eq_cstr, GDExtensionInterfaceStringOperatorPlusEqCstr);
- SETUP_LEGACY_FUNC(string_operator_plus_eq_wcstr, GDExtensionInterfaceStringOperatorPlusEqWcstr);
- SETUP_LEGACY_FUNC(string_operator_plus_eq_c32str, GDExtensionInterfaceStringOperatorPlusEqC32str);
- SETUP_LEGACY_FUNC(xml_parser_open_buffer, GDExtensionInterfaceXmlParserOpenBuffer);
- SETUP_LEGACY_FUNC(file_access_store_buffer, GDExtensionInterfaceFileAccessStoreBuffer);
- SETUP_LEGACY_FUNC(file_access_get_buffer, GDExtensionInterfaceFileAccessGetBuffer);
- SETUP_LEGACY_FUNC(worker_thread_pool_add_native_group_task, GDExtensionInterfaceWorkerThreadPoolAddNativeGroupTask);
- SETUP_LEGACY_FUNC(worker_thread_pool_add_native_task, GDExtensionInterfaceWorkerThreadPoolAddNativeTask);
- SETUP_LEGACY_FUNC(packed_byte_array_operator_index, GDExtensionInterfacePackedByteArrayOperatorIndex);
- SETUP_LEGACY_FUNC(packed_byte_array_operator_index_const, GDExtensionInterfacePackedByteArrayOperatorIndexConst);
- SETUP_LEGACY_FUNC(packed_color_array_operator_index, GDExtensionInterfacePackedColorArrayOperatorIndex);
- SETUP_LEGACY_FUNC(packed_color_array_operator_index_const, GDExtensionInterfacePackedColorArrayOperatorIndexConst);
- SETUP_LEGACY_FUNC(packed_float32_array_operator_index, GDExtensionInterfacePackedFloat32ArrayOperatorIndex);
- SETUP_LEGACY_FUNC(packed_float32_array_operator_index_const, GDExtensionInterfacePackedFloat32ArrayOperatorIndexConst);
- SETUP_LEGACY_FUNC(packed_float64_array_operator_index, GDExtensionInterfacePackedFloat64ArrayOperatorIndex);
- SETUP_LEGACY_FUNC(packed_float64_array_operator_index_const, GDExtensionInterfacePackedFloat64ArrayOperatorIndexConst);
- SETUP_LEGACY_FUNC(packed_int32_array_operator_index, GDExtensionInterfacePackedInt32ArrayOperatorIndex);
- SETUP_LEGACY_FUNC(packed_int32_array_operator_index_const, GDExtensionInterfacePackedInt32ArrayOperatorIndexConst);
- SETUP_LEGACY_FUNC(packed_int64_array_operator_index, GDExtensionInterfacePackedInt64ArrayOperatorIndex);
- SETUP_LEGACY_FUNC(packed_int64_array_operator_index_const, GDExtensionInterfacePackedInt64ArrayOperatorIndexConst);
- SETUP_LEGACY_FUNC(packed_string_array_operator_index, GDExtensionInterfacePackedStringArrayOperatorIndex);
- SETUP_LEGACY_FUNC(packed_string_array_operator_index_const, GDExtensionInterfacePackedStringArrayOperatorIndexConst);
- SETUP_LEGACY_FUNC(packed_vector2_array_operator_index, GDExtensionInterfacePackedVector2ArrayOperatorIndex);
- SETUP_LEGACY_FUNC(packed_vector2_array_operator_index_const, GDExtensionInterfacePackedVector2ArrayOperatorIndexConst);
- SETUP_LEGACY_FUNC(packed_vector3_array_operator_index, GDExtensionInterfacePackedVector3ArrayOperatorIndex);
- SETUP_LEGACY_FUNC(packed_vector3_array_operator_index_const, GDExtensionInterfacePackedVector3ArrayOperatorIndexConst);
- SETUP_LEGACY_FUNC(array_operator_index, GDExtensionInterfaceArrayOperatorIndex);
- SETUP_LEGACY_FUNC(array_operator_index_const, GDExtensionInterfaceArrayOperatorIndexConst);
- SETUP_LEGACY_FUNC(array_ref, GDExtensionInterfaceArrayRef);
- SETUP_LEGACY_FUNC(array_set_typed, GDExtensionInterfaceArraySetTyped);
- SETUP_LEGACY_FUNC(dictionary_operator_index, GDExtensionInterfaceDictionaryOperatorIndex);
- SETUP_LEGACY_FUNC(dictionary_operator_index_const, GDExtensionInterfaceDictionaryOperatorIndexConst);
- SETUP_LEGACY_FUNC(object_method_bind_call, GDExtensionInterfaceObjectMethodBindCall);
- SETUP_LEGACY_FUNC(object_method_bind_ptrcall, GDExtensionInterfaceObjectMethodBindPtrcall);
- SETUP_LEGACY_FUNC(object_destroy, GDExtensionInterfaceObjectDestroy);
- SETUP_LEGACY_FUNC(global_get_singleton, GDExtensionInterfaceGlobalGetSingleton);
- SETUP_LEGACY_FUNC(object_get_instance_binding, GDExtensionInterfaceObjectGetInstanceBinding);
- SETUP_LEGACY_FUNC(object_set_instance_binding, GDExtensionInterfaceObjectSetInstanceBinding);
- SETUP_LEGACY_FUNC(object_set_instance, GDExtensionInterfaceObjectSetInstance);
- SETUP_LEGACY_FUNC(object_cast_to, GDExtensionInterfaceObjectCastTo);
- SETUP_LEGACY_FUNC(object_get_instance_from_id, GDExtensionInterfaceObjectGetInstanceFromId);
- SETUP_LEGACY_FUNC(object_get_instance_id, GDExtensionInterfaceObjectGetInstanceId);
- SETUP_LEGACY_FUNC(ref_get_object, GDExtensionInterfaceRefGetObject);
- SETUP_LEGACY_FUNC(ref_set_object, GDExtensionInterfaceRefSetObject);
- SETUP_LEGACY_FUNC(script_instance_create, GDExtensionInterfaceScriptInstanceCreate);
- SETUP_LEGACY_FUNC(classdb_construct_object, GDExtensionInterfaceClassdbConstructObject);
- SETUP_LEGACY_FUNC(classdb_get_method_bind, GDExtensionInterfaceClassdbGetMethodBind);
- SETUP_LEGACY_FUNC(classdb_get_class_tag, GDExtensionInterfaceClassdbGetClassTag);
- SETUP_LEGACY_FUNC(classdb_register_extension_class, GDExtensionInterfaceClassdbRegisterExtensionClass);
- SETUP_LEGACY_FUNC(classdb_register_extension_class_method, GDExtensionInterfaceClassdbRegisterExtensionClassMethod);
- SETUP_LEGACY_FUNC(classdb_register_extension_class_integer_constant, GDExtensionInterfaceClassdbRegisterExtensionClassIntegerConstant);
- SETUP_LEGACY_FUNC(classdb_register_extension_class_property, GDExtensionInterfaceClassdbRegisterExtensionClassProperty);
- SETUP_LEGACY_FUNC(classdb_register_extension_class_property_group, GDExtensionInterfaceClassdbRegisterExtensionClassPropertyGroup);
- SETUP_LEGACY_FUNC(classdb_register_extension_class_property_subgroup, GDExtensionInterfaceClassdbRegisterExtensionClassPropertySubgroup);
- SETUP_LEGACY_FUNC(classdb_register_extension_class_signal, GDExtensionInterfaceClassdbRegisterExtensionClassSignal);
- SETUP_LEGACY_FUNC(classdb_unregister_extension_class, GDExtensionInterfaceClassdbUnregisterExtensionClass);
- SETUP_LEGACY_FUNC(get_library_path, GDExtensionInterfaceGetLibraryPath);
-
- return legacy_gdextension_interface;
-}
-
-#undef SETUP_LEGACY_FUNC
diff --git a/core/object/ref_counted.h b/core/object/ref_counted.h
index 58706fb9a9..3386514706 100644
--- a/core/object/ref_counted.h
+++ b/core/object/ref_counted.h
@@ -242,8 +242,11 @@ public:
template <class T>
struct PtrToArg<Ref<T>> {
_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
+ if (p_ptr == nullptr) {
+ return Ref<T>();
+ }
// p_ptr points to a RefCounted object
- return Ref<T>(const_cast<T *>(reinterpret_cast<const T *>(p_ptr)));
+ return Ref<T>(const_cast<T *>(*reinterpret_cast<T *const *>(p_ptr)));
}
typedef Ref<T> EncodeT;
@@ -259,8 +262,11 @@ struct PtrToArg<const Ref<T> &> {
typedef Ref<T> EncodeT;
_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
+ if (p_ptr == nullptr) {
+ return Ref<T>();
+ }
// p_ptr points to a RefCounted object
- return Ref<T>((T *)p_ptr);
+ return Ref<T>(*((T *const *)p_ptr));
}
};
diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp
index 71f40660f4..6f047d80aa 100644
--- a/core/object/script_language.cpp
+++ b/core/object/script_language.cpp
@@ -34,7 +34,6 @@
#include "core/core_string_names.h"
#include "core/debugger/engine_debugger.h"
#include "core/debugger/script_debugger.h"
-#include "core/variant/typed_array.h"
#include <stdint.h>
@@ -461,6 +460,52 @@ void ScriptLanguage::get_core_type_words(List<String> *p_core_type_words) const
void ScriptLanguage::frame() {
}
+TypedArray<int> ScriptLanguage::CodeCompletionOption::get_option_characteristics(const String &p_base) {
+ // Return characacteristics of the match found by order of importance.
+ // Matches will be ranked by a lexicographical order on the vector returned by this function.
+ // The lower values indicate better matches and that they should go before in the order of appearance.
+ if (last_matches == matches) {
+ return charac;
+ }
+ charac.clear();
+ // Ensure base is not empty and at the same time that matches is not empty too.
+ if (p_base.length() == 0) {
+ last_matches = matches;
+ charac.push_back(location);
+ return charac;
+ }
+ charac.push_back(matches.size());
+ charac.push_back((matches[0].first == 0) ? 0 : 1);
+ charac.push_back(location);
+ const char32_t *target_char = &p_base[0];
+ int bad_case = 0;
+ for (const Pair<int, int> &match_segment : matches) {
+ const char32_t *string_to_complete_char = &display[match_segment.first];
+ for (int j = 0; j < match_segment.second; j++, string_to_complete_char++, target_char++) {
+ if (*string_to_complete_char != *target_char) {
+ bad_case++;
+ }
+ }
+ }
+ charac.push_back(bad_case);
+ charac.push_back(matches[0].first);
+ last_matches = matches;
+ return charac;
+}
+
+void ScriptLanguage::CodeCompletionOption::clear_characteristics() {
+ charac = TypedArray<int>();
+}
+
+TypedArray<int> ScriptLanguage::CodeCompletionOption::get_option_cached_characteristics() const {
+ // Only returns the cached value and warns if it was not updated since the last change of matches.
+ if (last_matches != matches) {
+ WARN_PRINT("Characteristics are not up to date.");
+ }
+
+ return charac;
+}
+
bool PlaceHolderScriptInstance::set(const StringName &p_name, const Variant &p_value) {
if (script->is_placeholder_fallback_enabled()) {
return false;
diff --git a/core/object/script_language.h b/core/object/script_language.h
index 696c9a94a5..829f01fbcc 100644
--- a/core/object/script_language.h
+++ b/core/object/script_language.h
@@ -35,6 +35,7 @@
#include "core/io/resource.h"
#include "core/templates/pair.h"
#include "core/templates/rb_map.h"
+#include "core/variant/typed_array.h"
class ScriptLanguage;
template <typename T>
@@ -305,8 +306,8 @@ public:
virtual Error open_in_external_editor(const Ref<Script> &p_script, int p_line, int p_col) { return ERR_UNAVAILABLE; }
virtual bool overrides_external_editor() { return false; }
- /* Keep enum in Sync with: */
- /* /scene/gui/code_edit.h - CodeEdit::CodeCompletionKind */
+ // Keep enums in sync with:
+ // scene/gui/code_edit.h - CodeEdit::CodeCompletionKind
enum CodeCompletionKind {
CODE_COMPLETION_KIND_CLASS,
CODE_COMPLETION_KIND_FUNCTION,
@@ -321,6 +322,7 @@ public:
CODE_COMPLETION_KIND_MAX
};
+ // scene/gui/code_edit.h - CodeEdit::CodeCompletionLocation
enum CodeCompletionLocation {
LOCATION_LOCAL = 0,
LOCATION_PARENT_MASK = 1 << 8,
@@ -336,6 +338,7 @@ public:
Ref<Resource> icon;
Variant default_value;
Vector<Pair<int, int>> matches;
+ Vector<Pair<int, int>> last_matches;
int location = LOCATION_OTHER;
CodeCompletionOption() {}
@@ -346,6 +349,13 @@ public:
kind = p_kind;
location = p_location;
}
+
+ TypedArray<int> get_option_characteristics(const String &p_base);
+ void clear_characteristics();
+ TypedArray<int> get_option_cached_characteristics() const;
+
+ private:
+ TypedArray<int> charac;
};
virtual Error complete_code(const String &p_code, const String &p_path, Object *p_owner, List<CodeCompletionOption> *r_options, bool &r_force, String &r_call_hint) { return ERR_UNAVAILABLE; }
diff --git a/core/variant/method_ptrcall.h b/core/variant/method_ptrcall.h
index df1e524494..cbfb9cc257 100644
--- a/core/variant/method_ptrcall.h
+++ b/core/variant/method_ptrcall.h
@@ -159,7 +159,10 @@ MAKE_PTRARG_BY_REFERENCE(Variant);
template <class T>
struct PtrToArg<T *> {
_FORCE_INLINE_ static T *convert(const void *p_ptr) {
- return const_cast<T *>(reinterpret_cast<const T *>(p_ptr));
+ if (p_ptr == nullptr) {
+ return nullptr;
+ }
+ return const_cast<T *>(*reinterpret_cast<T *const *>(p_ptr));
}
typedef Object *EncodeT;
_FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) {
@@ -170,7 +173,10 @@ struct PtrToArg<T *> {
template <class T>
struct PtrToArg<const T *> {
_FORCE_INLINE_ static const T *convert(const void *p_ptr) {
- return reinterpret_cast<const T *>(p_ptr);
+ if (p_ptr == nullptr) {
+ return nullptr;
+ }
+ return *reinterpret_cast<T *const *>(p_ptr);
}
typedef const Object *EncodeT;
_FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) {
diff --git a/core/variant/variant_internal.h b/core/variant/variant_internal.h
index 8013c1a32a..c23066c0c6 100644
--- a/core/variant/variant_internal.h
+++ b/core/variant/variant_internal.h
@@ -502,7 +502,7 @@ public:
case Variant::PACKED_COLOR_ARRAY:
return get_color_array(v);
case Variant::OBJECT:
- return v->_get_obj().obj;
+ return get_object(v);
case Variant::VARIANT_MAX:
ERR_FAIL_V(nullptr);
}