[armedbear-cvs] r11991 - trunk/abcl/src/org/armedbear/lisp

Ville Voutilainen vvoutilainen at common-lisp.net
Wed Jun 3 20:05:51 UTC 2009


Author: vvoutilainen
Date: Wed Jun  3 16:05:46 2009
New Revision: 11991

Log:
Move IOException handling away from reader's tight loops.


Modified:
   trunk/abcl/src/org/armedbear/lisp/ConcatenatedStream.java
   trunk/abcl/src/org/armedbear/lisp/EchoStream.java
   trunk/abcl/src/org/armedbear/lisp/FaslReader.java
   trunk/abcl/src/org/armedbear/lisp/LispReader.java
   trunk/abcl/src/org/armedbear/lisp/Stream.java
   trunk/abcl/src/org/armedbear/lisp/SynonymStream.java
   trunk/abcl/src/org/armedbear/lisp/TwoWayStream.java

Modified: trunk/abcl/src/org/armedbear/lisp/ConcatenatedStream.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/ConcatenatedStream.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/ConcatenatedStream.java	Wed Jun  3 16:05:46 2009
@@ -111,7 +111,14 @@
             else
                 return eofValue;
         }
-        return _charReady() ? readChar(eofError, eofValue) : NIL;
+	try 
+	  {
+	    return _charReady() ? readChar(eofError, eofValue) : NIL;
+	  }
+	catch (java.io.IOException e)
+	  {
+	    return error(new StreamError(this, e));
+	  }
     }
 
     @Override
@@ -132,7 +139,7 @@
 
     // Returns -1 at end of file.
     @Override
-    protected int _readChar() throws ConditionThrowable
+    protected int _readChar() throws ConditionThrowable, java.io.IOException
     {
         int n;
         if (unreadChar >= 0) {
@@ -159,7 +166,7 @@
     }
 
     @Override
-    protected boolean _charReady() throws ConditionThrowable
+    protected boolean _charReady() throws ConditionThrowable, java.io.IOException
     {
         if (unreadChar >= 0)
             return true;

Modified: trunk/abcl/src/org/armedbear/lisp/EchoStream.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/EchoStream.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/EchoStream.java	Wed Jun  3 16:05:46 2009
@@ -133,7 +133,7 @@
 
     // Returns -1 at end of file.
     @Override
-    protected int _readChar() throws ConditionThrowable
+    protected int _readChar() throws ConditionThrowable, java.io.IOException
     {
         int n = in._readChar();
         if (n >= 0) {
@@ -147,14 +147,14 @@
     }
 
     @Override
-    protected void _unreadChar(int n) throws ConditionThrowable
+    protected void _unreadChar(int n) throws ConditionThrowable, java.io.IOException
     {
         in._unreadChar(n);
         unreadChar = n;
     }
 
     @Override
-    protected boolean _charReady() throws ConditionThrowable
+    protected boolean _charReady() throws ConditionThrowable, java.io.IOException
     {
         return in._charReady();
     }

Modified: trunk/abcl/src/org/armedbear/lisp/FaslReader.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/FaslReader.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/FaslReader.java	Wed Jun  3 16:05:46 2009
@@ -44,12 +44,19 @@
         public LispObject execute(Stream stream, char ignored)
             throws ConditionThrowable
         {
-            while (true) {
+          try 
+            {
+              while (true) {
                 int n = stream._readChar();
                 if (n < 0)
-                    return null;
+                  return null;
                 if (n == '\n')
-                    return null;
+                  return null;
+              }
+            }
+          catch (java.io.IOException e)
+            {
+              return null;
             }
         }
     };
@@ -65,49 +72,57 @@
         {
             final Readtable rt = FaslReadtable.getInstance();
             FastStringBuffer sb = new FastStringBuffer();
-            while (true) {
-                int n = stream._readChar();
-                if (n < 0) {
+            try 
+              {
+                while (true) {
+                  int n = stream._readChar();
+                  if (n < 0) {
                     error(new EndOfFile(stream));
                     // Not reached.
                     return null;
-                }
-                char c = (char) n;
-                if (rt.getSyntaxType(c) == Readtable.SYNTAX_TYPE_SINGLE_ESCAPE) {
+                  }
+                  char c = (char) n;
+                  if (rt.getSyntaxType(c) == Readtable.SYNTAX_TYPE_SINGLE_ESCAPE) {
                     // Single escape.
                     n = stream._readChar();
                     if (n < 0) {
-                        error(new EndOfFile(stream));
-                        // Not reached.
-                        return null;
+                      error(new EndOfFile(stream));
+                      // Not reached.
+                      return null;
                     }
                     sb.append((char)n);
                     continue;
-                }
-                if (Utilities.isPlatformWindows) {
+                  }
+                  if (Utilities.isPlatformWindows) {
                     if (c == '\r') {
-                        n = stream._readChar();
-                        if (n < 0) {
-                            error(new EndOfFile(stream));
-                            // Not reached.
-                            return null;
-                        }
-                        if (n == '\n') {
-                            sb.append('\n');
-                        } else {
-                            // '\r' was not followed by '\n'.
-                            stream._unreadChar(n);
-                            sb.append('\r');
-                        }
-                        continue;
+                      n = stream._readChar();
+                      if (n < 0) {
+                        error(new EndOfFile(stream));
+                        // Not reached.
+                        return null;
+                      }
+                      if (n == '\n') {
+                        sb.append('\n');
+                      } else {
+                        // '\r' was not followed by '\n'.
+                        stream._unreadChar(n);
+                        sb.append('\r');
+                      }
+                      continue;
                     }
-                }
-                if (c == terminator)
+                  }
+                  if (c == terminator)
                     break;
-                // Default.
-                sb.append(c);
-            }
-            return new SimpleString(sb);
+                  // Default.
+                  sb.append(c);
+                }
+                return new SimpleString(sb);
+              }
+            catch (java.io.IOException e)
+              {
+                return new SimpleString(sb);
+		//                return null;
+              }
         }
     };
 
@@ -206,28 +221,38 @@
             final boolean suppress =
                 (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL);
             FastStringBuffer sb = new FastStringBuffer();
-            while (true) {
-                int ch = stream._readChar();
-                if (ch < 0)
+	    try 
+	      {
+		while (true) {
+		  int ch = stream._readChar();
+		  if (ch < 0)
                     break;
-                char c = (char) ch;
-                if (c == '0' || c == '1')
+		  char c = (char) ch;
+		  if (c == '0' || c == '1')
                     sb.append(c);
-                else {
+		  else {
                     int syntaxType = rt.getSyntaxType(c);
                     if (syntaxType == Readtable.SYNTAX_TYPE_WHITESPACE ||
                         syntaxType == Readtable.SYNTAX_TYPE_TERMINATING_MACRO) {
-                        stream._unreadChar(c);
-                        break;
+		      stream._unreadChar(c);
+		      break;
                     } else if (!suppress) {
-                        String name = LispCharacter.charToName(c);
-                        if (name == null)
-                            name = "#\\" + c;
-                        error(new ReaderError("Illegal element for bit-vector: " + name,
-                                               stream));
+		      String name = LispCharacter.charToName(c);
+		      if (name == null)
+			name = "#\\" + c;
+		      error(new ReaderError("Illegal element for bit-vector: " + name,
+					    stream));
                     }
-                }
-            }
+		  }
+		}
+	      }
+	    catch (java.io.IOException e)
+	      {
+		error(new ReaderError("IO error: ",
+				      stream));
+		return NIL;
+	      }
+
             if (suppress)
                 return NIL;
             if (n >= 0) {

Modified: trunk/abcl/src/org/armedbear/lisp/LispReader.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/LispReader.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/LispReader.java	Wed Jun  3 16:05:46 2009
@@ -44,12 +44,19 @@
         public LispObject execute(Stream stream, char ignored)
             throws ConditionThrowable
         {
-            while (true) {
+          try 
+            {
+              while (true) {
                 int n = stream._readChar();
                 if (n < 0)
-                    return null;
+                  return null;
                 if (n == '\n')
-                    return null;
+                  return null;
+              }
+            }
+          catch (java.io.IOException e)
+            {
+              return null;
             }
         }
     };
@@ -66,48 +73,56 @@
             final LispThread thread = LispThread.currentThread();
             final Readtable rt = (Readtable) Symbol.CURRENT_READTABLE.symbolValue(thread);
             FastStringBuffer sb = new FastStringBuffer();
-            while (true) {
-                int n = stream._readChar();
-                if (n < 0) {
+            try 
+              {
+                while (true) {
+                  int n = stream._readChar();
+                  if (n < 0) {
                     error(new EndOfFile(stream));
                     // Not reached.
                     return null;
-                }
-                char c = (char) n;
-                if (rt.getSyntaxType(c) == Readtable.SYNTAX_TYPE_SINGLE_ESCAPE) {
+                  }
+                  char c = (char) n;
+                  if (rt.getSyntaxType(c) == Readtable.SYNTAX_TYPE_SINGLE_ESCAPE) {
                     // Single escape.
                     n = stream._readChar();
                     if (n < 0) {
-                        error(new EndOfFile(stream));
-                        // Not reached.
-                        return null;
+                      error(new EndOfFile(stream));
+                      // Not reached.
+                      return null;
                     }
                     sb.append((char)n);
                     continue;
-                }
-                if (Utilities.isPlatformWindows) {
+                  }
+                  if (Utilities.isPlatformWindows) {
                     if (c == '\r') {
-                        n = stream._readChar();
-                        if (n < 0) {
-                            error(new EndOfFile(stream));
-                            // Not reached.
-                            return null;
-                        }
-                        if (n == '\n') {
-                            sb.append('\n');
-                        } else {
-                            // '\r' was not followed by '\n'.
-                            stream._unreadChar(n);
-                            sb.append('\r');
-                        }
-                        continue;
+                      n = stream._readChar();
+                      if (n < 0) {
+                        error(new EndOfFile(stream));
+                        // Not reached.
+                        return null;
+                      }
+                      if (n == '\n') {
+                        sb.append('\n');
+                      } else {
+                        // '\r' was not followed by '\n'.
+                        stream._unreadChar(n);
+                        sb.append('\r');
+                      }
+                      continue;
                     }
-                }
-                if (c == terminator)
+                  }
+                  if (c == terminator)
                     break;
-                // Default.
-                sb.append(c);
-            }
+                  // Default.
+                  sb.append(c);
+                }
+              }
+            catch (java.io.IOException e)
+              {
+                //error(new EndOfFile(stream));
+		return new SimpleString(sb);
+              }
             return new SimpleString(sb);
         }
     };
@@ -206,28 +221,36 @@
             final Readtable rt = (Readtable) Symbol.CURRENT_READTABLE.symbolValue(thread);
             final boolean suppress = Symbol.READ_SUPPRESS.symbolValue(thread) != NIL;
             FastStringBuffer sb = new FastStringBuffer();
-            while (true) {
-                int ch = stream._readChar();
-                if (ch < 0)
+            try 
+              {
+                while (true) {
+                  int ch = stream._readChar();
+                  if (ch < 0)
                     break;
-                char c = (char) ch;
-                if (c == '0' || c == '1')
+                  char c = (char) ch;
+                  if (c == '0' || c == '1')
                     sb.append(c);
-                else {
+                  else {
                     int syntaxType = rt.getSyntaxType(c);
                     if (syntaxType == Readtable.SYNTAX_TYPE_WHITESPACE ||
                         syntaxType == Readtable.SYNTAX_TYPE_TERMINATING_MACRO) {
-                        stream._unreadChar(c);
-                        break;
+                      stream._unreadChar(c);
+                      break;
                     } else if (!suppress) {
-                        String name = LispCharacter.charToName(c);
-                        if (name == null)
-                            name = "#\\" + c;
-                        error(new ReaderError("Illegal element for bit-vector: " + name,
-                                               stream));
+                      String name = LispCharacter.charToName(c);
+                      if (name == null)
+                        name = "#\\" + c;
+                      error(new ReaderError("Illegal element for bit-vector: " + name,
+                                            stream));
                     }
+                  }
                 }
-            }
+              }
+            catch (java.io.IOException e)
+              {
+                error(new ReaderError("IO error-vector: ",
+                                      stream));
+              }
             if (suppress)
                 return NIL;
             if (n >= 0) {

Modified: trunk/abcl/src/org/armedbear/lisp/Stream.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Stream.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/Stream.java	Wed Jun  3 16:05:46 2009
@@ -398,16 +398,22 @@
                                                  recursive, thread);
     if (result != eofValue && !recursive)
       {
-        if (_charReady())
+        try {
+          if (_charReady())
+            {
+              int n = _readChar();
+              if (n >= 0)
+                {
+                  char c = (char) n;
+                  Readtable rt = (Readtable) Symbol.CURRENT_READTABLE.symbolValue(thread);
+                  if (!rt.isWhitespace(c))
+                      _unreadChar(c);
+                }
+            } 
+        }
+        catch (IOException e) 
           {
-            int n = _readChar();
-            if (n >= 0)
-              {
-                char c = (char) n;
-                Readtable rt = (Readtable) Symbol.CURRENT_READTABLE.symbolValue(thread);
-                if (!rt.isWhitespace(c))
-                  _unreadChar(c);
-              }
+            return error(new StreamError(this, e));
           }
       }
     if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
@@ -432,7 +438,15 @@
         final Readtable rt = (Readtable) Symbol.CURRENT_READTABLE.symbolValue(thread);
         while (true)
           {
-            int n = _readChar();
+            int n = -1;
+            try
+              {
+                n = _readChar();
+              }
+            catch (IOException e)
+              {
+                error(new StreamError(this, e));
+              }
             if (n < 0)
               {
                 if (eofError)
@@ -467,33 +481,40 @@
                              boolean recursive, LispThread thread)
     throws ConditionThrowable
   {
-    LispObject result = faslReadPreservingWhitespace(eofError, eofValue,
-                                                     recursive, thread);
-    if (result != eofValue && !recursive)
+    try 
       {
-        if (_charReady())
+        LispObject result = faslReadPreservingWhitespace(eofError, eofValue,
+                                                         recursive, thread);
+        if (result != eofValue && !recursive)
           {
-            int n = _readChar();
-            if (n >= 0)
+            if (_charReady())
               {
-                char c = (char) n;
-                Readtable rt = FaslReadtable.getInstance();
-                if (!rt.isWhitespace(c))
-                  _unreadChar(c);
+                int n = _readChar();
+                if (n >= 0)
+                  {
+                    char c = (char) n;
+                    Readtable rt = FaslReadtable.getInstance();
+                    if (!rt.isWhitespace(c))
+                        _unreadChar(c);
+                  }
               }
           }
+        if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
+            return NIL;
+        else
+            return result;
+      }
+    catch (IOException e)
+      {
+        return error(new StreamError(this, e));
       }
-    if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
-      return NIL;
-    else
-      return result;
   }
 
   private final LispObject faslReadPreservingWhitespace(boolean eofError,
                                                         LispObject eofValue,
                                                         boolean recursive,
                                                         LispThread thread)
-    throws ConditionThrowable
+      throws ConditionThrowable, IOException
   {
     if (recursive)
       {
@@ -504,16 +525,16 @@
             if (n < 0)
               {
                 if (eofError)
-                  return error(new EndOfFile(this));
+                    return error(new EndOfFile(this));
                 else
-                  return eofValue;
+                    return eofValue;
               }
             char c = (char) n;
             if (rt.isWhitespace(c))
-              continue;
+                continue;
             LispObject result = processChar(c, rt);
             if (result != null)
-              return result;
+                return result;
           }
       }
     else
@@ -683,66 +704,74 @@
     Readtable rt = null;
     if (useFaslReadtable)
       rt = FaslReadtable.getInstance();
-    while (true)
+    try 
       {
-        if (!useFaslReadtable)
-          rt = (Readtable) Symbol.CURRENT_READTABLE.symbolValue(thread);
-        char c = flushWhitespace(rt);
-        if (c == ')')
-          {
-            return first == null ? NIL : first;
-          }
-        if (c == '.')
+        while (true)
           {
-            int n = _readChar();
-            if (n < 0)
-              return error(new EndOfFile(this));
-            char nextChar = (char) n;
-            if (isTokenDelimiter(nextChar, rt))
+            if (!useFaslReadtable)
+                rt = (Readtable) Symbol.CURRENT_READTABLE.symbolValue(thread);
+            char c = flushWhitespace(rt);
+            if (c == ')')
+              {
+                return first == null ? NIL : first;
+              }
+            if (c == '.')
               {
-                if (last == null)
+                int n = _readChar();
+                if (n < 0)
+                    return error(new EndOfFile(this));
+                char nextChar = (char) n;
+                if (isTokenDelimiter(nextChar, rt))
                   {
-                    if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
-                      return NIL;
-                    else
-                      return error(new ReaderError("Nothing appears before . in list.",
-                                                    this));
+                    if (last == null)
+                      {
+                        if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
+                            return NIL;
+                        else
+                            return error(new ReaderError("Nothing appears before . in list.",
+                                                         this));
+                      }
+                    _unreadChar(nextChar);
+                    LispObject obj = read(true, NIL, true, thread);
+                    if (requireProperList)
+                      {
+                        if (!obj.listp())
+                            error(new ReaderError("The value " +
+                                                  obj.writeToString() +
+                                                  " is not of type " +
+                                                  Symbol.LIST.writeToString() + ".",
+                                                  this));
+                      }
+                    last.cdr = obj;
+                    continue;
                   }
+                // normal token beginning with '.'
                 _unreadChar(nextChar);
-                LispObject obj = read(true, NIL, true, thread);
-                if (requireProperList)
-                  {
-                    if (!obj.listp())
-                      error(new ReaderError("The value " +
-                                             obj.writeToString() +
-                                             " is not of type " +
-                                             Symbol.LIST.writeToString() + ".",
-                                             this));
-                  }
-                last.cdr = obj;
+              }
+            LispObject obj = processChar(c, rt);
+            if (obj == null)
+              {
+                // A comment.
                 continue;
               }
-            // normal token beginning with '.'
-            _unreadChar(nextChar);
-          }
-        LispObject obj = processChar(c, rt);
-        if (obj == null)
-          {
-            // A comment.
-            continue;
-          }
-        if (first == null)
-          {
-            first = new Cons(obj);
-            last = first;
-          }
-        else
-          {
-            Cons newCons = new Cons(obj);
-            last.cdr = newCons;
-            last = newCons;
+            if (first == null)
+              {
+                first = new Cons(obj);
+                last = first;
+              }
+            else
+              {
+                Cons newCons = new Cons(obj);
+                last.cdr = newCons;
+                last = newCons;
+              }
           }
       }
+    catch (IOException e)
+      {
+        error(new StreamError(this, e));
+        return null;
+      }
   }
 
   private static final boolean isTokenDelimiter(char c, Readtable rt)
@@ -767,18 +796,25 @@
     throws ConditionThrowable
   {
     int numArg = -1;
-    char c;
-    while (true)
+    char c = 0;
+    try 
       {
-        int n = _readChar();
-        if (n < 0)
-          return error(new EndOfFile(this));
-        c = (char) n;
-        if (c < '0' || c > '9')
-          break;
-        if (numArg < 0)
-          numArg = 0;
-        numArg = numArg * 10 + c - '0';
+        while (true)
+          {
+            int n = _readChar();
+            if (n < 0)
+                return error(new EndOfFile(this));
+            c = (char) n;
+            if (c < '0' || c > '9')
+                break;
+            if (numArg < 0)
+                numArg = 0;
+            numArg = numArg * 10 + c - '0';
+          }
+      }
+    catch (IOException e)
+      {
+        error(new StreamError(this, e));
       }
     final LispThread thread = LispThread.currentThread();
     final Readtable rt;
@@ -809,61 +845,75 @@
   public LispObject readCharacterLiteral(Readtable rt, LispThread thread)
     throws ConditionThrowable
   {
-    int n = _readChar();
-    if (n < 0)
-      return error(new EndOfFile(this));
-    char c = (char) n;
-    FastStringBuffer sb = new FastStringBuffer(c);
-    while (true)
+    try 
       {
-        n = _readChar();
+        int n = _readChar();
         if (n < 0)
-          break;
-        c = (char) n;
-        if (rt.isWhitespace(c))
-          break;
-        if (c == '(' || c == ')')
+            return error(new EndOfFile(this));
+        char c = (char) n;
+        FastStringBuffer sb = new FastStringBuffer(c);
+        while (true)
           {
-            _unreadChar(c);
-            break;
+            n = _readChar();
+            if (n < 0)
+                break;
+            c = (char) n;
+            if (rt.isWhitespace(c))
+                break;
+            if (c == '(' || c == ')')
+              {
+                _unreadChar(c);
+                break;
+              }
+            sb.append(c);
           }
-        sb.append(c);
+        if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
+            return NIL;
+        if (sb.length() == 1)
+            return LispCharacter.getInstance(sb.charAt(0));
+        String token = sb.toString();
+        n = LispCharacter.nameToChar(token);
+        if (n >= 0)
+            return LispCharacter.getInstance((char)n);
+        return error(new LispError("Unrecognized character name: \"" + token + '"'));
+      }
+    catch (IOException e)
+      {
+        return error(new StreamError(this, e));
       }
-    if (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL)
-      return NIL;
-    if (sb.length() == 1)
-      return LispCharacter.getInstance(sb.charAt(0));
-    String token = sb.toString();
-    n = LispCharacter.nameToChar(token);
-    if (n >= 0)
-      return LispCharacter.getInstance((char)n);
-    return error(new LispError("Unrecognized character name: \"" + token + '"'));
   }
 
   public void skipBalancedComment() throws ConditionThrowable
   {
-    while (true)
+    try 
       {
-        int n = _readChar();
-        if (n < 0)
-          return;
-        if (n == '|')
-          {
-            n = _readChar();
-            if (n == '#')
-              return;
-            else
-              _unreadChar(n);
-          }
-        else if (n == '#')
+        while (true)
           {
-            n = _readChar();
+            int n = _readChar();
+            if (n < 0)
+                return;
             if (n == '|')
-              skipBalancedComment(); // Nested comment. Recurse!
-            else
-              _unreadChar(n);
+              {
+                n = _readChar();
+                if (n == '#')
+                    return;
+                else
+                    _unreadChar(n);
+              }
+            else if (n == '#')
+              {
+                n = _readChar();
+                if (n == '|')
+                    skipBalancedComment(); // Nested comment. Recurse!
+                else
+                    _unreadChar(n);
+              }
           }
       }
+    catch (IOException e)
+      {
+        error(new StreamError(this, e));
+      }
   }
 
   public LispObject readArray(int rank) throws ConditionThrowable
@@ -979,32 +1029,39 @@
   private String readMultipleEscape(Readtable rt) throws ConditionThrowable
   {
     FastStringBuffer sb = new FastStringBuffer();
-    while (true)
+    try 
       {
-        int n = _readChar();
-        if (n < 0)
-          {
-            error(new EndOfFile(this));
-            // Not reached.
-            return null;
-          }
-        char c = (char) n;
-        byte syntaxType = rt.getSyntaxType(c);
-        if (syntaxType == Readtable.SYNTAX_TYPE_SINGLE_ESCAPE)
+        while (true)
           {
-            n = _readChar();
+            int n = _readChar();
             if (n < 0)
               {
                 error(new EndOfFile(this));
                 // Not reached.
                 return null;
               }
-            sb.append((char)n);
-            continue;
+            char c = (char) n;
+            byte syntaxType = rt.getSyntaxType(c);
+            if (syntaxType == Readtable.SYNTAX_TYPE_SINGLE_ESCAPE)
+              {
+                n = _readChar();
+                if (n < 0)
+                  {
+                    error(new EndOfFile(this));
+                    // Not reached.
+                    return null;
+                  }
+                sb.append((char)n);
+                continue;
+              }
+            if (syntaxType == Readtable.SYNTAX_TYPE_MULTIPLE_ESCAPE)
+                break;
+            sb.append(c);
           }
-        if (syntaxType == Readtable.SYNTAX_TYPE_MULTIPLE_ESCAPE)
-          break;
-        sb.append(c);
+      } 
+    catch (IOException e)
+      {
+        error(new StreamError(this, e));
       }
     return sb.toString();
   }
@@ -1159,7 +1216,16 @@
         byte syntaxType = rt.getSyntaxType(c);
         if (syntaxType == Readtable.SYNTAX_TYPE_SINGLE_ESCAPE)
           {
-            int n = _readChar();
+            int n = -1;
+            try
+              {
+                n = _readChar();
+              }
+            catch (IOException e)
+              {
+                error(new StreamError(this, e));
+                return flags;
+              }
             if (n < 0)
               {
                 error(new EndOfFile(this));
@@ -1191,52 +1257,60 @@
             sb.setCharAt(0, LispCharacter.toLowerCase(c));
           }
       }
-    while (true)
-      {
-        int n = _readChar();
-        if (n < 0)
-          break;
-        char c = (char) n;
-        if (rt.isWhitespace(c))
-          {
-            _unreadChar(n);
-            break;
-          }
-        byte syntaxType = rt.getSyntaxType(c);
-        if (syntaxType == Readtable.SYNTAX_TYPE_TERMINATING_MACRO)
-          {
-            _unreadChar(c);
-            break;
-          }
-        rt.checkInvalid(c, this);
-        if (syntaxType == Readtable.SYNTAX_TYPE_SINGLE_ESCAPE)
-          {
-            n = _readChar();
-            if (n < 0)
+    try {
+      while (true)
+        {
+          int n = _readChar();
+          if (n < 0)
               break;
-            sb.append((char)n);
-            if (flags == null)
-              flags = new BitSet(sb.length());
-            flags.set(sb.length() - 1);
-            continue;
-          }
-        if (syntaxType == Readtable.SYNTAX_TYPE_MULTIPLE_ESCAPE)
-          {
-            int begin = sb.length();
-            sb.append(readMultipleEscape(rt));
-            int end = sb.length();
-            if (flags == null)
-              flags = new BitSet(sb.length());
-            for (int i = begin; i < end; i++)
-              flags.set(i);
-            continue;
-          }
-        if (readtableCase == Keyword.UPCASE)
-          c = LispCharacter.toUpperCase(c);
-        else if (readtableCase == Keyword.DOWNCASE)
-          c = LispCharacter.toLowerCase(c);
-        sb.append(c);
+          char c = (char) n;
+          if (rt.isWhitespace(c))
+            {
+              _unreadChar(n);
+              break;
+            }
+          byte syntaxType = rt.getSyntaxType(c);
+          if (syntaxType == Readtable.SYNTAX_TYPE_TERMINATING_MACRO)
+            {
+              _unreadChar(c);
+              break;
+            }
+          rt.checkInvalid(c, this);
+          if (syntaxType == Readtable.SYNTAX_TYPE_SINGLE_ESCAPE)
+            {
+              n = _readChar();
+              if (n < 0)
+                  break;
+              sb.append((char)n);
+              if (flags == null)
+                  flags = new BitSet(sb.length());
+              flags.set(sb.length() - 1);
+              continue;
+            }
+          if (syntaxType == Readtable.SYNTAX_TYPE_MULTIPLE_ESCAPE)
+            {
+              int begin = sb.length();
+              sb.append(readMultipleEscape(rt));
+              int end = sb.length();
+              if (flags == null)
+                  flags = new BitSet(sb.length());
+              for (int i = begin; i < end; i++)
+                  flags.set(i);
+              continue;
+            }
+          if (readtableCase == Keyword.UPCASE)
+              c = LispCharacter.toUpperCase(c);
+          else if (readtableCase == Keyword.DOWNCASE)
+              c = LispCharacter.toLowerCase(c);
+          sb.append(c);
+        }
+    }
+    catch (IOException e)
+      {
+        error(new StreamError(this, e));
+        return flags;
       }
+
     return flags;
   }
 
@@ -1537,18 +1611,26 @@
 
   private char flushWhitespace(Readtable rt) throws ConditionThrowable
   {
-    while (true)
+    try 
       {
-        int n = _readChar();
-        if (n < 0)
+        while (true)
           {
-            error(new EndOfFile(this));
-            // Not reached.
-            return 0;
+            int n = _readChar();
+            if (n < 0)
+              {
+                error(new EndOfFile(this));
+                // Not reached.
+                return 0;
+              }
+            char c = (char) n;
+            if (!rt.isWhitespace(c))
+                return c;
           }
-        char c = (char) n;
-        if (!rt.isWhitespace(c))
-          return c;
+      } 
+    catch (IOException e)
+      {
+        error(new StreamError(this, e));
+        return 0;
       }
   }
 
@@ -1581,23 +1663,30 @@
   {
     final LispThread thread = LispThread.currentThread();
     FastStringBuffer sb = new FastStringBuffer();
-    while (true)
+    try 
       {
-        int n = _readChar();
-        if (n < 0)
+        while (true)
           {
-            if (sb.length() == 0)
+            int n = _readChar();
+            if (n < 0)
               {
-                if (eofError)
-                  return error(new EndOfFile(this));
-                return thread.setValues(eofValue, T);
+                if (sb.length() == 0)
+                  {
+                    if (eofError)
+                        return error(new EndOfFile(this));
+                    return thread.setValues(eofValue, T);
+                  }
+                return thread.setValues(new SimpleString(sb), T);
               }
-            return thread.setValues(new SimpleString(sb), T);
+            if (n == '\n')
+                return thread.setValues(new SimpleString(sb), NIL);
+            else
+                sb.append((char)n);
           }
-        if (n == '\n')
-          return thread.setValues(new SimpleString(sb), NIL);
-        else
-          sb.append((char)n);
+      } 
+    catch (IOException e)
+      {
+        return error(new StreamError(this, e));
       }
   }
 
@@ -1605,24 +1694,39 @@
   // recursive-p is ignored
   public LispObject readChar() throws ConditionThrowable
   {
-    int n = _readChar();
-    if (n < 0)
-      return error(new EndOfFile(this));
-    return LispCharacter.getInstance((char)n);
+    try 
+      {
+        int n = _readChar();
+        if (n < 0)
+            return error(new EndOfFile(this));
+        return LispCharacter.getInstance((char)n);
+      } 
+    catch (IOException e)
+      {
+        return error(new StreamError(this, e));
+      }
+
   }
 
   public LispObject readChar(boolean eofError, LispObject eofValue)
     throws ConditionThrowable
   {
-    int n = _readChar();
-    if (n < 0)
+    try 
       {
-        if (eofError)
-          return error(new EndOfFile(this));
-        else
-          return eofValue;
+        int n = _readChar();
+        if (n < 0)
+          {
+            if (eofError)
+                return error(new EndOfFile(this));
+            else
+                return eofValue;
+          }
+        return LispCharacter.getInstance((char)n);
+      }
+    catch (IOException e)
+      {
+        return error(new StreamError(this, e));
       }
-    return LispCharacter.getInstance((char)n);
   }
 
   // read-char-no-hang &optional stream eof-error-p eof-value recursive-p => char
@@ -1630,15 +1734,29 @@
   public LispObject readCharNoHang(boolean eofError, LispObject eofValue)
     throws ConditionThrowable
   {
-    return _charReady() ? readChar(eofError, eofValue) : NIL;
+    try 
+      {
+        return _charReady() ? readChar(eofError, eofValue) : NIL;
+      } 
+    catch (IOException e)
+      {
+        return error(new StreamError(this, e));
+      }
   }
 
 
   // unread-char character &optional input-stream => nil
   public LispObject unreadChar(LispCharacter c) throws ConditionThrowable
   {
-    _unreadChar(c.value);
-    return NIL;
+    try 
+      {
+        _unreadChar(c.value);
+        return NIL;
+      } 
+    catch (IOException e)
+      {
+        return error(new StreamError(this, e));
+      }
   }
 
   public LispObject finishOutput() throws ConditionThrowable
@@ -1735,17 +1853,23 @@
   {
     if (pastEnd)
       return NIL;
-    
-    if (! _charReady())
-      return NIL;
-    
-    int n = _readChar();
-    if (n < 0)
-      return NIL;
-
-    _unreadChar(n);
-    
-    return T;
+    try
+      {
+        if (! _charReady())
+            return NIL;
+        
+        int n = _readChar();
+        if (n < 0)
+            return NIL;
+        
+        _unreadChar(n);
+        
+        return T;
+      }
+    catch (IOException e)
+      {
+        return error(new StreamError(this, e));
+      }
   }
 
   public LispObject fileLength() throws ConditionThrowable
@@ -1791,44 +1915,35 @@
    * @return a character, or -1 at end-of-file
    * @throws org.armedbear.lisp.ConditionThrowable
    */
-  protected int _readChar() throws ConditionThrowable
+  protected int _readChar() throws ConditionThrowable, IOException
   {
     if (reader == null)
         streamNotCharacterInputStream();
 
-    try
-      {
-        int n = reader.read();
-        
-        if (n < 0) {
-            pastEnd = true;
-            return -1;
-        }
+    int n = reader.read();
+    
+    if (n < 0) {
+        pastEnd = true;
+        return -1;
+    }
         
-        ++offset;
-        if (eolStyle == EolStyle.CRLF && n == '\r') {
-            n = _readChar();
-            if (n != '\n') {
-                _unreadChar(n);
-                return '\r';
-            }
-            else
-              return '\n';
+    ++offset;
+    if (eolStyle == EolStyle.CRLF && n == '\r') {
+        n = _readChar();
+        if (n != '\n') {
+            _unreadChar(n);
+            return '\r';
         }
+        else
+            return '\n';
+    }
 
-        if (n == eolChar) {
-          ++lineNumber;
-          return '\n';
-        }
+    if (n == eolChar) {
+        ++lineNumber;
+        return '\n';
+    }
 
-        return n;
-      }
-    catch (IOException e)
-      {
-        error(new StreamError(this, e));
-      }
-    // Not reached.
-    return -1;
+    return n;
   }
 
   /** Puts a character back into the (underlying) stream
@@ -1836,45 +1951,28 @@
    * @param n
    * @throws org.armedbear.lisp.ConditionThrowable
    */
-  protected void _unreadChar(int n) throws ConditionThrowable
+  protected void _unreadChar(int n) throws ConditionThrowable, IOException
   {
     if (reader == null)
         streamNotCharacterInputStream();
-
-    try
-      {
-        reader.unread(n);
-        --offset;
-        pastEnd = false;
-        if (n == eolChar)
-          --lineNumber;
-      }
-    catch (IOException e)
-      {
-        error(new StreamError(this, e));
-      }
+    reader.unread(n);
+    --offset;
+    pastEnd = false;
+    if (n == eolChar)
+        --lineNumber;
   }
 
+
   /** Returns a boolean indicating input readily available
    * 
    * @return true if a character is available
    * @throws org.armedbear.lisp.ConditionThrowable
    */
-  protected boolean _charReady() throws ConditionThrowable
+  protected boolean _charReady() throws ConditionThrowable, IOException
   {
     if (reader == null)
         streamNotCharacterInputStream();
-
-    try
-      {
-        return reader.ready();
-      }
-    catch (IOException e)
-      {
-        error(new StreamError(this, e));
-      }
-    // Not reached.
-    return false;
+    return reader.ready();
   }
 
   /** Writes a character into the underlying stream,
@@ -2087,8 +2185,15 @@
     if (reader != null)
       {
         int c = 0;
-        while (_charReady() && (c >= 0))
-          c = _readChar();
+        try 
+          {
+            while (_charReady() && (c >= 0))
+                c = _readChar();
+          }
+        catch (IOException e)
+          {
+            error(new StreamError(this, e));
+          }
       }
     else if (in != null)
       {

Modified: trunk/abcl/src/org/armedbear/lisp/SynonymStream.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/SynonymStream.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/SynonymStream.java	Wed Jun  3 16:05:46 2009
@@ -125,19 +125,19 @@
     }
 
     @Override
-    protected int _readChar() throws ConditionThrowable
+    protected int _readChar() throws ConditionThrowable, java.io.IOException
     {
         return checkStream(symbol.symbolValue())._readChar();
     }
 
     @Override
-    protected void _unreadChar(int n) throws ConditionThrowable
+    protected void _unreadChar(int n) throws ConditionThrowable, java.io.IOException
     {
         checkStream(symbol.symbolValue())._unreadChar(n);
     }
 
     @Override
-    protected boolean _charReady() throws ConditionThrowable
+    protected boolean _charReady() throws ConditionThrowable, java.io.IOException
     {
         return checkStream(symbol.symbolValue())._charReady();
     }

Modified: trunk/abcl/src/org/armedbear/lisp/TwoWayStream.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/TwoWayStream.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/TwoWayStream.java	Wed Jun  3 16:05:46 2009
@@ -120,19 +120,19 @@
 
     // Returns -1 at end of file.
     @Override
-    protected int _readChar() throws ConditionThrowable
+    protected int _readChar() throws ConditionThrowable, java.io.IOException
     {
         return in._readChar();
     }
 
     @Override
-    protected void _unreadChar(int n) throws ConditionThrowable
+    protected void _unreadChar(int n) throws ConditionThrowable, java.io.IOException
     {
         in._unreadChar(n);
     }
 
     @Override
-    protected boolean _charReady() throws ConditionThrowable
+    protected boolean _charReady() throws ConditionThrowable, java.io.IOException
     {
         return in._charReady();
     }




More information about the armedbear-cvs mailing list