mirror of
https://github.com/godotengine/godot.git
synced 2024-11-22 12:12:28 +00:00
Fix variant getters not setting return type
The validated getters were only setting the value without changing the type, leading to wrong results. This uses the same path used for methods to the same purpose.
This commit is contained in:
parent
48049b8d9e
commit
8a9e3524a9
@ -42,27 +42,6 @@
|
||||
typedef void (*VariantFunc)(Variant &r_ret, Variant &p_self, const Variant **p_args);
|
||||
typedef void (*VariantConstructFunc)(Variant &r_ret, const Variant **p_args);
|
||||
|
||||
template <class T>
|
||||
struct TypeAdjust {
|
||||
_FORCE_INLINE_ static void adjust(Variant *r_ret) {
|
||||
VariantTypeChanger<typename GetSimpleTypeT<T>::type_t>::change(r_ret);
|
||||
}
|
||||
};
|
||||
|
||||
template <> //do nothing for variant
|
||||
struct TypeAdjust<Variant> {
|
||||
_FORCE_INLINE_ static void adjust(Variant *r_ret) {
|
||||
}
|
||||
};
|
||||
|
||||
template <> //do nothing for variant
|
||||
struct TypeAdjust<Object *> {
|
||||
_FORCE_INLINE_ static void adjust(Variant *r_ret) {
|
||||
VariantInternal::clear(r_ret);
|
||||
*r_ret = (Object *)nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
template <class R, class T, class... P>
|
||||
static _FORCE_INLINE_ void vc_method_call(R (T::*method)(P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) {
|
||||
call_with_variant_args_ret_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, r_error, p_defvals);
|
||||
@ -124,12 +103,12 @@ static _FORCE_INLINE_ void vc_ptrcall(void (T::*method)(P...) const, void *p_bas
|
||||
|
||||
template <class R, class T, class... P>
|
||||
static _FORCE_INLINE_ void vc_change_return_type(R (T::*method)(P...), Variant *v) {
|
||||
TypeAdjust<R>::adjust(v);
|
||||
VariantTypeAdjust<R>::adjust(v);
|
||||
}
|
||||
|
||||
template <class R, class T, class... P>
|
||||
static _FORCE_INLINE_ void vc_change_return_type(R (T::*method)(P...) const, Variant *v) {
|
||||
TypeAdjust<R>::adjust(v);
|
||||
VariantTypeAdjust<R>::adjust(v);
|
||||
}
|
||||
|
||||
template <class T, class... P>
|
||||
@ -144,7 +123,7 @@ static _FORCE_INLINE_ void vc_change_return_type(void (T::*method)(P...) const,
|
||||
|
||||
template <class R, class... P>
|
||||
static _FORCE_INLINE_ void vc_change_return_type(R (*method)(P...), Variant *v) {
|
||||
TypeAdjust<R>::adjust(v);
|
||||
VariantTypeAdjust<R>::adjust(v);
|
||||
}
|
||||
|
||||
template <class R, class T, class... P>
|
||||
|
@ -1128,4 +1128,26 @@ struct VariantTypeChanger {
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct VariantTypeAdjust {
|
||||
_FORCE_INLINE_ static void adjust(Variant *r_ret) {
|
||||
VariantTypeChanger<typename GetSimpleTypeT<T>::type_t>::change(r_ret);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantTypeAdjust<Variant> {
|
||||
_FORCE_INLINE_ static void adjust(Variant *r_ret) {
|
||||
// Do nothing for variant.
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantTypeAdjust<Object *> {
|
||||
_FORCE_INLINE_ static void adjust(Variant *r_ret) {
|
||||
VariantInternal::clear(r_ret);
|
||||
*r_ret = (Object *)nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // VARIANT_INTERNAL_H
|
||||
|
@ -44,6 +44,7 @@
|
||||
*member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \
|
||||
} \
|
||||
static void validated_get(const Variant *base, Variant *member) { \
|
||||
VariantTypeAdjust<m_member_type>::adjust(member); \
|
||||
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \
|
||||
} \
|
||||
static void ptr_get(const void *base, void *member) { \
|
||||
@ -74,6 +75,7 @@
|
||||
*member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \
|
||||
} \
|
||||
static void validated_get(const Variant *base, Variant *member) { \
|
||||
VariantTypeAdjust<m_member_type>::adjust(member); \
|
||||
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \
|
||||
} \
|
||||
static void ptr_get(const void *base, void *member) { \
|
||||
@ -107,6 +109,7 @@
|
||||
*member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \
|
||||
} \
|
||||
static void validated_get(const Variant *base, Variant *member) { \
|
||||
VariantTypeAdjust<m_member_type>::adjust(member); \
|
||||
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \
|
||||
} \
|
||||
static void ptr_get(const void *base, void *member) { \
|
||||
@ -137,6 +140,7 @@
|
||||
*member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \
|
||||
} \
|
||||
static void validated_get(const Variant *base, Variant *member) { \
|
||||
VariantTypeAdjust<m_member_type>::adjust(member); \
|
||||
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \
|
||||
} \
|
||||
static void ptr_get(const void *base, void *member) { \
|
||||
@ -170,6 +174,7 @@
|
||||
*member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \
|
||||
} \
|
||||
static void validated_get(const Variant *base, Variant *member) { \
|
||||
VariantTypeAdjust<m_member_type>::adjust(member); \
|
||||
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \
|
||||
} \
|
||||
static void ptr_get(const void *base, void *member) { \
|
||||
@ -200,6 +205,7 @@
|
||||
*member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \
|
||||
} \
|
||||
static void validated_get(const Variant *base, Variant *member) { \
|
||||
VariantTypeAdjust<m_member_type>::adjust(member); \
|
||||
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \
|
||||
} \
|
||||
static void ptr_get(const void *base, void *member) { \
|
||||
@ -233,6 +239,7 @@
|
||||
*member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(m_index); \
|
||||
} \
|
||||
static void validated_get(const Variant *base, Variant *member) { \
|
||||
VariantTypeAdjust<m_member_type>::adjust(member); \
|
||||
*VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(m_index); \
|
||||
} \
|
||||
static void ptr_get(const void *base, void *member) { \
|
||||
@ -617,6 +624,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
|
||||
oob = true; \
|
||||
return; \
|
||||
} \
|
||||
VariantTypeAdjust<m_elem_type>::adjust(value); \
|
||||
*VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
|
||||
oob = false; \
|
||||
} \
|
||||
@ -694,6 +702,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
|
||||
oob = true; \
|
||||
return; \
|
||||
} \
|
||||
VariantTypeAdjust<m_elem_type>::adjust(value); \
|
||||
*VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
|
||||
oob = false; \
|
||||
} \
|
||||
@ -768,6 +777,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
|
||||
oob = true; \
|
||||
return; \
|
||||
} \
|
||||
VariantTypeAdjust<m_elem_type>::adjust(value); \
|
||||
*VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \
|
||||
oob = false; \
|
||||
} \
|
||||
@ -830,6 +840,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
|
||||
oob = true; \
|
||||
return; \
|
||||
} \
|
||||
VariantTypeAdjust<m_elem_type>::adjust(value); \
|
||||
*VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))m_accessor[index]; \
|
||||
oob = false; \
|
||||
} \
|
||||
@ -886,6 +897,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const {
|
||||
oob = true; \
|
||||
return; \
|
||||
} \
|
||||
VariantTypeAdjust<m_elem_type>::adjust(value); \
|
||||
*VariantGetInternalPtr<m_elem_type>::get_ptr(value) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_get(index); \
|
||||
oob = false; \
|
||||
} \
|
||||
|
Loading…
Reference in New Issue
Block a user