From 7ea416f4c33631d76fd5b12830c0d326803061c1 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Fri, 25 Jun 2010 23:57:30 -0700 Subject: [PATCH] Add callable gc method exposed to user code, use it in mlist-cycle.rs test (still not quite working; some memory corruption in the recursive tag constructors, not the GC) --- src/lib/sys.rs | 1 + src/rt/rust_builtin.cpp | 5 +++++ src/test/run-pass/mlist-cycle.rs | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/src/lib/sys.rs b/src/lib/sys.rs index 84da28f7253..3d858413375 100644 --- a/src/lib/sys.rs +++ b/src/lib/sys.rs @@ -3,5 +3,6 @@ fn size_of[T]() -> uint; fn align_of[T]() -> uint; fn refcount[T](@T t) -> uint; + fn gc(); } diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 71aa644b144..eb84355f169 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -81,6 +81,11 @@ refcount(rust_task *task, type_desc *t, size_t *v) { return (*v) - 1; } +extern "C" CDECL void +gc(rust_task *task) { + task->gc(1); +} + extern "C" CDECL rust_vec* vec_alloc(rust_task *task, type_desc *t, size_t n_elts) { diff --git a/src/test/run-pass/mlist-cycle.rs b/src/test/run-pass/mlist-cycle.rs index 2a371317541..313455f8e68 100644 --- a/src/test/run-pass/mlist-cycle.rs +++ b/src/test/run-pass/mlist-cycle.rs @@ -1,5 +1,7 @@ // -*- rust -*- +use std; + type cell = tup(mutable @list); type list = tag(link(@cell), nil()); @@ -7,4 +9,6 @@ fn main() { let @cell first = tup(@nil()); let @cell second = tup(@link(first)); first._0 = link(second); + std.sys.rustrt.gc(); + let @cell third = tup(@nil()); }