summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorRadomir Dopieralski <openstack@sheep.art.pl>2021-02-21 16:25:17 +0100
committerRadomir Dopieralski <openstack@sheep.art.pl>2021-02-27 20:52:38 +0100
commite505c59ed838095ccb2bd996fc77bd4aeada2d80 (patch)
tree9e724f7edfa6413da8ac259757a6ad624b7ffad6 /py
parent121c6bcc9b20d7419f2654680215fd8b4bd455c4 (diff)
Separate mp_obj_list_pop so it can be used outside of objlist.c
Diffstat (limited to 'py')
-rw-r--r--py/objlist.c12
-rw-r--r--py/objlist.h1
2 files changed, 9 insertions, 4 deletions
diff --git a/py/objlist.c b/py/objlist.c
index 51ec920be..309e0e542 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -270,13 +270,10 @@ STATIC mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in) {
return mp_const_none; // return None, as per CPython
}
-STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args) {
- mp_check_self(MP_OBJ_IS_TYPE(args[0], &mp_type_list));
- mp_obj_list_t *self = mp_instance_cast_to_native_base(args[0], &mp_type_list);
+mp_obj_t mp_obj_list_pop(mp_obj_list_t *self, size_t index) {
if (self->len == 0) {
mp_raise_IndexError_varg(translate("pop from empty %q"), MP_QSTR_list);
}
- size_t index = mp_get_index(self->base.type, self->len, n_args == 1 ? MP_OBJ_NEW_SMALL_INT(-1) : args[1], false);
mp_obj_t ret = self->items[index];
self->len -= 1;
memmove(self->items + index, self->items + index + 1, (self->len - index) * sizeof(mp_obj_t));
@@ -289,6 +286,13 @@ STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args) {
return ret;
}
+STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args) {
+ mp_check_self(MP_OBJ_IS_TYPE(args[0], &mp_type_list));
+ mp_obj_list_t *self = mp_instance_cast_to_native_base(args[0], &mp_type_list);
+ size_t index = mp_get_index(self->base.type, self->len, n_args == 1 ? MP_OBJ_NEW_SMALL_INT(-1) : args[1], false);
+ return mp_obj_list_pop(self, index);
+}
+
STATIC void mp_quicksort(mp_obj_t *head, mp_obj_t *tail, mp_obj_t key_fn, mp_obj_t binop_less_result) {
MP_STACK_CHECK();
while (head < tail) {
diff --git a/py/objlist.h b/py/objlist.h
index f02030557..cec23e06c 100644
--- a/py/objlist.h
+++ b/py/objlist.h
@@ -36,5 +36,6 @@ typedef struct _mp_obj_list_t {
} mp_obj_list_t;
void mp_obj_list_init(mp_obj_list_t *o, size_t n);
+mp_obj_t mp_obj_list_pop(mp_obj_list_t *self, size_t index);
#endif // MICROPY_INCLUDED_PY_OBJLIST_H