Author: Armin Rigo <[email protected]>
Branch:
Changeset: r59075:e965f9c5b2a6
Date: 2012-11-23 20:26 +0100
http://bitbucket.org/pypy/pypy/changeset/e965f9c5b2a6/
Log: Move things around, for _always_inline_ to work
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
@@ -100,6 +100,41 @@
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):
@@ -128,61 +163,36 @@
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)])
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit