From dff3f896d7f7ef20762f0be7c8d5aa457c04b71a Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 20 Jan 2014 18:37:30 +0200 Subject: [PATCH] mp_identity(): Add generic identity function. Useful as getiter method for objects which are their own iterators, etc. --- py/obj.c | 6 ++++++ py/obj.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/py/obj.c b/py/obj.c index dd081ee35e..7dd9cc0a24 100644 --- a/py/obj.c +++ b/py/obj.c @@ -288,3 +288,9 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) { } return MP_OBJ_NEW_SMALL_INT(len); } + +// Return input argument. Useful as .getiter for objects which are +// their own iterators, etc. +mp_obj_t mp_identity(mp_obj_t self) { + return self; +} diff --git a/py/obj.h b/py/obj.h index faf0231474..d7154a743c 100644 --- a/py/obj.h +++ b/py/obj.h @@ -351,6 +351,8 @@ extern const mp_obj_type_t fun_native_type; extern const mp_obj_type_t fun_bc_type; void mp_obj_fun_bc_get(mp_obj_t self_in, int *n_args, uint *n_state, const byte **code); +mp_obj_t mp_identity(mp_obj_t self); + // generator extern const mp_obj_type_t gen_instance_type;