summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-07-10 22:33:50 -0700
committerOri Bernstein <ori@eigenstate.org>2018-07-10 22:33:50 -0700
commit22267862832ef46191a23e97a10295f932bf41a8 (patch)
treec9815e348560bb139aba6abb62be7be93b726a57
parent349fb0a3a44d80d9655037eb660af844bc5a3244 (diff)
downloadmc-22267862832ef46191a23e97a10295f932bf41a8.tar.gz
Make bio and regex disposable.
-rw-r--r--lib/bio/bio.myr8
-rw-r--r--lib/regex/compile.myr17
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/bio/bio.myr b/lib/bio/bio.myr
index b76f985..032a926 100644
--- a/lib/bio/bio.myr
+++ b/lib/bio/bio.myr
@@ -38,11 +38,19 @@ pkg bio =
/* pkg funcs */
pkglocal const ensureread : (f : file#, n : std.size -> std.result(std.size, err))
pkglocal const ensurewrite : (f : file#, n : std.size -> std.result(std.size, err))
+
+ impl disposable file#
;;
const Bufsz = 16*std.KiB
const Small = 512
+impl disposable file# =
+ __dispose__ = {f
+ close(f)
+ }
+;;
+
/* Creates a file from an fd, opened in the given mode. */
const mk = {mode, vt
var f
diff --git a/lib/regex/compile.myr b/lib/regex/compile.myr
index 0d05b81..3d56bb7 100644
--- a/lib/regex/compile.myr
+++ b/lib/regex/compile.myr
@@ -7,7 +7,12 @@ pkg regex =
const parse : (re : byte[:] -> std.result(ast#, status))
const compile : (re : byte[:] -> std.result(regex#, status))
const dbgcompile : (re : byte[:], trace : bool -> std.result(regex#, status))
+
const free : (re : regex# -> void)
+ const astfree : (re : ast# -> void)
+
+ impl disposable regex#
+ impl disposable ast#
;;
type parseresult = union
@@ -21,6 +26,18 @@ const compile = {pat
-> regexcompile(std.mk([.pat = pat, .nmatch = 1]), 0)
}
+impl disposable regex# =
+ __dispose__ = {re
+ free(re)
+ }
+;;
+
+impl disposable ast# =
+ __dispose__ = {ast
+ astfree(ast)
+ }
+;;
+
const parse = {pat
var re