Skip to content

Commit

Permalink
throw "cannot unbox" when bigint is too large
Browse files Browse the repository at this point in the history
  • Loading branch information
FROGGS committed Aug 22, 2015
1 parent 64fba68 commit 4108c94
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/6model/reprs/P6bigint.c
Expand Up @@ -2,14 +2,19 @@

/* A forced 64-bit version of mp_get_long, since on some platforms long is
* not all that long. */
static MVMuint64 mp_get_int64(mp_int * a) {
int i;
static MVMuint64 mp_get_int64(MVMThreadContext *tc, mp_int * a) {
int i, bits;
MVMuint64 res;

if (a->used == 0) {
return 0;
}

bits = mp_count_bits(a);
if (bits > 64) {
MVM_exception_throw_adhoc(tc, "Cannot unbox %d bit wide bigint into native integer", bits);
}

/* get number of digits of the lsb we have to read */
i = MIN(a->used,(int)((sizeof(MVMuint64)*CHAR_BIT+DIGIT_BIT-1)/DIGIT_BIT))-1;

Expand Down Expand Up @@ -85,12 +90,12 @@ static MVMint64 get_int(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, vo
if (MP_LT == mp_cmp_d(i, 0)) {
MVMint64 ret;
mp_neg(i, i);
ret = mp_get_int64(i);
ret = mp_get_int64(tc, i);
mp_neg(i, i);
return -ret;
}
else {
return mp_get_int64(i);
return mp_get_int64(tc, i);
}
}
else {
Expand Down

0 comments on commit 4108c94

Please sign in to comment.