[pypy-svn] r52265 - in pypy/dist/pypy/translator: jvm oosupport/test_template

niko at codespeak.net niko at codespeak.net
Fri Mar 7 19:13:10 CET 2008


Author: niko
Date: Fri Mar  7 19:13:09 2008
New Revision: 52265

Modified:
   pypy/dist/pypy/translator/jvm/genjvm.py
   pypy/dist/pypy/translator/oosupport/test_template/builtin.py
Log:
add a test for reading in binary strings with hi bit set, and
comment out some obnoxious jvm printouts that cloud up py.test output



Modified: pypy/dist/pypy/translator/jvm/genjvm.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/genjvm.py	(original)
+++ pypy/dist/pypy/translator/jvm/genjvm.py	Fri Mar  7 19:13:09 2008
@@ -166,9 +166,9 @@
                 yield chunk
 
         for files in split_list(self.jasmin_files):
-            print "Invoking jasmin on %s" % files
+            #print "Invoking jasmin on %s" % files
             self._invoke(jascmd + files, False)
-            print "... completed!"
+            #print "... completed!"
                            
         self.compiled = True
         self._compile_helper()

Modified: pypy/dist/pypy/translator/oosupport/test_template/builtin.py
==============================================================================
--- pypy/dist/pypy/translator/oosupport/test_template/builtin.py	(original)
+++ pypy/dist/pypy/translator/oosupport/test_template/builtin.py	Fri Mar  7 19:13:09 2008
@@ -14,6 +14,29 @@
             return os.O_CREAT
         assert self.interpret(fn, []) == NT_OS['O_CREAT']
 
+    def test_os_read_hibytes(self):
+        """
+        Test that we read in characters with the high bit set correctly
+        This can be a problem on JVM or CLI, where we use unicode strings to
+        encode byte arrays!
+        """
+        tmpfile = str(udir.udir.join("os_read_hibytes.txt"))
+        def chrs2int(b):
+            assert len(b) == 4
+            first = ord(b[0]) # big endian
+            if first & 0x80 != 0:
+                first = first - 0x100
+            return first << 24 | ord(b[1]) << 16 | ord(b[2]) << 8 | ord(b[3])
+        def fn():
+            fd = os.open(tmpfile, os.O_RDONLY|os.O_BINARY, 0666)
+            res = os.read(fd, 4)
+            os.close(fd)
+            return chrs2int(res)
+        f = file(tmpfile, 'w')
+        f.write("".join([chr(x) for x in [0x06, 0x64, 0x90, 0x00]]))
+        f.close()
+        assert self.interpret(fn, []) == fn()
+        
     def test_os_read_binary_crlf(self):
         tmpfile = str(udir.udir.join("os_read_test"))
         def fn(flag):



More information about the Pypy-commit mailing list