shithub: mc

Download patch

ref: 22267862832ef46191a23e97a10295f932bf41a8
parent: 349fb0a3a44d80d9655037eb660af844bc5a3244
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Jul 10 18:33:50 EDT 2018

Make bio and regex disposable.

--- a/lib/bio/bio.myr
+++ b/lib/bio/bio.myr
@@ -38,10 +38,18 @@
 	/* 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
--- a/lib/regex/compile.myr
+++ b/lib/regex/compile.myr
@@ -7,7 +7,12 @@
 	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
@@ -20,6 +25,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