summaryrefslogtreecommitdiffstats
path: root/mpi-patches/use-txr-allocator
blob: 2f85a574ca7c6bdbd4a1d8eadc018b9f5be3d260 (plain)
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
Index: mpi-1.8.6/mpi.c
===================================================================
--- mpi-1.8.6.orig/mpi.c	2011-12-08 22:17:15.000000000 -0800
+++ mpi-1.8.6/mpi.c	2011-12-08 22:27:07.000000000 -0800
@@ -15,6 +15,11 @@
 #include <string.h>
 #include <ctype.h>
 
+typedef unsigned char mem_t;
+extern mem_t *chk_malloc(size_t size);
+extern mem_t *chk_calloc(size_t n, size_t size);
+extern mem_t *chk_realloc(mem_t *, size_t size);
+
 #if MP_DEBUG
 #include <stdio.h>
 
@@ -154,7 +159,7 @@
   #define  s_mp_copy(sp, dp, count) memcpy(dp, sp, (count) * sizeof(mp_digit))
  #endif /* MP_MEMCPY */
 
- #define  s_mp_alloc(nb, ni)  calloc(nb, ni)
+ #define  s_mp_alloc(nb, ni)  chk_calloc(nb, ni)
  #define  s_mp_free(ptr) {if(ptr) free(ptr);}
 #endif /* MP_MACRO */
 
@@ -282,7 +287,7 @@
 {
   ARGCHK(mp != NULL && prec > 0, MP_BADARG);
 
-  if((DIGITS(mp) = s_mp_alloc(prec, sizeof(mp_digit))) == NULL)
+  if((DIGITS(mp) = (mp_digit *) s_mp_alloc(prec, sizeof(mp_digit))) == NULL)
     return MP_MEM;
 
   SIGN(mp) = MP_ZPOS;
@@ -312,7 +317,7 @@
   if(mp == from)
     return MP_OKAY;
 
-  if((DIGITS(mp) = s_mp_alloc(USED(from), sizeof(mp_digit))) == NULL)
+  if((DIGITS(mp) = (mp_digit *) s_mp_alloc(USED(from), sizeof(mp_digit))) == NULL)
     return MP_MEM;
 
   s_mp_copy(DIGITS(from), DIGITS(mp), USED(from));
@@ -358,7 +363,7 @@
       s_mp_copy(DIGITS(from), DIGITS(to), USED(from));
       
     } else {
-      if((tmp = s_mp_alloc(USED(from), sizeof(mp_digit))) == NULL)
+      if((tmp = (mp_digit *) s_mp_alloc(USED(from), sizeof(mp_digit))) == NULL)
 	return MP_MEM;
 
       s_mp_copy(DIGITS(from), tmp, USED(from));
@@ -2670,7 +2675,7 @@
     /* Set min to next nearest default precision block size */
     min = ((min + (s_mp_defprec - 1)) / s_mp_defprec) * s_mp_defprec;
 
-    if((tmp = s_mp_alloc(min, sizeof(mp_digit))) == NULL)
+    if((tmp = (mp_digit *) s_mp_alloc(min, sizeof(mp_digit))) == NULL)
       return MP_MEM;
 
     s_mp_copy(DIGITS(mp), tmp, USED(mp));
@@ -2757,7 +2762,7 @@
 /* Allocate ni records of nb bytes each, and return a pointer to that     */
 void    *s_mp_alloc(size_t nb, size_t ni)
 {
-  return calloc(nb, ni);
+  return chk_calloc(nb, ni);
 
 } /* end s_mp_alloc() */
 #endif