diff options
author | Damien George <damien.p.george@gmail.com> | 2017-11-24 13:04:24 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-11-24 14:48:23 +1100 |
commit | 5e34a113eaaf736fb4f703a3ee0892e1705d0a63 (patch) | |
tree | 835e0a77f839a4bcffb689c901d989957dced749 /extmod/modbtree.c | |
parent | 5b2f62aff312949c9c7edec6cfaaf4f97d93c442 (diff) |
py/runtime: Add MP_BINARY_OP_CONTAINS as reverse of MP_BINARY_OP_IN.
Before this patch MP_BINARY_OP_IN had two meanings: coming from bytecode it
meant that the args needed to be swapped, but coming from within the
runtime meant that the args were already in the correct order. This lead
to some confusion in the code and comments stating how args were reversed.
It also lead to 2 bugs: 1) containment for a subclass of a native type
didn't work; 2) the expression "{True} in True" would illegally succeed and
return True. In both of these cases it was because the args to
MP_BINARY_OP_IN ended up being reversed twice.
To fix these things this patch introduces MP_BINARY_OP_CONTAINS which
corresponds exactly to the __contains__ special method, and this is the
operator that built-in types should implement. MP_BINARY_OP_IN is now only
emitted by the compiler and is converted to MP_BINARY_OP_CONTAINS by
swapping the arguments.
Diffstat (limited to 'extmod/modbtree.c')
-rw-r--r-- | extmod/modbtree.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/extmod/modbtree.c b/extmod/modbtree.c index 5c1311532..8b7688580 100644 --- a/extmod/modbtree.c +++ b/extmod/modbtree.c @@ -282,7 +282,7 @@ STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { STATIC mp_obj_t btree_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { mp_obj_btree_t *self = MP_OBJ_TO_PTR(lhs_in); switch (op) { - case MP_BINARY_OP_IN: { + case MP_BINARY_OP_CONTAINS: { DBT key, val; key.data = (void*)mp_obj_str_get_data(rhs_in, &key.size); int res = __bt_get(self->db, &key, &val, 0); |