Make freed object different than null in comparison operators
This is so everything is consistent, as a freed object is not equivalent to `null` in general. The booleanization of a freed object still returns `false` to work as an easy check for validity of objects. Similarly, the negation of a freed object returns `true`. Also makes freed objects different from each other (if they are not the same reference).
This commit is contained in:
parent
970be7afdc
commit
150b50cfcd
|
@ -931,7 +931,7 @@ bool Variant::is_zero() const {
|
||||||
return *reinterpret_cast<const ::RID *>(_data._mem) == ::RID();
|
return *reinterpret_cast<const ::RID *>(_data._mem) == ::RID();
|
||||||
}
|
}
|
||||||
case OBJECT: {
|
case OBJECT: {
|
||||||
return _get_obj().obj == nullptr;
|
return get_validated_object() == nullptr;
|
||||||
}
|
}
|
||||||
case CALLABLE: {
|
case CALLABLE: {
|
||||||
return reinterpret_cast<const Callable *>(_data._mem)->is_null();
|
return reinterpret_cast<const Callable *>(_data._mem)->is_null();
|
||||||
|
|
|
@ -549,14 +549,14 @@ public:
|
||||||
class OperatorEvaluatorEqualObject {
|
class OperatorEvaluatorEqualObject {
|
||||||
public:
|
public:
|
||||||
static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
|
static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
|
||||||
const Object *a = p_left.get_validated_object();
|
const ObjectID &a = VariantInternal::get_object_id(&p_left);
|
||||||
const Object *b = p_right.get_validated_object();
|
const ObjectID &b = VariantInternal::get_object_id(&p_right);
|
||||||
*r_ret = a == b;
|
*r_ret = a == b;
|
||||||
r_valid = true;
|
r_valid = true;
|
||||||
}
|
}
|
||||||
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
|
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
|
||||||
const Object *a = left->get_validated_object();
|
const ObjectID &a = VariantInternal::get_object_id(left);
|
||||||
const Object *b = right->get_validated_object();
|
const ObjectID &b = VariantInternal::get_object_id(right);
|
||||||
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = a == b;
|
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = a == b;
|
||||||
}
|
}
|
||||||
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
|
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
|
||||||
|
@ -568,12 +568,12 @@ public:
|
||||||
class OperatorEvaluatorEqualObjectNil {
|
class OperatorEvaluatorEqualObjectNil {
|
||||||
public:
|
public:
|
||||||
static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
|
static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
|
||||||
const Object *a = p_left.get_validated_object();
|
const Object *a = p_left.operator Object *();
|
||||||
*r_ret = a == nullptr;
|
*r_ret = a == nullptr;
|
||||||
r_valid = true;
|
r_valid = true;
|
||||||
}
|
}
|
||||||
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
|
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
|
||||||
const Object *a = left->get_validated_object();
|
const Object *a = left->operator Object *();
|
||||||
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = a == nullptr;
|
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = a == nullptr;
|
||||||
}
|
}
|
||||||
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
|
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
|
||||||
|
@ -585,12 +585,12 @@ public:
|
||||||
class OperatorEvaluatorEqualNilObject {
|
class OperatorEvaluatorEqualNilObject {
|
||||||
public:
|
public:
|
||||||
static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
|
static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
|
||||||
const Object *b = p_right.get_validated_object();
|
const Object *b = p_right.operator Object *();
|
||||||
*r_ret = nullptr == b;
|
*r_ret = nullptr == b;
|
||||||
r_valid = true;
|
r_valid = true;
|
||||||
}
|
}
|
||||||
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
|
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
|
||||||
const Object *b = right->get_validated_object();
|
const Object *b = right->operator Object *();
|
||||||
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = nullptr == b;
|
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = nullptr == b;
|
||||||
}
|
}
|
||||||
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
|
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
|
||||||
|
@ -620,14 +620,14 @@ public:
|
||||||
class OperatorEvaluatorNotEqualObject {
|
class OperatorEvaluatorNotEqualObject {
|
||||||
public:
|
public:
|
||||||
static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
|
static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
|
||||||
Object *a = p_left.get_validated_object();
|
const ObjectID &a = VariantInternal::get_object_id(&p_left);
|
||||||
Object *b = p_right.get_validated_object();
|
const ObjectID &b = VariantInternal::get_object_id(&p_right);
|
||||||
*r_ret = a != b;
|
*r_ret = a != b;
|
||||||
r_valid = true;
|
r_valid = true;
|
||||||
}
|
}
|
||||||
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
|
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
|
||||||
Object *a = left->get_validated_object();
|
const ObjectID &a = VariantInternal::get_object_id(left);
|
||||||
Object *b = right->get_validated_object();
|
const ObjectID &b = VariantInternal::get_object_id(right);
|
||||||
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = a != b;
|
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = a != b;
|
||||||
}
|
}
|
||||||
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
|
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
|
||||||
|
@ -639,12 +639,12 @@ public:
|
||||||
class OperatorEvaluatorNotEqualObjectNil {
|
class OperatorEvaluatorNotEqualObjectNil {
|
||||||
public:
|
public:
|
||||||
static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
|
static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
|
||||||
Object *a = p_left.get_validated_object();
|
Object *a = p_left.operator Object *();
|
||||||
*r_ret = a != nullptr;
|
*r_ret = a != nullptr;
|
||||||
r_valid = true;
|
r_valid = true;
|
||||||
}
|
}
|
||||||
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
|
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
|
||||||
Object *a = left->get_validated_object();
|
Object *a = left->operator Object *();
|
||||||
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = a != nullptr;
|
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = a != nullptr;
|
||||||
}
|
}
|
||||||
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
|
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
|
||||||
|
@ -656,12 +656,12 @@ public:
|
||||||
class OperatorEvaluatorNotEqualNilObject {
|
class OperatorEvaluatorNotEqualNilObject {
|
||||||
public:
|
public:
|
||||||
static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
|
static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) {
|
||||||
Object *b = p_right.get_validated_object();
|
Object *b = p_right.operator Object *();
|
||||||
*r_ret = nullptr != b;
|
*r_ret = nullptr != b;
|
||||||
r_valid = true;
|
r_valid = true;
|
||||||
}
|
}
|
||||||
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
|
static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) {
|
||||||
Object *b = right->get_validated_object();
|
Object *b = right->operator Object *();
|
||||||
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = nullptr != b;
|
*VariantGetInternalPtr<bool>::get_ptr(r_ret) = nullptr != b;
|
||||||
}
|
}
|
||||||
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
|
static void ptr_evaluate(const void *left, const void *right, void *r_ret) {
|
||||||
|
|
Loading…
Reference in New Issue