From: Finn B. <bc...@us...> - 2001-02-01 14:16:45
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv6669 Modified Files: parser.java Log Message: Attempt to work around a bug in MRJ2.1 for mac. Sometimes reader.read(..) returns a large negative numbers. Experiments done by Frode Reinsnes indicate that this should help. So far this is not made conditional on a registry entry. Perhaps it should be. Index: parser.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/parser.java,v retrieving revision 2.4 retrieving revision 2.5 diff -C2 -r2.4 -r2.5 *** parser.java 1999/05/17 19:59:43 2.4 --- parser.java 2001/02/01 14:16:44 2.5 *************** *** 6,17 **** public class parser { ! public static String getLine(InputStream istream, int line) { ! if (istream == null) return ""; try { String text=null; - DataInputStream s = new DataInputStream(istream); for(int i=0; i <line; i++) { ! text = s.readLine(); } return text; --- 6,16 ---- public class parser { ! public static String getLine(BufferedReader reader, int line) { ! if (reader == null) return ""; try { String text=null; for(int i=0; i <line; i++) { ! text = reader.readLine(); } return text; *************** *** 21,31 **** } ! static PyException fixParseError(InputStream istream, Throwable t, String filename) { ! return fixParseError(istream, t, filename, false); } ! static PyException fixParseError(InputStream istream, Throwable t, String filename, boolean forceNewline) { --- 20,30 ---- } ! static PyException fixParseError(BufferedReader reader, Throwable t, String filename) { ! return fixParseError(reader, t, filename, false); } ! static PyException fixParseError(BufferedReader reader, Throwable t, String filename, boolean forceNewline) { *************** *** 39,43 **** line = tok.next.beginLine; } ! String text=getLine(istream, line); return new PySyntaxError(e.getMessage(), line, col, text, filename, forceNewline); --- 38,42 ---- line = tok.next.beginLine; } ! String text=getLine(reader, line); return new PySyntaxError(e.getMessage(), line, col, text, filename, forceNewline); *************** *** 50,54 **** int line = e.errorLine; //System.err.println("eof seen: "+eofSeen+", "+e.curChar+", "+col+", "+line); ! String text = getLine(istream, line); if (eofSeen) col -= 1; --- 49,53 ---- int line = e.errorLine; //System.err.println("eof seen: "+eofSeen+", "+e.curChar+", "+col+", "+line); ! String text = getLine(reader, line); if (eofSeen) col -= 1; *************** *** 67,73 **** String filename) { - if (!istream.markSupported()) { - istream = new BufferedInputStream(istream); - } int nbytes; try { --- 66,69 ---- *************** *** 81,87 **** if (nbytes > 100000) nbytes = 100000; ! //System.err.println("marking istream"); ! istream.mark(nbytes); ! PythonGrammar g = new PythonGrammar(istream); SimpleNode node = null; try { --- 77,92 ---- if (nbytes > 100000) nbytes = 100000; ! ! Reader reader = new InputStreamReader(istream); ! //if (Options.fixMacReaderBug); ! reader = new FixMacReaderBug(reader); ! ! BufferedReader bufreader = new BufferedReader(reader); ! ! try { ! bufreader.mark(nbytes); ! } catch (IOException exc) { } ! ! PythonGrammar g = new PythonGrammar(bufreader); SimpleNode node = null; try { *************** *** 102,107 **** try { //System.err.println("resetting istream"); ! istream.reset(); ! throw fixParseError(istream, t, filename, g.token_source.forcedNewline); } --- 107,112 ---- try { //System.err.println("resetting istream"); ! bufreader.reset(); ! throw fixParseError(bufreader, t, filename, g.token_source.forcedNewline); } *************** *** 136,139 **** --- 141,162 ---- } return node; + } + } + + + /** + * A workaround for a bug in MRJ2.2's FileReader, where the value returned + * from read(b, o, l) sometimes are wrong. + */ + class FixMacReaderBug extends FilterReader { + public FixMacReaderBug(Reader in) { + super(in); + } + + public int read(char b[], int off, int len) throws IOException { + int l = super.read(b, off, len); + if (l < -1) + l += off; + return l; } } |