summaryrefslogtreecommitdiff
path: root/lib/regex
diff options
context:
space:
mode:
authorOri Bernstein <ori@markovcorp.com>2017-12-27 11:50:08 -0800
committerOri Bernstein <ori@markovcorp.com>2017-12-27 11:50:08 -0800
commitf069b33395af1e4a5213b5f5110d583c0af5be7b (patch)
treea58a03747ce604bd2b10d4de6d649fb93115845c /lib/regex
parentb1b28999b0f574f815db036dd1ba8318fb1ec35a (diff)
downloadmc-f069b33395af1e4a5213b5f5110d583c0af5be7b.tar.gz
Free all matching threads.
Diffstat (limited to 'lib/regex')
-rw-r--r--lib/regex/interp.myr14
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/regex/interp.myr b/lib/regex/interp.myr
index 3856c57..e7449b1 100644
--- a/lib/regex/interp.myr
+++ b/lib/regex/interp.myr
@@ -49,11 +49,11 @@ const search = {re, str
for var i = 0; i < str.len; i++
thr = run(re, str[i:], 0, false)
m = getmatches(re, thr)
+ cleanup(re)
match m
| `std.Some _: break
| `std.None: /* nothing */
;;
- cleanup(re)
;;
-> m
}
@@ -66,11 +66,11 @@ const isearch = {re, str
for var i = 0; i < str.len; i++
thr = run(re, str[i:], 0, false)
m = getidxmatches(re, thr)
+ cleanup(re)
match m
| `std.Some _: break
| `std.None: /* nothing */
;;
- cleanup(re)
;;
-> m
}
@@ -180,6 +180,7 @@ const getmatches = {re, thr
if thr == Zthr
-> `std.None
;;
+
ret = std.slalloc(re.nmatch)
for var i = 0; i < re.nmatch; i++
if thr.mgroup[i][0] != -1 && thr.mgroup[i][1] != -1
@@ -189,6 +190,7 @@ const getmatches = {re, thr
;;
;;
thrfree(re, thr)
+
-> `std.Some ret
}
@@ -269,6 +271,8 @@ const run = {re, str, idx, wholestr
goto done
elif !wholestr
bestmatch = thr
+ else
+ thrfree(re, thr)
;;
elif !thr.matched
std.bsput(states, thr.ip)
@@ -446,18 +450,16 @@ const mkthread = {re, ip
var thr : rethread#
thr = std.alloc()
-
thr.next = Zthr
-
thr.ip = ip
thr.tid = re.nexttid++
thr.dead = false
thr.matched = false
-
thr.mgroup = [][:]
-
re.nthr++
+ trace(re, thr, "\tcreated {}", thr.tid)
+
-> thr
}