py/binary: Change mp_uint_t to size_t for index, size, align args.

Reduces code size for nan-box builds, otherwise changes nothing.
This commit is contained in:
Damien George 2019-09-02 13:09:44 +10:00
parent 24c3e9b283
commit c348e79187
3 changed files with 17 additions and 17 deletions

View File

@ -42,7 +42,7 @@
#define alignof(type) offsetof(struct { char c; type t; }, t) #define alignof(type) offsetof(struct { char c; type t; }, t)
#endif #endif
size_t 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, size_t *palign) {
size_t size = 0; size_t size = 0;
int align = 1; int align = 1;
switch (struct_type) { switch (struct_type) {
@ -113,7 +113,7 @@ size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign) {
return size; return size;
} }
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, size_t index) {
mp_int_t val = 0; mp_int_t val = 0;
switch (typecode) { switch (typecode) {
case 'b': case 'b':
@ -162,7 +162,7 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index) {
// The long long type is guaranteed to hold at least 64 bits, and size is at // The long long type is guaranteed to hold at least 64 bits, and size is at
// most 8 (for q and Q), so we will always be able to parse the given data // most 8 (for q and Q), so we will always be able to parse the given data
// and fit it into a long long. // and fit it into a long long.
long long mp_binary_get_int(mp_uint_t size, bool is_signed, bool big_endian, const byte *src) { long long mp_binary_get_int(size_t size, bool is_signed, bool big_endian, const byte *src) {
int delta; int delta;
if (!big_endian) { if (!big_endian) {
delta = -1; delta = -1;
@ -187,12 +187,12 @@ long long mp_binary_get_int(mp_uint_t size, bool is_signed, bool big_endian, con
#define is_signed(typecode) (typecode > 'Z') #define is_signed(typecode) (typecode > 'Z')
mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte *p_base, byte **ptr) { mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte *p_base, byte **ptr) {
byte *p = *ptr; byte *p = *ptr;
mp_uint_t align; size_t align;
size_t 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 == '@') {
// Align p relative to p_base // Align p relative to p_base
p = p_base + (uintptr_t)MP_ALIGN(p - p_base, (size_t)align); p = p_base + (uintptr_t)MP_ALIGN(p - p_base, align);
#if MP_ENDIANNESS_LITTLE #if MP_ENDIANNESS_LITTLE
struct_type = '<'; struct_type = '<';
#else #else
@ -231,7 +231,7 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte *p_base, byte *
} }
} }
void mp_binary_set_int(mp_uint_t val_sz, bool big_endian, byte *dest, mp_uint_t val) { void mp_binary_set_int(size_t val_sz, bool big_endian, byte *dest, mp_uint_t val) {
if (MP_ENDIANNESS_LITTLE && !big_endian) { if (MP_ENDIANNESS_LITTLE && !big_endian) {
memcpy(dest, &val, val_sz); memcpy(dest, &val, val_sz);
} else if (MP_ENDIANNESS_BIG && big_endian) { } 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
void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p_base, byte **ptr) { void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p_base, byte **ptr) {
byte *p = *ptr; byte *p = *ptr;
mp_uint_t align; size_t align;
size_t 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 == '@') {
// Align p relative to p_base // Align p relative to p_base
p = p_base + (uintptr_t)MP_ALIGN(p - p_base, (size_t)align); p = p_base + (uintptr_t)MP_ALIGN(p - p_base, align);
if (MP_ENDIANNESS_LITTLE) { if (MP_ENDIANNESS_LITTLE) {
struct_type = '<'; struct_type = '<';
} else { } else {
@ -315,7 +315,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p
mp_binary_set_int(MIN((size_t)size, sizeof(val)), struct_type == '>', p, val); mp_binary_set_int(MIN((size_t)size, sizeof(val)), struct_type == '>', p, val);
} }
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, size_t index, mp_obj_t val_in) {
switch (typecode) { switch (typecode) {
#if MICROPY_PY_BUILTINS_FLOAT #if MICROPY_PY_BUILTINS_FLOAT
case 'f': case 'f':
@ -342,7 +342,7 @@ void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t v
} }
} }
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, size_t index, mp_int_t val) {
switch (typecode) { switch (typecode) {
case 'b': case 'b':
((signed char*)p)[index] = val; ((signed char*)p)[index] = val;

View File

@ -34,13 +34,13 @@
// type-specification errors due to end-of-string. // type-specification errors due to end-of-string.
#define BYTEARRAY_TYPECODE 1 #define BYTEARRAY_TYPECODE 1
size_t 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, size_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, size_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, size_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, size_t index, mp_int_t val);
mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte *p_base, byte **ptr); mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte *p_base, byte **ptr);
void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p_base, byte **ptr); void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p_base, byte **ptr);
long long mp_binary_get_int(mp_uint_t size, bool is_signed, bool big_endian, const byte *src); long long mp_binary_get_int(size_t size, bool is_signed, bool big_endian, const byte *src);
void mp_binary_set_int(mp_uint_t val_sz, bool big_endian, byte *dest, mp_uint_t val); void mp_binary_set_int(size_t val_sz, bool big_endian, byte *dest, mp_uint_t val);
#endif // MICROPY_INCLUDED_PY_BINARY_H #endif // MICROPY_INCLUDED_PY_BINARY_H

View File

@ -97,7 +97,7 @@ STATIC size_t calc_size_items(const char *fmt, size_t *total_sz) {
size += cnt; size += cnt;
} else { } else {
total_cnt += cnt; total_cnt += cnt;
mp_uint_t align; size_t align;
size_t sz = mp_binary_get_size(fmt_type, *fmt, &align); size_t sz = mp_binary_get_size(fmt_type, *fmt, &align);
while (cnt--) { while (cnt--) {
// Apply alignment // Apply alignment