Skip to content

Commit 241ee16

Browse files
committed
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 <[email protected]>
1 parent fdbd232 commit 241ee16

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

py/mpconfig.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,14 @@ typedef time_t mp_timestamp_t;
11291129
#define MICROPY_PY_FUNCTION_ATTRS_CODE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_FULL_FEATURES)
11301130
#endif
11311131

1132+
// Whether bound_method can just use == (feature disabled), or requires a call to
1133+
// mp_obj_equal (feature enabled), to test equality of the self and meth entities.
1134+
// This is only needed if objects and functions can be identical without being the
1135+
// same thing, eg when using an object proxy.
1136+
#ifndef MICROPY_PY_BOUND_METHOD_FULL_EQUALITY_CHECK
1137+
#define MICROPY_PY_BOUND_METHOD_FULL_EQUALITY_CHECK (0)
1138+
#endif
1139+
11321140
// Whether to support the descriptors __get__, __set__, __delete__, __set_name__
11331141
// This costs some code size and makes load/store/delete of instance
11341142
// attributes slower for the classes that use this feature

py/objboundmeth.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ static mp_obj_t bound_meth_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_
102102
}
103103
mp_obj_bound_meth_t *lhs = MP_OBJ_TO_PTR(lhs_in);
104104
mp_obj_bound_meth_t *rhs = MP_OBJ_TO_PTR(rhs_in);
105+
#if MICROPY_PY_BOUND_METHOD_FULL_EQUALITY_CHECK
106+
return mp_obj_new_bool(mp_obj_equal(lhs->self, rhs->self) && mp_obj_equal(lhs->meth, rhs->meth));
107+
#else
105108
return mp_obj_new_bool(lhs->self == rhs->self && lhs->meth == rhs->meth);
109+
#endif
106110
}
107111

108112
#if MICROPY_PY_FUNCTION_ATTRS

0 commit comments

Comments
 (0)