extmod/machine_signal: Fix fault when no args are passed to Signal().

This commit is contained in:
Damien George 2019-04-26 14:47:31 +10:00
parent f66c4cbfa6
commit 775ffdcc3b

View File

@ -43,13 +43,13 @@ typedef struct _machine_signal_t {
} machine_signal_t;
STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_obj_t pin = args[0];
mp_obj_t pin;
bool invert = false;
#if defined(MICROPY_PY_MACHINE_PIN_MAKE_NEW)
mp_pin_p_t *pin_p = NULL;
if (mp_obj_is_obj(pin)) {
if (n_args > 0 && mp_obj_is_obj(args[0])) {
mp_obj_base_t *pin_base = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
pin_p = (mp_pin_p_t*)pin_base->type->protocol;
}
@ -96,6 +96,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t
// Otherwise there should be 1 or 2 args
{
if (n_args == 1) {
pin = args[0];
if (n_kw == 0) {
} else if (n_kw == 1 && args[1] == MP_OBJ_NEW_QSTR(MP_QSTR_invert)) {
invert = mp_obj_is_true(args[2]);