[pypy-svn] r30894 - in pypy/dist/pypy/translator/cli: . src src/stub test
antocuni at codespeak.net
antocuni at codespeak.net
Wed Aug 2 14:53:55 CEST 2006
Author: antocuni
Date: Wed Aug 2 14:53:48 2006
New Revision: 30894
Modified:
pypy/dist/pypy/translator/cli/src/ll_os.cs
pypy/dist/pypy/translator/cli/src/stub/main.il
pypy/dist/pypy/translator/cli/support.py
pypy/dist/pypy/translator/cli/test/test_constant.py
Log:
string literals with non-printable characters was not rendered
properly, and the corresponding test was buggy because it didn't test
anything due to constant folding. Both issues have been fixed.
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 Wed Aug 2 14:53:48 2006
@@ -163,7 +163,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_TRUNC) !=0 ) return FileMode.Create;
if ((flags & O_CREAT) !=0 ) return FileMode.OpenOrCreate;
return FileMode.Open;
}
@@ -189,9 +189,15 @@
}
if (System.Environment.NewLine == "\r\n")
- f = new CRLFFile(stream, reader, writer);
+ {
+ Console.Error.WriteLine("opening {0} for reading (with CRLF conversion)", name);
+ f = new CRLFFile(stream, reader, writer);
+ }
else
- f = new TextFile(stream, reader, writer);
+ {
+ Console.Error.WriteLine("opening {0} for reading (without CRLF conversion)", name);
+ f = new TextFile(stream, reader, writer);
+ }
}
fdcount++;
@@ -208,10 +214,22 @@
public static int ll_os_write(int fd, string buffer)
{
+ PrintString("ll_os_write", buffer);
getfd(fd).Write(buffer);
return buffer.Length;
}
+ private static void PrintString(string source, string s)
+ {
+ Console.WriteLine(source);
+ Console.WriteLine(s);
+ Console.WriteLine("Length: {0}", s.Length);
+ for (int i=0; i<s.Length; i++)
+ Console.Write("{0} ", (int)s[i]);
+ Console.WriteLine();
+ Console.WriteLine();
+ }
+
public static string ll_os_read(int fd, long count)
{
return ll_os_read(fd, (int)count);
@@ -241,8 +259,7 @@
return res;
}
// path is not a file nor a dir, raise OSError
- //Helpers.raise_OSError(2); // ENOENT
- PrebuiltGraphs.raiseOSError(2);
+ Helpers.raise_OSError(2); // ENOENT
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 Wed Aug 2 14:53:48 2006
@@ -36,15 +36,3 @@
}
}
}
-
-/// 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/support.py
==============================================================================
--- pypy/dist/pypy/translator/cli/support.py (original)
+++ pypy/dist/pypy/translator/cli/support.py Wed Aug 2 14:53:48 2006
@@ -9,7 +9,7 @@
def line_repr(s):
return ''.join([char_repr(c) for c in s])
def array_repr(s):
- return ' '.join(['%x 00' % ord(c) for c in s+'\001'])
+ return ' '.join(['%x 00' % ord(c) for c in s]+['00'])
try:
return '"%s"' % line_repr(s)
Modified: pypy/dist/pypy/translator/cli/test/test_constant.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_constant.py (original)
+++ pypy/dist/pypy/translator/cli/test/test_constant.py Wed Aug 2 14:53:48 2006
@@ -76,10 +76,16 @@
assert self.ll_to_string(self.interpret(fn, [])) == 'hello "world"'
def test_string_literal2(self):
- s = '\001\002\003'
- def fn():
- return ord(s[0]) + ord(s[1])
- assert self.interpret(fn, []) == 3
+ literals = ['\001\002\003', '\004\005\006']
+ def fn(i):
+ s = literals[i]
+ return len(s), ord(s[0]) + ord(s[1]) + ord(s[2])
+ res = self.interpret(fn, [0])
+ assert res.item0 == 3
+ assert res.item1 == 6
+ res = self.interpret(fn, [1])
+ assert res.item0 == 3
+ assert res.item1 == 15
def test_float_special(self):
self._skip_win('inf & nan')
More information about the Pypy-commit
mailing list