[pypy-svn] r70477 - in pypy/trunk: lib-python pypy/module/posix pypy/module/posix/test pypy/rpython/module

exarkun at codespeak.net exarkun at codespeak.net
Sun Jan 10 17:52:27 CET 2010


Author: exarkun
Date: Sun Jan 10 17:52:26 2010
New Revision: 70477

Modified:
   pypy/trunk/lib-python/conftest.py
   pypy/trunk/pypy/module/posix/__init__.py
   pypy/trunk/pypy/module/posix/interp_posix.py
   pypy/trunk/pypy/module/posix/test/test_posix2.py
   pypy/trunk/pypy/rpython/module/ll_os.py
Log:
implement os.openpty

Modified: pypy/trunk/lib-python/conftest.py
==============================================================================
--- pypy/trunk/lib-python/conftest.py	(original)
+++ pypy/trunk/lib-python/conftest.py	Sun Jan 10 17:52:26 2010
@@ -311,7 +311,7 @@
     RegrTest('test_normalization.py'),
     RegrTest('test_ntpath.py'),
     RegrTest('test_opcodes.py', core=True),
-    RegrTest('test_openpty.py', skip="unsupported extension module"),
+    RegrTest('test_openpty.py'),
     RegrTest('test_operations.py', core=True),
     RegrTest('test_operator.py', core=True),
     RegrTest('test_optparse.py'),

Modified: pypy/trunk/pypy/module/posix/__init__.py
==============================================================================
--- pypy/trunk/pypy/module/posix/__init__.py	(original)
+++ pypy/trunk/pypy/module/posix/__init__.py	Sun Jan 10 17:52:26 2010
@@ -93,6 +93,8 @@
         interpleveldefs['readlink'] = 'interp_posix.readlink'
     if hasattr(os, 'fork'):
         interpleveldefs['fork'] = 'interp_posix.fork'
+    if hasattr(os, 'openpty'):
+        interpleveldefs['openpty'] = 'interp_posix.openpty'
     if hasattr(os, 'waitpid'):
         interpleveldefs['waitpid'] = 'interp_posix.waitpid'
     if hasattr(os, 'execv'):

Modified: pypy/trunk/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/trunk/pypy/module/posix/interp_posix.py	(original)
+++ pypy/trunk/pypy/module/posix/interp_posix.py	Sun Jan 10 17:52:26 2010
@@ -507,6 +507,14 @@
         raise wrap_oserror(space, e) 
     return space.wrap(pid)
 
+def openpty(space):
+    "Open a pseudo-terminal, returning open fd's for both master and slave end."
+    try:
+        master_fd, slave_fd = os.openpty()
+    except OSError, e:
+        raise wrap_oserror(space, e)
+    return space.newtuple([space.wrap(master_fd), space.wrap(slave_fd)])
+
 def waitpid(space, pid, options):
     """ waitpid(pid, options) -> (pid, status)
     

Modified: pypy/trunk/pypy/module/posix/test/test_posix2.py
==============================================================================
--- pypy/trunk/pypy/module/posix/test/test_posix2.py	(original)
+++ pypy/trunk/pypy/module/posix/test/test_posix2.py	Sun Jan 10 17:52:26 2010
@@ -245,6 +245,21 @@
             assert os.WEXITSTATUS(status1) == 4
         pass # <- please, inspect.getsource(), don't crash
 
+
+    if hasattr(__import__(os.name), "openpty"):
+        def test_openpty(self):
+            os = self.posix
+            master_fd, slave_fd = self.posix.openpty()
+            try:
+                assert isinstance(master_fd, int)
+                assert isinstance(slave_fd, int)
+                os.write(slave_fd, 'x')
+                assert os.read(master_fd, 1) == 'x'
+            finally:
+                os.close(master_fd)
+                os.close(slave_fd)
+
+
     if hasattr(__import__(os.name), "execv"):
         def test_execv(self):
             os = self.posix

Modified: pypy/trunk/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/trunk/pypy/rpython/module/ll_os.py	(original)
+++ pypy/trunk/pypy/rpython/module/ll_os.py	Sun Jan 10 17:52:26 2010
@@ -1400,6 +1400,30 @@
         return extdef([], int, llimpl=fork_llimpl,
                       export_name="ll_os.ll_os_fork")
 
+    @registering_if(os, 'openpty')
+    def register_os_openpty(self):
+        os_openpty = self.llexternal(
+            'openpty',
+            [rffi.INTP, rffi.INTP, rffi.VOIDP, rffi.VOIDP, rffi.VOIDP],
+            rffi.INT,
+            compilation_info=ExternalCompilationInfo(libraries=['util']))
+        def openpty_llimpl():
+            master_p = lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
+            slave_p = lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
+            result = os_openpty(master_p, slave_p, None, None, None)
+            master_fd = master_p[0]
+            slave_fd = slave_p[0]
+            lltype.free(master_p, flavor='raw')
+            lltype.free(slave_p, flavor='raw')
+            if result == -1:
+                raise OSError(rposix.get_errno(), "os_openpty failed")
+            return (rffi.cast(lltype.Signed, master_fd),
+                    rffi.cast(lltype.Signed, slave_fd))
+
+        return extdef([], (int, int), "ll_os.ll_os_openpty",
+                      llimpl=openpty_llimpl)
+
+
     @registering(os._exit)
     def register_os__exit(self):
         os__exit = self.llexternal('_exit', [rffi.INT], lltype.Void)



More information about the Pypy-commit mailing list