diff options
| author | Paul Eggert | 2019-08-21 00:06:00 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-08-21 00:11:45 -0700 |
| commit | 39fee209942ab7c35b4789f0010264cd6a52197b (patch) | |
| tree | 96f1858c890436713ba0da0fca93d1f33d7dd33a /src/pdumper.c | |
| parent | 3881542edeac3e94291c2ce574edf0b0e52764a8 (diff) | |
| download | emacs-39fee209942ab7c35b4789f0010264cd6a52197b.tar.gz emacs-39fee209942ab7c35b4789f0010264cd6a52197b.zip | |
Be more careful about pointers to bignum vals
This uses ‘const’ to be better at catching bugs that
mistakenly attempt to modify a bignum value.
Lisp bignums are supposed to be immutable.
* src/alloc.c (make_pure_bignum):
* src/fns.c (sxhash_bignum):
Accept Lisp_Object instead of struct Lisp_Bignum *, as that’s
simpler now. Caller changed.
* src/bignum.h (bignum_val, xbignum_val): New inline functions.
Prefer them to &i->value and XBIGNUM (i)->value, since they
apply ‘const’ to the result.
* src/timefns.c (lisp_to_timespec): Use mpz_t const *
to point to a bignum value.
Diffstat (limited to 'src/pdumper.c')
| -rw-r--r-- | src/pdumper.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/pdumper.c b/src/pdumper.c index 326a346a632..73a50cee53a 100644 --- a/src/pdumper.c +++ b/src/pdumper.c | |||
| @@ -2211,7 +2211,7 @@ dump_bignum (struct dump_context *ctx, Lisp_Object object) | |||
| 2211 | const struct Lisp_Bignum *bignum = XBIGNUM (object); | 2211 | const struct Lisp_Bignum *bignum = XBIGNUM (object); |
| 2212 | START_DUMP_PVEC (ctx, &bignum->header, struct Lisp_Bignum, out); | 2212 | START_DUMP_PVEC (ctx, &bignum->header, struct Lisp_Bignum, out); |
| 2213 | verify (sizeof (out->value) >= sizeof (struct bignum_reload_info)); | 2213 | verify (sizeof (out->value) >= sizeof (struct bignum_reload_info)); |
| 2214 | dump_field_fixup_later (ctx, out, bignum, &bignum->value); | 2214 | dump_field_fixup_later (ctx, out, bignum, xbignum_val (object)); |
| 2215 | dump_off bignum_offset = finish_dump_pvec (ctx, &out->header); | 2215 | dump_off bignum_offset = finish_dump_pvec (ctx, &out->header); |
| 2216 | if (ctx->flags.dump_object_contents) | 2216 | if (ctx->flags.dump_object_contents) |
| 2217 | { | 2217 | { |
| @@ -3397,19 +3397,18 @@ dump_cold_buffer (struct dump_context *ctx, Lisp_Object data) | |||
| 3397 | static void | 3397 | static void |
| 3398 | dump_cold_bignum (struct dump_context *ctx, Lisp_Object object) | 3398 | dump_cold_bignum (struct dump_context *ctx, Lisp_Object object) |
| 3399 | { | 3399 | { |
| 3400 | const struct Lisp_Bignum *bignum = XBIGNUM (object); | 3400 | mpz_t const *n = xbignum_val (object); |
| 3401 | size_t sz_nlimbs = mpz_size (bignum->value); | 3401 | size_t sz_nlimbs = mpz_size (*n); |
| 3402 | eassert (sz_nlimbs < DUMP_OFF_MAX); | 3402 | eassert (sz_nlimbs < DUMP_OFF_MAX); |
| 3403 | dump_align_output (ctx, alignof (mp_limb_t)); | 3403 | dump_align_output (ctx, alignof (mp_limb_t)); |
| 3404 | dump_off nlimbs = (dump_off) sz_nlimbs; | 3404 | dump_off nlimbs = (dump_off) sz_nlimbs; |
| 3405 | Lisp_Object descriptor | 3405 | Lisp_Object descriptor |
| 3406 | = list2 (dump_off_to_lisp (ctx->offset), | 3406 | = list2 (dump_off_to_lisp (ctx->offset), |
| 3407 | dump_off_to_lisp ((mpz_sgn (bignum->value) < 0 | 3407 | dump_off_to_lisp (mpz_sgn (*n) < 0 ? -nlimbs : nlimbs)); |
| 3408 | ? -nlimbs : nlimbs))); | ||
| 3409 | Fputhash (object, descriptor, ctx->bignum_data); | 3408 | Fputhash (object, descriptor, ctx->bignum_data); |
| 3410 | for (mp_size_t i = 0; i < nlimbs; ++i) | 3409 | for (mp_size_t i = 0; i < nlimbs; ++i) |
| 3411 | { | 3410 | { |
| 3412 | mp_limb_t limb = mpz_getlimbn (bignum->value, i); | 3411 | mp_limb_t limb = mpz_getlimbn (*n, i); |
| 3413 | dump_write (ctx, &limb, sizeof (limb)); | 3412 | dump_write (ctx, &limb, sizeof (limb)); |
| 3414 | } | 3413 | } |
| 3415 | } | 3414 | } |
| @@ -5205,8 +5204,8 @@ dump_do_dump_relocation (const uintptr_t dump_base, | |||
| 5205 | { | 5204 | { |
| 5206 | struct Lisp_Bignum *bignum = dump_ptr (dump_base, reloc_offset); | 5205 | struct Lisp_Bignum *bignum = dump_ptr (dump_base, reloc_offset); |
| 5207 | struct bignum_reload_info reload_info; | 5206 | struct bignum_reload_info reload_info; |
| 5208 | verify (sizeof (reload_info) <= sizeof (bignum->value)); | 5207 | verify (sizeof (reload_info) <= sizeof (*bignum_val (bignum))); |
| 5209 | memcpy (&reload_info, &bignum->value, sizeof (reload_info)); | 5208 | memcpy (&reload_info, bignum_val (bignum), sizeof (reload_info)); |
| 5210 | const mp_limb_t *limbs = | 5209 | const mp_limb_t *limbs = |
| 5211 | dump_ptr (dump_base, reload_info.data_location); | 5210 | dump_ptr (dump_base, reload_info.data_location); |
| 5212 | mpz_roinit_n (bignum->value, limbs, reload_info.nlimbs); | 5211 | mpz_roinit_n (bignum->value, limbs, reload_info.nlimbs); |