[pypy-svn] r46487 - pypy/dist/pypy/translator/jvm/src/pypy

antocuni at codespeak.net antocuni at codespeak.net
Tue Sep 11 22:14:57 CEST 2007


Author: antocuni
Date: Tue Sep 11 22:14:57 2007
New Revision: 46487

Modified:
   pypy/dist/pypy/translator/jvm/src/pypy/ll_os.java
Log:
implement ll_os_close; fix a bug in ll_os_open when the EOF is reached.




Modified: pypy/dist/pypy/translator/jvm/src/pypy/ll_os.java
==============================================================================
--- pypy/dist/pypy/translator/jvm/src/pypy/ll_os.java	(original)
+++ pypy/dist/pypy/translator/jvm/src/pypy/ll_os.java	Tue Sep 11 22:14:57 2007
@@ -9,6 +9,7 @@
 {
     public abstract void write(String buffer);
     public abstract String read(int count);
+    public abstract void close();
 }
 
 class PrintStreamWrapper extends FileWrapper
@@ -30,6 +31,11 @@
         ll_os.throwOSError(PyPy.EBADF, "Write-only fd");
         return null; // never reached
     }
+
+    public void close()
+    {
+        ll_os.throwOSError(PyPy.EBADF, "Cannot close stdout or stderr");
+    }
 }
 
 class InputStreamWrapper extends FileWrapper
@@ -58,6 +64,11 @@
             return null; // never reached
         }
     }
+
+    public void close()
+    {
+        ll_os.throwOSError(PyPy.EBADF, "Cannot close stdin");
+    }
 }
 
 class RandomAccessFileWrapper extends FileWrapper
@@ -94,13 +105,26 @@
         try {
             byte[] buffer = new byte[count];
             int n = this.file.read(buffer);
-            return new String(buffer, 0, n);
+            if (n == -1)
+                return ""; // XXX: is it right?
+            else
+                return new String(buffer, 0, n);
         }
         catch(IOException e) {
             ll_os.throwOSError(PyPy.EIO, e.getMessage());
             return null; // never reached
         }
     }
+
+    public void close()
+    {
+        try {
+            this.file.close();
+        }
+        catch(IOException e) {
+            ll_os.throwOSError(PyPy.EIO, e.getMessage());
+        }
+    }
 }
 
 
@@ -199,6 +223,13 @@
         return fdcount;
     }
 
+    public static void ll_os_close(int fd)
+    {
+        FileWrapper wrapper = getfd(fd);
+        wrapper.close();
+        FileDescriptors.remove(new Integer(fd));
+    }
+
     public static String ll_os_read(int fd, int count)
     {
         return getfd(fd).read(count);


More information about the pypy-svn mailing list