summaryrefslogtreecommitdiff
path: root/src/timefns.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2019-08-18 12:11:06 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2019-08-18 12:12:45 -0700
commit780509f29f0aa006a578744f7e871eb6d5ce5931 (patch)
treef8b9af7529ea7d617038eebf12b62299a19750d9 /src/timefns.c
parentf92d61c06c82d515ee83e340b8af4b1489778404 (diff)
downloademacs-780509f29f0aa006a578744f7e871eb6d5ce5931.tar.gz
emacs-780509f29f0aa006a578744f7e871eb6d5ce5931.tar.bz2
emacs-780509f29f0aa006a578744f7e871eb6d5ce5931.zip
Improve bignum_integer static checking
* src/bignum.h (bignum_integer): Now returns pointer-to-const, to catch trivial mistakes where the caller might try to modify a Lisp bignum. Lisp bignums are supposed to be immutable. All callers changed.
Diffstat (limited to 'src/timefns.c')
-rw-r--r--src/timefns.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/timefns.c b/src/timefns.c
index bf49843aae7..3948f873354 100644
--- a/src/timefns.c
+++ b/src/timefns.c
@@ -423,7 +423,7 @@ decode_float_time (double t, struct lisp_time *result)
static Lisp_Object
ticks_hz_list4 (Lisp_Object ticks, Lisp_Object hz)
{
- mpz_t *zticks = bignum_integer (&mpz[0], ticks);
+ mpz_t const *zticks = bignum_integer (&mpz[0], ticks);
#if FASTER_TIMEFNS && TRILLION <= ULONG_MAX
mpz_mul_ui (mpz[0], *zticks, TRILLION);
#else
@@ -557,8 +557,8 @@ frac_to_double (Lisp_Object numerator, Lisp_Object denominator)
verify (FLT_RADIX == 2 || FLT_RADIX == 16);
enum { LOG2_FLT_RADIX = FLT_RADIX == 2 ? 1 : 4 };
- mpz_t *n = bignum_integer (&mpz[0], numerator);
- mpz_t *d = bignum_integer (&mpz[1], denominator);
+ mpz_t const *n = bignum_integer (&mpz[0], numerator);
+ mpz_t const *d = bignum_integer (&mpz[1], denominator);
ptrdiff_t nbits = mpz_sizeinbase (*n, 2);
ptrdiff_t dbits = mpz_sizeinbase (*d, 2);
eassume (0 < nbits);
@@ -1061,8 +1061,8 @@ time_arith (Lisp_Object a, Lisp_Object b, bool subtract)
{
/* The plan is to decompose ta into na/da and tb into nb/db.
Start by computing da and db. */
- mpz_t *da = bignum_integer (&mpz[1], ta.hz);
- mpz_t *db = bignum_integer (&mpz[2], tb.hz);
+ mpz_t const *da = bignum_integer (&mpz[1], ta.hz);
+ mpz_t const *db = bignum_integer (&mpz[2], tb.hz);
/* The plan is to compute (na * (db/g) + nb * (da/g)) / lcm (da, db)
where g = gcd (da, db). Start by computing g. */
@@ -1082,9 +1082,9 @@ time_arith (Lisp_Object a, Lisp_Object b, bool subtract)
/* ticks = (fb * na) OPER (fa * nb), where OPER is + or -.
OP is the multiply-add or multiply-sub form of OPER. */
- mpz_t *na = bignum_integer (&mpz[0], ta.ticks);
+ mpz_t const *na = bignum_integer (&mpz[0], ta.ticks);
mpz_mul (mpz[0], *fb, *na);
- mpz_t *nb = bignum_integer (&mpz[3], tb.ticks);
+ mpz_t const *nb = bignum_integer (&mpz[3], tb.ticks);
(subtract ? mpz_submul : mpz_addmul) (mpz[0], *fa, *nb);
ticks = make_integer_mpz ();
}
@@ -1144,8 +1144,8 @@ time_cmp (Lisp_Object a, Lisp_Object b)
return 0;
struct lisp_time tb = lisp_time_struct (b, 0);
- mpz_t *za = bignum_integer (&mpz[0], ta.ticks);
- mpz_t *zb = bignum_integer (&mpz[1], tb.ticks);
+ mpz_t const *za = bignum_integer (&mpz[0], ta.ticks);
+ mpz_t const *zb = bignum_integer (&mpz[1], tb.ticks);
if (! (FASTER_TIMEFNS && EQ (ta.hz, tb.hz)))
{
/* This could be sped up by looking at the signs, sizes, and