[MLton] cvs commit: fixed IntInf.size bug that leads to a seg fault
Stephen Weeks
sweeks@mlton.org
Sun, 12 Sep 2004 19:48:35 -0700
sweeks 04/09/12 19:48:33
Modified: basis-library/integer int-inf.sig int-inf.sml
basis-library/mlton int-inf.sig
doc changelog
doc/user-guide extensions.tex
runtime/basis IntInf.c
Log:
MAIL fixed IntInf.size bug that leads to a seg fault
size now returns 1 on small ints, as it used to.
MLton.IntInf.size is no longer exported.
Added an assert in the end of setFrontier() in IntInf.c to ensure that
we never set the frontier beyond the allotted bytes. I think that
check is sufficiently strong to catch the bug that we don't need to
take further measures like telling gmp not to realloc.
Revision Changes Path
1.11 +0 -1 mlton/basis-library/integer/int-inf.sig
Index: int-inf.sig
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/integer/int-inf.sig,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- int-inf.sig 10 Nov 2003 18:38:02 -0000 1.10
+++ int-inf.sig 13 Sep 2004 02:48:33 -0000 1.11
@@ -26,6 +26,5 @@
Big of Word.word Vector.vector
| Small of Int.int
val rep: int -> rep
- val size: int -> Int.int
val toInt64: int -> Int64.int
end
1.24 +2 -3 mlton/basis-library/integer/int-inf.sml
Index: int-inf.sml
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/integer/int-inf.sml,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- int-inf.sml 23 Jun 2004 17:16:02 -0000 1.23
+++ int-inf.sml 13 Sep 2004 02:48:33 -0000 1.24
@@ -1,4 +1,4 @@
-(* Copyright (C) 1999-2002 Henry Cejtin, Matthew Fluet, Suresh
+(* Copyright (C) 1999-2004 Henry Cejtin, Matthew Fluet, Suresh
* Jagannathan, and Stephen Weeks.
* Copyright (C) 1997-1999 NEC Research Institute.
*
@@ -63,7 +63,7 @@
Vector.length (Prim.toVector arg) -? 1
fun size (arg: bigInt): smallInt =
if isSmall arg
- then 0
+ then 1
else bigSize arg
val bytesPerWord = 0w4
@@ -1002,7 +1002,6 @@
val sameSign = bigSameSign
val scan = bigScan
val sign = bigSign
- val size = size
val toInt = bigToInt
val toInt64 = bigToInt64
val toLarge = fn x => x
1.7 +0 -1 mlton/basis-library/mlton/int-inf.sig
Index: int-inf.sig
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/mlton/int-inf.sig,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- int-inf.sig 13 Jan 2004 03:38:11 -0000 1.6
+++ int-inf.sig 13 Sep 2004 02:48:33 -0000 1.7
@@ -12,5 +12,4 @@
Big of word vector
| Small of int
val rep: t -> rep
- val size: t -> int
end
1.136 +4 -0 mlton/doc/changelog
Index: changelog
===================================================================
RCS file: /cvsroot/mlton/mlton/doc/changelog,v
retrieving revision 1.135
retrieving revision 1.136
diff -u -r1.135 -r1.136
--- changelog 6 Sep 2004 05:15:49 -0000 1.135
+++ changelog 13 Sep 2004 02:48:33 -0000 1.136
@@ -1,5 +1,9 @@
Here are the changes since version 20040227.
+* 2004-09-12
+ - Fixed bug in IntInf that could cause a seg fault.
+ - Remove MLton.IntInf.size.
+
* 2004-09-05
- Made -detect-overflow and -safe expert options.
1.75 +0 -5 mlton/doc/user-guide/extensions.tex
Index: extensions.tex
===================================================================
RCS file: /cvsroot/mlton/mlton/doc/user-guide/extensions.tex,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -r1.74 -r1.75
--- extensions.tex 6 Sep 2004 05:18:26 -0000 1.74
+++ extensions.tex 13 Sep 2004 02:48:33 -0000 1.75
@@ -294,7 +294,6 @@
Big of word vector
| Small of int
val rep: t -> rep
- val size: t -> int
end
\end{verbatim}
@@ -323,10 +322,6 @@
\entry{rep i}
return the underlying representation of i.
-
-\entry{size i}
-return the number of heap words taken by {\tt i}. Returns {\tt 0} if
-{\tt i} is small.
\end{description}
1.19 +12 -11 mlton/runtime/basis/IntInf.c
Index: IntInf.c
===================================================================
RCS file: /cvsroot/mlton/mlton/runtime/basis/IntInf.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- IntInf.c 7 Sep 2004 00:46:20 -0000 1.18
+++ IntInf.c 13 Sep 2004 02:48:33 -0000 1.19
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999-2002 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 1999-2004 Henry Cejtin, Matthew Fluet, Suresh
* Jagannathan, and Stephen Weeks.
* Copyright (C) 1997-1999 NEC Research Institute.
*
@@ -117,8 +117,9 @@
return (res);
}
-static inline void setFrontier (pointer p) {
+static inline void setFrontier (pointer p, uint bytes) {
p = GC_alignFrontier (&gcState, p);
+ assert (p - gcState.frontier <= bytes);
GC_profileAllocInc (&gcState, p - gcState.frontier);
gcState.frontier = p;
assert (gcState.frontier <= gcState.limitPlusSlop);
@@ -132,7 +133,7 @@
* If the answer doesn't need all of the space allocated, we adjust
* the array size and roll the frontier slightly back.
*/
-static pointer answer (__mpz_struct *ans) {
+static pointer answer (__mpz_struct *ans, uint bytes) {
bignum *bp;
int size;
@@ -167,14 +168,14 @@
return (pointer)(ans<<1 | 1);
}
}
- setFrontier ((pointer)&bp->limbs[size]);
+ setFrontier ((pointer)&bp->limbs[size], bytes);
bp->counter = 0;
bp->card = size + 1; /* +1 for isNeg word */
bp->magic = BIGMAGIC;
return (pointer)&bp->isneg;
}
-static pointer binary (pointer lhs, pointer rhs, uint bytes,
+static inline pointer binary (pointer lhs, pointer rhs, uint bytes,
void(*binop)(__mpz_struct *resmpz,
__gmp_const __mpz_struct *lhsspace,
__gmp_const __mpz_struct *rhsspace)) {
@@ -188,7 +189,7 @@
fill (lhs, &lhsmpz, lhsspace);
fill (rhs, &rhsmpz, rhsspace);
binop (&resmpz, &lhsmpz, &rhsmpz);
- return answer (&resmpz);
+ return answer (&resmpz, bytes);
}
pointer IntInf_add (pointer lhs, pointer rhs, uint bytes) {
@@ -252,7 +253,7 @@
initRes(&resmpz, bytes);
fill(arg, &argmpz, argspace);
unop(&resmpz, &argmpz);
- return answer(&resmpz);
+ return answer (&resmpz, bytes);
}
pointer IntInf_neg(pointer arg, uint bytes) {
@@ -282,7 +283,7 @@
initRes(&resmpz, bytes);
fill(arg, &argmpz, argspace);
shop(&resmpz, &argmpz, (ulong)shift);
- return answer(&resmpz);
+ return answer (&resmpz, bytes);
}
pointer IntInf_arshift(pointer arg, uint shift, uint bytes) {
@@ -373,7 +374,7 @@
sp->counter = 0;
sp->card = size;
sp->magic = STRMAGIC;
- setFrontier (&sp->chars[wordAlign(size)]);
+ setFrontier (&sp->chars[wordAlign(size)], bytes);
return (pointer)str;
}
@@ -459,7 +460,7 @@
resmpz._mp_d[qsize++] = carry;
}
resmpz._mp_size = resIsNeg ? - qsize : qsize;
- return answer (&resmpz);
+ return answer (&resmpz, bytes);
}
@@ -549,5 +550,5 @@
}
}
resmpz._mp_size = resIsNeg ? - nsize : nsize;
- return answer (&resmpz);
+ return answer (&resmpz, bytes);
}