diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-06-17 11:23:04 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-06-18 10:14:06 -0700 |
commit | 185d8ebc898f623acaff580eb934c6e345307a93 (patch) | |
tree | ccbd5696116a4d0a217cf6f35c80c8036472edd9 /mpi/mpi.h | |
parent | 7dc634268cb7e33b02462667c1827e7dc146c4ad (diff) | |
download | txr-185d8ebc898f623acaff580eb934c6e345307a93.tar.gz txr-185d8ebc898f623acaff580eb934c6e345307a93.tar.bz2 txr-185d8ebc898f623acaff580eb934c6e345307a93.zip |
mpi: fix some careless use of integer types.
MPI has a mp_size type for sizing of the digit arrays and some
other uses. It is not consistently used. Moreover, it is
typedef'd as a signed type. The type int is used for
iterating over digits, instead of the matching mpi_size type.
The int type is used as a size argument in some functions,
and in functions that return the number of bits.
This patch makes mp_size unsigned and replaces most uses of
int with a more appropriate type.
Because mp_size is now used for indexing, and is unsigned,
some downward loop termination tests have to be changed;
the always true condition ix >= 0 cannot be used.
* arith.c (width): Use mp_size for local variable which
iterates over digits inside mpi_int object, and for bit
count. Use unum to convert bit count to Lisp integer:
mp_size could be out of range of cnum.
* mpi/mpi-types.h (mp_size): Typedef to unsigned.
(MP_SIZE_MAX): New macro.
(MP_DIGIT_BIT, MP_WORD_BIT): Cast the value to mp_size rather
than to int.
* mpi/mpi.c (s_mp_defprec): Declare variable as mp_size.
(s_mp_setz, s_mp_copy, mp_size, s_highest_bit_mp,
s_mp_set_bit, s_mp_ispow2, s_mp_outlen, mp_set_int,
mp_set_uintptr, mp_set_double_intptr, mp_expt, mp_sqrt,
mp_exptmod, mp_hash, mp_gcd, mp_shift, mp_bit, mp_to_double,
mp_print, mp_read_signed_bin, mp_signed_bin_size,
mp_read_unsigned_bin, mp_unsigned_bin_size,
mp_to_unsigned_bin, mp_to_unsigned_buf, mp_count_bits,
mp_is_pow_two, mp_read_radix, mp_radix_size,
mp_value_radix_size, mp_toradix_case, s_mp_setz, s_mp_copy,
mp_size, s_highest_bit_mp, s_mp_set_bit, s_mp_mul_2,
s_mp_mod_2d, s_mp_div_2d, s_mp_div_d, s_mp_sqr, s_mp_sqr,
s_mp_div, s_mp_cmp, s_mp_cmp_d, s_mp_ispow2, s_mp_outlen): In
all these functions, use size_t for external size, mp_size for
number of digits and bits, in return values, arguments and
local variables. Tests in descending loops are adjusted for
unsigned logic.
* mpi/mpi.h (mp_get_prec, mp_set_prec, mp_read_signed_bin,
mp_signed_bin_size, mp_read_unsigned_bin,
mp_unsigned_bin_size, mp_to_unsigned_buf, mp_count_bits,
mp_is_pow_two, mp_radix_size, mp_value_radix_size):
Declarations updated.
* mpi/mplogic.c (mpl_not, mpl_and, mpl_or, mpl_xor, mpl_rsh,
mpl_lsh, mpl_num_set, mpl_num_clear, mpl_parity): Just like
in mpi.c
* rand.c (make_random_state): Use mp_size and ucnum for local
variables holding digit and bit counts.
* sysif.c (off_t_num): Use mp_size for digit count.
Diffstat (limited to 'mpi/mpi.h')
-rw-r--r-- | mpi/mpi.h | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -55,8 +55,8 @@ typedef struct { #define DIGITS(MP) ((MP)->dp) #define DIGIT(MP,N) (MP)->dp[(N)] -unsigned int mp_get_prec(void); -void mp_set_prec(unsigned int prec); +mp_size mp_get_prec(void); +void mp_set_prec(mp_size prec); mp_err mp_init(mp_int *mp); INLINE mp_err mp_init_minimal(mp_int *mp) @@ -160,17 +160,17 @@ void mp_print(mp_int *mp, FILE *ofp); #define BITS 1 #define BYTES CHAR_BIT -mp_err mp_read_signed_bin(mp_int *mp, unsigned char *str, int len); -int mp_signed_bin_size(mp_int *mp); +mp_err mp_read_signed_bin(mp_int *mp, unsigned char *str, size_t len); +size_t mp_signed_bin_size(mp_int *mp); mp_err mp_to_signed_bin(mp_int *mp, unsigned char *str); -mp_err mp_read_unsigned_bin(mp_int *mp, unsigned char *str, int len); -int mp_unsigned_bin_size(mp_int *mp); +mp_err mp_read_unsigned_bin(mp_int *mp, unsigned char *str, size_t len); +size_t mp_unsigned_bin_size(mp_int *mp); mp_err mp_to_unsigned_bin(mp_int *mp, unsigned char *str); -mp_err mp_to_unsigned_buf(mp_int *mp, unsigned char *str, int size); +mp_err mp_to_unsigned_buf(mp_int *mp, unsigned char *str, size_t size); -int mp_count_bits(mp_int *mp); -int mp_is_pow_two(mp_int *mp); +mp_size mp_count_bits(mp_int *mp); +mp_size mp_is_pow_two(mp_int *mp); #if MP_COMPAT_MACROS #define mp_read_raw(mp, str, len) mp_read_signed_bin((mp), (str), (len)) @@ -182,8 +182,8 @@ int mp_is_pow_two(mp_int *mp); #endif mp_err mp_read_radix(mp_int *mp, unsigned char *str, int radix); -int mp_radix_size(mp_int *mp, int radix); -int mp_value_radix_size(int num, int qty, int radix); +mp_size mp_radix_size(mp_int *mp, int radix); +mp_size mp_value_radix_size(mp_size num, mp_size qty, int radix); mp_err mp_toradix(mp_int *mp, unsigned char *str, int radix); mp_err mp_toradix_case(mp_int *mp, unsigned char *str, int radix, int low); |