py/objboundmeth: Add option to use mp_is_equal instead of == comparison.
This option is needed for ports such as webassembly where objects are proxied and can be identical without being the same C pointer. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -1129,6 +1129,14 @@ typedef time_t mp_timestamp_t;
|
|||||||
#define MICROPY_PY_FUNCTION_ATTRS_CODE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_FULL_FEATURES)
|
#define MICROPY_PY_FUNCTION_ATTRS_CODE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_FULL_FEATURES)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Whether bound_method can just use == (feature disabled), or requires a call to
|
||||||
|
// mp_obj_equal (feature enabled), to test equality of the self and meth entities.
|
||||||
|
// This is only needed if objects and functions can be identical without being the
|
||||||
|
// same thing, eg when using an object proxy.
|
||||||
|
#ifndef MICROPY_PY_BOUND_METHOD_FULL_EQUALITY_CHECK
|
||||||
|
#define MICROPY_PY_BOUND_METHOD_FULL_EQUALITY_CHECK (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
// Whether to support the descriptors __get__, __set__, __delete__, __set_name__
|
// Whether to support the descriptors __get__, __set__, __delete__, __set_name__
|
||||||
// This costs some code size and makes load/store/delete of instance
|
// This costs some code size and makes load/store/delete of instance
|
||||||
// attributes slower for the classes that use this feature
|
// attributes slower for the classes that use this feature
|
||||||
|
|||||||
@@ -102,7 +102,11 @@ static mp_obj_t bound_meth_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_
|
|||||||
}
|
}
|
||||||
mp_obj_bound_meth_t *lhs = MP_OBJ_TO_PTR(lhs_in);
|
mp_obj_bound_meth_t *lhs = MP_OBJ_TO_PTR(lhs_in);
|
||||||
mp_obj_bound_meth_t *rhs = MP_OBJ_TO_PTR(rhs_in);
|
mp_obj_bound_meth_t *rhs = MP_OBJ_TO_PTR(rhs_in);
|
||||||
|
#if MICROPY_PY_BOUND_METHOD_FULL_EQUALITY_CHECK
|
||||||
|
return mp_obj_new_bool(mp_obj_equal(lhs->self, rhs->self) && mp_obj_equal(lhs->meth, rhs->meth));
|
||||||
|
#else
|
||||||
return mp_obj_new_bool(lhs->self == rhs->self && lhs->meth == rhs->meth);
|
return mp_obj_new_bool(lhs->self == rhs->self && lhs->meth == rhs->meth);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MICROPY_PY_FUNCTION_ATTRS
|
#if MICROPY_PY_FUNCTION_ATTRS
|
||||||
|
|||||||
Reference in New Issue
Block a user