-
-
Notifications
You must be signed in to change notification settings - Fork 22.5k
[GDScript] Prevent some vararg methods binding arguments to member variables #88905
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
base: master
Are you sure you want to change the base?
[GDScript] Prevent some vararg methods binding arguments to member variables #88905
Conversation
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.
Can't test the other methods here AFAIK as groups don't work in the testing, unless I'm mistaken
core/object/object.cpp
Outdated
LocalVector<Variant> args; | ||
LocalVector<const Variant *> argptrs; |
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.
Allocations here are are too bad for performance. I'd suggest using alloca()
.
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.
Will do, wasn't well versed in using it when I wrote this one
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.
Added everywhere, might not be as relevant to the variant call one but shouldn't hurt
312936d
to
4d06340
Compare
args = (Variant *)alloca(sizeof(Variant) * argc); | ||
argptrs = (const Variant **)alloca(sizeof(Variant *) * argc); | ||
for (int i = 0; i < argc; i++) { | ||
memnew_placement(&args[i], Variant(*p_args[i + 1])); |
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.
Using the same method as used in:
This comment was marked as outdated.
This comment was marked as outdated.
4d06340
to
50e2146
Compare
50e2146
to
292c595
Compare
292c595
to
4841463
Compare
4841463
to
e246f31
Compare
e246f31
to
ee43927
Compare
ee43927
to
c867440
Compare
c867440
to
3224fe8
Compare
cf2ccae
to
f8ec296
Compare
f8ec296
to
15ca20e
Compare
15ca20e
to
70357b2
Compare
70357b2
to
002c0ed
Compare
002c0ed
to
77e5cb5
Compare
Calling some methods from GDScript with member variable arguments causes the pointer to that argument being passed instead of the value, affects: * `Signal.emit` * `Object.emit_signal` * `SceneTree.call_group/_flags`
77e5cb5
to
15bd4de
Compare
Calling some methods from GDScript with member variable arguments causes the pointer to that argument being passed instead of the value, affects:
Signal.emit
Object.emit_signal
SceneTree.call_group/_flags
Tried a separate method that's possibly more secure, by copying arguments into temporaries if they are member variables, this is a bit hit and miss and had some problems applying them just for vararg methods, this problem doesn't really affect other cases significantly either as most of the time it doesn't cause this kind of chain effect, so I feel this is more of a targeted situation where we can just fix it in the places where it's needed, instead of hitting every method called with a member variable with a temporary
I only added these fixes to the bound methods, so it won't affect calls from c++ normally, like
Signal.emit
, but instead the bound method undervariant_call
Note also that the
ptrcall
methods inVariant
use temporary storage for variants, and these are called from extensions AFAIK, so there's precedent for this solutionThe immediate, indiscriminate solution (as I couldn't reliably test for vararg, and therefore would miss some cases) would have been:
This is a bit brute force, but it works as well