diff options
-rw-r--r-- | jim.c | 14 | ||||
-rw-r--r-- | tests/alias.test | 17 |
2 files changed, 28 insertions, 3 deletions
@@ -5505,6 +5505,14 @@ int Jim_Collect(Jim_Interp *interp) continue; } + /* If the string is ::<reference we need to skip over the :: when doing the + * comparison + */ + if (str[0] == ':' && str[1] == ':') { + str +=2; + len -= 2; + } + /* Extract references from the object string repr. */ while (1) { int i; @@ -5526,9 +5534,9 @@ int Jim_Collect(Jim_Interp *interp) /* Ok, a reference for the given ID * was found. Mark it. */ - /* But if this is a command in the command table with refCount 1 - * don't mark it since it can be deleted. - */ + /* But if this is a command in the command table with refCount 1 + * don't mark it since it can be deleted. + */ if (p == str && objPtr->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 |