This repository has been archived by the owner on Nov 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mini-gmp.patch
169 lines (157 loc) · 4.09 KB
/
mini-gmp.patch
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
diff --git a/mini-gmp-6.3.0/mini-gmp.c b/mini-gmp-6.3.0/mini-gmp.c
index 69a72bf..e34d431 100644
--- a/mini-gmp-6.3.0/mini-gmp.c
+++ b/mini-gmp-6.3.0/mini-gmp.c
@@ -42,10 +42,11 @@ see https://www.gnu.org/licenses/. */
mpn/generic/sbpi1_div_qr.c, mpn/generic/sub_n.c,
mpn/generic/submul_1.c. */
-#include <assert.h>
+#define assert(expression) ((void)0)
+//#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <stdio.h>
+//#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -55,7 +56,41 @@ see https://www.gnu.org/licenses/. */
#include <float.h>
#endif
-
+void free(void*ptr) {}
+
+#define HEAP_SIZE 1024*1024*5 // 5MB
+char heap[HEAP_SIZE] __attribute__((aligned(8)));
+
+void * malloc(size_t size) {
+ #define HEAP_SIZE 1024*1024*5
+ static char* current_free_heap_ptr = heap;
+
+ // If size is 0, then malloc() returns either NULL, or a unique pointer value
+ // that can later be successfully passed to free()
+ if (size == 0) {
+ return NULL;
+ }
+
+ // check that there are enough space to allocate. If not,
+ // return NULL.
+ // On error, these functions return NULL.
+ if (current_free_heap_ptr + size > heap + HEAP_SIZE) {
+ return NULL;
+ }
+
+ void *ret = current_free_heap_ptr;
+ current_free_heap_ptr += (size + 7) & ~7;
+ return ret;
+}
+
+void *realloc( void *ptr, size_t new_size ) {
+ return malloc(new_size);
+}
+
+void abort() {
+ while (1) {}
+}
+
/* Macros */
#define GMP_LIMB_BITS (sizeof(mp_limb_t) * CHAR_BIT)
@@ -288,7 +323,7 @@ const int mp_bits_per_limb = GMP_LIMB_BITS;
static void
gmp_die (const char *msg)
{
- fprintf (stderr, "%s\n", msg);
+ //fprintf (stderr, "%s\n", msg);
abort();
}
@@ -4428,6 +4463,7 @@ mpz_init_set_str (mpz_t r, const char *sp, int base)
return mpz_set_str (r, sp, base);
}
+#if 0
size_t
mpz_out_str (FILE *stream, int base, const mpz_t x)
{
@@ -4442,7 +4478,7 @@ mpz_out_str (FILE *stream, int base, const mpz_t x)
gmp_free (str, len + 1);
return n;
}
-
+#endif
static int
gmp_detect_endian (void)
diff --git a/mini-gmp-6.3.0/mini-mpq.c b/mini-gmp-6.3.0/mini-mpq.c
index 58ce37f..a8cbc51 100644
--- a/mini-gmp-6.3.0/mini-mpq.c
+++ b/mini-gmp-6.3.0/mini-mpq.c
@@ -33,14 +33,50 @@ You should have received copies of the GNU General Public License and the
GNU Lesser General Public License along with the GNU MP Library. If not,
see https://www.gnu.org/licenses/. */
-#include <assert.h>
+#define assert(expression) ((void)0)
+//#include <assert.h>
#include <limits.h>
-#include <stdio.h>
+//#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mini-mpq.h"
+void free(void*ptr) {}
+
+#define HEAP_SIZE 1024*1024*5 // 5MB
+char heap[HEAP_SIZE] __attribute__((aligned(8)));
+
+void * malloc(size_t size) {
+ #define HEAP_SIZE 1024*1024*5
+ static char* current_free_heap_ptr = heap;
+
+ // If size is 0, then malloc() returns either NULL, or a unique pointer value
+ // that can later be successfully passed to free()
+ if (size == 0) {
+ return NULL;
+ }
+
+ // check that there are enough space to allocate. If not,
+ // return NULL.
+ // On error, these functions return NULL.
+ if (current_free_heap_ptr + size > heap + HEAP_SIZE) {
+ return NULL;
+ }
+
+ void *ret = current_free_heap_ptr;
+ current_free_heap_ptr += (size + 7) & ~7;
+ return ret;
+}
+
+void *realloc( void *ptr, size_t new_size ) {
+ return malloc(new_size);
+}
+
+void abort() {
+ while (1) {}
+}
+
#ifndef GMP_LIMB_HIGHBIT
/* Define macros and static functions already defined by mini-gmp.c */
#define GMP_LIMB_BITS (sizeof(mp_limb_t) * CHAR_BIT)
@@ -61,7 +97,7 @@ mpz_roinit_normal_n (mpz_t x, mp_srcptr xp, mp_size_t xs)
static void
gmp_die (const char *msg)
{
- fprintf (stderr, "%s\n", msg);
+ //fprintf (stderr, "%s\n", msg);
abort();
}
#endif
@@ -507,6 +543,7 @@ mpq_get_str (char *sp, int base, const mpq_t q)
return res;
}
+#if 0
size_t
mpq_out_str (FILE *stream, int base, const mpq_t x)
{
@@ -523,6 +560,7 @@ mpq_out_str (FILE *stream, int base, const mpq_t x)
gmp_free_func (str, len + 1);
return n;
}
+#endif
int
mpq_set_str (mpq_t r, const char *sp, int base)