Author: Alexander Hesse <webmas...@aquanasoft.de>
Branch: split-rpython
Changeset: r59929:355ee8f6486f
Date: 2013-01-10 21:15 +0100
http://bitbucket.org/pypy/pypy/changeset/355ee8f6486f/

Log:    split up interp_signal, added rlib.rsignal

diff --git a/pypy/module/signal/interp_signal.py 
b/pypy/module/signal/interp_signal.py
--- a/pypy/module/signal/interp_signal.py
+++ b/pypy/module/signal/interp_signal.py
@@ -12,99 +12,7 @@
 import sys
 from rpython.rlib import jit, rposix
 from rpython.rlib.rarithmetic import intmask, is_valid_int
-
-def setup():
-    for key, value in cpy_signal.__dict__.items():
-        if (key.startswith('SIG') or key.startswith('CTRL_')) and \
-                is_valid_int(value) and \
-                key != 'SIG_DFL' and key != 'SIG_IGN':
-            globals()[key] = value
-            yield key
-
-NSIG    = cpy_signal.NSIG
-SIG_DFL = cpy_signal.SIG_DFL
-SIG_IGN = cpy_signal.SIG_IGN
-signal_names = list(setup())
-signal_values = {}
-for key in signal_names:
-    signal_values[globals()[key]] = None
-if sys.platform == 'win32' and not hasattr(cpy_signal,'CTRL_C_EVENT'):
-    # XXX Hack to revive values that went missing,
-    #     Remove this once we are sure the host cpy module has them.
-    signal_values[0] = None
-    signal_values[1] = None
-    signal_names.append('CTRL_C_EVENT')
-    signal_names.append('CTRL_BREAK_EVENT')
-    CTRL_C_EVENT = 0
-    CTRL_BREAK_EVENT = 1
-includes = ['stdlib.h', 'src/signals.h']
-if sys.platform != 'win32':
-    includes.append('sys/time.h')
-
-cdir = py.path.local(cdir)
-
-eci = ExternalCompilationInfo(
-    includes = includes,
-    separate_module_files = [cdir / 'src' / 'signals.c'],
-    include_dirs = [str(cdir)],
-    export_symbols = ['pypysig_poll', 'pypysig_default',
-                      'pypysig_ignore', 'pypysig_setflag',
-                      'pypysig_reinstall',
-                      'pypysig_set_wakeup_fd',
-                      'pypysig_getaddr_occurred'],
-)
-
-class CConfig:
-    _compilation_info_ = eci
-
-if sys.platform != 'win32':
-    for name in """ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF""".split():
-        setattr(CConfig, name, rffi_platform.DefinedConstantInteger(name))
-
-    CConfig.timeval = rffi_platform.Struct(
-        'struct timeval',
-        [('tv_sec', rffi.LONG),
-         ('tv_usec', rffi.LONG)])
-
-    CConfig.itimerval = rffi_platform.Struct(
-        'struct itimerval',
-        [('it_value', CConfig.timeval),
-         ('it_interval', CConfig.timeval)])
-
-for k, v in rffi_platform.configure(CConfig).items():
-    globals()[k] = v
-
-def external(name, args, result, **kwds):
-    return rffi.llexternal(name, args, result, compilation_info=eci,
-                           sandboxsafe=True, **kwds)
-
-pypysig_ignore = external('pypysig_ignore', [rffi.INT], lltype.Void)
-pypysig_default = external('pypysig_default', [rffi.INT], lltype.Void)
-pypysig_setflag = external('pypysig_setflag', [rffi.INT], lltype.Void)
-pypysig_reinstall = external('pypysig_reinstall', [rffi.INT], lltype.Void)
-pypysig_set_wakeup_fd = external('pypysig_set_wakeup_fd', [rffi.INT], rffi.INT)
-pypysig_poll = external('pypysig_poll', [], rffi.INT, threadsafe=False)
-# don't bother releasing the GIL around a call to pypysig_poll: it's
-# pointless and a performance issue
-
-# don't use rffi.LONGP because the JIT doesn't support raw arrays so far
-struct_name = 'pypysig_long_struct'
-LONG_STRUCT = lltype.Struct(struct_name, ('c_value', lltype.Signed),
-                            hints={'c_name' : struct_name, 'external' : 'C'})
-del struct_name
-
-pypysig_getaddr_occurred = external('pypysig_getaddr_occurred', [],
-                                    lltype.Ptr(LONG_STRUCT), _nowrapper=True,
-                                    elidable_function=True)
-c_alarm = external('alarm', [rffi.INT], rffi.INT)
-c_pause = external('pause', [], rffi.INT, threadsafe=True)
-c_siginterrupt = external('siginterrupt', [rffi.INT, rffi.INT], rffi.INT)
-
-if sys.platform != 'win32':
-    itimervalP = rffi.CArrayPtr(itimerval)
-    c_setitimer = external('setitimer',
-                           [rffi.INT, itimervalP, itimervalP], rffi.INT)
-    c_getitimer = external('getitimer', [rffi.INT, itimervalP], rffi.INT)
+from rpython.rlib.rsignal import *
 
 
 class SignalActionFlag(AbstractActionFlag):
diff --git a/rpython/jit/metainterp/test/test_del.py 
b/rpython/jit/metainterp/test/test_del.py
--- a/rpython/jit/metainterp/test/test_del.py
+++ b/rpython/jit/metainterp/test/test_del.py
@@ -123,46 +123,8 @@
         res = self.meta_interp(main, [20])
         assert res == 1001
 
-# Minimal copy of pypy.module.signal.interp_signal.SignalActionFlag for
-# TestLLtype
-from rpython.rtyper.lltypesystem import lltype, rffi
-
-class Ticker(object):
-    def __init__(self):
-        self.ticker = rffi.llexternal('ticker', [],
-                                     lltype.Ptr(LONG_STRUCT),
-                                     compilation_info=eci,
-                                     sandboxsafe=True, _nowrapper=True,
-                                     elidable_function=True)
-    
-    def reset_ticker(self, value):
-        self.ticker().c_value = value
-
-    def decrement_ticker(self, by):
-        self.ticker().c_value -= by
-        return self.ticker().c_value
-
 class TestLLtype(DelTests, LLJitMixin):
-    def test_signal_action(self):
-        action = Ticker()
-        #
-        myjitdriver = JitDriver(greens = [], reds = ['n', 'x'])
-        class X:
-            pass
-        #
-        def f(n):
-            x = X()
-            action.reset_ticker(n)
-            while True:
-                myjitdriver.can_enter_jit(n=n, x=x)
-                myjitdriver.jit_merge_point(n=n, x=x)
-                x.foo = n
-                n -= 1
-                if action.decrement_ticker(1) < 0:
-                    break
-            return 42
-        self.meta_interp(f, [20])
-        self.check_resops(call_pure=0, setfield_raw=2, call=0, getfield_raw=2)
+    pass
 
 class TestOOtype(DelTests, OOJitMixin):
     def setup_class(cls):
diff --git a/rpython/rlib/rsignal.py b/rpython/rlib/rsignal.py
new file mode 100644
--- /dev/null
+++ b/rpython/rlib/rsignal.py
@@ -0,0 +1,100 @@
+import signal as cpy_signal
+import sys
+import py
+from rpython.conftest import cdir
+from rpython.rtyper.tool import rffi_platform
+from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.translator.tool.cbuild import ExternalCompilationInfo
+
+def setup():
+    for key, value in cpy_signal.__dict__.items():
+        if (key.startswith('SIG') or key.startswith('CTRL_')) and \
+                is_valid_int(value) and \
+                key != 'SIG_DFL' and key != 'SIG_IGN':
+            globals()[key] = value
+            yield key
+
+NSIG    = cpy_signal.NSIG
+SIG_DFL = cpy_signal.SIG_DFL
+SIG_IGN = cpy_signal.SIG_IGN
+signal_names = list(setup())
+signal_values = {}
+for key in signal_names:
+    signal_values[globals()[key]] = None
+if sys.platform == 'win32' and not hasattr(cpy_signal,'CTRL_C_EVENT'):
+    # XXX Hack to revive values that went missing,
+    #     Remove this once we are sure the host cpy module has them.
+    signal_values[0] = None
+    signal_values[1] = None
+    signal_names.append('CTRL_C_EVENT')
+    signal_names.append('CTRL_BREAK_EVENT')
+    CTRL_C_EVENT = 0
+    CTRL_BREAK_EVENT = 1
+includes = ['stdlib.h', 'src/signals.h']
+if sys.platform != 'win32':
+    includes.append('sys/time.h')
+
+cdir = py.path.local(cdir)
+
+eci = ExternalCompilationInfo(
+    includes = includes,
+    separate_module_files = [cdir / 'src' / 'signals.c'],
+    include_dirs = [str(cdir)],
+    export_symbols = ['pypysig_poll', 'pypysig_default',
+                      'pypysig_ignore', 'pypysig_setflag',
+                      'pypysig_reinstall',
+                      'pypysig_set_wakeup_fd',
+                      'pypysig_getaddr_occurred'],
+)
+
+class CConfig:
+    _compilation_info_ = eci
+
+if sys.platform != 'win32':
+    for name in """ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF""".split():
+        setattr(CConfig, name, rffi_platform.DefinedConstantInteger(name))
+
+    CConfig.timeval = rffi_platform.Struct(
+        'struct timeval',
+        [('tv_sec', rffi.LONG),
+         ('tv_usec', rffi.LONG)])
+
+    CConfig.itimerval = rffi_platform.Struct(
+        'struct itimerval',
+        [('it_value', CConfig.timeval),
+         ('it_interval', CConfig.timeval)])
+
+for k, v in rffi_platform.configure(CConfig).items():
+    globals()[k] = v
+
+def external(name, args, result, **kwds):
+    return rffi.llexternal(name, args, result, compilation_info=eci,
+                           sandboxsafe=True, **kwds)
+
+pypysig_ignore = external('pypysig_ignore', [rffi.INT], lltype.Void)
+pypysig_default = external('pypysig_default', [rffi.INT], lltype.Void)
+pypysig_setflag = external('pypysig_setflag', [rffi.INT], lltype.Void)
+pypysig_reinstall = external('pypysig_reinstall', [rffi.INT], lltype.Void)
+pypysig_set_wakeup_fd = external('pypysig_set_wakeup_fd', [rffi.INT], rffi.INT)
+pypysig_poll = external('pypysig_poll', [], rffi.INT, threadsafe=False)
+# don't bother releasing the GIL around a call to pypysig_poll: it's
+# pointless and a performance issue
+
+# don't use rffi.LONGP because the JIT doesn't support raw arrays so far
+struct_name = 'pypysig_long_struct'
+LONG_STRUCT = lltype.Struct(struct_name, ('c_value', lltype.Signed),
+                            hints={'c_name' : struct_name, 'external' : 'C'})
+del struct_name
+
+pypysig_getaddr_occurred = external('pypysig_getaddr_occurred', [],
+                                    lltype.Ptr(LONG_STRUCT), _nowrapper=True,
+                                    elidable_function=True)
+c_alarm = external('alarm', [rffi.INT], rffi.INT)
+c_pause = external('pause', [], rffi.INT, threadsafe=True)
+c_siginterrupt = external('siginterrupt', [rffi.INT, rffi.INT], rffi.INT)
+
+if sys.platform != 'win32':
+    itimervalP = rffi.CArrayPtr(itimerval)
+    c_setitimer = external('setitimer',
+                           [rffi.INT, itimervalP, itimervalP], rffi.INT)
+    c_getitimer = external('getitimer', [rffi.INT, itimervalP], rffi.INT)
diff --git a/pypy/module/signal/test/test_interp_signal.py 
b/rpython/rlib/test/test_rsignal.py
rename from pypy/module/signal/test/test_interp_signal.py
rename to rpython/rlib/test/test_rsignal.py
--- a/pypy/module/signal/test/test_interp_signal.py
+++ b/rpython/rlib/test/test_rsignal.py
@@ -1,16 +1,16 @@
 import os, py
 from rpython.translator.c.test.test_genc import compile
-from pypy.module.signal import interp_signal
+from rpython.rlib import rsignal
 
 def setup_module(mod):
     if not hasattr(os, 'kill') or not hasattr(os, 'getpid'):
         py.test.skip("requires os.kill() and os.getpid()")
-    if not hasattr(interp_signal, 'SIGUSR1'):
+    if not hasattr(signals, 'SIGUSR1'):
         py.test.skip("requires SIGUSR1 in signal")
 
 
 def check(expected):
-    res = interp_signal.pypysig_poll()
+    res = rsignal.pypysig_poll()
     os.write(1, "poll() => %d, expected %d\n" % (res, expected))
     assert res == expected
 
@@ -19,18 +19,18 @@
     check(-1)
     check(-1)
     for i in range(3):
-        interp_signal.pypysig_setflag(interp_signal.SIGUSR1)
-        os.kill(os.getpid(), interp_signal.SIGUSR1)
-        check(interp_signal.SIGUSR1)
+        rsignal.pypysig_setflag(rsignal.SIGUSR1)
+        os.kill(os.getpid(), rsignal.SIGUSR1)
+        check(rsignal.SIGUSR1)
         check(-1)
         check(-1)
 
-    interp_signal.pypysig_ignore(interp_signal.SIGUSR1)
-    os.kill(os.getpid(), interp_signal.SIGUSR1)
+    rsignal.pypysig_ignore(rsignal.SIGUSR1)
+    os.kill(os.getpid(), rsignal.SIGUSR1)
     check(-1)
     check(-1)
 
-    interp_signal.pypysig_default(interp_signal.SIGUSR1)
+    rsignal.pypysig_default(rsignal.SIGUSR1)
     check(-1)
 
 
diff --git a/rpython/translator/c/src/signals.h 
b/rpython/translator/c/src/signals.h
--- a/rpython/translator/c/src/signals.h
+++ b/rpython/translator/c/src/signals.h
@@ -13,7 +13,7 @@
 int pypysig_poll(void);   /* => signum or -1 */
 
 /* When a signal is received, pypysig_counter is set to -1. */
-/* This is a struct for the JIT. See interp_signal.py. */
+/* This is a struct for the JIT. See rsignal.py. */
 struct pypysig_long_struct {
     long value;
 };
diff --git a/rpython/translator/c/test/test_extfunc.py 
b/rpython/translator/c/test/test_extfunc.py
--- a/rpython/translator/c/test/test_extfunc.py
+++ b/rpython/translator/c/test/test_extfunc.py
@@ -547,13 +547,13 @@
 if hasattr(os, 'kill'):
     def test_kill_to_send_sigusr1():
         import signal
-        from pypy.module.signal import interp_signal
+        from rpython.rlib import rsignal
         def does_stuff():
-            interp_signal.pypysig_setflag(signal.SIGUSR1)
+            rsignal.pypysig_setflag(signal.SIGUSR1)
             os.kill(os.getpid(), signal.SIGUSR1)
-            interp_signal.pypysig_ignore(signal.SIGUSR1)
+            rsignal.pypysig_ignore(signal.SIGUSR1)
             while True:
-                n = interp_signal.pypysig_poll()
+                n = rsignal.pypysig_poll()
                 if n < 0 or n == signal.SIGUSR1:
                     break
             return n
@@ -564,14 +564,14 @@
 if hasattr(os, 'killpg'):
     def test_killpg():
         import signal
-        from pypy.module.signal import interp_signal
+        from rpython.rlib import rsignal
         def does_stuff():
             os.setpgid(0, 0)     # become its own separated process group
-            interp_signal.pypysig_setflag(signal.SIGUSR1)
+            rsignal.pypysig_setflag(signal.SIGUSR1)
             os.killpg(os.getpgrp(), signal.SIGUSR1)
-            interp_signal.pypysig_ignore(signal.SIGUSR1)
+            rsignal.pypysig_ignore(signal.SIGUSR1)
             while True:
-                n = interp_signal.pypysig_poll()
+                n = rsignal.pypysig_poll()
                 if n < 0 or n == signal.SIGUSR1:
                     break
             return n
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to