Commit f5dd6f7f authored by Kaspar Schleiser's avatar Kaspar Schleiser Committed by Damien George
Browse files

py/binary: Make return type of mp_binary_get_size size_t instead of int.

Fixes sign-compare warning.
parent b5cef5c7
...@@ -40,8 +40,8 @@ ...@@ -40,8 +40,8 @@
#define alignof(type) offsetof(struct { char c; type t; }, t) #define alignof(type) offsetof(struct { char c; type t; }, t)
#endif #endif
int mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign) { size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign) {
int size = 0; size_t size = 0;
int align = 1; int align = 1;
switch (struct_type) { switch (struct_type) {
case '<': case '>': case '<': case '>':
...@@ -179,7 +179,7 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte **ptr) { ...@@ -179,7 +179,7 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte **ptr) {
byte *p = *ptr; byte *p = *ptr;
mp_uint_t align; mp_uint_t align;
int size = mp_binary_get_size(struct_type, val_type, &align); size_t size = mp_binary_get_size(struct_type, val_type, &align);
if (struct_type == '@') { if (struct_type == '@') {
// Make pointer aligned // Make pointer aligned
p = (byte*)(((mp_uint_t)p + align - 1) & ~((mp_uint_t)align - 1)); p = (byte*)(((mp_uint_t)p + align - 1) & ~((mp_uint_t)align - 1));
...@@ -244,7 +244,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte ** ...@@ -244,7 +244,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **
byte *p = *ptr; byte *p = *ptr;
mp_uint_t align; mp_uint_t align;
int size = mp_binary_get_size(struct_type, val_type, &align); size_t size = mp_binary_get_size(struct_type, val_type, &align);
if (struct_type == '@') { if (struct_type == '@') {
// Make pointer aligned // Make pointer aligned
p = (byte*)(((mp_uint_t)p + align - 1) & ~((mp_uint_t)align - 1)); p = (byte*)(((mp_uint_t)p + align - 1) & ~((mp_uint_t)align - 1));
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
// (underlyingly they're same). // (underlyingly they're same).
#define BYTEARRAY_TYPECODE 0 #define BYTEARRAY_TYPECODE 0
int mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign); size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign);
mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index); mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index);
void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t val_in); void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t val_in);
void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, mp_int_t val); void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, mp_int_t val);
......
...@@ -102,7 +102,7 @@ STATIC void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t ...@@ -102,7 +102,7 @@ STATIC void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
#if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY #if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY
STATIC mp_obj_array_t *array_new(char typecode, mp_uint_t n) { STATIC mp_obj_array_t *array_new(char typecode, mp_uint_t n) {
int typecode_size = mp_binary_get_size('@', typecode, NULL); int typecode_size = mp_binary_get_size('@', typecode, NULL);
if (typecode_size <= 0) { if (typecode_size == 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "bad typecode")); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "bad typecode"));
} }
mp_obj_array_t *o = m_new_obj(mp_obj_array_t); mp_obj_array_t *o = m_new_obj(mp_obj_array_t);
...@@ -134,7 +134,7 @@ STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) { ...@@ -134,7 +134,7 @@ STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
&& mp_get_buffer(initializer, &bufinfo, MP_BUFFER_READ)) { && mp_get_buffer(initializer, &bufinfo, MP_BUFFER_READ)) {
// construct array from raw bytes // construct array from raw bytes
// we round-down the len to make it a multiple of sz (CPython raises error) // we round-down the len to make it a multiple of sz (CPython raises error)
int sz = mp_binary_get_size('@', typecode, NULL); size_t sz = mp_binary_get_size('@', typecode, NULL);
mp_uint_t len = bufinfo.len / sz; mp_uint_t len = bufinfo.len / sz;
mp_obj_array_t *o = array_new(typecode, len); mp_obj_array_t *o = array_new(typecode, len);
memcpy(o->items, bufinfo.buf, len * sz); memcpy(o->items, bufinfo.buf, len * sz);
...@@ -262,7 +262,7 @@ STATIC mp_obj_t array_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) ...@@ -262,7 +262,7 @@ STATIC mp_obj_t array_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in)
array_get_buffer(lhs_in, &lhs_bufinfo, MP_BUFFER_READ); array_get_buffer(lhs_in, &lhs_bufinfo, MP_BUFFER_READ);
mp_get_buffer_raise(rhs_in, &rhs_bufinfo, MP_BUFFER_READ); mp_get_buffer_raise(rhs_in, &rhs_bufinfo, MP_BUFFER_READ);
int sz = mp_binary_get_size('@', lhs_bufinfo.typecode, NULL); size_t sz = mp_binary_get_size('@', lhs_bufinfo.typecode, NULL);
// convert byte count to element count (in case rhs is not multiple of sz) // convert byte count to element count (in case rhs is not multiple of sz)
mp_uint_t rhs_len = rhs_bufinfo.len / sz; mp_uint_t rhs_len = rhs_bufinfo.len / sz;
...@@ -305,7 +305,7 @@ STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg) { ...@@ -305,7 +305,7 @@ STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg) {
mp_obj_array_t *self = self_in; mp_obj_array_t *self = self_in;
if (self->free == 0) { if (self->free == 0) {
int item_sz = mp_binary_get_size('@', self->typecode, NULL); size_t item_sz = mp_binary_get_size('@', self->typecode, NULL);
// TODO: alloc policy // TODO: alloc policy
self->free = 8; self->free = 8;
self->items = m_renew(byte, self->items, item_sz * self->len, item_sz * (self->len + self->free)); self->items = m_renew(byte, self->items, item_sz * self->len, item_sz * (self->len + self->free));
...@@ -326,7 +326,7 @@ STATIC mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in) { ...@@ -326,7 +326,7 @@ STATIC mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in) {
mp_buffer_info_t arg_bufinfo; mp_buffer_info_t arg_bufinfo;
mp_get_buffer_raise(arg_in, &arg_bufinfo, MP_BUFFER_READ); mp_get_buffer_raise(arg_in, &arg_bufinfo, MP_BUFFER_READ);
int sz = mp_binary_get_size('@', self->typecode, NULL); size_t sz = mp_binary_get_size('@', self->typecode, NULL);
// convert byte count to element count // convert byte count to element count
mp_uint_t len = arg_bufinfo.len / sz; mp_uint_t len = arg_bufinfo.len / sz;
...@@ -371,7 +371,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value ...@@ -371,7 +371,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
// Assign // Assign
mp_uint_t src_len; mp_uint_t src_len;
void *src_items; void *src_items;
int item_sz = mp_binary_get_size('@', o->typecode, NULL); size_t item_sz = mp_binary_get_size('@', o->typecode, NULL);
if (MP_OBJ_IS_TYPE(value, &mp_type_array) || MP_OBJ_IS_TYPE(value, &mp_type_bytearray)) { if (MP_OBJ_IS_TYPE(value, &mp_type_array) || MP_OBJ_IS_TYPE(value, &mp_type_bytearray)) {
mp_obj_array_t *src_slice = value; mp_obj_array_t *src_slice = value;
if (item_sz != mp_binary_get_size('@', src_slice->typecode, NULL)) { if (item_sz != mp_binary_get_size('@', src_slice->typecode, NULL)) {
...@@ -418,7 +418,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value ...@@ -418,7 +418,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
} }
mp_obj_array_t *res; mp_obj_array_t *res;
int sz = mp_binary_get_size('@', o->typecode & TYPECODE_MASK, NULL); size_t sz = mp_binary_get_size('@', o->typecode & TYPECODE_MASK, NULL);
assert(sz > 0); assert(sz > 0);
if (0) { if (0) {
// dummy // dummy
...@@ -460,7 +460,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value ...@@ -460,7 +460,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
mp_obj_array_t *o = o_in; mp_obj_array_t *o = o_in;
int sz = mp_binary_get_size('@', o->typecode & TYPECODE_MASK, NULL); size_t sz = mp_binary_get_size('@', o->typecode & TYPECODE_MASK, NULL);
bufinfo->buf = o->items; bufinfo->buf = o->items;
bufinfo->len = o->len * sz; bufinfo->len = o->len * sz;
bufinfo->typecode = o->typecode & TYPECODE_MASK; bufinfo->typecode = o->typecode & TYPECODE_MASK;
......
...@@ -219,7 +219,7 @@ STATIC mp_obj_t adc_read_timed(mp_obj_t self_in, mp_obj_t buf_in, mp_obj_t freq_ ...@@ -219,7 +219,7 @@ STATIC mp_obj_t adc_read_timed(mp_obj_t self_in, mp_obj_t buf_in, mp_obj_t freq_
mp_buffer_info_t bufinfo; mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_WRITE); mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_WRITE);
int typesize = mp_binary_get_size('@', bufinfo.typecode, NULL); size_t typesize = mp_binary_get_size('@', bufinfo.typecode, NULL);
// Init TIM6 at the required frequency (in Hz) // Init TIM6 at the required frequency (in Hz)
timer_tim6_init(mp_obj_get_int(freq_in)); timer_tim6_init(mp_obj_get_int(freq_in));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment