From 24ff063e8056703f9e01d0d37a58e8e707f7d46d Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 24 Mar 2014 10:47:13 +0000 Subject: [PATCH] py: Remove obsolete declarations; make mp_obj_get_array consistent. --- py/builtin.h | 4 +--- py/builtinimport.c | 2 +- py/obj.c | 28 ++++++++++++++++++---------- py/obj.h | 4 ++-- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/py/builtin.h b/py/builtin.h index d9414045de..69b94e0181 100644 --- a/py/builtin.h +++ b/py/builtin.h @@ -1,4 +1,4 @@ -mp_obj_t mp_builtin___import__(int n_args, mp_obj_t *args); +mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args); MP_DECLARE_CONST_FUN_OBJ(mp_builtin___build_class___obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin___import___obj); @@ -6,7 +6,6 @@ MP_DECLARE_CONST_FUN_OBJ(mp_builtin___repl_print___obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_abs_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_all_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_any_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_bytes_obj); // Temporary hack MP_DECLARE_CONST_FUN_OBJ(mp_builtin_callable_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_chr_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_dir_obj); @@ -30,7 +29,6 @@ MP_DECLARE_CONST_FUN_OBJ(mp_builtin_range_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_repr_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_sorted_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_sum_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_str_obj); MP_DECLARE_CONST_FUN_OBJ(mp_namedtuple_obj); diff --git a/py/builtinimport.c b/py/builtinimport.c index 2b9b3a30b9..d4d56b5171 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -128,7 +128,7 @@ void do_load(mp_obj_t module_obj, vstr_t *file) { rt_globals_set(old_globals); } -mp_obj_t mp_builtin___import__(int n_args, mp_obj_t *args) { +mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args) { /* printf("import:\n"); for (int i = 0; i < n_args; i++) { diff --git a/py/obj.c b/py/obj.c index 717df51641..18f66a2b47 100644 --- a/py/obj.c +++ b/py/obj.c @@ -206,21 +206,29 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) { } #endif -mp_obj_t *mp_obj_get_array_fixed_n(mp_obj_t o_in, machine_int_t n) { - if (MP_OBJ_IS_TYPE(o_in, &tuple_type) || MP_OBJ_IS_TYPE(o_in, &list_type)) { +void mp_obj_get_array(mp_obj_t o, uint *len, mp_obj_t **items) { + if (MP_OBJ_IS_TYPE(o, &tuple_type)) { + mp_obj_tuple_get(o, len, items); + } else if (MP_OBJ_IS_TYPE(o, &list_type)) { + mp_obj_list_get(o, len, items); + } else { + nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "object '%s' is not a tuple or list", mp_obj_get_type_str(o))); + } +} + +void mp_obj_get_array_fixed_n(mp_obj_t o, uint len, mp_obj_t **items) { + if (MP_OBJ_IS_TYPE(o, &tuple_type) || MP_OBJ_IS_TYPE(o, &list_type)) { uint seq_len; - mp_obj_t *seq_items; - if (MP_OBJ_IS_TYPE(o_in, &tuple_type)) { - mp_obj_tuple_get(o_in, &seq_len, &seq_items); + if (MP_OBJ_IS_TYPE(o, &tuple_type)) { + mp_obj_tuple_get(o, &seq_len, items); } else { - mp_obj_list_get(o_in, &seq_len, &seq_items); + mp_obj_list_get(o, &seq_len, items); } - if (seq_len != n) { - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_IndexError, "requested length %d but object has length %d", n, seq_len)); + if (seq_len != len) { + nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_IndexError, "requested length %d but object has length %d", len, seq_len)); } - return seq_items; } else { - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "object '%s' is not a tuple or list", mp_obj_get_type_str(o_in))); + nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "object '%s' is not a tuple or list", mp_obj_get_type_str(o))); } } diff --git a/py/obj.h b/py/obj.h index f80bd43523..49e92795c6 100644 --- a/py/obj.h +++ b/py/obj.h @@ -175,7 +175,6 @@ struct _mp_obj_type_t { abs float complex hash bool int none str equal int str - get_array_n tuple list unpack seq list tuple */ @@ -311,7 +310,8 @@ mp_float_t mp_obj_get_float(mp_obj_t self_in); void mp_obj_get_complex(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag); #endif //qstr mp_obj_get_qstr(mp_obj_t arg); -mp_obj_t *mp_obj_get_array_fixed_n(mp_obj_t o, machine_int_t n); +void mp_obj_get_array(mp_obj_t o, uint *len, mp_obj_t **items); +void mp_obj_get_array_fixed_n(mp_obj_t o, uint len, mp_obj_t **items); uint mp_get_index(const mp_obj_type_t *type, machine_uint_t len, mp_obj_t index, bool is_slice); mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); /* may return NULL */