summaryrefslogtreecommitdiffstats
path: root/mpi-patches/use-txr-allocator
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-12-09 22:25:51 -0800
committerKaz Kylheku <kaz@kylheku.com>2011-12-09 22:25:51 -0800
commit236a20e92316535bc75dde63d51431875e253bfb (patch)
tree6ec4fb84a27cb311027495db9d3c34b791fe207e /mpi-patches/use-txr-allocator
parentb1088a2502cba1a61b862f708489c8d4baa722fe (diff)
downloadtxr-236a20e92316535bc75dde63d51431875e253bfb.tar.gz
txr-236a20e92316535bc75dde63d51431875e253bfb.tar.bz2
txr-236a20e92316535bc75dde63d51431875e253bfb.zip
Bignum support, here we go!
Bignums, based on Michael Fromberger's MPI library, are integrated into the input syntax, stream output, equality testing, the garbage collector, and hashing. The plus operation handles transitions between fixnums and bignums. Other operations are still fixnum only. * Makefile (CFLAGS): Add mpi directory to include file search. (OBJS): Include new arith.o module and all of MPI_OBJS. (MPI_OBJS, MPI_OBJS_BASE): New variables. * configure (mpi_version, have_quilt, have_patch): New variables. Script detects whether patch and quilt are available. Unpacks mpi library, applies patches. Detects 128 bit integer type. Records more information in config.h about the sizes of types. * dep.mk: Updated. * depend.txr: Make work with paths that have directory components. * eval.c (eval_init): Rename of nump to fixnump. * gc.c (finalize, mark_obj): Handle BGNUM case. * hash.c: (hash_c_str): Changed to return unsigned long instead of long. (equal_hash): Handle BGNUM case. (eql_hash): Handle bignums with equal-hash, but other objects as eq. * lib.c (num_s): Variable renamed to fixnum_s. (bignum_s): New symbol variable. (code2type): Follow rename of num_s. Handle BGNUM case. (typeof): Follow rename of num_s. (eql): Handle bignums using equal, and other types using eq. (equal): Handle BGNUM case. (chk_calloc): New function. (c_num): Wording change in error message: is not a fixnum. (nump): Renamed to fixnump. (bignump): New function. (plus): Function removed, reimplemented in arith.c. (int_str): Handle integers which are too large for wcstol using bignum conversion. Base 0 is no longer passed to wcstol but converted to 10 because the special semantics for 0 would be inconsistent for bignums. (obj_init): Follow rename of num_s. Initialize bignum_s.
Diffstat (limited to 'mpi-patches/use-txr-allocator')
-rw-r--r--mpi-patches/use-txr-allocator70
1 files changed, 70 insertions, 0 deletions
diff --git a/mpi-patches/use-txr-allocator b/mpi-patches/use-txr-allocator
new file mode 100644
index 00000000..2f85a574
--- /dev/null
+++ b/mpi-patches/use-txr-allocator
@@ -0,0 +1,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