Skip to content

Commit c770ccd

Browse files
committed
make ->subscr take an instance to pass when instance_subscr is called from subscr.
1 parent fa57de0 commit c770ccd

23 files changed

Lines changed: 35 additions & 36 deletions

extmod/machine_mem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ STATIC void machine_mem_print(const mp_print_t *print, mp_obj_t self_in, mp_prin
6060
mp_printf(print, "<%u-bit memory>", 8 * self->elem_size);
6161
}
6262

63-
STATIC mp_obj_t machine_mem_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
63+
STATIC mp_obj_t machine_mem_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value, mp_obj_t instance) {
6464
// TODO support slice index to read/write multiple values at once
6565
machine_mem_obj_t *self = MP_OBJ_TO_PTR(self_in);
6666
if (value == MP_OBJ_NULL) {

extmod/modbtree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ STATIC mp_obj_t btree_iternext(mp_obj_t self_in) {
246246
}
247247
}
248248

249-
STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
249+
STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value, mp_obj_t instance) {
250250
mp_obj_btree_t *self = MP_OBJ_TO_PTR(self_in);
251251
if (value == MP_OBJ_NULL) {
252252
// delete

extmod/moductypes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ STATIC void uctypes_struct_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
518518
}
519519
}
520520

521-
STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) {
521+
STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value, mp_obj_t instance) {
522522
mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in);
523523

524524
if (value == MP_OBJ_NULL) {

ports/unix/modjni.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ STATIC void get_jclass_name(jobject obj, char *buf) {
241241
check_exception();
242242
}
243243

244-
STATIC mp_obj_t jobject_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
244+
STATIC mp_obj_t jobject_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value, mp_obj_t instance) {
245245
mp_obj_jobject_t *self = self_in;
246246
mp_uint_t idx = mp_obj_get_int(index);
247247
char class_name[64];

py/obj.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -488,15 +488,14 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
488488
}
489489

490490
mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
491+
return mp_obj_subscr_impl(base, index, value, base);
492+
}
493+
494+
mp_obj_t mp_obj_subscr_impl(mp_obj_t base, mp_obj_t index, mp_obj_t value, mp_obj_t instance) {
491495
mp_obj_type_t *type = mp_obj_get_type(base);
492-
mp_obj_t instance = base;
493-
// If we got an MP_OBJ_SENTINEL as the type, then we got called by instance_subscr
494-
if (type == MP_OBJ_SENTINEL) {
495-
instance = ((mp_obj_t *)base)[1];
496-
type = mp_obj_get_type(((mp_obj_t *)base)[2]);
497-
}
496+
498497
if (type->subscr != NULL) {
499-
mp_obj_t ret = type->subscr(instance, index, value);
498+
mp_obj_t ret = type->subscr(base, index, value, instance);
500499
// May have called port specific C code. Make sure it didn't mess up the heap.
501500
assert_heap_ok();
502501
if (ret != MP_OBJ_NULL) {
@@ -551,7 +550,7 @@ STATIC mp_obj_t generic_it_iternext(mp_obj_t self_in) {
551550
mp_obj_type_t *type = mp_obj_get_type(self->obj);
552551
mp_obj_t current_length = type->unary_op(MP_UNARY_OP_LEN, self->obj);
553552
if (self->cur < MP_OBJ_SMALL_INT_VALUE(current_length)) {
554-
mp_obj_t o_out = type->subscr(self->obj, MP_OBJ_NEW_SMALL_INT(self->cur), MP_OBJ_SENTINEL);
553+
mp_obj_t o_out = type->subscr(self->obj, MP_OBJ_NEW_SMALL_INT(self->cur), MP_OBJ_SENTINEL, self->obj);
555554
self->cur += 1;
556555
return o_out;
557556
} else {

py/obj.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ typedef mp_obj_t (*mp_call_fun_t)(mp_obj_t fun, size_t n_args, size_t n_kw, cons
444444
typedef mp_obj_t (*mp_unary_op_fun_t)(mp_unary_op_t op, mp_obj_t);
445445
typedef mp_obj_t (*mp_binary_op_fun_t)(mp_binary_op_t op, mp_obj_t, mp_obj_t);
446446
typedef void (*mp_attr_fun_t)(mp_obj_t self_in, qstr attr, mp_obj_t *dest);
447-
typedef mp_obj_t (*mp_subscr_fun_t)(mp_obj_t self_in, mp_obj_t index, mp_obj_t value);
447+
typedef mp_obj_t (*mp_subscr_fun_t)(mp_obj_t self_in, mp_obj_t index, mp_obj_t value, mp_obj_t instance);
448448
typedef mp_obj_t (*mp_getiter_fun_t)(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf);
449449

450450
// Buffer protocol
@@ -708,6 +708,7 @@ mp_obj_t mp_obj_id(mp_obj_t o_in);
708708
mp_obj_t mp_obj_len(mp_obj_t o_in);
709709
mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); // may return MP_OBJ_NULL
710710
mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t val);
711+
mp_obj_t mp_obj_subscr_impl(mp_obj_t base, mp_obj_t index, mp_obj_t val, mp_obj_t instance);
711712
mp_obj_t mp_generic_unary_op(mp_unary_op_t op, mp_obj_t o_in);
712713

713714
// cell

py/objarray.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ STATIC mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in) {
396396
STATIC MP_DEFINE_CONST_FUN_OBJ_2(array_extend_obj, array_extend);
397397
#endif
398398

399-
STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) {
399+
STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value, mp_obj_t instance) {
400400
if (value == MP_OBJ_NULL) {
401401
// delete item
402402
// TODO implement

py/objdict.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ mp_obj_t mp_obj_dict_get(mp_obj_t self_in, mp_obj_t index) {
174174
}
175175
}
176176

177-
STATIC mp_obj_t dict_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
177+
STATIC mp_obj_t dict_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value, mp_obj_t instance) {
178178
if (value == MP_OBJ_NULL) {
179179
// delete
180180
mp_obj_dict_delete(self_in, index);

py/objlist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ STATIC mp_obj_t list_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) {
158158
}
159159
}
160160

161-
STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
161+
STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value, mp_obj_t instance) {
162162
if (value == MP_OBJ_NULL) {
163163
// delete
164164
#if MICROPY_PY_BUILTINS_SLICE

py/objrange.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ STATIC mp_obj_t range_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs
158158
}
159159
#endif
160160

161-
STATIC mp_obj_t range_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
161+
STATIC mp_obj_t range_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value, mp_obj_t instance) {
162162
if (value == MP_OBJ_SENTINEL) {
163163
// load
164164
mp_obj_range_t *self = MP_OBJ_TO_PTR(self_in);

0 commit comments

Comments
 (0)