Commit d5e74947 authored by Kirill Smelkov's avatar Kirill Smelkov

golang.pyx: pyselect: * -> py* in logic which analyzes cases

For clarity to denote that things work at Python level:

    - casev	-> pycasev
    - case	-> pycase
    - recv	-> pyrecv
    - send	-> pysend

Channel object is still denoted as `ch` to reduce noise for when chan IO
code will be move into libgolang. `ch` will be renamed to `pych` after
that.
parent b9333e00
...@@ -473,31 +473,31 @@ pydefault = object() ...@@ -473,31 +473,31 @@ pydefault = object()
# if _ == 3: # if _ == 3:
# # default case # # default case
# ... # ...
def pyselect(*casev): def pyselect(*pycasev):
# select promise: if multiple cases are ready - one will be selected randomly # select promise: if multiple cases are ready - one will be selected randomly
ncasev = list(enumerate(casev)) npycasev = list(enumerate(pycasev))
random.shuffle(ncasev) random.shuffle(npycasev)
# first pass: poll all cases and bail out in the end if default was provided # first pass: poll all cases and bail out in the end if default was provided
recvv = [] # [](n, ch, commaok) recvv = [] # [](n, ch, commaok)
sendv = [] # [](n, ch, tx) sendv = [] # [](n, ch, tx)
ndefault = None ndefault = None
for (n, case) in ncasev: for (n, pycase) in npycasev:
# default: remember we have it # default: remember we have it
if case is pydefault: if pycase is pydefault:
if ndefault is not None: if ndefault is not None:
pypanic("pyselect: multiple default") pypanic("pyselect: multiple default")
ndefault = n ndefault = n
# send # send
elif isinstance(case, tuple): elif isinstance(pycase, tuple):
send, tx = case pysend, tx = pycase
if send.__self__.__class__ is not pychan: if pysend.__self__.__class__ is not pychan:
pypanic("pyselect: send on non-chan: %r" % (send.__self__.__class__,)) pypanic("pyselect: send on non-chan: %r" % (pysend.__self__.__class__,))
if send.__name__ != "send": # XXX better check PyCFunction directly if pysend.__name__ != "send": # XXX better check PyCFunction directly
pypanic("pyselect: send expected: %r" % (send,)) pypanic("pyselect: send expected: %r" % (pysend,))
ch = send.__self__ ch = pysend.__self__
if ch is not pynilchan: # nil chan is never ready if ch is not pynilchan: # nil chan is never ready
ch._mu.acquire() ch._mu.acquire()
if 1: if 1:
...@@ -510,17 +510,17 @@ def pyselect(*casev): ...@@ -510,17 +510,17 @@ def pyselect(*casev):
# recv # recv
else: else:
recv = case pyrecv = pycase
if recv.__self__.__class__ is not pychan: if pyrecv.__self__.__class__ is not pychan:
pypanic("pyselect: recv on non-chan: %r" % (recv.__self__.__class__,)) pypanic("pyselect: recv on non-chan: %r" % (pyrecv.__self__.__class__,))
if recv.__name__ == "recv": # XXX better check PyCFunction directly if pyrecv.__name__ == "recv": # XXX better check PyCFunction directly
commaok = False commaok = False
elif recv.__name__ == "recv_": # XXX better check PyCFunction directly elif pyrecv.__name__ == "recv_": # XXX better check PyCFunction directly
commaok = True commaok = True
else: else:
pypanic("pyselect: recv expected: %r" % (recv,)) pypanic("pyselect: recv expected: %r" % (pyrecv,))
ch = recv.__self__ ch = pyrecv.__self__
if ch is not pynilchan: # nil chan is never ready if ch is not pynilchan: # nil chan is never ready
ch._mu.acquire() ch._mu.acquire()
if 1: if 1:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment