Hello,

last weekend I started another try to implement the
InterpCmd class. It is still far from ready (right now
the Tcl8.3 interp.test runs quiet only until test 17.4).

But since I don't trust my hard disks any longer,
I will make the diffs public as soon as possible :-)

So here are some minor patches to Channel related
classes: Corrected error messages and a move of the
actual closing of the channel from CloseCmd.cmdProc()
into TclIO.unregisterChannel().

I think, I will release the next set of patches with the
real InterpCmd classes, when the interp.test runs smooth
until test 19.9. All tests after that are related to safe
interps, so there seems to be a good point for a milestone,
having an interp command only for the "unsafe" features.

Stay tuned...
Greetings, Krischan
-- 
Christian Krone, SQL Datenbanksysteme GmbH
Mail mailto:[EMAIL PROTECTED]
--- Channel.java.org    Sun May 16 08:15:28 1999
+++ Channel.java        Sun Jul 16 19:44:56 2000
@@ -37,6 +37,12 @@
     protected String chanName;
 
     /**
+     * How many interpreters hold references to this IO channel?
+     */
+
+    protected int refCount;
+
+    /**
      * Perform a read on the sub-classed channel.  
      * 
      * @param interp is used for TclExceptions.  
--- CloseCmd.java.org   Wed Oct 14 23:09:19 1998
+++ CloseCmd.java       Sun Jul 16 20:14:22 2000
@@ -43,13 +43,6 @@
                     + argv[1].toString() + "\"");
        }
 
-       try {
-           chan.close();
-           TclIO.unregisterChannel(interp, chan);
-       } catch (IOException e) {
-           throw new TclRuntimeError(
-                   "CloseCmd.cmdProc() Error: IOException when closing " +
-                   chan.getChanName());
-       }
+       TclIO.unregisterChannel(interp, chan);
     }
 }
--- FileChannel.java.org        Mon May 24 14:44:49 1999
+++ FileChannel.java    Sun Jul 16 21:13:01 2000
@@ -174,8 +174,8 @@
            throw new TclRuntimeError("FileChannel.read: null file object");
        }
        if ((mode & TclIO.WRONLY) != 0) {
-           throw new TclException(interp, "channel" +
-               getChanName() + "\"wasn't opened for reading");
+           throw new TclException(interp, "channel \"" +
+               getChanName() + "\" wasn't opened for reading");
        }
 
        // Create the Buffered Reader if it does not already exist
--- StdChannel.java.org Mon May 24 14:43:50 1999
+++ StdChannel.java     Sun Jul 16 21:08:58 2000
@@ -316,4 +316,27 @@
     boolean eof() {
        return eofCond;
     }
+
+    /** 
+     * Gets the chanName that is the key for the chanTable hashtable.
+     * @return channelId
+     */
+
+    String getChanName() {
+        switch (stdType) {
+            case STDIN: {
+               return "stdin";
+           }
+            case STDOUT: {
+               return "stdout";
+           } 
+           case STDERR: {
+               return "stderr";
+           }
+           default: {
+               throw new TclRuntimeError(
+                        "Error: unexpected stdType for StdChannel");
+           }
+       }
+    }
 }
--- TclIO.java.org      Wed Oct 14 23:09:20 1998
+++ TclIO.java  Sun Jul 16 20:18:25 2000
@@ -68,14 +68,25 @@
         if (interp != null) {
             Hashtable chanTable = getInterpChanTable(interp);
            chanTable.put(chan.getChanName(), chan);
+           chan.refCount++;
        }
     }
 
 
     static void unregisterChannel(Interp interp, Channel chan) {
         
-        Hashtable chanTable = getInterpChanTable(interp);
+       Hashtable chanTable = getInterpChanTable(interp);
        chanTable.remove(chan.getChanName());
+
+       if (--chan.refCount < 0) {
+           try {
+             chan.close();
+           } catch (IOException e) {
+             throw new TclRuntimeError(
+                   "CloseCmd.cmdProc() Error: IOException when closing " +
+                   chan.getChanName());
+           }
+       }
     }
 
 

Reply via email to