-
-
Notifications
You must be signed in to change notification settings - Fork 21.7k
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
Add metadata to TypedArray and validate at runtime #95492
base: master
Are you sure you want to change the base?
Conversation
- Adds metadata to `ContainerTypeValidate` to validate at runtime that elements added to TypedArray fit the the element type. - Adds metadata to TypedArray's `GetTypeInfo<>` so it's included in `extension_api.json` and language bindings can use the right element type for the Array.
Code-wise, I think this is the right approach to do these checks. However, I think we should have a core discussion to decide if we want to have these checks. Do we want I could personally see arguments for both sides. Getting specific with sizes potentially allows packing the data tighter when copying to/from native containers (although, inside the |
That's fair. I said this on RC but I'll say it again here for the record, the motivation behind this PR is to generate GDExtension-based C# bindings with the correct element type for typed arrays. The godot-cpp bindings generator is using the element type as-is. So instead of assuming I also checked what godot-rust does, and they do treat And this is the list of APIs where a TypedArray with an integer element type appears (grouped by element type):
|
If static type information about the array is available (
If the array is untyped ( There are some special cases to consider:
TLDR: unless I'm missing something, using |
I'm not sure about this.
That makes sense. If we could have an early out for That said, I still think we should connect with other Godot core folks outside of GDExtension, and get more input on if these "bounds checks" are even desirable. I feel like |
ContainerTypeValidate
to validate at runtime that elements added to TypedArray fit the the element type.GetTypeInfo<>
so it's included inextension_api.json
and language bindings can use the right element type for the Array.As an example, the method
CodeEdit::get_folded_lines
that returnsTypedArray<int>
:https://github.com/godotengine/godot/blob/c184105cf55614078b509b0a57c4bbd0beb62be7/scene/gui/code_edit.cpp#L1722
{ "name": "get_folded_lines", "is_const": true, "is_vararg": false, "is_static": false, "is_virtual": false, "hash": 3995934104, "return_value": { "type": "typedarray::int", + "meta": "int32" } },