Skip to content

Instantly share code, notes, and snippets.

@niner
Created February 25, 2017 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niner/da7d13490b3548b5176fa2192eaeee8b to your computer and use it in GitHub Desktop.
Save niner/da7d13490b3548b5176fa2192eaeee8b to your computer and use it in GitHub Desktop.
diff --git a/src/6model/reprs/P6bigint.c b/src/6model/reprs/P6bigint.c
index 533766e9..d810a1c9 100644
--- a/src/6model/reprs/P6bigint.c
+++ b/src/6model/reprs/P6bigint.c
@@ -6,7 +6,7 @@
/* A forced 64-bit version of mp_get_long, since on some platforms long is
* not all that long. */
-static MVMuint64 mp_get_int64(MVMThreadContext *tc, mp_int * a) {
+static MVMuint64 mp_get_int64(MVMThreadContext *tc, mp_int * a, int sign) {
int i, bits;
MVMuint64 res;
@@ -15,7 +15,7 @@ static MVMuint64 mp_get_int64(MVMThreadContext *tc, mp_int * a) {
}
bits = mp_count_bits(a);
- if (bits > 64) {
+ if (bits > (sign ? 63 : 64)) {
MVM_exception_throw_adhoc(tc, "Cannot unbox %d bit wide bigint into native integer", bits);
}
@@ -92,10 +92,10 @@ static MVMint64 get_int(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, vo
if (MVM_BIGINT_IS_BIG(body)) {
mp_int *i = body->u.bigint;
if (MP_NEG == SIGN(i)) {
- return -mp_get_int64(tc, i);
+ return -mp_get_int64(tc, i, 1);
}
else {
- return mp_get_int64(tc, i);
+ return mp_get_int64(tc, i, 1);
}
}
else {
@@ -123,7 +123,7 @@ static MVMuint64 get_uint(MVMThreadContext *tc, MVMSTable *st, MVMObject *root,
if (MP_NEG == SIGN(i))
MVM_exception_throw_adhoc(tc, "Cannot unbox negative bigint into native unsigned integer");
else
- return mp_get_int64(tc, i);
+ return mp_get_int64(tc, i, 0);
}
else {
return body->u.smallint.value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment