Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2003-05-12
22:37 • Ticket [636161ffff] Tcl_FS* problems on windows&threads status still Ope... artifact: 06b803b638 user: vincentdarley
2003-05-11
07:18 • Ticket [636161ffff]: 5 changes artifact: 7d6f972845 user: hobbs
2002-11-11
20:00 • Ticket [636161ffff]: 6 changes artifact: 5a8fd88f93 user: vincentdarley
05:41 • Ticket [636161ffff]: 5 changes artifact: 9d2f442165 user: zoro2
2002-11-10
18:39 • Ticket [636161ffff]: 4 changes artifact: 5fc8e52fd1 user: zoro2
11:26 • New ticket [636161ffff]. artifact: 7c82a81352 user: zoro2

Tcl_FS* problems on windows&threads

Open636161ffffffffffffffffffffffffffffffffffCreated 24 years agoUpdated 24 years ago
Descriptionplain2002-11-10 11:26:49
This simple code (run inside a threaded tclkit with
Itcl liked static) breaks on Windows:

package require Thread
load {} Itcl
set id [thread::create]
thread::send $id {load {} Itcl}

It panics out in thread's Tcl_FSEvalFile:

#0  0x004149db in Tcl_Close ()
#1  0x00452e2a in Tcl_FSEvalFile ()
#2  0x0042edbe in Tcl_SourceObjCmd ()
#3  0x00405bc6 in TclEvalObjvInternal ()
#4  0x00405d6f in Tcl_EvalObjv ()
#5  0x004069a4 in Tcl_EvalObjEx ()
#6  0x0042cabb in Tcl_UplevelObjCmd ()
#7  0x00405bc6 in TclEvalObjvInternal ()
#8  0x0042375e in TclExecuteByteCode ()
#9  0x00422ad3 in TclCompEvalObj ()
#10 0x0042d0e1 in TclObjInterpProc ()
#11 0x00405bc6 in TclEvalObjvInternal ()
#12 0x0042375e in TclExecuteByteCode ()
#13 0x00422ad3 in TclCompEvalObj ()
#14 0x0042d0e1 in TclObjInterpProc ()
#15 0x00405bc6 in TclEvalObjvInternal ()
#16 0x00405ac3 in TclEvalObjvInternal ()
#17 0x00406533 in Tcl_EvalEx ()
#18 0x00452e70 in Tcl_FSEvalFile ()
#19 0x0042edbe in Tcl_SourceObjCmd ()
#20 0x00405bc6 in TclEvalObjvInternal ()
#21 0x00405d6f in Tcl_EvalObjv ()
#22 0x004069a4 in Tcl_EvalObjEx ()
#23 0x0042cabb in Tcl_UplevelObjCmd ()
#24 0x00405bc6 in TclEvalObjvInternal ()
#25 0x0042375e in TclExecuteByteCode ()
#26 0x00422ad3 in TclCompEvalObj ()
#27 0x0042d0e1 in TclObjInterpProc ()
#28 0x00405bc6 in TclEvalObjvInternal ()
#29 0x0042375e in TclExecuteByteCode ()
#30 0x00422ad3 in TclCompEvalObj ()
#31 0x004069fa in Tcl_EvalObjEx ()
#32 0x004390c6 in NamespaceEvalCmd ()
#33 0x00438974 in Tcl_NamespaceObjCmd ()
#34 0x00405bc6 in TclEvalObjvInternal ()
#35 0x00406533 in Tcl_EvalEx ()
#36 0x004068cc in Tcl_Eval ()
#37 0x00482c9c in Itcl_Init ()
#38 0x0041eecb in Tcl_LoadObjCmd ()
#39 0x00405bc6 in TclEvalObjvInternal ()
#40 0x00406533 in Tcl_EvalEx ()
#41 0x0047cc3c in ThreadSendEval ()
#42 0x0047e073 in ThreadEventProc ()
#43 0x00458056 in Tcl_ServiceEvent ()
#44 0x004582fd in Tcl_DoOneEvent ()
#45 0x0047dcf0 in ThreadWait ()
#46 0x0047c69c in ThreadWaitObjCmd ()
#47 0x00405bc6 in TclEvalObjvInternal ()
#48 0x00406533 in Tcl_EvalEx ()
#49 0x004068cc in Tcl_Eval ()
#50 0x0047d052 in NewThread@4 ()
#51 0x7800248d in _libuser32_a_iname ()
#52 0x77e837cd in _libuser32_a_iname () 

When replaced Tcl_Close() in Tcl_FSEvalFile(), Tcl
panics about Tcl_FindHashEntry on deleted table. It
seems that refCount is messed somehow.

BT:
#1  0x0041fcb3 in BogusFind ()
#2  0x0043854a in Tcl_FindNamespaceVar ()
#3  0x00408525 in TclLookupSimpleVar ()
#4  0x00407ef9 in TclLookupVar ()
#5  0x00408b9f in Tcl_SetVar2Ex ()
#6  0x00408b37 in Tcl_SetVar2 ()
#7  0x004131fe in Tcl_SetErrorCodeVA ()
#8  0x00413235 in Tcl_SetErrorCode ()
#9  0x00405920 in TclInterpReady ()
#10 0x00405d43 in Tcl_EvalObjv ()
#11 0x004069a4 in Tcl_EvalObjEx ()
#12 0x004016cd in rcOutput ()
#13 0x00414708 in CloseChannel ()
#14 0x00414610 in FlushChannel ()
#15 0x00414aad in Tcl_Close ()
#16 0x004133cd in TclFinalizeIOSubsystem ()
#17 0x00410b82 in Tcl_FinalizeThread ()
#18 0x00410a61 in Tcl_Finalize ()
#19 0x00410823 in Tcl_Exit ()
#20 0x004dca8c in Tk_MainEx ()
#21 0x004022ae in WinMain@16 ()
#22 0x0057b131 in main ()
zoro2plain2002-11-10 18:39:05
Logged In: YES 
user_id=191529

Here's a quick fix which seems to work fine for loading Itcl
on windows. It is ugly and the problem does return in other
places as well :-(. I'll try and find the source of the problem.

--- tclO/generic/tclIOUtil.c        2002-08-16
16:37:50.000000000 +0200
+++ tcl/generic/tclIOUtil.c 2002-11-10 12:35:12.000000000 +0100
@@ -29,6 +29,7 @@
 /* for tclWinProcs->useWide */
 #include "tclWinInt.h"
 #endif
+#include "tclIO.h"

 /*
  * Prototypes for procedures defined later in this file.
@@ -1339,6 +1340,7 @@
        goto end;
     }
     chan = Tcl_FSOpenFileChannel(interp, pathPtr, "r", 0644);
+    ((Channel *) chan)->state->refCount=0;
     if (chan == (Tcl_Channel) NULL) {
         Tcl_ResetResult(interp);
        Tcl_AppendResult(interp, "couldn't read file \"",
zoro2plain2002-11-11 05:41:58
Logged In: YES 
user_id=191529

I digged a bit more and found out that this problem occured
with the vfs package - which is used in TclKit to load
itcl.tcl and other modules.

The problem is weird, and probably not vfs module related,
since it only happens in Tcl_FSEvalFile and only on Windows
- using Tcl's open/read/close does not cause any errors at
all. It probably sets refCount wrong somewhere in either vfs
or Tcl module.

A good workaround is to rewrite source to use
open/read/close for each thread:

proc ::source {file} {
    if {[catch {set fh [open $file r]; set body [read $fh];
close $fh} rc]} {
        return -code error -errorinfo $rc -errorcode
$::errorCode $rc
    }
    set s [info script]
    info script $file
    if {[catch {uplevel 1 $body} rc]==1} {
        info script $s
        catch {thread::send -async $threadpool::mainthread
[list puts $::errorInfo]}
        return -code error -errorinfo $rc -errorcode
$::errorCode $rc
    }
    info script $s
    return $rc
}

This code slows things down a bit, but it does not require
any patches to the core and may prove useful until a real
solution is found.
vincentdarleyplain2002-11-11 20:00:37
Logged In: YES 
user_id=32170

This appears to be an IO system problem, not a file system
problem.
hobbsplain2003-05-11 07:18:20
Logged In: YES 
user_id=72656

FWIW, I have also found the need to overload source with the 
open/read/close/eval alternative - but only in tclkits (works 
fine in regular shells).  I suspect that there is some VFS or 
tclkit issue lingering there.
vincentdarley Ticket [636161ffff]: 1 change [History diff]2003-05-12 22:37:13
Log in (anonymous is fine) to add a comment.