Changeset 13724


Ignore:
Timestamp:
01/06/12 14:35:39 (11 years ago)
Author:
Mark Evenson
Message:

backport r13706: use new API to fix Stream.readToken() bug reported by Blake McBride?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.0.x/abcl/src/org/armedbear/lisp/Stream.java

    r13598 r13724  
    10311031            return NIL;
    10321032        final LispObject readtableCase = rt.getReadtableCase();
    1033         final String token;
    1034         if (readtableCase == Keyword.INVERT)
    1035             token = invert(sb.toString(), flags);
    1036         else
    1037             token = sb.toString();
     1033        final String token =  sb.toString();
     1034        final boolean invert = readtableCase == Keyword.INVERT;
    10381035        final int length = token.length();
    10391036        if (length > 0) {
     
    10741071                }
    10751072            }
    1076             if (firstChar == ':')
    1077                 if (flags == null || !flags.get(0))
    1078                     return PACKAGE_KEYWORD.intern(token.substring(1));
    1079             int index = findUnescapedDoubleColon(token, flags);
    1080             if (index > 0) {
    1081                 String packageName = token.substring(0, index);
    1082                 String symbolName = token.substring(index + 2);
    1083                 Package pkg = Packages.findPackage(packageName);
     1073           
     1074            String symbolName;
     1075            String packageName = null;
     1076            BitSet symbolFlags;
     1077            BitSet packageFlags = null;
     1078            Package pkg = null;
     1079            boolean internSymbol = true;
     1080            if (firstChar == ':' && (flags == null || !flags.get(0))) {
     1081                    symbolName = token.substring(1);
     1082                    pkg = PACKAGE_KEYWORD;
     1083                    if (flags != null)
     1084                        symbolFlags = flags.get(1, flags.size());
     1085                    else
     1086                        symbolFlags = null;
     1087            } else {
     1088                int index = findUnescapedDoubleColon(token, flags);
     1089                if (index > 0) {
     1090                    packageName = token.substring(0, index);
     1091                    packageFlags = (flags != null) ? flags.get(0, index) :  null;
     1092                    symbolName = token.substring(index + 2);
     1093                    symbolFlags = (flags != null) ? flags.get(index+2, flags.size()) : null;
     1094                } else {
     1095                    index = findUnescapedSingleColon(token, flags);
     1096                    if (index > 0) {
     1097                        packageName = token.substring(0, index);
     1098                        packageFlags = (flags != null) ? flags.get(0, index) : null;
     1099                        symbolName = token.substring(index + 1);
     1100                        symbolFlags = (flags != null) ? flags.get(index+2, flags.size()) : null;
     1101                        internSymbol = false;
     1102                    } else {
     1103                        pkg = (Package)Symbol._PACKAGE_.symbolValue(thread);
     1104                        symbolName = token;
     1105                        symbolFlags = flags;
     1106                    }
     1107                }
     1108            }
     1109            if (pkg == null) {
     1110                if (invert)
     1111                    packageName = invert(packageName, packageFlags);
     1112
     1113                pkg = Packages.findPackage(packageName);
    10841114                if (pkg == null)
    1085                     return error(new LispError("Package \"" + packageName +
    1086                                                "\" not found."));
     1115                    return error(new ReaderError("The package \"" + packageName + "\" can't be found.", this));
     1116            }
     1117            if (invert)
     1118                symbolName = invert(symbolName, symbolFlags);
     1119           
     1120            if (internSymbol) {
    10871121                return pkg.intern(symbolName);
    1088             }
    1089             index = findUnescapedSingleColon(token, flags);
    1090             if (index > 0) {
    1091                 final String packageName = token.substring(0, index);
    1092                 Package pkg = Packages.findPackage(packageName);
    1093                 if (pkg == null)
    1094                     return error(new PackageError("Package \"" + packageName +
    1095                                                   "\" not found."));
    1096                 final String symbolName = token.substring(index + 1);
    1097                 final SimpleString s = new SimpleString(symbolName);
    1098                 Symbol symbol = pkg.findExternalSymbol(s);
     1122            } else {
     1123                Symbol symbol = pkg.findExternalSymbol(symbolName);
    10991124                if (symbol != null)
    11001125                    return symbol;
     1126
    11011127                // Error!
    1102                 if (pkg.findInternalSymbol(s) != null)
     1128                if (pkg.findInternalSymbol(symbolName) != null)
    11031129                    return error(new ReaderError("The symbol \"" + symbolName +
    11041130                                                 "\" is not external in package " +
     
    11121138            }
    11131139        }
    1114         // Intern token in current package.
    1115         return ((Package)Symbol._PACKAGE_.symbolValue(thread)).intern(new SimpleString(token));
     1140        return error(new ReaderError("Can't intern zero-length symbol.", this));
    11161141    }
    11171142
Note: See TracChangeset for help on using the changeset viewer.