[pypy-svn] r30843 - in pypy/dist/pypy/translator/cli: . src src/stub test
antocuni at codespeak.net
antocuni at codespeak.net
Tue Aug 1 14:06:49 CEST 2006
Author: antocuni
Date: Tue Aug 1 14:06:42 2006
New Revision: 30843
Modified:
pypy/dist/pypy/translator/cli/function.py
pypy/dist/pypy/translator/cli/src/ll_os.cs
pypy/dist/pypy/translator/cli/src/stub/main.il
pypy/dist/pypy/translator/cli/test/test_exception.py
Log:
Don't longer ignore last_exception when catching an exception.
Modified: pypy/dist/pypy/translator/cli/function.py
==============================================================================
--- pypy/dist/pypy/translator/cli/function.py (original)
+++ pypy/dist/pypy/translator/cli/function.py Tue Aug 1 14:06:42 2006
@@ -125,7 +125,10 @@
self.store(link.target.inputargs[1])
else:
# the exception value is on the stack, store it in the proper place
+ self.ilasm.opcode('dup')
self.store(link.last_exc_value)
+ self.ilasm.get_field(('Object_meta', 'Object', 'meta'))
+ self.store(link.last_exception)
self._setup_link(link)
target_label = self._get_block_name(target)
Modified: pypy/dist/pypy/translator/cli/src/ll_os.cs
==============================================================================
--- pypy/dist/pypy/translator/cli/src/ll_os.cs (original)
+++ pypy/dist/pypy/translator/cli/src/ll_os.cs Tue Aug 1 14:06:42 2006
@@ -46,6 +46,46 @@
}
}
+ class CRLFFile: IFile
+ {
+ private FileStream stream;
+ private TextWriter writer;
+ private TextReader reader;
+ public CRLFFile(FileStream stream, TextReader reader, TextWriter writer)
+ {
+ this.stream = stream;
+ this.writer = writer;
+ this.reader = reader;
+ }
+
+ public FileStream GetStream()
+ {
+ return stream;
+ }
+
+ public void Write(string buffer)
+ {
+ Debug.Assert(writer != null); // XXX: raise OSError?
+ writer.Write(buffer);
+ writer.Flush();
+ }
+
+ public string Read(int count)
+ {
+ Debug.Assert(reader != null); // XXX: raise OSError?
+ System.Text.StringBuilder builder = new System.Text.StringBuilder(count);
+ while (count-- > 0) {
+ int ch = reader.Read();
+ if (ch == -1)
+ break;
+ if (ch == '\r' && reader.Peek() == '\n')
+ ch = reader.Read();
+ builder.Append((char)ch);
+ }
+ return builder.ToString();
+ }
+ }
+
class BinaryFile: IFile
{
private FileStream stream;
@@ -124,7 +164,7 @@
private static FileMode get_file_mode(int flags) {
if ((flags & O_APPEND) !=0 ) return FileMode.Append;
if ((flags & O_TRUNC) !=0 ) return FileMode.Truncate;
- if ((flags & O_CREAT) !=0 ) return FileMode.CreateNew;
+ if ((flags & O_CREAT) !=0 ) return FileMode.OpenOrCreate;
return FileMode.Open;
}
@@ -143,8 +183,15 @@
if (f_access == FileAccess.Read || f_access == FileAccess.ReadWrite)
reader = new StreamReader(stream);
if (f_access == FileAccess.Write || f_access == FileAccess.ReadWrite)
- writer = new StreamWriter(stream);
- f = new TextFile(stream, reader, writer);
+ {
+ Console.Error.WriteLine("opening {0} for writing", name);
+ writer = new StreamWriter(stream);
+ }
+
+ if (System.Environment.NewLine == "\r\n")
+ f = new CRLFFile(stream, reader, writer);
+ else
+ f = new TextFile(stream, reader, writer);
}
fdcount++;
@@ -194,7 +241,8 @@
return res;
}
// path is not a file nor a dir, raise OSError
- Helpers.raise_OSError(2); // ENOENT
+ //Helpers.raise_OSError(2); // ENOENT
+ PrebuiltGraphs.raiseOSError(2);
return null; // never reached
}
Modified: pypy/dist/pypy/translator/cli/src/stub/main.il
==============================================================================
--- pypy/dist/pypy/translator/cli/src/stub/main.il (original)
+++ pypy/dist/pypy/translator/cli/src/stub/main.il Tue Aug 1 14:06:42 2006
@@ -36,3 +36,15 @@
}
}
}
+
+/// XXX: remove
+.class public PrebuiltGraphs
+{
+ .method public static void raiseOSError(int32 errno_1) il managed
+ {
+ ldstr "This is only a stub, it should not be called"
+ newobj instance void class [mscorlib]System.ApplicationException::.ctor(string)
+ throw
+ ret
+ }
+}
Modified: pypy/dist/pypy/translator/cli/test/test_exception.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_exception.py (original)
+++ pypy/dist/pypy/translator/cli/test/test_exception.py Tue Aug 1 14:06:42 2006
@@ -3,4 +3,19 @@
from pypy.rpython.test.test_exception import BaseTestException
class TestCliException(CliTest, BaseTestException):
- pass
+ def test_nested_try(self):
+ def helper(x):
+ if x == 0:
+ raise ValueError
+ def dummy():
+ pass
+ def fn(x):
+ try:
+ try:
+ helper(x)
+ finally:
+ dummy()
+ except ValueError, e:
+ raise
+
+ self.interpret_raises(ValueError, fn, [0])
More information about the Pypy-commit
mailing list