1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
From eccbc8541be2ba527cc47963ffccccf5e7540a41 Mon Sep 17 00:00:00 2001
From: Timo Paulssen <timonator@perpetuum-immobile.de>
Date: Tue, 15 Jan 2019 17:51:47 +0100
Subject: Make MoarVM Compatible With Old & New LibTomMath
Thanks to @czurnieden for the implementation and
making us aware of this issue.
Closes #1034
--- a/src/math/bigintops.c
+++ b/src/math/bigintops.c
@@ -1142,6 +1142,16 @@
return c;
}
+
+/*
+ The old version of LibTomMath has it publically defined the new one not,
+ so we can take the (non)existance as a marker.
+ */
+#ifndef MP_GEN_RANDOM_MAX
+#define MP_GEN_RANDOM_MAX MP_MASK
+#define MP_NEW_LTM_VERSION
+#endif
+
MVMObject * MVM_bigint_rand(MVMThreadContext *tc, MVMObject *type, MVMObject *b) {
MVMObject *result;
MVMP6bigintBody *ba;
@@ -1164,7 +1174,14 @@
if (use_small_arithmetic) {
if (MP_GEN_RANDOM_MAX >= abs(smallint_max)) {
- mp_digit result_int = MP_GEN_RANDOM();
+ mp_digit result_int ;
+#ifdef MP_NEW_LTM_VERSION
+ mp_digit p = MP_GEN_RANDOM_MAX;
+ mp_rand_digit(&p);
+ result_int = p;
+#else
+ result_int = MP_GEN_RANDOM();
+#endif
result_int = result_int % smallint_max;
if(have_to_negate)
result_int *= -1;
|