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/Group.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/Group.c')
| -rw-r--r-- | shared-bindings/displayio/Group.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/shared-bindings/displayio/Group.c b/shared-bindings/displayio/Group.c index c7a72891a..bbf7190a3 100644 --- a/shared-bindings/displayio/Group.c +++ b/shared-bindings/displayio/Group.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 "supervisor/shared/translate.h" @@ -80,8 +81,12 @@ STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_arg } // Helper to ensure we have the native super class instead of a subclass. -static displayio_group_t* native_group(mp_obj_t group_obj) { +displayio_group_t* native_group(mp_obj_t group_obj) { mp_obj_t native_group = mp_instance_cast_to_native_base(group_obj, &displayio_group_type); + if (native_group == MP_OBJ_NULL) { + mp_raise_ValueError_varg(translate("Must be a %q subclass."), MP_QSTR_Group); + } + mp_obj_assert_native_inited(native_group); return MP_OBJ_TO_PTR(native_group); } |
