py/objint: Use size_t for arguments that measure bytes/sizes.
This commit is contained in:
parent
8bb7d958f1
commit
6dff3df501
@ -252,8 +252,8 @@ int mp_print_mp_int(const mp_print_t *print, mp_obj_t x, int base, int base_char
|
|||||||
// enough, a dynamic one will be allocated.
|
// enough, a dynamic one will be allocated.
|
||||||
char stack_buf[sizeof(mp_int_t) * 4];
|
char stack_buf[sizeof(mp_int_t) * 4];
|
||||||
char *buf = stack_buf;
|
char *buf = stack_buf;
|
||||||
mp_uint_t buf_size = sizeof(stack_buf);
|
size_t buf_size = sizeof(stack_buf);
|
||||||
mp_uint_t fmt_size = 0;
|
size_t fmt_size = 0;
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
if (prec > 1) {
|
if (prec > 1) {
|
||||||
|
@ -133,8 +133,8 @@ void mp_obj_int_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
|
|||||||
// enough, a dynamic one will be allocated.
|
// enough, a dynamic one will be allocated.
|
||||||
char stack_buf[sizeof(mp_int_t) * 4];
|
char stack_buf[sizeof(mp_int_t) * 4];
|
||||||
char *buf = stack_buf;
|
char *buf = stack_buf;
|
||||||
mp_uint_t buf_size = sizeof(stack_buf);
|
size_t buf_size = sizeof(stack_buf);
|
||||||
mp_uint_t fmt_size;
|
size_t fmt_size;
|
||||||
|
|
||||||
char *str = mp_obj_int_formatted(&buf, &buf_size, &fmt_size, self_in, 10, NULL, '\0', '\0');
|
char *str = mp_obj_int_formatted(&buf, &buf_size, &fmt_size, self_in, 10, NULL, '\0', '\0');
|
||||||
mp_print_str(print, str);
|
mp_print_str(print, str);
|
||||||
@ -180,7 +180,7 @@ size_t mp_int_format_size(size_t num_bits, int base, const char *prefix, char co
|
|||||||
//
|
//
|
||||||
// The resulting formatted string will be returned from this function and the
|
// The resulting formatted string will be returned from this function and the
|
||||||
// formatted size will be in *fmt_size.
|
// formatted size will be in *fmt_size.
|
||||||
char *mp_obj_int_formatted(char **buf, mp_uint_t *buf_size, mp_uint_t *fmt_size, mp_const_obj_t self_in,
|
char *mp_obj_int_formatted(char **buf, size_t *buf_size, size_t *fmt_size, mp_const_obj_t self_in,
|
||||||
int base, const char *prefix, char base_char, char comma) {
|
int base, const char *prefix, char base_char, char comma) {
|
||||||
fmt_int_t num;
|
fmt_int_t num;
|
||||||
if (MP_OBJ_IS_SMALL_INT(self_in)) {
|
if (MP_OBJ_IS_SMALL_INT(self_in)) {
|
||||||
@ -211,7 +211,7 @@ char *mp_obj_int_formatted(char **buf, mp_uint_t *buf_size, mp_uint_t *fmt_size,
|
|||||||
sign = '-';
|
sign = '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
uint needed_size = mp_int_format_size(sizeof(fmt_int_t) * 8, base, prefix, comma);
|
size_t needed_size = mp_int_format_size(sizeof(fmt_int_t) * 8, base, prefix, comma);
|
||||||
if (needed_size > *buf_size) {
|
if (needed_size > *buf_size) {
|
||||||
*buf = m_new(char, needed_size);
|
*buf = m_new(char, needed_size);
|
||||||
*buf_size = needed_size;
|
*buf_size = needed_size;
|
||||||
|
@ -53,12 +53,12 @@ mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val);
|
|||||||
size_t mp_int_format_size(size_t num_bits, int base, const char *prefix, char comma);
|
size_t mp_int_format_size(size_t num_bits, int base, const char *prefix, char comma);
|
||||||
|
|
||||||
void mp_obj_int_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind);
|
void mp_obj_int_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind);
|
||||||
char *mp_obj_int_formatted(char **buf, mp_uint_t *buf_size, mp_uint_t *fmt_size, mp_const_obj_t self_in,
|
char *mp_obj_int_formatted(char **buf, size_t *buf_size, size_t *fmt_size, mp_const_obj_t self_in,
|
||||||
int base, const char *prefix, char base_char, char comma);
|
int base, const char *prefix, char base_char, char comma);
|
||||||
char *mp_obj_int_formatted_impl(char **buf, mp_uint_t *buf_size, mp_uint_t *fmt_size, mp_const_obj_t self_in,
|
char *mp_obj_int_formatted_impl(char **buf, size_t *buf_size, size_t *fmt_size, mp_const_obj_t self_in,
|
||||||
int base, const char *prefix, char base_char, char comma);
|
int base, const char *prefix, char base_char, char comma);
|
||||||
mp_int_t mp_obj_int_hash(mp_obj_t self_in);
|
mp_int_t mp_obj_int_hash(mp_obj_t self_in);
|
||||||
void mp_obj_int_to_bytes_impl(mp_obj_t self_in, bool big_endian, mp_uint_t len, byte *buf);
|
void mp_obj_int_to_bytes_impl(mp_obj_t self_in, bool big_endian, size_t len, byte *buf);
|
||||||
int mp_obj_int_sign(mp_obj_t self_in);
|
int mp_obj_int_sign(mp_obj_t self_in);
|
||||||
mp_obj_t mp_obj_int_abs(mp_obj_t self_in);
|
mp_obj_t mp_obj_int_abs(mp_obj_t self_in);
|
||||||
mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in);
|
mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in);
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
const mp_obj_int_t mp_maxsize_obj = {{&mp_type_int}, MP_SSIZE_MAX};
|
const mp_obj_int_t mp_maxsize_obj = {{&mp_type_int}, MP_SSIZE_MAX};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void mp_obj_int_to_bytes_impl(mp_obj_t self_in, bool big_endian, mp_uint_t len, byte *buf) {
|
void mp_obj_int_to_bytes_impl(mp_obj_t self_in, bool big_endian, size_t len, byte *buf) {
|
||||||
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int));
|
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int));
|
||||||
mp_obj_int_t *self = self_in;
|
mp_obj_int_t *self = self_in;
|
||||||
long long val = self->val;
|
long long val = self->val;
|
||||||
|
@ -90,12 +90,12 @@ STATIC mp_obj_int_t *mp_obj_int_new_mpz(void) {
|
|||||||
// formatted size will be in *fmt_size.
|
// formatted size will be in *fmt_size.
|
||||||
//
|
//
|
||||||
// This particular routine should only be called for the mpz representation of the int.
|
// This particular routine should only be called for the mpz representation of the int.
|
||||||
char *mp_obj_int_formatted_impl(char **buf, mp_uint_t *buf_size, mp_uint_t *fmt_size, mp_const_obj_t self_in,
|
char *mp_obj_int_formatted_impl(char **buf, size_t *buf_size, size_t *fmt_size, mp_const_obj_t self_in,
|
||||||
int base, const char *prefix, char base_char, char comma) {
|
int base, const char *prefix, char base_char, char comma) {
|
||||||
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int));
|
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int));
|
||||||
const mp_obj_int_t *self = MP_OBJ_TO_PTR(self_in);
|
const mp_obj_int_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
|
||||||
mp_uint_t needed_size = mp_int_format_size(mpz_max_num_bits(&self->mpz), base, prefix, comma);
|
size_t needed_size = mp_int_format_size(mpz_max_num_bits(&self->mpz), base, prefix, comma);
|
||||||
if (needed_size > *buf_size) {
|
if (needed_size > *buf_size) {
|
||||||
*buf = m_new(char, needed_size);
|
*buf = m_new(char, needed_size);
|
||||||
*buf_size = needed_size;
|
*buf_size = needed_size;
|
||||||
@ -107,7 +107,7 @@ char *mp_obj_int_formatted_impl(char **buf, mp_uint_t *buf_size, mp_uint_t *fmt_
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mp_obj_int_to_bytes_impl(mp_obj_t self_in, bool big_endian, mp_uint_t len, byte *buf) {
|
void mp_obj_int_to_bytes_impl(mp_obj_t self_in, bool big_endian, size_t len, byte *buf) {
|
||||||
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int));
|
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int));
|
||||||
mp_obj_int_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_int_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
mpz_as_bytes(&self->mpz, big_endian, len, buf);
|
mpz_as_bytes(&self->mpz, big_endian, len, buf);
|
||||||
|
Loading…
Reference in New Issue
Block a user