From 500866719dde1cb03d87b550cc8998b31d9e1316 Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Thu, 8 Jul 2021 22:15:07 +1000 Subject: collect: correctly handle references as globally scoped names When a reference is used as a command name (e.g. in oo.tcl) it is created in the global namespace as :: --- jim.c | 14 +++++++++++--- tests/alias.test | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/jim.c b/jim.c index cfc0f8f..f339758 100644 --- a/jim.c +++ b/jim.c @@ -5505,6 +5505,14 @@ int Jim_Collect(Jim_Interp *interp) continue; } + /* If the string is ::refCount == 1 && Jim_FindHashEntry(&interp->commands, objPtr)) { #ifdef JIM_DEBUG_GC printf("No MARK: %lu - command with refcount=1\n", id); diff --git a/tests/alias.test b/tests/alias.test index 00870d1..9ad2dfd 100644 --- a/tests/alias.test +++ b/tests/alias.test @@ -265,4 +265,21 @@ test upcall-1.6 {delete local command with upcall} -body { rename a c } -returnCodes error -result {can't rename local command "a"} +test collect-1.1 {ensure globally scoped references are deleted} { + collect + set result {} + + # Create a globally scoped reference as a function name + set a ::[ref testfunction -] + proc $a {} { return 3 } + lappend result [$a] + # It shouldn't be collected + lappend result [collect] + lappend result [$a] + unset a + # Now it should be collected + lappend result [collect] + set result +} {3 0 3 1} + testreport -- cgit v1.1