diff options
| author | Damien George <damien@micropython.org> | 2025-07-25 00:09:18 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-07-31 11:38:35 +1000 |
| commit | 241ee163c0c8a33267c699af59492641d0770f30 (patch) | |
| tree | db12b3ab753a1a40777a24544a100a9d0f8a121a /py | |
| parent | fdbd23268d69d77a411aa5c2d792eaf5e77d454a (diff) | |
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>
Diffstat (limited to 'py')
| -rw-r--r-- | py/mpconfig.h | 8 | ||||
| -rw-r--r-- | py/objboundmeth.c | 4 |
2 files changed, 12 insertions, 0 deletions
diff --git a/py/mpconfig.h b/py/mpconfig.h index 6ef6ec52e..c316aa4b2 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1129,6 +1129,14 @@ typedef time_t mp_timestamp_t; #define MICROPY_PY_FUNCTION_ATTRS_CODE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_FULL_FEATURES) #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__ // This costs some code size and makes load/store/delete of instance // attributes slower for the classes that use this feature diff --git a/py/objboundmeth.c b/py/objboundmeth.c index e3503ff15..6df67f7bf 100644 --- a/py/objboundmeth.c +++ b/py/objboundmeth.c @@ -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 *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); + #endif } #if MICROPY_PY_FUNCTION_ATTRS |
