Skip to content

Commit 24ff063

Browse files
committed
py: Remove obsolete declarations; make mp_obj_get_array consistent.
1 parent 4b2b7ce commit 24ff063

4 files changed

Lines changed: 22 additions & 16 deletions

File tree

py/builtin.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
mp_obj_t mp_builtin___import__(int n_args, mp_obj_t *args);
1+
mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args);
22

33
MP_DECLARE_CONST_FUN_OBJ(mp_builtin___build_class___obj);
44
MP_DECLARE_CONST_FUN_OBJ(mp_builtin___import___obj);
55
MP_DECLARE_CONST_FUN_OBJ(mp_builtin___repl_print___obj);
66
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_abs_obj);
77
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_all_obj);
88
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_any_obj);
9-
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_bytes_obj); // Temporary hack
109
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_callable_obj);
1110
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_chr_obj);
1211
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_dir_obj);
@@ -30,7 +29,6 @@ MP_DECLARE_CONST_FUN_OBJ(mp_builtin_range_obj);
3029
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_repr_obj);
3130
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_sorted_obj);
3231
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_sum_obj);
33-
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_str_obj);
3432

3533
MP_DECLARE_CONST_FUN_OBJ(mp_namedtuple_obj);
3634

py/builtinimport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void do_load(mp_obj_t module_obj, vstr_t *file) {
128128
rt_globals_set(old_globals);
129129
}
130130

131-
mp_obj_t mp_builtin___import__(int n_args, mp_obj_t *args) {
131+
mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args) {
132132
/*
133133
printf("import:\n");
134134
for (int i = 0; i < n_args; i++) {

py/obj.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,21 +206,29 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
206206
}
207207
#endif
208208

209-
mp_obj_t *mp_obj_get_array_fixed_n(mp_obj_t o_in, machine_int_t n) {
210-
if (MP_OBJ_IS_TYPE(o_in, &tuple_type) || MP_OBJ_IS_TYPE(o_in, &list_type)) {
209+
void mp_obj_get_array(mp_obj_t o, uint *len, mp_obj_t **items) {
210+
if (MP_OBJ_IS_TYPE(o, &tuple_type)) {
211+
mp_obj_tuple_get(o, len, items);
212+
} else if (MP_OBJ_IS_TYPE(o, &list_type)) {
213+
mp_obj_list_get(o, len, items);
214+
} else {
215+
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)));
216+
}
217+
}
218+
219+
void mp_obj_get_array_fixed_n(mp_obj_t o, uint len, mp_obj_t **items) {
220+
if (MP_OBJ_IS_TYPE(o, &tuple_type) || MP_OBJ_IS_TYPE(o, &list_type)) {
211221
uint seq_len;
212-
mp_obj_t *seq_items;
213-
if (MP_OBJ_IS_TYPE(o_in, &tuple_type)) {
214-
mp_obj_tuple_get(o_in, &seq_len, &seq_items);
222+
if (MP_OBJ_IS_TYPE(o, &tuple_type)) {
223+
mp_obj_tuple_get(o, &seq_len, items);
215224
} else {
216-
mp_obj_list_get(o_in, &seq_len, &seq_items);
225+
mp_obj_list_get(o, &seq_len, items);
217226
}
218-
if (seq_len != n) {
219-
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_IndexError, "requested length %d but object has length %d", n, seq_len));
227+
if (seq_len != len) {
228+
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_IndexError, "requested length %d but object has length %d", len, seq_len));
220229
}
221-
return seq_items;
222230
} else {
223-
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)));
231+
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)));
224232
}
225233
}
226234

py/obj.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ struct _mp_obj_type_t {
175175
abs float complex
176176
hash bool int none str
177177
equal int str
178-
get_array_n tuple list
179178
180179
unpack seq list tuple
181180
*/
@@ -311,7 +310,8 @@ mp_float_t mp_obj_get_float(mp_obj_t self_in);
311310
void mp_obj_get_complex(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
312311
#endif
313312
//qstr mp_obj_get_qstr(mp_obj_t arg);
314-
mp_obj_t *mp_obj_get_array_fixed_n(mp_obj_t o, machine_int_t n);
313+
void mp_obj_get_array(mp_obj_t o, uint *len, mp_obj_t **items);
314+
void mp_obj_get_array_fixed_n(mp_obj_t o, uint len, mp_obj_t **items);
315315
uint mp_get_index(const mp_obj_type_t *type, machine_uint_t len, mp_obj_t index, bool is_slice);
316316
mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); /* may return NULL */
317317

0 commit comments

Comments
 (0)