GDExtension: Pass count when freeing method and property lists for script instances #89055
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, the
free_property_list
andfree_method_list
functions onGDExtensionScriptInstanceInfo2
don't accept the number of items in the list. Since the GDExtension probably allocated memory for each item in the list, it will need to loop over all the elements in the list in order to free that memory.In order to work around this, all existing GDExtensions that provide a scripting language do some sort of hack to save the list count. For example, the Luau bindings allocate the list with some extra room at the front to stash the count and then do some pointer math:
https://github.com/Fumohouse/godot-luau-script/blob/69d5e02fc1e94101cf31d7bd9b384ad2423cdd96/src/luau_script.h#L222
In any case, none of these hacks or workarounds would be necessary if Godot simply passed the count to the
free_property_list
andfree_method_list
functions, which is what this PR does!(In addition to these changes, I also wrapped more of the code to support deprecated structs in
ScriptInstanceExtension
with#ifndef DISABLE_DEPRECATED
to make builds without deprecated code a little lighter.)