Skip to content

Commit

Permalink
Merge pull request #58929 from reduz/remove-variant-arg-macros
Browse files Browse the repository at this point in the history
Remove VARIANT_ARG* macros
  • Loading branch information
akien-mga authored Mar 9, 2022
2 parents f17c550 + 21637df commit 33c907f
Show file tree
Hide file tree
Showing 59 changed files with 417 additions and 467 deletions.
4 changes: 2 additions & 2 deletions core/extension/gdnative_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static void gdnative_variant_call(GDNativeVariantPtr p_self, const GDNativeStrin
const Variant **args = (const Variant **)p_args;
Variant ret;
Callable::CallError error;
self->call(*method, args, p_argcount, ret, error);
self->callp(*method, args, p_argcount, ret, error);
memnew_placement(r_return, Variant(ret));

if (r_error) {
Expand Down Expand Up @@ -152,7 +152,7 @@ static void gdnative_variant_set_indexed(GDNativeVariantPtr p_self, GDNativeInt

bool valid;
bool oob;
self->set_indexed(p_index, value, valid, oob);
self->set_indexed(p_index, *value, valid, oob);
*r_valid = valid;
*r_oob = oob;
}
Expand Down
2 changes: 1 addition & 1 deletion core/math/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
}

Callable::CallError ce;
base.call(call->method, (const Variant **)argp.ptr(), argp.size(), r_ret, ce);
base.callp(call->method, (const Variant **)argp.ptr(), argp.size(), r_ret, ce);

if (ce.error != Callable::CallError::CALL_OK) {
r_error_str = vformat(RTR("On call to '%s':"), String(call->method));
Expand Down
8 changes: 4 additions & 4 deletions core/object/class_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1197,15 +1197,15 @@ bool ClassDB::set_property(Object *p_object, const StringName &p_property, const
if (psg->_setptr) {
psg->_setptr->call(p_object, arg, 2, ce);
} else {
p_object->call(psg->setter, arg, 2, ce);
p_object->callp(psg->setter, arg, 2, ce);
}

} else {
const Variant *arg[1] = { &p_value };
if (psg->_setptr) {
psg->_setptr->call(p_object, arg, 1, ce);
} else {
p_object->call(psg->setter, arg, 1, ce);
p_object->callp(psg->setter, arg, 1, ce);
}
}

Expand Down Expand Up @@ -1238,14 +1238,14 @@ bool ClassDB::get_property(Object *p_object, const StringName &p_property, Varia
Variant index = psg->index;
const Variant *arg[1] = { &index };
Callable::CallError ce;
r_value = p_object->call(psg->getter, arg, 1, ce);
r_value = p_object->callp(psg->getter, arg, 1, ce);

} else {
Callable::CallError ce;
if (psg->_getptr) {
r_value = psg->_getptr->call(p_object, nullptr, 0, ce);
} else {
r_value = p_object->call(psg->getter, nullptr, 0, ce);
r_value = p_object->callp(psg->getter, nullptr, 0, ce);
}
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion core/object/make_virtuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
if (script_instance) {\\
Callable::CallError ce; \\
$CALLSIARGS\\
$CALLSIBEGINscript_instance->call(_gdvirtual_##m_name##_sn, $CALLSIARGPASS, ce);\\
$CALLSIBEGINscript_instance->callp(_gdvirtual_##m_name##_sn, $CALLSIARGPASS, ce);\\
if (ce.error == Callable::CallError::CALL_OK) {\\
$CALLSIRET\\
return true;\\
Expand Down
41 changes: 6 additions & 35 deletions core/object/message_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "core/config/project_settings.h"
#include "core/core_string_names.h"
#include "core/object/class_db.h"
#include "core/object/script_language.h"

MessageQueue *MessageQueue::singleton = nullptr;
Expand All @@ -40,23 +41,8 @@ MessageQueue *MessageQueue::get_singleton() {
return singleton;
}

Error MessageQueue::push_call(ObjectID p_id, const StringName &p_method, const Variant **p_args, int p_argcount, bool p_show_error) {
return push_callable(Callable(p_id, p_method), p_args, p_argcount, p_show_error);
}

Error MessageQueue::push_call(ObjectID p_id, const StringName &p_method, VARIANT_ARG_DECLARE) {
VARIANT_ARGPTRS;

int argc = 0;

for (int i = 0; i < VARIANT_ARG_MAX; i++) {
if (argptr[i]->get_type() == Variant::NIL) {
break;
}
argc++;
}

return push_call(p_id, p_method, argptr, argc, false);
Error MessageQueue::push_callp(ObjectID p_id, const StringName &p_method, const Variant **p_args, int p_argcount, bool p_show_error) {
return push_callablep(Callable(p_id, p_method), p_args, p_argcount, p_show_error);
}

Error MessageQueue::push_set(ObjectID p_id, const StringName &p_prop, const Variant &p_value) {
Expand Down Expand Up @@ -113,8 +99,8 @@ Error MessageQueue::push_notification(ObjectID p_id, int p_notification) {
return OK;
}

Error MessageQueue::push_call(Object *p_object, const StringName &p_method, VARIANT_ARG_DECLARE) {
return push_call(p_object->get_instance_id(), p_method, VARIANT_ARG_PASS);
Error MessageQueue::push_callp(Object *p_object, const StringName &p_method, const Variant **p_args, int p_argcount, bool p_show_error) {
return push_callp(p_object->get_instance_id(), p_method, p_args, p_argcount, p_show_error);
}

Error MessageQueue::push_notification(Object *p_object, int p_notification) {
Expand All @@ -125,7 +111,7 @@ Error MessageQueue::push_set(Object *p_object, const StringName &p_prop, const V
return push_set(p_object->get_instance_id(), p_prop, p_value);
}

Error MessageQueue::push_callable(const Callable &p_callable, const Variant **p_args, int p_argcount, bool p_show_error) {
Error MessageQueue::push_callablep(const Callable &p_callable, const Variant **p_args, int p_argcount, bool p_show_error) {
_THREAD_SAFE_METHOD_

int room_needed = sizeof(Message) + sizeof(Variant) * p_argcount;
Expand Down Expand Up @@ -155,21 +141,6 @@ Error MessageQueue::push_callable(const Callable &p_callable, const Variant **p_
return OK;
}

Error MessageQueue::push_callable(const Callable &p_callable, VARIANT_ARG_DECLARE) {
VARIANT_ARGPTRS;

int argc = 0;

for (int i = 0; i < VARIANT_ARG_MAX; i++) {
if (argptr[i]->get_type() == Variant::NIL) {
break;
}
argc++;
}

return push_callable(p_callable, argptr, argc);
}

void MessageQueue::statistics() {
Map<StringName, int> set_count;
Map<int, int> notify_count;
Expand Down
43 changes: 37 additions & 6 deletions core/object/message_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
#ifndef MESSAGE_QUEUE_H
#define MESSAGE_QUEUE_H

#include "core/object/class_db.h"
#include "core/object/object_id.h"
#include "core/os/thread_safe.h"
#include "core/variant/variant.h"

class Object;

class MessageQueue {
_THREAD_SAFE_CLASS_
Expand Down Expand Up @@ -73,14 +76,42 @@ class MessageQueue {
public:
static MessageQueue *get_singleton();

Error push_call(ObjectID p_id, const StringName &p_method, const Variant **p_args, int p_argcount, bool p_show_error = false);
Error push_call(ObjectID p_id, const StringName &p_method, VARIANT_ARG_LIST);
Error push_callp(ObjectID p_id, const StringName &p_method, const Variant **p_args, int p_argcount, bool p_show_error = false);
template <typename... VarArgs>
Error push_call(ObjectID p_id, const StringName &p_method, VarArgs... p_args) {
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
const Variant *argptrs[sizeof...(p_args) + 1];
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
argptrs[i] = &args[i];
}
return push_callp(p_id, p_method, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
}

Error push_notification(ObjectID p_id, int p_notification);
Error push_set(ObjectID p_id, const StringName &p_prop, const Variant &p_value);
Error push_callable(const Callable &p_callable, const Variant **p_args, int p_argcount, bool p_show_error = false);
Error push_callable(const Callable &p_callable, VARIANT_ARG_LIST);
Error push_callablep(const Callable &p_callable, const Variant **p_args, int p_argcount, bool p_show_error = false);

template <typename... VarArgs>
Error push_callable(const Callable &p_callable, VarArgs... p_args) {
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
const Variant *argptrs[sizeof...(p_args) + 1];
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
argptrs[i] = &args[i];
}
return push_callablep(p_callable, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
}

Error push_callp(Object *p_object, const StringName &p_method, const Variant **p_args, int p_argcount, bool p_show_error = false);
template <typename... VarArgs>
Error push_call(Object *p_object, const StringName &p_method, VarArgs... p_args) {
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
const Variant *argptrs[sizeof...(p_args) + 1];
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
argptrs[i] = &args[i];
}
return push_callp(p_object, p_method, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
}

Error push_call(Object *p_object, const StringName &p_method, VARIANT_ARG_LIST);
Error push_notification(Object *p_object, int p_notification);
Error push_set(Object *p_object, const StringName &p_prop, const Variant &p_value);

Expand Down
52 changes: 8 additions & 44 deletions core/object/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ Variant Object::_call_bind(const Variant **p_args, int p_argcount, Callable::Cal

StringName method = *p_args[0];

return call(method, &p_args[1], p_argcount - 1, r_error);
return callp(method, &p_args[1], p_argcount - 1, r_error);
}

Variant Object::_call_deferred_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
Expand All @@ -700,7 +700,7 @@ Variant Object::_call_deferred_bind(const Variant **p_args, int p_argcount, Call

StringName method = *p_args[0];

MessageQueue::get_singleton()->push_call(get_instance_id(), method, &p_args[1], p_argcount - 1, true);
MessageQueue::get_singleton()->push_callp(get_instance_id(), method, &p_args[1], p_argcount - 1, true);

return Variant();
}
Expand Down Expand Up @@ -750,31 +750,14 @@ Variant Object::callv(const StringName &p_method, const Array &p_args) {
}

Callable::CallError ce;
Variant ret = call(p_method, argptrs, p_args.size(), ce);
Variant ret = callp(p_method, argptrs, p_args.size(), ce);
if (ce.error != Callable::CallError::CALL_OK) {
ERR_FAIL_V_MSG(Variant(), "Error calling method from 'callv': " + Variant::get_call_error_text(this, p_method, argptrs, p_args.size(), ce) + ".");
}
return ret;
}

Variant Object::call(const StringName &p_name, VARIANT_ARG_DECLARE) {
VARIANT_ARGPTRS;

int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
if (argptr[i]->get_type() == Variant::NIL) {
break;
}
argc++;
}

Callable::CallError error;

Variant ret = call(p_name, argptr, argc, error);
return ret;
}

Variant Object::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
Variant Object::callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
r_error.error = Callable::CallError::CALL_OK;

if (p_method == CoreStringNames::get_singleton()->_free) {
Expand Down Expand Up @@ -808,7 +791,7 @@ Variant Object::call(const StringName &p_method, const Variant **p_args, int p_a
OBJ_DEBUG_LOCK

if (script_instance) {
ret = script_instance->call(p_method, p_args, p_argcount, r_error);
ret = script_instance->callp(p_method, p_args, p_argcount, r_error);
//force jumptable
switch (r_error.error) {
case Callable::CallError::CALL_OK:
Expand Down Expand Up @@ -1027,12 +1010,12 @@ Variant Object::_emit_signal(const Variant **p_args, int p_argcount, Callable::C
args = &p_args[1];
}

emit_signal(signal, args, argc);
emit_signalp(signal, args, argc);

return Variant();
}

Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int p_argcount) {
Error Object::emit_signalp(const StringName &p_name, const Variant **p_args, int p_argcount) {
if (_block_signals) {
return ERR_CANT_ACQUIRE_RESOURCE; //no emit, signals blocked
}
Expand Down Expand Up @@ -1091,7 +1074,7 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int
}

if (c.flags & CONNECT_DEFERRED) {
MessageQueue::get_singleton()->push_callable(c.callable, args, argc, true);
MessageQueue::get_singleton()->push_callablep(c.callable, args, argc, true);
} else {
Callable::CallError ce;
_emitting = true;
Expand Down Expand Up @@ -1139,21 +1122,6 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int
return err;
}

Error Object::emit_signal(const StringName &p_name, VARIANT_ARG_DECLARE) {
VARIANT_ARGPTRS;

int argc = 0;

for (int i = 0; i < VARIANT_ARG_MAX; i++) {
if (argptr[i]->get_type() == Variant::NIL) {
break;
}
argc++;
}

return emit_signal(p_name, argptr, argc);
}

void Object::_add_user_signal(const String &p_name, const Array &p_args) {
// this version of add_user_signal is meant to be used from scripts or external apis
// without access to ADD_SIGNAL in bind_methods
Expand Down Expand Up @@ -1648,10 +1616,6 @@ void Object::_bind_methods() {
BIND_ENUM_CONSTANT(CONNECT_REFERENCE_COUNTED);
}

void Object::call_deferred(const StringName &p_method, VARIANT_ARG_DECLARE) {
MessageQueue::get_singleton()->push_call(this, p_method, VARIANT_ARG_PASS);
}

void Object::set_deferred(const StringName &p_property, const Variant &p_value) {
MessageQueue::get_singleton()->push_set(this, p_property, p_value);
}
Expand Down
Loading

0 comments on commit 33c907f

Please sign in to comment.