File: fix-for-new-ltm.patch

package info (click to toggle)
moarvm 2018.12%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 18,196 kB
  • sloc: ansic: 223,172; perl: 7,638; sh: 4,452; makefile: 1,089; python: 568; asm: 8
file content (45 lines) | stat: -rw-r--r-- 1,301 bytes parent folder | download
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;