From 0a246e9b549a03f6d8e8a6ef6d15964831a2df60 Mon Sep 17 00:00:00 2001 From: Ced Naru Date: Wed, 4 Oct 2023 19:13:07 +0200 Subject: [PATCH] expose Object::free_instance_binding to GDExtension --- core/extension/gdextension_interface.cpp | 6 ++++++ core/extension/gdextension_interface.h | 11 +++++++++++ core/object/object.cpp | 2 +- core/object/object.h | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/core/extension/gdextension_interface.cpp b/core/extension/gdextension_interface.cpp index 2b4a37b1e08..843f9ceecfc 100644 --- a/core/extension/gdextension_interface.cpp +++ b/core/extension/gdextension_interface.cpp @@ -1152,6 +1152,11 @@ static void gdextension_object_set_instance_binding(GDExtensionObjectPtr p_objec o->set_instance_binding(p_token, p_binding, p_callbacks); } +static void gdextension_object_free_instance_binding(GDExtensionObjectPtr p_object, void *p_token) { + Object *o = (Object *)p_object; + o->free_instance_binding(p_token); +} + static void gdextension_object_set_instance(GDExtensionObjectPtr p_object, GDExtensionConstStringNamePtr p_classname, GDExtensionClassInstancePtr p_instance) { const StringName classname = *reinterpret_cast(p_classname); Object *o = (Object *)p_object; @@ -1491,6 +1496,7 @@ void gdextension_setup_interface() { REGISTER_INTERFACE_FUNC(global_get_singleton); REGISTER_INTERFACE_FUNC(object_get_instance_binding); REGISTER_INTERFACE_FUNC(object_set_instance_binding); + REGISTER_INTERFACE_FUNC(object_free_instance_binding); REGISTER_INTERFACE_FUNC(object_set_instance); REGISTER_INTERFACE_FUNC(object_get_class_name); REGISTER_INTERFACE_FUNC(object_cast_to); diff --git a/core/extension/gdextension_interface.h b/core/extension/gdextension_interface.h index fbd1480e692..ae7c5e0d2a3 100644 --- a/core/extension/gdextension_interface.h +++ b/core/extension/gdextension_interface.h @@ -2191,6 +2191,17 @@ typedef void *(*GDExtensionInterfaceObjectGetInstanceBinding)(GDExtensionObjectP */ typedef void (*GDExtensionInterfaceObjectSetInstanceBinding)(GDExtensionObjectPtr p_o, void *p_token, void *p_binding, const GDExtensionInstanceBindingCallbacks *p_callbacks); +/** + * @name object_free_instance_binding + * @since 4.2 + * + * Free an Object's instance binding. + * + * @param p_o A pointer to the Object. + * @param p_library A token the library received by the GDExtension's entry point function. + */ +typedef void (*GDExtensionInterfaceObjectFreeInstanceBinding)(GDExtensionObjectPtr p_o, void *p_token); + /** * @name object_set_instance * @since 4.1 diff --git a/core/object/object.cpp b/core/object/object.cpp index f62b93d0ffc..147e8f21366 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -1863,7 +1863,6 @@ bool Object::has_instance_binding(void *p_token) { return found; } -#ifdef TOOLS_ENABLED void Object::free_instance_binding(void *p_token) { bool found = false; _instance_binding_mutex.lock(); @@ -1888,6 +1887,7 @@ void Object::free_instance_binding(void *p_token) { _instance_binding_mutex.unlock(); } +#ifdef TOOLS_ENABLED void Object::clear_internal_extension() { ERR_FAIL_NULL(_extension); diff --git a/core/object/object.h b/core/object/object.h index 60dc031d4d6..a444db0f703 100644 --- a/core/object/object.h +++ b/core/object/object.h @@ -970,9 +970,9 @@ public: // Used on creation by binding only. void set_instance_binding(void *p_token, void *p_binding, const GDExtensionInstanceBindingCallbacks *p_callbacks); bool has_instance_binding(void *p_token); + void free_instance_binding(void *p_token); #ifdef TOOLS_ENABLED - void free_instance_binding(void *p_token); void clear_internal_extension(); void reset_internal_extension(ObjectGDExtension *p_extension); #endif