summaryrefslogtreecommitdiff
path: root/py/objtype.c
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2019-04-05 13:03:03 -0700
committerScott Shawcroft <scott@tannewt.org>2019-04-09 18:32:52 -0700
commit5028f87b0988775d37c59ac2f65035468936bb0c (patch)
treec372020ed51f8c5079d4a89d4d87781bff97a999 /py/objtype.c
parent9026f13a25d60a2d39f4233f9213f3d49eb5855a (diff)
Tweak pybadge and fix display bugs
* Update pybadge pins and flash for rev D * TileGrid now validates the type of the pixel_shader. * Display actually handles incoming subclass objects. * MicroPython will inspect native parents to see if special accessors are used.
Diffstat (limited to 'py/objtype.c')
-rw-r--r--py/objtype.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/py/objtype.c b/py/objtype.c
index f205c224e..4dec478e9 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -964,6 +964,18 @@ STATIC bool check_for_special_accessors(mp_obj_t key, mp_obj_t value) {
#endif
return false;
}
+
+STATIC bool map_has_special_accessors(const mp_map_t *map) {
+ for (size_t i = 0; i < map->alloc; i++) {
+ if (MP_MAP_SLOT_IS_FILLED(map, i)) {
+ const mp_map_elem_t *elem = &map->table[i];
+ if (check_for_special_accessors(elem->key, elem->value)) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
#endif
STATIC void type_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
@@ -1158,20 +1170,6 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
o->locals_dict = make_dict_long_lived(locals_dict, 10);
- #if ENABLE_SPECIAL_ACCESSORS
- // Check if the class has any special accessor methods
- if (!(o->flags & TYPE_FLAG_HAS_SPECIAL_ACCESSORS)) {
- for (size_t i = 0; i < o->locals_dict->map.alloc; i++) {
- if (MP_MAP_SLOT_IS_FILLED(&o->locals_dict->map, i)) {
- const mp_map_elem_t *elem = &o->locals_dict->map.table[i];
- if (check_for_special_accessors(elem->key, elem->value)) {
- o->flags |= TYPE_FLAG_HAS_SPECIAL_ACCESSORS;
- break;
- }
- }
- }
- }
- #endif
const mp_obj_type_t *native_base;
size_t num_native_bases = instance_count_native_bases(o, &native_base);
@@ -1180,6 +1178,16 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
}
mp_map_t *locals_map = &o->locals_dict->map;
+ #if ENABLE_SPECIAL_ACCESSORS
+ // Check if the class has any special accessor methods
+ if (!(o->flags & TYPE_FLAG_HAS_SPECIAL_ACCESSORS) &&
+ (map_has_special_accessors(locals_map) ||
+ (num_native_bases == 1 &&
+ map_has_special_accessors(&native_base->locals_dict->map)))) {
+ o->flags |= TYPE_FLAG_HAS_SPECIAL_ACCESSORS;
+ }
+ #endif
+
mp_map_elem_t *elem = mp_map_lookup(locals_map, MP_OBJ_NEW_QSTR(MP_QSTR___new__), MP_MAP_LOOKUP);
if (elem != NULL) {
// __new__ slot exists; check if it is a function