From 63ea50be35afb6d7b9dbcd20fe3c31de6187858e Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Mon, 16 Mar 2020 20:55:18 -0400 Subject: updated tests, fixed bugs --- std/mem.toc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'std') diff --git a/std/mem.toc b/std/mem.toc index 06890b5..5e8c5fa 100644 --- a/std/mem.toc +++ b/std/mem.toc @@ -1,14 +1,14 @@ -// TODO: check for failed malloc -malloc ::= #foreign("malloc", "libc.so.6") fn(#C size_t) #C &"void"; +// TODO: check for failed calloc +calloc ::= #foreign("calloc", "libc.so.6") fn(#C size_t, #C size_t) #C &"void"; free ::= #foreign("free", "libc.so.6") fn(#C &"void"); new ::= fn(t :: Type) &t { - malloc((sizeof t) as u64) + calloc(1, (sizeof t) as u64) } -news ::= fn(t :: Type, n :: int) []t { +news ::= fn(t :: Type, n : int) []t { s: []t; - s.data = malloc((n * sizeof t) as u64); + s.data = calloc(n as u64, (sizeof t) as u64); s.len = n; s } -- cgit v1.2.3