Skip to content

Commit f5dd6f7

Browse files
kaspar030dpgeorge
authored andcommitted
py/binary: Make return type of mp_binary_get_size size_t instead of int.
Fixes sign-compare warning.
1 parent b5cef5c commit f5dd6f7

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

py/binary.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
#define alignof(type) offsetof(struct { char c; type t; }, t)
4141
#endif
4242

43-
int mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign) {
44-
int size = 0;
43+
size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign) {
44+
size_t size = 0;
4545
int align = 1;
4646
switch (struct_type) {
4747
case '<': case '>':
@@ -179,7 +179,7 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte **ptr) {
179179
byte *p = *ptr;
180180
mp_uint_t align;
181181

182-
int size = mp_binary_get_size(struct_type, val_type, &align);
182+
size_t size = mp_binary_get_size(struct_type, val_type, &align);
183183
if (struct_type == '@') {
184184
// Make pointer aligned
185185
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 **
244244
byte *p = *ptr;
245245
mp_uint_t align;
246246

247-
int size = mp_binary_get_size(struct_type, val_type, &align);
247+
size_t size = mp_binary_get_size(struct_type, val_type, &align);
248248
if (struct_type == '@') {
249249
// Make pointer aligned
250250
p = (byte*)(((mp_uint_t)p + align - 1) & ~((mp_uint_t)align - 1));

py/binary.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
// (underlyingly they're same).
3333
#define BYTEARRAY_TYPECODE 0
3434

35-
int mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign);
35+
size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign);
3636
mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index);
3737
void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t val_in);
3838
void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, mp_int_t val);

py/objarray.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ STATIC void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
102102
#if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY
103103
STATIC mp_obj_array_t *array_new(char typecode, mp_uint_t n) {
104104
int typecode_size = mp_binary_get_size('@', typecode, NULL);
105-
if (typecode_size <= 0) {
105+
if (typecode_size == 0) {
106106
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "bad typecode"));
107107
}
108108
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) {
134134
&& mp_get_buffer(initializer, &bufinfo, MP_BUFFER_READ)) {
135135
// construct array from raw bytes
136136
// we round-down the len to make it a multiple of sz (CPython raises error)
137-
int sz = mp_binary_get_size('@', typecode, NULL);
137+
size_t sz = mp_binary_get_size('@', typecode, NULL);
138138
mp_uint_t len = bufinfo.len / sz;
139139
mp_obj_array_t *o = array_new(typecode, len);
140140
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)
262262
array_get_buffer(lhs_in, &lhs_bufinfo, MP_BUFFER_READ);
263263
mp_get_buffer_raise(rhs_in, &rhs_bufinfo, MP_BUFFER_READ);
264264

265-
int sz = mp_binary_get_size('@', lhs_bufinfo.typecode, NULL);
265+
size_t sz = mp_binary_get_size('@', lhs_bufinfo.typecode, NULL);
266266

267267
// convert byte count to element count (in case rhs is not multiple of sz)
268268
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) {
305305
mp_obj_array_t *self = self_in;
306306

307307
if (self->free == 0) {
308-
int item_sz = mp_binary_get_size('@', self->typecode, NULL);
308+
size_t item_sz = mp_binary_get_size('@', self->typecode, NULL);
309309
// TODO: alloc policy
310310
self->free = 8;
311311
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) {
326326
mp_buffer_info_t arg_bufinfo;
327327
mp_get_buffer_raise(arg_in, &arg_bufinfo, MP_BUFFER_READ);
328328

329-
int sz = mp_binary_get_size('@', self->typecode, NULL);
329+
size_t sz = mp_binary_get_size('@', self->typecode, NULL);
330330

331331
// convert byte count to element count
332332
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
371371
// Assign
372372
mp_uint_t src_len;
373373
void *src_items;
374-
int item_sz = mp_binary_get_size('@', o->typecode, NULL);
374+
size_t item_sz = mp_binary_get_size('@', o->typecode, NULL);
375375
if (MP_OBJ_IS_TYPE(value, &mp_type_array) || MP_OBJ_IS_TYPE(value, &mp_type_bytearray)) {
376376
mp_obj_array_t *src_slice = value;
377377
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
418418
}
419419

420420
mp_obj_array_t *res;
421-
int sz = mp_binary_get_size('@', o->typecode & TYPECODE_MASK, NULL);
421+
size_t sz = mp_binary_get_size('@', o->typecode & TYPECODE_MASK, NULL);
422422
assert(sz > 0);
423423
if (0) {
424424
// 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
460460

461461
STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
462462
mp_obj_array_t *o = o_in;
463-
int sz = mp_binary_get_size('@', o->typecode & TYPECODE_MASK, NULL);
463+
size_t sz = mp_binary_get_size('@', o->typecode & TYPECODE_MASK, NULL);
464464
bufinfo->buf = o->items;
465465
bufinfo->len = o->len * sz;
466466
bufinfo->typecode = o->typecode & TYPECODE_MASK;

stmhal/adc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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_
219219

220220
mp_buffer_info_t bufinfo;
221221
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_WRITE);
222-
int typesize = mp_binary_get_size('@', bufinfo.typecode, NULL);
222+
size_t typesize = mp_binary_get_size('@', bufinfo.typecode, NULL);
223223

224224
// Init TIM6 at the required frequency (in Hz)
225225
timer_tim6_init(mp_obj_get_int(freq_in));

0 commit comments

Comments
 (0)