Skip to content

Fix a problem where Object.callv() and Callable.callv() would not correctly invoke when a read-only Array was passed. #915

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions core/object/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,19 +739,33 @@ void Object::setvar(const Variant &p_key, const Variant &p_value, bool *r_valid)
}

Variant Object::callv(const StringName &p_method, const Array &p_args) {
Variant ret;
Callable::CallError ce;
const Variant **argptrs = nullptr;

if (p_args.size() > 0) {
argptrs = (const Variant **)alloca(sizeof(Variant *) * p_args.size());
for (int i = 0; i < p_args.size(); i++) {
argptrs[i] = &p_args[i];
const int argcount = p_args.size();
if (argcount) {
argptrs = (const Variant **)alloca(sizeof(Variant*) * argcount);
if (p_args.is_read_only() && argcount > 1) {
Variant *args = (Variant *)alloca(sizeof(Variant) * argcount);
for (int i = 0; i < argcount; i++) {
new (&args[i]) Variant(p_args[i]);
argptrs[i] = &args[i];
}
ret = callp(p_method, argptrs, argcount, ce);
for (int i = argcount - 1; i >= 0; i--) {
args[i].~Variant();
}
} else {
for (int i = 0; i < argcount; i++) {
argptrs[i] = &p_args[i];
}
ret = callp(p_method, argptrs, argcount, ce);
}
} else {
ret = callp(p_method, argptrs, argcount, ce);
}

Callable::CallError ce;
const Variant ret = callp(p_method, argptrs, p_args.size(), ce);
if (ce.error != Callable::CallError::CALL_OK) {
ERR_FAIL_V_MSG(Variant(), vformat("Error calling method from 'callv': %s.", Variant::get_call_error_text(this, p_method, argptrs, p_args.size(), ce)));
ERR_FAIL_V_MSG(Variant(), vformat("Error calling method from 'callv': %s.", Variant::get_call_error_text(this, p_method, argptrs, argcount, ce)));
}
return ret;
}
Expand Down
26 changes: 20 additions & 6 deletions core/variant/callable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,31 @@ void Callable::callp(const Variant **p_arguments, int p_argcount, Variant &r_ret
}

Variant Callable::callv(const Array &p_arguments) const {
int argcount = p_arguments.size();
Variant ret;
CallError ce;
const Variant **argptrs = nullptr;
const int argcount = p_arguments.size();
if (argcount) {
argptrs = (const Variant **)alloca(sizeof(Variant *) * argcount);
for (int i = 0; i < argcount; i++) {
argptrs[i] = &p_arguments[i];
if (p_arguments.is_read_only() && argcount > 1) {
Variant *args = (Variant *)alloca(sizeof(Variant) * argcount);
for (int i = 0; i < argcount; i++) {
new (&args[i]) Variant(p_arguments[i]);
argptrs[i] = &args[i];
}
callp(argptrs, argcount, ret, ce);
for (int i = argcount - 1; i >= 0; i--) {
args[i].~Variant();
}
} else {
for (int i = 0; i < argcount; i++) {
argptrs[i] = &p_arguments[i];
}
callp(argptrs, argcount, ret, ce);
}
} else {
callp(argptrs, argcount, ret, ce);
}
CallError ce;
Variant ret;
callp(argptrs, argcount, ret, ce);
return ret;
}

Expand Down