-
Notifications
You must be signed in to change notification settings - Fork 315
structs redux #1318
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
structs redux #1318
Changes from all commits
412d1f9
907dedb
5aa9cc4
2cd8d99
f027c2a
7f43c0f
126783a
6ea6d00
01a4c05
ef89c7f
ed04cb2
4c99518
d540e6d
259393e
072ced0
8c4de69
433113f
1f1bb67
58e756b
6b2239e
ead222f
97bdc7b
f816969
88a80e9
fd1ad97
ae725fb
b89e06b
65568c3
bfb7dc8
0fe2915
61d1aa6
9f3a822
9cf04bf
991fdad
22bc867
8b9aa20
3dfe741
af0b101
358ef84
3c0446f
9a2e1bf
2190c83
9348ab2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -393,3 +393,5 @@ $RECYCLE.BIN/ | |
| *.msp | ||
| *.lnk | ||
| *.generated.props | ||
| .gdbinit | ||
| CLAUDE.md | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -854,6 +854,20 @@ Variant Object::callp(const StringName &p_method, const Variant **p_args, int p_ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Variant ret; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| OBJ_DEBUG_LOCK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifdef MODULE_GDSCRIPT_ENABLED | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Special case for GDScriptStructClass to support struct constructors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // This is needed because GDScriptStructClass::callp needs to be called directly, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // but callp is not virtual so Object::callp doesn't dispatch to it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (get_class_name() == StringName("GDScriptStructClass")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Forward to GDScriptStructClass::callp by using a Callable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Callable callable = Callable(this, p_method); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (callable.is_valid()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| callable.callp(p_args, p_argcount, ret, r_error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ret; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+857
to
+869
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win Avoid constructing a
⚡ Proposed fix `#ifdef` MODULE_GDSCRIPT_ENABLED
// Special case for GDScriptStructClass to support struct constructors
- if (get_class_name() == StringName("GDScriptStructClass")) {
+ static const StringName gdscript_struct_class_name = StringName("GDScriptStructClass");
+ if (get_class_name() == gdscript_struct_class_name) {
// Forward to GDScriptStructClass::callp by using a Callable
Callable callable = Callable(this, p_method);
if (callable.is_valid()) {
callable.callp(p_args, p_argcount, ret, r_error);
return ret;
}
}
`#endif`📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (script_instance) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ret = script_instance->callp(p_method, p_args, p_argcount, r_error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Force jump table. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Add
MAX_RECURSION_DEPTHguard to struct (de)serialization. The STRUCT branches recurse through_from_native/_to_nativewithp_depth + 1but omit theERR_FAIL_COND_V_MSG(p_depth > Variant::MAX_RECURSION_DEPTH, ...)check that the OBJECT (Line 822) and DICTIONARY (Line 921) branches use. Nested structs re-enter the STRUCT case unbounded, so deeply nested/untrusted JSON can drive unbounded recursion and stack overflow during deserialization.core/io/json.cpp#L862-L899: add the depth guard before recursively encoding struct field values in_from_native.core/io/json.cpp#L1379-L1410: add the depth guard before recursively decoding struct field values in_to_native.📍 Affects 1 file
core/io/json.cpp#L862-L899(this comment)core/io/json.cpp#L1379-L1410🤖 Prompt for AI Agents