--- original/library/tcl8.5/safe.tcl	2010-03-06 13:03:49.000000000 +0000
+++ patched/library/tcl8.5/safe.tcl	2010-03-08 19:01:07.000000000 +0000
@@ -337,11 +337,15 @@
 	incr i
     }
 
-    set morepaths [::tcl::tm::list]
+    # Reverse the list because ::tcl::tm::add adds to the head of the list.
+    set morepaths [lreverse [::tcl::tm::list]]
+    set firstpass 1
     while {[llength $morepaths]} {
 	set addpaths $morepaths
 	set morepaths {}
 
+	# Add each $dir to the access path if it is not already there.
+	# Set morepaths to the subdirectories of the $dir that are added.
 	foreach dir $addpaths {
 	    # Prevent the addition of dirs on the tm list to the
 	    # result if they are already known.
@@ -355,7 +359,12 @@
 	    lappend map_access_path    $token $dir
 	    lappend remap_access_path  $dir $token
 	    lappend norm_access_path   [file normalize $dir]
-	    lappend slave_tm_path $token
+	    if {$firstpass} {
+		# $dir is in [::tcl::tm::list] and belongs in the slave_tm_path.
+		# Later passes handle subdirectories, which belong in the
+		# access path but not in the module path.
+		lappend slave_tm_path  $token
+	    }
 	    incr i
 
 	    # [Bug 2854929]
@@ -366,6 +375,7 @@
 	    # subdirectories.
 	    lappend morepaths {*}[glob -nocomplain -directory $dir -type d *]
 	}
+	set firstpass 0
     }
 
     set state(access_path)       $access_path
@@ -1146,7 +1156,7 @@
     # access_path,slave : Ditto, as the path tokens as seen by the slave.
     # access_path,map   : dict ( token -> path )
     # access_path,remap : dict ( path -> token )
-    # tm_path_slave     : List of TM root directories, as tokens seen by the slave.
+    # tm_path_slave     : List of TM module paths, as tokens seen by the slave.
     # staticsok         : Value of option -statics
     # nestedok          : Value of option -nested
     # cleanupHook       : Value of option -deleteHook
