From 860ffb0a4365bba62cbd692392375df9fd4a72e7 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 5 Jan 2014 22:34:09 +0200 Subject: Convert many object types structs to use C99 tagged initializer syntax. --- py/objlist.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'py/objlist.c') diff --git a/py/objlist.c b/py/objlist.c index 6c0de405fe..a656a4aeb6 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -208,14 +208,12 @@ static MP_DEFINE_CONST_FUN_OBJ_2(list_sort_obj, list_sort); const mp_obj_type_t list_type = { { &mp_const_type }, "list", - list_print, // print - list_make_new, // make_new - NULL, // call_n - NULL, // unary_op - list_binary_op, // binary_op - list_getiter, // getiter - NULL, // iternext - { // method list + .print = list_print, + .make_new = list_make_new, + .unary_op = NULL, + .binary_op = list_binary_op, + .getiter = list_getiter, + .methods = { { "append", &list_append_obj }, { "clear", &list_clear_obj }, { "copy", &list_copy_obj }, @@ -287,14 +285,8 @@ mp_obj_t list_it_iternext(mp_obj_t self_in) { static const mp_obj_type_t list_it_type = { { &mp_const_type }, "list_iterator", - NULL, // print - NULL, // make_new - NULL, // call_n - NULL, // unary_op - NULL, // binary_op - NULL, // getiter - list_it_iternext, // iternext - { { NULL, NULL }, }, // method list + .iternext = list_it_iternext, + .methods = { { NULL, NULL }, }, }; mp_obj_t mp_obj_new_list_iterator(mp_obj_list_t *list, int cur) { -- cgit v1.2.3 From c553162ebcc01765fd1556731ec98067f3981cd5 Mon Sep 17 00:00:00 2001 From: "John R. Lenton" Date: Sun, 5 Jan 2014 21:57:27 +0000 Subject: Fix off-by-one in non-default values of index's 2nd and 3rd arguments. --- py/objlist.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'py/objlist.c') diff --git a/py/objlist.c b/py/objlist.c index 6c0de405fe..b52f767eec 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -182,13 +182,17 @@ static mp_obj_t list_index(int n_args, const mp_obj_t *args) { assert(MP_OBJ_IS_TYPE(args[0], &list_type)); mp_obj_list_t *self = args[0]; mp_obj_t *value = args[1]; + uint start = 0; + uint stop = self->len; - uint start = mp_get_index(self->base.type, self->len, - n_args >= 3 ? args[2] : mp_obj_new_int(0)); - uint stop = mp_get_index(self->base.type, self->len, - n_args >= 4 ? args[3] : mp_obj_new_int(-1)); + if (n_args >= 3) { + start = mp_get_index(self->base.type, self->len, args[2]); + if (n_args >= 4) { + stop = mp_get_index(self->base.type, self->len, args[3]); + } + } - for (uint i = start; i <= stop; i++) { + for (uint i = start; i < stop; i++) { if (mp_obj_equal(self->items[i], value)) { return mp_obj_new_int(i); } -- cgit v1.2.3