Commit 30561db4 authored by Kirill Smelkov's avatar Kirill Smelkov

golang: pyselect: Switch into using inplace tx data

This prepares pyselect codebase for future logic where all channel
element types will be sent via inplace _selcase data. For PyObject we
could previously go with "wiring ptx through pycase[1]", but for
arbitrary type, that has to be first converted from Python object to
C-level object, we would have to store the result somewhere, and that
would mean extra allocation and pyselect code complexity increase, even
for cases that don't use anything but chan[object].

So do the preparation and switch pyselect into using inplace tx.
parent 47111d3e
......@@ -300,15 +300,15 @@ def pyselect(*pycasev):
if pysend.__name__ != "send": # XXX better check PyCFunction directly
pypanic("pyselect: send expected: %r" % (pysend,))
# wire ptx through pycase[1]
p_tx = &(_tcase.ob_item[1])
tx = <object>(p_tx[0])
tx = <object>(_tcase.ob_item[1])
# incref tx as if corresponding channel is holding pointer to the object while it is being sent.
# we'll decref the object if it won't be sent.
# see pychan.send for details.
Py_INCREF(tx)
casev[i] = _selsend(pych._ch, p_tx)
casev[i] = _selsend(pych._ch, NULL)
casev[i].flags = _INPLACE_DATA
(<PyObject **>&casev[i].itxrx)[0] = <PyObject *>tx
# recv
else:
......@@ -331,9 +331,8 @@ def pyselect(*pycasev):
# decref not sent tx (see ^^^ send prepare)
for i in range(n):
if casev[i].op == _CHANSEND and (i != selected):
p_tx = <PyObject **>casev[i].ptx()
_tx = p_tx[0]
tx = <object>_tx
_tx = (<PyObject **>casev[i].ptx())[0]
tx = <object>_tx
Py_DECREF(tx)
# return what was selected
......
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