diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2019-05-13 17:31:30 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2019-05-13 17:31:30 -0700 |
| commit | f29de5132562cd6e88661d150fa1ee3ab8b771e1 (patch) | |
| tree | 1f3ac8c4779e4badc825d22fac3c38aceb5bb99e /shared-bindings/displayio/Display.c | |
| parent | a6785d7ff74e156c5bcfdd8f46b1cccae41cc3bf (diff) | |
Check native object in case of early access
If a native displayio object is accessed before it's super().__init__()
has been called, then a placeholder is given that will cause a crash if
accessed. This is tricky to get right so we detect this case and raise
a NotInplementedError instead of crashing.
Fixes #1881
Diffstat (limited to 'shared-bindings/displayio/Display.c')
| -rw-r--r-- | shared-bindings/displayio/Display.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 52ab2ef31..84302a175 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -31,6 +31,7 @@ #include "lib/utils/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" +#include "py/objtype.h" #include "py/runtime.h" #include "shared-bindings/displayio/Group.h" #include "shared-bindings/microcontroller/Pin.h" @@ -172,6 +173,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a // Helper to ensure we have the native super class instead of a subclass. static displayio_display_obj_t* native_display(mp_obj_t display_obj) { mp_obj_t native_display = mp_instance_cast_to_native_base(display_obj, &displayio_display_type); + mp_obj_assert_native_inited(native_display); return MP_OBJ_TO_PTR(native_display); } @@ -184,11 +186,7 @@ STATIC mp_obj_t displayio_display_obj_show(mp_obj_t self_in, mp_obj_t group_in) displayio_display_obj_t *self = native_display(self_in); displayio_group_t* group = NULL; if (group_in != mp_const_none) { - mp_obj_t native_layer = mp_instance_cast_to_native_base(group_in, &displayio_group_type); - if (native_layer == MP_OBJ_NULL) { - mp_raise_ValueError(translate("Must be a Group subclass.")); - } - group = MP_OBJ_TO_PTR(native_layer); + group = MP_OBJ_TO_PTR(native_group(group_in)); } common_hal_displayio_display_show(self, group); |
