diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-09-27 15:10:30 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-09-27 15:10:30 +0000 |
commit | 4292560697b56ebc25df3e1669bd345ffc4f7484 (patch) | |
tree | 83f90a73e964e8d66a6195fded0481dc752a0db0 /src/mpfr-impl.h | |
parent | dbad66e5f328924afc32904740aac1351db1ae06 (diff) | |
download | mpfr-4292560697b56ebc25df3e1669bd345ffc4f7484.tar.gz |
[src]
* mpfr-impl.h: document the memory allocated for a significand;
added a cast to avoid a direct conversion from mp_limb_t * to
mp_size_t *.
* init2.c, round_prec.c, set_prec.c: code clean-up by correcting
the type expected for the second argument of MPFR_SET_MANT_PTR
(this macro has a cast, so that this should not change anything,
but the old type mpfr_limb_ptr was meaningless and confusing).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@10902 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/mpfr-impl.h')
-rw-r--r-- | src/mpfr-impl.h | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/mpfr-impl.h b/src/mpfr-impl.h index c97164e52..cb5e82092 100644 --- a/src/mpfr-impl.h +++ b/src/mpfr-impl.h @@ -1074,12 +1074,28 @@ typedef uintmax_t mpfr_ueexp_t; #define MPFR_BYTES_PER_MP_LIMB (GMP_NUMB_BITS/CHAR_BIT) -/* Heap memory handling */ +/* Heap memory handling + -------------------- + Memory allocated for a significand (mantissa) has the following + format: + * A mp_size_t in a mpfr_size_limb_t union (see below). + * An array of mp_limb_t (not all of them are necessarily used, + as the precision can change without a reallocation). + The goal of the mpfr_size_limb_t union is to make sure that + size and alignment requirements are satisfied if mp_size_t and + mp_limb_t have different sizes and/or alignment requirements. + Moreover, pointer conversions are not fully specified by the + C standard, and the use of a union (and the double casts below) + might help even if mp_size_t and mp_limb_t have the same size + and the same alignment requirements. Still, there is currently + no guarantee that this code is portable. Note that union members + are not used at all. +*/ typedef union { mp_size_t s; mp_limb_t l; } mpfr_size_limb_t; #define MPFR_GET_ALLOC_SIZE(x) \ - (((mp_size_t *) MPFR_MANT(x))[-1] + 0) + (((mp_size_t *) (mpfr_size_limb_t *) MPFR_MANT(x))[-1] + 0) #define MPFR_SET_ALLOC_SIZE(x, n) \ - (((mp_size_t *) MPFR_MANT(x))[-1] = (n)) + (((mp_size_t *) (mpfr_size_limb_t *) MPFR_MANT(x))[-1] = (n)) #define MPFR_MALLOC_SIZE(s) \ (sizeof(mpfr_size_limb_t) + MPFR_BYTES_PER_MP_LIMB * (size_t) (s)) #define MPFR_SET_MANT_PTR(x,p) \ |