More size_t usage
This commit is contained in:
parent
d956b3b359
commit
966a48b23a
|
@ -26,10 +26,10 @@
|
||||||
|
|
||||||
#include "lib/utils/buffer_helper.h"
|
#include "lib/utils/buffer_helper.h"
|
||||||
|
|
||||||
void normalize_buffer_bounds(int32_t* start, int32_t end, uint32_t* length) {
|
void normalize_buffer_bounds(int32_t* start, int32_t end, size_t* length) {
|
||||||
if (end < 0) {
|
if (end < 0) {
|
||||||
end += *length;
|
end += *length;
|
||||||
} else if (((uint32_t) end) > *length) {
|
} else if (((size_t) end) > *length) {
|
||||||
end = *length;
|
end = *length;
|
||||||
}
|
}
|
||||||
if (*start < 0) {
|
if (*start < 0) {
|
||||||
|
|
|
@ -28,7 +28,8 @@
|
||||||
#define MICROPY_INCLUDED_LIB_UTILS_BUFFER_HELPER_H
|
#define MICROPY_INCLUDED_LIB_UTILS_BUFFER_HELPER_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
void normalize_buffer_bounds(int32_t* start, int32_t end, uint32_t* length);
|
void normalize_buffer_bounds(int32_t* start, int32_t end, size_t* length);
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_LIB_UTILS_BUFFER_HELPER_H
|
#endif // MICROPY_INCLUDED_LIB_UTILS_BUFFER_HELPER_H
|
||||||
|
|
|
@ -275,13 +275,13 @@ STATIC mp_obj_t bitbangio_spi_write_readinto(size_t n_args, const mp_obj_t *pos_
|
||||||
mp_buffer_info_t buf_out_info;
|
mp_buffer_info_t buf_out_info;
|
||||||
mp_get_buffer_raise(args[ARG_buffer_out].u_obj, &buf_out_info, MP_BUFFER_READ);
|
mp_get_buffer_raise(args[ARG_buffer_out].u_obj, &buf_out_info, MP_BUFFER_READ);
|
||||||
int32_t out_start = args[ARG_out_start].u_int;
|
int32_t out_start = args[ARG_out_start].u_int;
|
||||||
uint32_t out_length = buf_out_info.len;
|
size_t out_length = buf_out_info.len;
|
||||||
normalize_buffer_bounds(&out_start, args[ARG_out_end].u_int, &out_length);
|
normalize_buffer_bounds(&out_start, args[ARG_out_end].u_int, &out_length);
|
||||||
|
|
||||||
mp_buffer_info_t buf_in_info;
|
mp_buffer_info_t buf_in_info;
|
||||||
mp_get_buffer_raise(args[ARG_buffer_in].u_obj, &buf_in_info, MP_BUFFER_WRITE);
|
mp_get_buffer_raise(args[ARG_buffer_in].u_obj, &buf_in_info, MP_BUFFER_WRITE);
|
||||||
int32_t in_start = args[ARG_in_start].u_int;
|
int32_t in_start = args[ARG_in_start].u_int;
|
||||||
uint32_t in_length = buf_in_info.len;
|
size_t in_length = buf_in_info.len;
|
||||||
normalize_buffer_bounds(&in_start, args[ARG_in_end].u_int, &in_length);
|
normalize_buffer_bounds(&in_start, args[ARG_in_end].u_int, &in_length);
|
||||||
|
|
||||||
if (out_length != in_length) {
|
if (out_length != in_length) {
|
||||||
|
|
|
@ -244,7 +244,7 @@ STATIC mp_obj_t busio_spi_write(size_t n_args, const mp_obj_t *pos_args, mp_map_
|
||||||
mp_buffer_info_t bufinfo;
|
mp_buffer_info_t bufinfo;
|
||||||
mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_READ);
|
mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_READ);
|
||||||
int32_t start = args[ARG_start].u_int;
|
int32_t start = args[ARG_start].u_int;
|
||||||
uint32_t length = bufinfo.len;
|
size_t length = bufinfo.len;
|
||||||
normalize_buffer_bounds(&start, args[ARG_end].u_int, &length);
|
normalize_buffer_bounds(&start, args[ARG_end].u_int, &length);
|
||||||
|
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
|
@ -288,7 +288,7 @@ STATIC mp_obj_t busio_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_m
|
||||||
mp_buffer_info_t bufinfo;
|
mp_buffer_info_t bufinfo;
|
||||||
mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_WRITE);
|
mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_WRITE);
|
||||||
int32_t start = args[ARG_start].u_int;
|
int32_t start = args[ARG_start].u_int;
|
||||||
uint32_t length = bufinfo.len;
|
size_t length = bufinfo.len;
|
||||||
normalize_buffer_bounds(&start, args[ARG_end].u_int, &length);
|
normalize_buffer_bounds(&start, args[ARG_end].u_int, &length);
|
||||||
|
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
|
@ -337,13 +337,13 @@ STATIC mp_obj_t busio_spi_write_readinto(size_t n_args, const mp_obj_t *pos_args
|
||||||
mp_buffer_info_t buf_out_info;
|
mp_buffer_info_t buf_out_info;
|
||||||
mp_get_buffer_raise(args[ARG_buffer_out].u_obj, &buf_out_info, MP_BUFFER_READ);
|
mp_get_buffer_raise(args[ARG_buffer_out].u_obj, &buf_out_info, MP_BUFFER_READ);
|
||||||
int32_t out_start = args[ARG_out_start].u_int;
|
int32_t out_start = args[ARG_out_start].u_int;
|
||||||
uint32_t out_length = buf_out_info.len;
|
size_t out_length = buf_out_info.len;
|
||||||
normalize_buffer_bounds(&out_start, args[ARG_out_end].u_int, &out_length);
|
normalize_buffer_bounds(&out_start, args[ARG_out_end].u_int, &out_length);
|
||||||
|
|
||||||
mp_buffer_info_t buf_in_info;
|
mp_buffer_info_t buf_in_info;
|
||||||
mp_get_buffer_raise(args[ARG_buffer_in].u_obj, &buf_in_info, MP_BUFFER_WRITE);
|
mp_get_buffer_raise(args[ARG_buffer_in].u_obj, &buf_in_info, MP_BUFFER_WRITE);
|
||||||
int32_t in_start = args[ARG_in_start].u_int;
|
int32_t in_start = args[ARG_in_start].u_int;
|
||||||
uint32_t in_length = buf_in_info.len;
|
size_t in_length = buf_in_info.len;
|
||||||
normalize_buffer_bounds(&in_start, args[ARG_in_end].u_int, &in_length);
|
normalize_buffer_bounds(&in_start, args[ARG_in_end].u_int, &in_length);
|
||||||
|
|
||||||
if (out_length != in_length) {
|
if (out_length != in_length) {
|
||||||
|
|
Loading…
Reference in New Issue