-
-
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
Set vararg methods' ptrcall of builtin classes, and let them can be called without arguments. #76047
Set vararg methods' ptrcall of builtin classes, and let them can be called without arguments. #76047
Conversation
0333954
to
10546d9
Compare
Thanks! This works in my testing along with the godot-cpp PR godotengine/godot-cpp#1091 The one thing I'm unsure about is using the lambda function to make the argument pointer. Why not convert this code: LocalVector<Variant> vars;
vars.resize(p_argcount);
LocalVector<const Variant *> vars_ptrs;
vars_ptrs.resize(p_argcount);
for (int i = 0; i < p_argcount; i++) {
vars[i] = PtrToArg<Variant>::convert(p_args[i]);
vars_ptrs[i] = &vars[i];
} ... into something like: LocalVector<Variant> vars;
LocalVector<const Variant *> vars_ptrs;
if (p_argcount > 0) {
vars.resize(p_argcount);
vars_ptrs.resize(p_argcount);
for (int i = 0; i < p_argcount; i++) {
vars[i] = PtrToArg<Variant>::convert(p_args[i]);
vars_ptrs[i] = &vars[i];
}
} else {
vars.push_back(Variant());
vars_ptrs.push_back(&vars[0]);
} That seems much simpler and easier to understand to me, and it avoids a lambda, which we don't use much in Godot. |
dbbab3d
to
8e566ee
Compare
Because zero argument calling sill need to memnew a Of course, this only a micro optimization. |
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.
Thanks!
With the latest changes, this looks great to me! And it's working perfectly from the perspective of GDExtension (via PR godotengine/godot-cpp#1091).
However, it'd be great to get a review from someone on the @godotengine/core team, to double check that this wouldn't have any unexpected implications elsewhere.
The two
From a glance these all seem to support the case m_method_ptr(&base, vars_ptrs.ptr(), p_argcount, ret, ce); avoiding the pointless If I'm wrong and one of the methods actually doesn't handle the case gracefully, then I propose handling it there (should be easy). |
8e566ee
to
67e1401
Compare
@rburing Now I remove the branch of I'm not sure this change is safe or not, please review carefully. |
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.
Looks good to me.
vars.resize(p_argcount); \ | ||
LocalVector<const Variant *> vars_ptrs; \ | ||
vars.resize(p_argcount); \ |
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.
This reordering (leftover from the previous version) is not necessary, but it doesn't hurt either.
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.
Thanks for your continued work on this!
I just retested the latest PR with godot-cpp, and it seems to be working just fine, including when passing no arguments to a vararg function.
Thanks! |
VariantBuiltInMethodInfo::ptrcall
for builtin vararg methods.I don't not the reason why the origin logic set vararg methods'
VariantBuiltInMethodInfo::ptrcall
tonullptr
, I just set them like normal method, and in my test, it work fine.This pr is made for implementing builtin classes' vararg methods in gdextension( refer to this pr #1091).