diff options
-rw-r--r-- | ext/rpatricia/rpatricia.c | 10 | ||||
-rw-r--r-- | test/test_gc.rb | 13 |
2 files changed, 19 insertions, 4 deletions
diff --git a/ext/rpatricia/rpatricia.c b/ext/rpatricia/rpatricia.c index f9564d2..866572c 100644 --- a/ext/rpatricia/rpatricia.c +++ b/ext/rpatricia/rpatricia.c @@ -12,13 +12,15 @@ static VALUE cPatricia, cNode; static void dummy(void) {} -/* - * this method only exists for backwards compatibility, we now rely - * on the GC to do all the dirty work of freeing node data for us - */ static VALUE p_destroy (VALUE self) { + patricia_tree_t *tree; + + Data_Get_Struct(self, patricia_tree_t, tree); + Clear_Patricia(tree, dummy); + tree->head = NULL; /* Clear_Patricia() should do this, actually */ + return Qtrue; } diff --git a/test/test_gc.rb b/test/test_gc.rb index 316d355..2ea6df1 100644 --- a/test/test_gc.rb +++ b/test/test_gc.rb @@ -15,6 +15,19 @@ class TestGc < Test::Unit::TestCase @strings.add('127.0.0.0/24', "localhost") end + def test_clear + 1_000_000.times do + @strings.clear + assert_equal 0, @strings.num_nodes + @strings.add('10.0.0.0/8', "big lan") + assert_equal 1, @strings.num_nodes + @strings.add('127.0.0.0/8', "localhost") + assert_equal 2, @strings.num_nodes + @strings.add('192.168.1.0/24', "home") + assert_equal 3, @strings.num_nodes + end + end + def test_gc_dup 100000.times do tmp = @strings.dup |