[pypy-svn] r45729 - in pypy/branch/pypy-more-rtti-inprogress: rpython rpython/module translator/c translator/c/src translator/c/test

arigo at codespeak.net arigo at codespeak.net
Thu Aug 16 16:27:23 CEST 2007


Author: arigo
Date: Thu Aug 16 16:27:20 2007
New Revision: 45729

Modified:
   pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py
   pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py
   pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py
   pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h
   pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_extfunc.py
Log:
os.kill()...


Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py	Thu Aug 16 16:27:20 2007
@@ -151,8 +151,6 @@
 # external function declarations
 posix = __import__(os.name)
 declare(os._exit    , noneannotation, 'll_os/_exit')
-if hasattr(os, 'kill'):
-    declare(os.kill     , noneannotation, 'll_os/kill')
 if hasattr(os, 'link'):
     declare(os.link     , noneannotation, 'll_os/link')
 if hasattr(os, 'symlink'):

Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py	Thu Aug 16 16:27:20 2007
@@ -772,6 +772,22 @@
         self.register(os.umask, [int], int, llimpl=umask_lltypeimpl,
                       export_name="ll_os.ll_os_umask")
 
+    if hasattr(os, 'kill'):
+        @registering(os.kill)
+        def register_os_kill(self):
+            os_kill = rffi.llexternal('kill', [rffi.PID_T, rffi.INT],
+                                      rffi.INT,
+                                      includes=['sys/types.h', 'signal.h'])
+
+            def kill_lltypeimpl(pid, sig):
+                res = os_kill(rffi.cast(rffi.PID_T, pid),
+                              rffi.cast(rffi.INT, sig))
+                if res < 0:
+                    raise OSError(rffi.get_errno(), "os_kill failed")
+
+            self.register(os.kill, [int, int], s_None, llimpl=kill_lltypeimpl,
+                          export_name="ll_os.ll_os_kill")
+
 # --------------------------- os.stat & variants ---------------------------
 
     @registering(os.fstat)
@@ -861,10 +877,6 @@
     # XXX deprecated style, this is all waiting to be converted to rffi
     __metaclass__ = ClassMethods
 
-    def ll_os_kill(cls, pid, sig):
-        os.kill(pid, sig)
-    ll_os_kill.suggested_primitive = True
-
     def ll_os_link(cls, path1, path2):
         os.link(cls.from_rstr(path1), cls.from_rstr(path2))
     ll_os_link.suggested_primitive = True

Modified: pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py	Thu Aug 16 16:27:20 2007
@@ -20,7 +20,6 @@
 # references to functions, so we cannot insert classmethods here.
 
 EXTERNALS = {
-    impl.ll_os_kill.im_func:    'LL_os_kill',
     impl.ll_os_link.im_func:    'LL_os_link',
     impl.ll_os_symlink.im_func: 'LL_os_symlink',
     impl.ll_os_fork.im_func:    'LL_os_fork',

Modified: pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h	Thu Aug 16 16:27:20 2007
@@ -68,15 +68,6 @@
 
 #include "ll_osdefs.h"
 
-#ifdef HAVE_KILL
-void LL_os_kill(int pid, int sig) {
-    int error = kill(pid, sig);
-    if (error != 0) {
-	RPYTHON_RAISE_OSERROR(errno);
-    }
-}
-#endif
-
 #ifdef HAVE_FILESYSTEM_WITH_LINKS
 
 void LL_os_link(RPyString * path1, RPyString * path2) {

Modified: pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_extfunc.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_extfunc.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_extfunc.py	Thu Aug 16 16:27:20 2007
@@ -641,6 +641,22 @@
         status1 = f1()
         assert os.WIFEXITED(status1)
         assert os.WEXITSTATUS(status1) == 4
+    if hasattr(os, 'kill'):
+        def test_kill():
+            import signal
+            def does_stuff():
+                pid = os.fork()
+                if pid == 0:   # child
+                    time.sleep(5)
+                    os._exit(4)
+                os.kill(pid, signal.SIGTERM)  # in the parent
+                pid1, status1 = os.waitpid(pid, 0)
+                assert pid1 == pid
+                return status1
+            f1 = compile(does_stuff, [])
+            status1 = f1()
+            assert os.WIFSIGNALED(status1)
+            assert os.WTERMSIG(status1) == signal.SIGTERM
 elif hasattr(os, 'waitpid'):
     # windows has no fork but some waitpid to be emulated
     def test_waitpid():



More information about the Pypy-commit mailing list