[pypy-svn] pypy improve-unwrap_spec: simplify unwrap_spec for modules select, signal

amauryfa commits-noreply at bitbucket.org
Wed Feb 16 19:20:20 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: improve-unwrap_spec
Changeset: r42084:6ac5da276e32
Date: 2011-02-16 18:30 +0100
http://bitbucket.org/pypy/pypy/changeset/6ac5da276e32/

Log:	simplify unwrap_spec for modules select, signal

diff --git a/pypy/module/select/interp_select.py b/pypy/module/select/interp_select.py
--- a/pypy/module/select/interp_select.py
+++ b/pypy/module/select/interp_select.py
@@ -1,7 +1,7 @@
 import math
 from pypy.interpreter.typedef import TypeDef
 from pypy.interpreter.baseobjspace import Wrappable
-from pypy.interpreter.gateway import W_Root, ObjSpace, interp2app
+from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.error import (
     OperationError, operationerrfmt, wrap_oserror)
 from pypy.rlib import rpoll
@@ -18,18 +18,18 @@
     def __init__(self):
         self.fddict = {}
 
+    @unwrap_spec(events=int)
     def register(self, space, w_fd, events=defaultevents):
         fd = space.c_filedescriptor_w(w_fd)
         self.fddict[fd] = events
-    register.unwrap_spec = ['self', ObjSpace, W_Root, int]
 
+    @unwrap_spec(events=int)
     def modify(self, space, w_fd, events):
         fd = space.c_filedescriptor_w(w_fd)
         if fd not in self.fddict:
             raise wrap_oserror(space, OSError(errno.ENOENT, "poll.modify"),
                                exception_name='w_IOError')
         self.fddict[fd] = events
-    modify.unwrap_spec = ['self', ObjSpace, W_Root, int]
 
     def unregister(self, space, w_fd):
         fd = space.c_filedescriptor_w(w_fd)
@@ -38,7 +38,6 @@
         except KeyError:
             raise OperationError(space.w_KeyError,
                                  space.wrap(fd)) # XXX should this maybe be w_fd?
-    unregister.unwrap_spec = ['self', ObjSpace, W_Root]
 
     def poll(self, space, w_timeout=None):
         if space.is_w(w_timeout, space.w_None):
@@ -68,14 +67,10 @@
             retval_w.append(space.newtuple([space.wrap(fd),
                                             space.wrap(revents)]))
         return space.newlist(retval_w)
-    poll.unwrap_spec = ['self', ObjSpace, W_Root]
 
 pollmethods = {}
 for methodname in 'register modify unregister poll'.split():
-    method = getattr(Poll, methodname)
-    assert hasattr(method,'unwrap_spec'), methodname
-    assert method.im_func.func_code.co_argcount == len(method.unwrap_spec), methodname
-    pollmethods[methodname] = interp2app(method, unwrap_spec=method.unwrap_spec)
+    pollmethods[methodname] = interp2app(getattr(Poll, methodname))
 Poll.typedef = TypeDef('select.poll', **pollmethods)
 
 def select(space, w_iwtd, w_owtd, w_ewtd, w_timeout=None):

diff --git a/pypy/module/select/interp_epoll.py b/pypy/module/select/interp_epoll.py
--- a/pypy/module/select/interp_epoll.py
+++ b/pypy/module/select/interp_epoll.py
@@ -3,7 +3,7 @@
 import errno
 
 from pypy.interpreter.baseobjspace import Wrappable
-from pypy.interpreter.gateway import interp2app, unwrap_spec, ObjSpace, W_Root
+from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.error import OperationError, operationerrfmt, exception_from_errno
 from pypy.interpreter.typedef import TypeDef, GetSetProperty
 from pypy.rpython.lltypesystem import lltype, rffi
@@ -60,7 +60,7 @@
         self.space = space
         self.epfd = epfd
 
-    @unwrap_spec(ObjSpace, W_Root, int)
+    @unwrap_spec(sizehint=int)
     def descr__new__(space, w_subtype, sizehint=-1):
         if sizehint == -1:
             sizehint = FD_SETSIZE - 1
@@ -74,7 +74,7 @@
 
         return space.wrap(W_Epoll(space, epfd))
 
-    @unwrap_spec(ObjSpace, W_Root, int)
+    @unwrap_spec(fd=int)
     def descr_fromfd(space, w_cls, fd):
         return space.wrap(W_Epoll(space, fd))
 
@@ -107,32 +107,29 @@
     def descr_get_closed(space, self):
         return space.wrap(self.epfd < 0)
 
-    @unwrap_spec("self", ObjSpace)
     def descr_fileno(self, space):
         self.check_closed()
         return space.wrap(self.epfd)
 
-    @unwrap_spec("self", ObjSpace)
     def descr_close(self, space):
         self.check_closed()
         self.close()
 
-    @unwrap_spec("self", ObjSpace, W_Root, int)
+    @unwrap_spec(eventmask=int)
     def descr_register(self, space, w_fd, eventmask=-1):
         self.check_closed()
         self.epoll_ctl(EPOLL_CTL_ADD, w_fd, eventmask)
 
-    @unwrap_spec("self", ObjSpace, W_Root)
     def descr_unregister(self, space, w_fd):
         self.check_closed()
         self.epoll_ctl(EPOLL_CTL_DEL, w_fd, 0, ignore_ebadf=True)
 
-    @unwrap_spec("self", ObjSpace, W_Root, int)
+    @unwrap_spec(eventmask=int)
     def descr_modify(self, space, w_fd, eventmask=-1):
         self.check_closed()
         self.epoll_ctl(EPOLL_CTL_MOD, w_fd, eventmask)
 
-    @unwrap_spec("self", ObjSpace, float, int)
+    @unwrap_spec(timeout=float, maxevents=int)
     def descr_poll(self, space, timeout=-1.0, maxevents=-1):
         self.check_closed()
         if timeout < 0:

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
@@ -1,6 +1,5 @@
 from __future__ import with_statement
 from pypy.interpreter.error import OperationError, exception_from_errno
-from pypy.interpreter.baseobjspace import W_Root, ObjSpace
 from pypy.interpreter.executioncontext import AsyncAction, AbstractActionFlag
 from pypy.interpreter.executioncontext import PeriodicAsyncAction
 from pypy.interpreter.gateway import unwrap_spec
@@ -192,6 +191,7 @@
             self.fire_after_thread_switch()
 
 
+ at unwrap_spec(signum=int)
 def getsignal(space, signum):
     """
     getsignal(sig) -> action
@@ -207,18 +207,16 @@
     if signum in action.handlers_w:
         return action.handlers_w[signum]
     return space.wrap(SIG_DFL)
-getsignal.unwrap_spec = [ObjSpace, int]
 
 @jit.dont_look_inside
+ at unwrap_spec(timeout=int)
 def alarm(space, timeout):
     return space.wrap(c_alarm(timeout))
-alarm.unwrap_spec = [ObjSpace, int]
 
 @jit.dont_look_inside
 def pause(space):
     c_pause()
     return space.w_None
-pause.unwrap_spec = [ObjSpace]
 
 def check_signum(space, signum):
     if signum < 1 or signum >= NSIG:
@@ -226,6 +224,7 @@
                              space.wrap("signal number out of range"))
 
 @jit.dont_look_inside
+ at unwrap_spec(signum=int)
 def signal(space, signum, w_handler):
     """
     signal(sig, action) -> action
@@ -262,8 +261,8 @@
         pypysig_setflag(signum)
         action.handlers_w[signum] = w_handler
     return old_handler
-signal.unwrap_spec = [ObjSpace, int, W_Root]
 
+ at unwrap_spec(fd=int)
 def set_wakeup_fd(space, fd):
     """Sets the fd to be written to (with '\0') when a signal
     comes in.  Returns the old fd.  A library can use this to
@@ -280,14 +279,13 @@
                 space.wrap("set_wakeup_fd only works in main thread"))
     old_fd = pypysig_set_wakeup_fd(fd)
     return space.wrap(intmask(old_fd))
-set_wakeup_fd.unwrap_spec = [ObjSpace, int]
 
+ at unwrap_spec(signum=int, flag=int)
 def siginterrupt(space, signum, flag):
     check_signum(space, signum)
     if rffi.cast(lltype.Signed, c_siginterrupt(signum, flag)) < 0:
         errno = rposix.get_errno()
         raise OperationError(space.w_RuntimeError, space.wrap(errno))
-siginterrupt.unwrap_spec = [ObjSpace, int, int]
 
 
 #__________________________________________________________
@@ -310,7 +308,7 @@
     return space.getattr(mod, space.wrap("ItimerError"))
 
 @jit.dont_look_inside
- at unwrap_spec(ObjSpace, int, float, float)
+ at unwrap_spec(which=int, first=float, interval=float)
 def setitimer(space, which, first, interval=0):
     with lltype.scoped_alloc(itimervalP.TO, 1) as new:
 
@@ -327,7 +325,7 @@
             return itimer_retval(space, old[0])
 
 @jit.dont_look_inside
- at unwrap_spec(ObjSpace, int)
+ at unwrap_spec(which=int)
 def getitimer(space, which):
     with lltype.scoped_alloc(itimervalP.TO, 1) as old:
 


More information about the Pypy-commit mailing list