Commit 24ff063e authored by Damien George's avatar Damien George
Browse files

py: Remove obsolete declarations; make mp_obj_get_array consistent.

parent 4b2b7cec
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___build_class___obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin___import___obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin___import___obj);
...@@ -6,7 +6,6 @@ MP_DECLARE_CONST_FUN_OBJ(mp_builtin___repl_print___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_abs_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_all_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_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_callable_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_chr_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_chr_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_dir_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_dir_obj);
...@@ -30,7 +29,6 @@ MP_DECLARE_CONST_FUN_OBJ(mp_builtin_range_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_repr_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_sorted_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_sum_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_str_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_namedtuple_obj); MP_DECLARE_CONST_FUN_OBJ(mp_namedtuple_obj);
......
...@@ -128,7 +128,7 @@ void do_load(mp_obj_t module_obj, vstr_t *file) { ...@@ -128,7 +128,7 @@ void do_load(mp_obj_t module_obj, vstr_t *file) {
rt_globals_set(old_globals); 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"); printf("import:\n");
for (int i = 0; i < n_args; i++) { for (int i = 0; i < n_args; i++) {
......
...@@ -206,21 +206,29 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) { ...@@ -206,21 +206,29 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
} }
#endif #endif
mp_obj_t *mp_obj_get_array_fixed_n(mp_obj_t o_in, machine_int_t n) { void mp_obj_get_array(mp_obj_t o, uint *len, mp_obj_t **items) {
if (MP_OBJ_IS_TYPE(o_in, &tuple_type) || MP_OBJ_IS_TYPE(o_in, &list_type)) { 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; uint seq_len;
mp_obj_t *seq_items; if (MP_OBJ_IS_TYPE(o, &tuple_type)) {
if (MP_OBJ_IS_TYPE(o_in, &tuple_type)) { mp_obj_tuple_get(o, &seq_len, items);
mp_obj_tuple_get(o_in, &seq_len, &seq_items);
} else { } else {
mp_obj_list_get(o_in, &seq_len, &seq_items); mp_obj_list_get(o, &seq_len, items);
} }
if (seq_len != n) { if (seq_len != len) {
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_IndexError, "requested length %d but object has length %d", n, seq_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 { } 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)));
} }
} }
......
...@@ -175,7 +175,6 @@ struct _mp_obj_type_t { ...@@ -175,7 +175,6 @@ struct _mp_obj_type_t {
abs float complex abs float complex
hash bool int none str hash bool int none str
equal int str equal int str
get_array_n tuple list
unpack seq list tuple unpack seq list tuple
*/ */
...@@ -311,7 +310,8 @@ mp_float_t mp_obj_get_float(mp_obj_t self_in); ...@@ -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); void mp_obj_get_complex(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
#endif #endif
//qstr mp_obj_get_qstr(mp_obj_t arg); //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); 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 */ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); /* may return NULL */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment