Skip to content

Commit c348e79

Browse files
committed
py/binary: Change mp_uint_t to size_t for index, size, align args.
Reduces code size for nan-box builds, otherwise changes nothing.
1 parent 24c3e9b commit c348e79

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

py/binary.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#define alignof(type) offsetof(struct { char c; type t; }, t)
4343
#endif
4444

45-
size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign) {
45+
size_t mp_binary_get_size(char struct_type, char val_type, size_t *palign) {
4646
size_t size = 0;
4747
int align = 1;
4848
switch (struct_type) {
@@ -113,7 +113,7 @@ size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign) {
113113
return size;
114114
}
115115

116-
mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index) {
116+
mp_obj_t mp_binary_get_val_array(char typecode, void *p, size_t index) {
117117
mp_int_t val = 0;
118118
switch (typecode) {
119119
case 'b':
@@ -162,7 +162,7 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index) {
162162
// The long long type is guaranteed to hold at least 64 bits, and size is at
163163
// most 8 (for q and Q), so we will always be able to parse the given data
164164
// and fit it into a long long.
165-
long long mp_binary_get_int(mp_uint_t size, bool is_signed, bool big_endian, const byte *src) {
165+
long long mp_binary_get_int(size_t size, bool is_signed, bool big_endian, const byte *src) {
166166
int delta;
167167
if (!big_endian) {
168168
delta = -1;
@@ -187,12 +187,12 @@ long long mp_binary_get_int(mp_uint_t size, bool is_signed, bool big_endian, con
187187
#define is_signed(typecode) (typecode > 'Z')
188188
mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte *p_base, byte **ptr) {
189189
byte *p = *ptr;
190-
mp_uint_t align;
190+
size_t align;
191191

192192
size_t size = mp_binary_get_size(struct_type, val_type, &align);
193193
if (struct_type == '@') {
194194
// Align p relative to p_base
195-
p = p_base + (uintptr_t)MP_ALIGN(p - p_base, (size_t)align);
195+
p = p_base + (uintptr_t)MP_ALIGN(p - p_base, align);
196196
#if MP_ENDIANNESS_LITTLE
197197
struct_type = '<';
198198
#else
@@ -231,7 +231,7 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte *p_base, byte *
231231
}
232232
}
233233

234-
void mp_binary_set_int(mp_uint_t val_sz, bool big_endian, byte *dest, mp_uint_t val) {
234+
void mp_binary_set_int(size_t val_sz, bool big_endian, byte *dest, mp_uint_t val) {
235235
if (MP_ENDIANNESS_LITTLE && !big_endian) {
236236
memcpy(dest, &val, val_sz);
237237
} else if (MP_ENDIANNESS_BIG && big_endian) {
@@ -252,12 +252,12 @@ void mp_binary_set_int(mp_uint_t val_sz, bool big_endian, byte *dest, mp_uint_t
252252

253253
void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p_base, byte **ptr) {
254254
byte *p = *ptr;
255-
mp_uint_t align;
255+
size_t align;
256256

257257
size_t size = mp_binary_get_size(struct_type, val_type, &align);
258258
if (struct_type == '@') {
259259
// Align p relative to p_base
260-
p = p_base + (uintptr_t)MP_ALIGN(p - p_base, (size_t)align);
260+
p = p_base + (uintptr_t)MP_ALIGN(p - p_base, align);
261261
if (MP_ENDIANNESS_LITTLE) {
262262
struct_type = '<';
263263
} else {
@@ -315,7 +315,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p
315315
mp_binary_set_int(MIN((size_t)size, sizeof(val)), struct_type == '>', p, val);
316316
}
317317

318-
void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t val_in) {
318+
void mp_binary_set_val_array(char typecode, void *p, size_t index, mp_obj_t val_in) {
319319
switch (typecode) {
320320
#if MICROPY_PY_BUILTINS_FLOAT
321321
case 'f':
@@ -342,7 +342,7 @@ void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t v
342342
}
343343
}
344344

345-
void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, mp_int_t val) {
345+
void mp_binary_set_val_array_from_int(char typecode, void *p, size_t index, mp_int_t val) {
346346
switch (typecode) {
347347
case 'b':
348348
((signed char*)p)[index] = val;

py/binary.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
// type-specification errors due to end-of-string.
3535
#define BYTEARRAY_TYPECODE 1
3636

37-
size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign);
38-
mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index);
39-
void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t val_in);
40-
void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, mp_int_t val);
37+
size_t mp_binary_get_size(char struct_type, char val_type, size_t *palign);
38+
mp_obj_t mp_binary_get_val_array(char typecode, void *p, size_t index);
39+
void mp_binary_set_val_array(char typecode, void *p, size_t index, mp_obj_t val_in);
40+
void mp_binary_set_val_array_from_int(char typecode, void *p, size_t index, mp_int_t val);
4141
mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte *p_base, byte **ptr);
4242
void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p_base, byte **ptr);
43-
long long mp_binary_get_int(mp_uint_t size, bool is_signed, bool big_endian, const byte *src);
44-
void mp_binary_set_int(mp_uint_t val_sz, bool big_endian, byte *dest, mp_uint_t val);
43+
long long mp_binary_get_int(size_t size, bool is_signed, bool big_endian, const byte *src);
44+
void mp_binary_set_int(size_t val_sz, bool big_endian, byte *dest, mp_uint_t val);
4545

4646
#endif // MICROPY_INCLUDED_PY_BINARY_H

py/modstruct.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ STATIC size_t calc_size_items(const char *fmt, size_t *total_sz) {
9797
size += cnt;
9898
} else {
9999
total_cnt += cnt;
100-
mp_uint_t align;
100+
size_t align;
101101
size_t sz = mp_binary_get_size(fmt_type, *fmt, &align);
102102
while (cnt--) {
103103
// Apply alignment

0 commit comments

Comments
 (0)