summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-09-04 00:01:57 -0700
committerOri Bernstein <ori@eigenstate.org>2017-09-04 00:01:57 -0700
commit99cc92c31eadabe470d781af2f5fd4410594e10e (patch)
treebecb7b37a86017052564637f6e52452fd7a12ef4 /lib
parent1b1439cd64f73986909b85c99c91c2195d4ab58f (diff)
downloadmc-99cc92c31eadabe470d781af2f5fd4410594e10e.tar.gz
Plug some leaks.
Diffstat (limited to 'lib')
-rw-r--r--lib/std/bigint.myr14
-rw-r--r--lib/std/bytealloc.myr2
-rw-r--r--lib/std/fltfmt.myr13
-rw-r--r--lib/std/fltparse.myr7
4 files changed, 25 insertions, 11 deletions
diff --git a/lib/std/bigint.myr b/lib/std/bigint.myr
index 45170dd..129890c 100644
--- a/lib/std/bigint.myr
+++ b/lib/std/bigint.myr
@@ -28,6 +28,7 @@ pkg std =
const bigdup : (a : bigint# -> bigint#)
const bigassign : (d : bigint#, s : bigint# -> bigint#)
const bigmove : (d : bigint#, s : bigint# -> bigint#)
+ const bigsteal : (d : bigint#, s : bigint# -> bigint#)
const bigparse : (s : byte[:] -> option(bigint#))
const bigclear : (a : bigint# -> bigint#)
const bigbfmt : (b : byte[:], a : bigint#, base : int -> size)
@@ -162,6 +163,12 @@ const bigmove = {d, s
-> d
}
+const bigsteal = {d, s
+ bigmove(d, s);
+ bigfree(s)
+ -> d
+}
+
const bigclear = {v
std.slfree(v.dig)
v.sign = 0
@@ -547,7 +554,7 @@ const bigdiv = {a : bigint#, b : bigint# -> bigint#
(q, r) = bigdivmod(a, b)
bigfree(r)
- -> bigmove(a, q)
+ -> bigsteal(a, q)
}
const bigmod = {a : bigint#, b : bigint# -> bigint#
@@ -555,7 +562,7 @@ const bigmod = {a : bigint#, b : bigint# -> bigint#
(q, r) = bigdivmod(a, b)
bigfree(q)
- -> bigmove(a, r)
+ -> bigsteal(a, r)
}
/* a /= b */
@@ -665,6 +672,7 @@ const bigdivmod = {a : bigint#, b : bigint# -> (bigint#, bigint#)
/* undo the biasing for remainder */
bigshri(u, shift)
trim(q)
+ bigfree(v)
-> (trim(q), trim(u))
}
@@ -698,7 +706,7 @@ const bigmodpow = {base, exp, mod
bigmul(base, base)
bigmod(base, mod)
;;
- -> bigmove(base, r)
+ -> bigsteal(base, r)
}
/* returns the number of leading zeros */
diff --git a/lib/std/bytealloc.myr b/lib/std/bytealloc.myr
index cfb6c72..76361ad 100644
--- a/lib/std/bytealloc.myr
+++ b/lib/std/bytealloc.myr
@@ -94,7 +94,7 @@ const zbytealloc = {sz
}
const tracealloc = {p, sz
- var stk : void#[13] /* [type, addr, sz, 10 stack slots] */
+ var stk : void#[23] /* [type, addr, sz, 10 stack slots] */
slfill(stk[:], (0 : void#))
stk[0] = (0 : void#)
diff --git a/lib/std/fltfmt.myr b/lib/std/fltfmt.myr
index 71bb183..9bf627d 100644
--- a/lib/std/fltfmt.myr
+++ b/lib/std/fltfmt.myr
@@ -63,12 +63,11 @@ const dragon4 = {sb, isneg, f, e, p, mode, cutoff
/* initialize */
roundup = false
- r = mkbigint(f)
- r = bigshli(r, max(e - p, 0))
+ u = mkbigint(0)
+ r = bigshli(mkbigint(f), max(e - p, 0))
s = bigshli(mkbigint(1), max(0, -(e - p)))
mm = bigshli(mkbigint(1), max((e - p), 0))
mp = bigdup(mm)
- u = mkbigint(0)
/* fixup: unequal gaps */
t = mkbigint(1)
@@ -224,10 +223,16 @@ const dragon4 = {sb, isneg, f, e, p, mode, cutoff
;;
;;
k--
-
while k >= -1
format(sb, 0, k--)
;;
+
+ bigfree(u)
+ bigfree(r)
+ bigfree(s)
+ bigfree(mm)
+ bigfree(mp)
+
}
const lowdig = {u
diff --git a/lib/std/fltparse.myr b/lib/std/fltparse.myr
index fcc97af..9836d1f 100644
--- a/lib/std/fltparse.myr
+++ b/lib/std/fltparse.myr
@@ -183,8 +183,8 @@ const fallback = {mant, exp, lim
while true
(xprime, rprime) = std.bigdivmod(u, v)
- std.bigmove(x, xprime)
- std.bigmove(r, rprime)
+ std.bigsteal(x, xprime)
+ std.bigsteal(r, rprime)
if k == lim.minexp
if std.biggei(x, lim.minsig) && std.biglei(x, lim.maxsig)
break
@@ -193,7 +193,8 @@ const fallback = {mant, exp, lim
goto done
;;
elif k > lim.maxexp
- -> std.flt64inf()
+ f = std.flt64inf()
+ goto done
;;
if std.biglti(x, lim.minsig)
std.bigmuli(u, 2)