Skip to content

Commit

Permalink
Merge pull request #82794 from dsnopek/gdextension-validated-call
Browse files Browse the repository at this point in the history
GDExtension: Convert `validated_call()` to `ptrcall()` (rather than `call()`)
  • Loading branch information
akien-mga committed Oct 6, 2023
2 parents 49e2bd9 + 55596ea commit a6a2d0d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
20 changes: 7 additions & 13 deletions core/extension/gdextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,29 +225,23 @@ class GDExtensionMethodBind : public MethodBind {
// This is added here, but it's unlikely to be provided by most extensions.
validated_call_func(method_userdata, extension_instance, reinterpret_cast<GDExtensionConstVariantPtr *>(p_args), (GDExtensionVariantPtr)r_ret);
} else {
#if 1
// Slow code-path, but works for the time being.
Callable::CallError ce;
call(p_object, p_args, argument_count, ce);
#else
// This is broken, because it needs more information to do the calling properly
// If not provided, go via ptrcall, which is faster than resorting to regular call.
const void **argptrs = (const void **)alloca(argument_count * sizeof(void *));
for (uint32_t i = 0; i < argument_count; i++) {
argptrs[i] = VariantInternal::get_opaque_pointer(p_args[i]);
}

bool returns = true;
void *ret_opaque;
if (returns) {
void *ret_opaque = nullptr;
if (r_ret) {
VariantInternal::initialize(r_ret, return_value_info.type);
ret_opaque = VariantInternal::get_opaque_pointer(r_ret);
} else {
ret_opaque = nullptr; // May be unnecessary as this is ignored, but just in case.
}

ptrcall(p_object, argptrs, ret_opaque);
#endif

if (r_ret && r_ret->get_type() == Variant::OBJECT) {
VariantInternal::update_object_id(r_ret);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/variant/variant_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ class VariantInternal {
case Variant::PACKED_COLOR_ARRAY:
return get_color_array(v);
case Variant::OBJECT:
return v->_get_obj().obj;
return get_object(v);
case Variant::VARIANT_MAX:
ERR_FAIL_V(nullptr);
}
Expand Down

0 comments on commit a6a2d0d

Please sign in to comment.