aboutsummaryrefslogtreecommitdiffstats
path: root/src/timefns.c
diff options
context:
space:
mode:
authorPaul Eggert2019-08-18 12:11:06 -0700
committerPaul Eggert2019-08-18 12:12:45 -0700
commit780509f29f0aa006a578744f7e871eb6d5ce5931 (patch)
treef8b9af7529ea7d617038eebf12b62299a19750d9 /src/timefns.c
parentf92d61c06c82d515ee83e340b8af4b1489778404 (diff)
downloademacs-780509f29f0aa006a578744f7e871eb6d5ce5931.tar.gz
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)
423static Lisp_Object 423static Lisp_Object
424ticks_hz_list4 (Lisp_Object ticks, Lisp_Object hz) 424ticks_hz_list4 (Lisp_Object ticks, Lisp_Object hz)
425{ 425{
426 mpz_t *zticks = bignum_integer (&mpz[0], ticks); 426 mpz_t const *zticks = bignum_integer (&mpz[0], ticks);
427#if FASTER_TIMEFNS && TRILLION <= ULONG_MAX 427#if FASTER_TIMEFNS && TRILLION <= ULONG_MAX
428 mpz_mul_ui (mpz[0], *zticks, TRILLION); 428 mpz_mul_ui (mpz[0], *zticks, TRILLION);
429#else 429#else
@@ -557,8 +557,8 @@ frac_to_double (Lisp_Object numerator, Lisp_Object denominator)
557 557
558 verify (FLT_RADIX == 2 || FLT_RADIX == 16); 558 verify (FLT_RADIX == 2 || FLT_RADIX == 16);
559 enum { LOG2_FLT_RADIX = FLT_RADIX == 2 ? 1 : 4 }; 559 enum { LOG2_FLT_RADIX = FLT_RADIX == 2 ? 1 : 4 };
560 mpz_t *n = bignum_integer (&mpz[0], numerator); 560 mpz_t const *n = bignum_integer (&mpz[0], numerator);
561 mpz_t *d = bignum_integer (&mpz[1], denominator); 561 mpz_t const *d = bignum_integer (&mpz[1], denominator);
562 ptrdiff_t nbits = mpz_sizeinbase (*n, 2); 562 ptrdiff_t nbits = mpz_sizeinbase (*n, 2);
563 ptrdiff_t dbits = mpz_sizeinbase (*d, 2); 563 ptrdiff_t dbits = mpz_sizeinbase (*d, 2);
564 eassume (0 < nbits); 564 eassume (0 < nbits);
@@ -1061,8 +1061,8 @@ time_arith (Lisp_Object a, Lisp_Object b, bool subtract)
1061 { 1061 {
1062 /* The plan is to decompose ta into na/da and tb into nb/db. 1062 /* The plan is to decompose ta into na/da and tb into nb/db.
1063 Start by computing da and db. */ 1063 Start by computing da and db. */
1064 mpz_t *da = bignum_integer (&mpz[1], ta.hz); 1064 mpz_t const *da = bignum_integer (&mpz[1], ta.hz);
1065 mpz_t *db = bignum_integer (&mpz[2], tb.hz); 1065 mpz_t const *db = bignum_integer (&mpz[2], tb.hz);
1066 1066
1067 /* The plan is to compute (na * (db/g) + nb * (da/g)) / lcm (da, db) 1067 /* The plan is to compute (na * (db/g) + nb * (da/g)) / lcm (da, db)
1068 where g = gcd (da, db). Start by computing g. */ 1068 where g = gcd (da, db). Start by computing g. */
@@ -1082,9 +1082,9 @@ time_arith (Lisp_Object a, Lisp_Object b, bool subtract)
1082 1082
1083 /* ticks = (fb * na) OPER (fa * nb), where OPER is + or -. 1083 /* ticks = (fb * na) OPER (fa * nb), where OPER is + or -.
1084 OP is the multiply-add or multiply-sub form of OPER. */ 1084 OP is the multiply-add or multiply-sub form of OPER. */
1085 mpz_t *na = bignum_integer (&mpz[0], ta.ticks); 1085 mpz_t const *na = bignum_integer (&mpz[0], ta.ticks);
1086 mpz_mul (mpz[0], *fb, *na); 1086 mpz_mul (mpz[0], *fb, *na);
1087 mpz_t *nb = bignum_integer (&mpz[3], tb.ticks); 1087 mpz_t const *nb = bignum_integer (&mpz[3], tb.ticks);
1088 (subtract ? mpz_submul : mpz_addmul) (mpz[0], *fa, *nb); 1088 (subtract ? mpz_submul : mpz_addmul) (mpz[0], *fa, *nb);
1089 ticks = make_integer_mpz (); 1089 ticks = make_integer_mpz ();
1090 } 1090 }
@@ -1144,8 +1144,8 @@ time_cmp (Lisp_Object a, Lisp_Object b)
1144 return 0; 1144 return 0;
1145 1145
1146 struct lisp_time tb = lisp_time_struct (b, 0); 1146 struct lisp_time tb = lisp_time_struct (b, 0);
1147 mpz_t *za = bignum_integer (&mpz[0], ta.ticks); 1147 mpz_t const *za = bignum_integer (&mpz[0], ta.ticks);
1148 mpz_t *zb = bignum_integer (&mpz[1], tb.ticks); 1148 mpz_t const *zb = bignum_integer (&mpz[1], tb.ticks);
1149 if (! (FASTER_TIMEFNS && EQ (ta.hz, tb.hz))) 1149 if (! (FASTER_TIMEFNS && EQ (ta.hz, tb.hz)))
1150 { 1150 {
1151 /* This could be sped up by looking at the signs, sizes, and 1151 /* This could be sped up by looking at the signs, sizes, and