Commits

Armin Rigo committed e965f9c

Move things around, for _always_inline_ to work

Comments (0)

Files changed (1)

pypy/module/select/interp_select.py

         if _c.FD_ISSET(fd, ll_list):
             reslist_w.append(list_w[i])
 
+def _call_select(space, iwtd_w, owtd_w, ewtd_w,
+                 ll_inl, ll_outl, ll_errl, ll_timeval):
+    fdlistin  = None
+    fdlistout = None
+    fdlisterr = None
+    nfds = -1
+    if ll_inl:
+        fdlistin, nfds = _build_fd_set(space, iwtd_w, ll_inl, nfds)
+    if ll_outl:
+        fdlistout, nfds = _build_fd_set(space, owtd_w, ll_outl, nfds)
+    if ll_errl:
+        fdlisterr, nfds = _build_fd_set(space, ewtd_w, ll_errl, nfds)
+
+    res = _c.select(nfds + 1, ll_inl, ll_outl, ll_errl, ll_timeval)
+
+    if res < 0:
+        errno = _c.geterrno()
+        msg = _c.socket_strerror_str(errno)
+        w_errortype = space.fromcache(Cache).w_error
+        raise OperationError(w_errortype, space.newtuple([
+            space.wrap(errno), space.wrap(msg)]))
+
+    resin_w = []
+    resout_w = []
+    reserr_w = []
+    if res > 0:
+        if fdlistin is not None:
+            _unbuild_fd_set(space, iwtd_w, fdlistin,  ll_inl,  resin_w)
+        if fdlistout is not None:
+            _unbuild_fd_set(space, owtd_w, fdlistout, ll_outl, resout_w)
+        if fdlisterr is not None:
+            _unbuild_fd_set(space, ewtd_w, fdlisterr, ll_errl, reserr_w)
+    return space.newtuple([space.newlist(resin_w),
+                           space.newlist(resout_w),
+                           space.newlist(reserr_w)])
 
 @unwrap_spec(w_timeout = WrappedDefault(None))
 def select(space, w_iwtd, w_owtd, w_ewtd, w_timeout):
     owtd_w = space.listview(w_owtd)
     ewtd_w = space.listview(w_ewtd)
 
+    if space.is_w(w_timeout, space.w_None):
+        timeout = -1.0
+    else:
+        timeout = space.float_w(w_timeout)
+
     ll_inl  = lltype.nullptr(_c.fd_set.TO)
     ll_outl = lltype.nullptr(_c.fd_set.TO)
     ll_errl = lltype.nullptr(_c.fd_set.TO)
     ll_timeval = lltype.nullptr(_c.timeval)
-    
+
     try:
-        fdlistin  = None
-        fdlistout = None
-        fdlisterr = None
-        nfds = -1
         if len(iwtd_w) > 0:
             ll_inl = lltype.malloc(_c.fd_set.TO, flavor='raw')
-            fdlistin, nfds = _build_fd_set(space, iwtd_w, ll_inl, nfds)
         if len(owtd_w) > 0:
             ll_outl = lltype.malloc(_c.fd_set.TO, flavor='raw')
-            fdlistout, nfds = _build_fd_set(space, owtd_w, ll_outl, nfds)
         if len(ewtd_w) > 0:
             ll_errl = lltype.malloc(_c.fd_set.TO, flavor='raw')
-            fdlisterr, nfds = _build_fd_set(space, ewtd_w, ll_errl, nfds)
-
-        if space.is_w(w_timeout, space.w_None):
-            timeout = -1.0
-        else:
-            timeout = space.float_w(w_timeout)
         if timeout >= 0.0:
             ll_timeval = rffi.make(_c.timeval)
             i = int(timeout)
             rffi.setintfield(ll_timeval, 'c_tv_sec', i)
             rffi.setintfield(ll_timeval, 'c_tv_usec', int((timeout-i)*1000000))
 
-        res = _c.select(nfds + 1, ll_inl, ll_outl, ll_errl, ll_timeval)
-
-        if res < 0:
-            errno = _c.geterrno()
-            msg = _c.socket_strerror_str(errno)
-            w_errortype = space.fromcache(Cache).w_error
-            raise OperationError(w_errortype, space.newtuple([
-                space.wrap(errno), space.wrap(msg)]))
-
-        resin_w = []
-        resout_w = []
-        reserr_w = []
-        if res > 0:
-            if fdlistin is not None:
-                _unbuild_fd_set(space, iwtd_w, fdlistin,  ll_inl,  resin_w)
-            if fdlistout is not None:
-                _unbuild_fd_set(space, owtd_w, fdlistout, ll_outl, resout_w)
-            if fdlisterr is not None:
-                _unbuild_fd_set(space, ewtd_w, fdlisterr, ll_errl, reserr_w)
+        # Call this as a separate helper to avoid a large piece of code
+        # in try:finally:.  Needed for calling further _always_inline_
+        # helpers like _build_fd_set().
+        return _call_select(space, iwtd_w, owtd_w, ewtd_w,
+                            ll_inl, ll_outl, ll_errl, ll_timeval)
     finally:
         if ll_timeval: lltype.free(ll_timeval, flavor='raw')
         if ll_errl:    lltype.free(ll_errl, flavor='raw')
         if ll_outl:    lltype.free(ll_outl, flavor='raw')
         if ll_inl:     lltype.free(ll_inl, flavor='raw')
-
-    return space.newtuple([space.newlist(resin_w),
-                           space.newlist(resout_w),
-                           space.newlist(reserr_w)])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.