[Starkit] Tclkit 8.4.11

Jeff Hobbs jeffh at ActiveState.com
Thu Sep 8 10:41:42 CEST 2005


> i found ./src/kit/src/kitInit.c ::
> 
>   "proc source file {\n"
>     "set old [info script]\n"
>     "info script $file\n"
>     "set fid [open $file]\n"
>     "set data [read $fid]\n"
>     "close $fid\n"
>     "uplevel 1 $data\n"
>     "info script $old\n"
>   "}\n"

	...[logger removed, note last line not reached]...

This source replacement was added due to some irregularities
with std channel inheritance on Windows as seen on Win/CE and
using starkits as Windows services.  It is not known to be
necessary anywhere else (although using a starkit as a unix
daemon may need checking).  It was a work-around to a problem
that more likely should be fixed in the C, but anyways ...

I see the problem quite clearly thanks to your logging.  If
you look at auto.tcl, it finishes the file with a 'return'.
The C version of source accepts this, and still correctly
resets the info script.  The workaround (which I wrote - my
bad) above does not handle this.  Simply seen as:

(Tcl) 51 % proc foo data {
puts "start"
puts "result: [uplevel 1 $data]"
puts "end"
}
(Tcl) 52 % foo {set a 1}
start
result: 1
end
(Tcl) 53 % foo {return}
start
(Tcl) 54 % list [catch {foo {return}} err] $err
start
0 {}

And simply corrected as:

(Tcl) 55 % proc foo data {
puts "start"
set code [catch {uplevel 1 $data} err]
puts "result: $code $err"
puts "end"
}
(Tcl) 56 % list [catch {foo {return}} err] $err
start
result: 2 
end
0 {}
(Tcl) 57 % 

JCW - I think the following may be more appropriate:

"proc source file {\n"
"    set old [info script]\n"
"    info script $file\n"
"    set fid [open $file]\n"
"    set data [read $fid]\n"
"    close $fid\n"
"    set code [catch {uplevel 1 $data} res]\n"
"    info script $old\n"
"    if {$code == 2} { set code 0 }\n"
"    return -code $code $res\n"
"}\n"

I think setting return to ok is the right thing to do.  Note
that we only use this ourselves for the restricted problem
case systems stated above.

Regards,

Jeff



More information about the Starkit mailing list