tcl-websh-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ronnie Brunner <ron...@netcetera.ch>
Subject Re: "cleanups": 4726
Date Thu, 13 Dec 2001 15:35:08 GMT
> I was thinking of something that just does a more simplistic cleanup:

I see the point, but I'm not sure whether this really helps. Modified
procs, namesapce vars, and global vars are all leaking. I'm sure you could
walk through namespaces and gather ALL variables including their
values in [Entry] and unset new vars and reset old vars in [Exit] (you
could even do that with all procs), but this just seems a very clumsy
approach to do the getstate in Tcl instead of in C.

After all this, it still seems the easiest to make the developer
responsible for keeping track of "session cross-talk" unless we can
really provide something that works (including odd stuff like loading
a library during a session).

> namespace eval sentry {
>     array set beginvars {}
>     array set beginfiles {}
>     array set beginprocs {}
>     set varpattern {}
>     set filepattern {}
>     set procpattern {}
> }
> 
> proc sentry::Entry { {varpat ""} {filepat ""} {procpat ""} } {
>     variable beginvars
>     variable beginfiles
>     variable varpattern $varpat
>     variable filepattern $filepat
>     variable procpattern $procpat
> 
>     if { $varpattern == "" } {
> 	set vars [uplevel [list info vars]]
>     } else {
> 	set vars [uplevel [list info vars $varpattern]]
>     }
>     foreach vr $vars {
> 	set beginvars($vr) 1
>     }
> 
>     if { $filepattern == "" } {
> 	set files [file channels]
>     } else {
> 	set files [file channels $filepattern]
>     }
>     foreach fl $files {
> 	set beginfiles($fl) 1
>     }
> 
>     if { $procpattern == "" } {
> 	set procs [uplevel [list info procs]]
>     } else {
> 	set procs [uplevel [list info procs $procpattern]]
>     }
>     foreach pr $procs {
> 	set beginprocs($pr) 1
>     }
> 
>     return [list [llength $vars] [llength $files] [llength $procs]] 
> }
> 
> proc sentry::Exit { } {
>     variable beginvars
>     variable beginfiles
>     variable beginprocs
>     variable varpattern 
>     variable filepattern
>     variable procpattern
> 
>     if { $varpattern == "" } {
> 	set vars [uplevel [list info vars]]
>     } else {
> 	set vars [uplevel [list info vars $varpattern]]
>     }
> 
>     if { $filepattern == "" } {
> 	set files [file channels]
>     } else {
> 	set files [file channels $filepattern]
>     }
> 
>     if { $procpattern == "" } {
> 	set procs [uplevel [list info procs]]
>     } else {
> 	set procs [uplevel [list info procs $procpattern]]
>     }
>     foreach vr $vars {
> 	if { ! [info exists beginvars($vr)] } {
> 	    uplevel [list unset $vr]
> 	}
>     }
>     
>     foreach fl $files {
> 	if { ! [info exists beginfiles($fl)] } {
> 	    close $fl
> 	}
>     }
> 
>     foreach pr $procs {
> 	if { ! [info exists beginprocs($pr)] } {
> 	    uplevel [list rename $pr {}]
> 	}
>     }
> }
> 
> Although the idea of saving the interpreter state is intriguing, I
> think that it might be more of a long term project to add something to
> Tcl itself.

------------------------------------------------------------------------
Ronnie Brunner                               ronnie.brunner@netcetera.ch
Netcetera AG, 8040 Zuerich    phone +41 1 247 79 79 Fax: +41 1 247 70 75

Mime
View raw message