ref: 99cc92c31eadabe470d781af2f5fd4410594e10e
parent: 1b1439cd64f73986909b85c99c91c2195d4ab58f
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Sep 3 20:01:57 EDT 2017
Plug some leaks.
--- a/lib/std/bigint.myr
+++ b/lib/std/bigint.myr
@@ -28,6 +28,7 @@
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 @@
-> 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 @@
(q, r) = bigdivmod(a, b)
bigfree(r)
- -> bigmove(a, q)
+ -> bigsteal(a, q)
}
const bigmod = {a : bigint#, b : bigint# -> bigint#
@@ -555,7 +562,7 @@
(q, r) = bigdivmod(a, b)
bigfree(q)
- -> bigmove(a, r)
+ -> bigsteal(a, r)
}
/* a /= b */
@@ -665,6 +672,7 @@
/* undo the biasing for remainder */
bigshri(u, shift)
trim(q)
+ bigfree(v)
-> (trim(q), trim(u))
}
@@ -698,7 +706,7 @@
bigmul(base, base)
bigmod(base, mod)
;;
- -> bigmove(base, r)
+ -> bigsteal(base, r)
}
/* returns the number of leading zeros */
--- a/lib/std/bytealloc.myr
+++ b/lib/std/bytealloc.myr
@@ -94,7 +94,7 @@
}
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#)
--- a/lib/std/fltfmt.myr
+++ b/lib/std/fltfmt.myr
@@ -63,12 +63,11 @@
/* 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 @@
;;
;;
k--
-
while k >= -1
format(sb, 0, k--)
;;
+
+ bigfree(u)
+ bigfree(r)
+ bigfree(s)
+ bigfree(mm)
+ bigfree(mp)
+
}
const lowdig = {u
--- a/lib/std/fltparse.myr
+++ b/lib/std/fltparse.myr
@@ -183,8 +183,8 @@
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 @@
goto done
;;
elif k > lim.maxexp
- -> std.flt64inf()
+ f = std.flt64inf()
+ goto done
;;
if std.biglti(x, lim.minsig)
std.bigmuli(u, 2)