summaryrefslogtreecommitdiffstats
path: root/ffi.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-06-18 08:34:08 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-06-18 10:14:34 -0700
commitf9964fe5c922535d5284ad22d62fddbdca315e97 (patch)
tree48aa53103215b6434c90eeec1606f16f04503f94 /ffi.c
parent1e35fa11db662e6237e76f800a9294809bcb1660 (diff)
downloadtxr-f9964fe5c922535d5284ad22d62fddbdca315e97.tar.gz
txr-f9964fe5c922535d5284ad22d62fddbdca315e97.tar.bz2
txr-f9964fe5c922535d5284ad22d62fddbdca315e97.zip
Handle returns of MPI functions that return MP_TOOBIG.
* arith.c (do_mp_error): New function. (num_from_buffer, plus, minus, mul, floordiv, expt, exptmod, logtrunc, sign_extend, ash, bit): Handle errors from select MPI functions: those that have the mp_ign attribute. * ffi.c (unum_carray, num_carray): Likewise. * rand.c (random): Likewise.
Diffstat (limited to 'ffi.c')
-rw-r--r--ffi.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/ffi.c b/ffi.c
index f8e133c9..fab5fa1e 100644
--- a/ffi.c
+++ b/ffi.c
@@ -4887,9 +4887,9 @@ val unum_carray(val carray)
struct txr_ffi_type *etft = scry->eltft;
ucnum size = (ucnum) etft->size * (ucnum) scry->nelem;
val ubn = make_bignum();
- if ((ucnum) (int) size != size)
- uw_throwf(error_s, lit("~a: bignum size overflow"), self, nao);
- mp_read_unsigned_bin(mp(ubn), scry->data, size);
+ mp_err mpe = mp_read_unsigned_bin(mp(ubn), scry->data, size);
+ if (mpe != MP_OKAY)
+ do_mp_error(self, mpe);
return normalize(ubn);
}
@@ -4901,9 +4901,9 @@ val num_carray(val carray)
ucnum size = (ucnum) etft->size * (ucnum) scry->nelem;
ucnum bits = size * 8;
val ubn = make_bignum();
- if ((ucnum) (int) size != size || bits / 8 != size)
- uw_throwf(error_s, lit("~a: bignum size overflow"), self, nao);
- mp_read_unsigned_bin(mp(ubn), scry->data, size);
+ mp_err mpe = mp_read_unsigned_bin(mp(ubn), scry->data, size);
+ if (mpe != MP_OKAY)
+ do_mp_error(self, mpe);
return sign_extend(normalize(ubn), unum(bits));
}