-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GDExtension: Pass count when freeing method and property lists for script instances #89055
GDExtension: Pass count when freeing method and property lists for script instances #89055
Conversation
3a566a9
to
6bea6b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good and the feature makes sense
6bea6b5
to
27ea7ed
Compare
Thinking about this a little more, I think now that the I'll update this PR to do that a little later. |
27ea7ed
to
0badf07
Compare
I just pushed the changes to dynamically allocate the deprecated native info struct! I re-tested this with the Luau GDExtension, using the older interface, and everything still seems to be working. |
Thanks! |
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.)