Use validation functions

This commit is contained in:
Jeff Epler 2022-06-23 11:45:02 -05:00
parent 18cb25e95c
commit 8227903b61
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE
3 changed files with 5 additions and 13 deletions

View File

@ -188,10 +188,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiobusio_pdmin___exit___obj, 4, 4,
STATIC mp_obj_t audiobusio_pdmin_obj_record(mp_obj_t self_obj, mp_obj_t destination, mp_obj_t destination_length) {
audiobusio_pdmin_obj_t *self = MP_OBJ_TO_PTR(self_obj);
check_for_deinit(self);
if (!mp_obj_is_small_int(destination_length) || MP_OBJ_SMALL_INT_VALUE(destination_length) < 0) {
mp_raise_TypeError(translate("destination_length must be an int >= 0"));
}
uint32_t length = MP_OBJ_SMALL_INT_VALUE(destination_length);
uint32_t length = mp_arg_validate_type_int(destination_length, MP_QSTR_length);
mp_arg_validate_length_min(length, 0, MP_QSTR_length);
mp_buffer_info_t bufinfo;
if (mp_obj_is_type(destination, &mp_type_fileio)) {

View File

@ -34,9 +34,7 @@ static mp_obj_t vectorio_circle_make_new(const mp_obj_type_t *type, size_t n_arg
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
mp_int_t radius = args[ARG_radius].u_int;
if (radius < 1) {
mp_raise_ValueError_varg(translate("%q must be >= 1"), MP_QSTR_radius);
}
mp_arg_validate_int_min(radius, 1, MP_QSTR_radius);
vectorio_circle_t *self = m_new_obj(vectorio_circle_t);
self->base.type = &vectorio_circle_type;

View File

@ -34,13 +34,9 @@ static mp_obj_t vectorio_rectangle_make_new(const mp_obj_type_t *type, size_t n_
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
mp_int_t width = args[ARG_width].u_int;
if (width < 1) {
mp_raise_ValueError_varg(translate("%q must be >= 1"), MP_QSTR_width);
}
mp_arg_validate_int_min(width, 1, MP_QSTR_width);
mp_int_t height = args[ARG_height].u_int;
if (height < 1) {
mp_raise_ValueError_varg(translate("%q must be >= 1"), MP_QSTR_height);
}
mp_arg_validate_int_min(height, 1, MP_QSTR_height);
vectorio_rectangle_t *self = m_new_obj(vectorio_rectangle_t);
self->base.type = &vectorio_rectangle_type;