Skip to content

Commit c12b221

Browse files
committed
Change mp_method_t.name from const char * to qstr.
Addresses issue adafruit#377.
1 parent 69b3ba0 commit c12b221

40 files changed

Lines changed: 375 additions & 216 deletions

py/builtin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ STATIC mp_obj_t mp_builtin_dir(uint n_args, const mp_obj_t *args) {
178178
}
179179
}
180180
if (meth != NULL) {
181-
for (; meth->name != NULL; meth++) {
182-
mp_obj_list_append(dir, MP_OBJ_NEW_QSTR(qstr_from_str(meth->name)));
181+
for (; meth->name != MP_QSTR_NULL; meth++) {
182+
mp_obj_list_append(dir, MP_OBJ_NEW_QSTR(meth->name));
183183
}
184184
}
185185
return dir;

py/obj.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ typedef bool (*mp_store_attr_fun_t)(mp_obj_t self_in, qstr attr, mp_obj_t value)
9696
typedef bool (*mp_store_item_fun_t)(mp_obj_t self_in, mp_obj_t index, mp_obj_t value); // return true if store succeeded
9797

9898
typedef struct _mp_method_t {
99-
const char *name;
99+
qstr name;
100100
mp_const_obj_t fun;
101101
} mp_method_t;
102102

py/objarray.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ STATIC machine_int_t array_get_buffer(mp_obj_t o_in, buffer_info_t *bufinfo, int
150150
}
151151

152152
STATIC const mp_method_t array_type_methods[] = {
153-
{ "append", &array_append_obj },
154-
{ NULL, NULL },
153+
{ MP_QSTR_append, &array_append_obj },
154+
{ MP_QSTR_NULL, NULL }, // end-of-list sentinel
155155
};
156156

157157
const mp_obj_type_t mp_type_array = {

py/objdict.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -424,18 +424,18 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_values_obj, dict_values);
424424
/* dict constructors & public C API */
425425

426426
STATIC const mp_method_t dict_type_methods[] = {
427-
{ "clear", &dict_clear_obj },
428-
{ "copy", &dict_copy_obj },
429-
{ "fromkeys", &dict_fromkeys_obj },
430-
{ "get", &dict_get_obj },
431-
{ "items", &dict_items_obj },
432-
{ "keys", &dict_keys_obj },
433-
{ "pop", &dict_pop_obj },
434-
{ "popitem", &dict_popitem_obj },
435-
{ "setdefault", &dict_setdefault_obj },
436-
{ "update", &dict_update_obj },
437-
{ "values", &dict_values_obj },
438-
{ NULL, NULL }, // end-of-list sentinel
427+
{ MP_QSTR_clear, &dict_clear_obj },
428+
{ MP_QSTR_copy, &dict_copy_obj },
429+
{ MP_QSTR_fromkeys, &dict_fromkeys_obj },
430+
{ MP_QSTR_get, &dict_get_obj },
431+
{ MP_QSTR_items, &dict_items_obj },
432+
{ MP_QSTR_keys, &dict_keys_obj },
433+
{ MP_QSTR_pop, &dict_pop_obj },
434+
{ MP_QSTR_popitem, &dict_popitem_obj },
435+
{ MP_QSTR_setdefault, &dict_setdefault_obj },
436+
{ MP_QSTR_update, &dict_update_obj },
437+
{ MP_QSTR_values, &dict_values_obj },
438+
{ MP_QSTR_NULL, NULL }, // end-of-list sentinel
439439
};
440440

441441
const mp_obj_type_t dict_type = {

py/objgenerator.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ STATIC mp_obj_t gen_instance_close(mp_obj_t self_in) {
193193
STATIC MP_DEFINE_CONST_FUN_OBJ_1(gen_instance_close_obj, gen_instance_close);
194194

195195
STATIC const mp_method_t gen_type_methods[] = {
196-
{ "close", &gen_instance_close_obj },
197-
{ "send", &gen_instance_send_obj },
198-
{ "throw", &gen_instance_throw_obj },
199-
{ NULL, NULL }, // end-of-list sentinel
196+
{ MP_QSTR_close, &gen_instance_close_obj },
197+
{ MP_QSTR_send, &gen_instance_send_obj },
198+
{ MP_QSTR_throw, &gen_instance_throw_obj },
199+
{ MP_QSTR_NULL, NULL }, // end-of-list sentinel
200200
};
201201

202202
const mp_obj_type_t gen_instance_type = {

py/objlist.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -329,18 +329,18 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(list_reverse_obj, list_reverse);
329329
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(list_sort_obj, 0, mp_obj_list_sort);
330330

331331
STATIC const mp_method_t list_type_methods[] = {
332-
{ "append", &list_append_obj },
333-
{ "clear", &list_clear_obj },
334-
{ "copy", &list_copy_obj },
335-
{ "count", &list_count_obj },
336-
{ "extend", &list_extend_obj },
337-
{ "index", &list_index_obj },
338-
{ "insert", &list_insert_obj },
339-
{ "pop", &list_pop_obj },
340-
{ "remove", &list_remove_obj },
341-
{ "reverse", &list_reverse_obj },
342-
{ "sort", &list_sort_obj },
343-
{ NULL, NULL }, // end-of-list sentinel
332+
{ MP_QSTR_append, &list_append_obj },
333+
{ MP_QSTR_clear, &list_clear_obj },
334+
{ MP_QSTR_copy, &list_copy_obj },
335+
{ MP_QSTR_count, &list_count_obj },
336+
{ MP_QSTR_extend, &list_extend_obj },
337+
{ MP_QSTR_index, &list_index_obj },
338+
{ MP_QSTR_insert, &list_insert_obj },
339+
{ MP_QSTR_pop, &list_pop_obj },
340+
{ MP_QSTR_remove, &list_remove_obj },
341+
{ MP_QSTR_reverse, &list_reverse_obj },
342+
{ MP_QSTR_sort, &list_sort_obj },
343+
{ MP_QSTR_NULL, NULL }, // end-of-list sentinel
344344
};
345345

346346
const mp_obj_type_t list_type = {

py/objset.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -424,24 +424,24 @@ STATIC mp_obj_t set_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
424424

425425

426426
STATIC const mp_method_t set_type_methods[] = {
427-
{ "add", &set_add_obj },
428-
{ "clear", &set_clear_obj },
429-
{ "copy", &set_copy_obj },
430-
{ "discard", &set_discard_obj },
431-
{ "difference", &set_diff_obj },
432-
{ "difference_update", &set_diff_update_obj },
433-
{ "intersection", &set_intersect_obj },
434-
{ "intersection_update", &set_intersect_update_obj },
435-
{ "isdisjoint", &set_isdisjoint_obj },
436-
{ "issubset", &set_issubset_obj },
437-
{ "issuperset", &set_issuperset_obj },
438-
{ "pop", &set_pop_obj },
439-
{ "remove", &set_remove_obj },
440-
{ "symmetric_difference", &set_symmetric_difference_obj },
441-
{ "symmetric_difference_update", &set_symmetric_difference_update_obj },
442-
{ "union", &set_union_obj },
443-
{ "update", &set_update_obj },
444-
{ NULL, NULL }, // end-of-list sentinel
427+
{ MP_QSTR_add, &set_add_obj },
428+
{ MP_QSTR_clear, &set_clear_obj },
429+
{ MP_QSTR_copy, &set_copy_obj },
430+
{ MP_QSTR_discard, &set_discard_obj },
431+
{ MP_QSTR_difference, &set_diff_obj },
432+
{ MP_QSTR_difference_update, &set_diff_update_obj },
433+
{ MP_QSTR_intersection, &set_intersect_obj },
434+
{ MP_QSTR_intersection_update, &set_intersect_update_obj },
435+
{ MP_QSTR_isdisjoint, &set_isdisjoint_obj },
436+
{ MP_QSTR_issubset, &set_issubset_obj },
437+
{ MP_QSTR_issuperset, &set_issuperset_obj },
438+
{ MP_QSTR_pop, &set_pop_obj },
439+
{ MP_QSTR_remove, &set_remove_obj },
440+
{ MP_QSTR_symmetric_difference, &set_symmetric_difference_obj },
441+
{ MP_QSTR_symmetric_difference_update, &set_symmetric_difference_update_obj },
442+
{ MP_QSTR_union, &set_union_obj },
443+
{ MP_QSTR_update, &set_update_obj },
444+
{ MP_QSTR_NULL, NULL }, // end-of-list sentinel
445445
};
446446

447447
const mp_obj_type_t set_type = {

py/objstr.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -694,18 +694,18 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(str_partition_obj, str_partition);
694694
STATIC MP_DEFINE_CONST_FUN_OBJ_2(str_rpartition_obj, str_rpartition);
695695

696696
STATIC const mp_method_t str_type_methods[] = {
697-
{ "find", &str_find_obj },
698-
{ "rfind", &str_rfind_obj },
699-
{ "join", &str_join_obj },
700-
{ "split", &str_split_obj },
701-
{ "startswith", &str_startswith_obj },
702-
{ "strip", &str_strip_obj },
703-
{ "format", &str_format_obj },
704-
{ "replace", &str_replace_obj },
705-
{ "count", &str_count_obj },
706-
{ "partition", &str_partition_obj },
707-
{ "rpartition", &str_rpartition_obj },
708-
{ NULL, NULL }, // end-of-list sentinel
697+
{ MP_QSTR_find, &str_find_obj },
698+
{ MP_QSTR_rfind, &str_rfind_obj },
699+
{ MP_QSTR_join, &str_join_obj },
700+
{ MP_QSTR_split, &str_split_obj },
701+
{ MP_QSTR_startswith, &str_startswith_obj },
702+
{ MP_QSTR_strip, &str_strip_obj },
703+
{ MP_QSTR_format, &str_format_obj },
704+
{ MP_QSTR_replace, &str_replace_obj },
705+
{ MP_QSTR_count, &str_count_obj },
706+
{ MP_QSTR_partition, &str_partition_obj },
707+
{ MP_QSTR_rpartition, &str_rpartition_obj },
708+
{ MP_QSTR_NULL, NULL }, // end-of-list sentinel
709709
};
710710

711711
const mp_obj_type_t str_type = {

py/objtuple.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ STATIC mp_obj_t tuple_index(uint n_args, const mp_obj_t *args) {
166166
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tuple_index_obj, 2, 4, tuple_index);
167167

168168
STATIC const mp_method_t tuple_type_methods[] = {
169-
{ "count", &tuple_count_obj },
170-
{ "index", &tuple_index_obj },
171-
{ NULL, NULL }, // end-of-list sentinel
169+
{ MP_QSTR_count, &tuple_count_obj },
170+
{ MP_QSTR_index, &tuple_index_obj },
171+
{ MP_QSTR_NULL, NULL }, // end-of-list sentinel
172172
};
173173

174174
const mp_obj_type_t tuple_type = {

py/objtype.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ STATIC mp_obj_t mp_obj_class_lookup(const mp_obj_type_t *type, qstr attr) {
4141
} else if (type->methods != NULL) {
4242
// search methods (the const set of methods)
4343

44-
for (const mp_method_t *meth = type->methods; meth->name != NULL; meth++) {
45-
if (strcmp(meth->name, qstr_str(attr)) == 0) {
44+
for (const mp_method_t *meth = type->methods; meth->name != MP_QSTR_NULL; meth++) {
45+
if (meth->name == attr) {
4646
return (mp_obj_t)meth->fun;
4747
}
4848
}

0 commit comments

Comments
 (0)