Skip to content

Commit

Permalink
Merge pull request godotengine#82799 from CedNaru/feature/expose_free…
Browse files Browse the repository at this point in the history
…_instance_binding

Expose `Object::free_instance_binding()` to GDExtension
  • Loading branch information
akien-mga committed Oct 5, 2023
2 parents 7c1abe8 + 0a246e9 commit c7ed5d7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions core/extension/gdextension_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const StringName *>(p_classname);
Object *o = (Object *)p_object;
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions core/extension/gdextension_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/object/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1871,7 +1871,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();
Expand All @@ -1896,6 +1895,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);

Expand Down
2 changes: 1 addition & 1 deletion core/object/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -970,9 +970,9 @@ class Object {
// 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
Expand Down

0 comments on commit c7ed5d7

Please sign in to comment.