Commit f6fab7b5 authored by Kirill Smelkov's avatar Kirill Smelkov

*: Annotate method receiver with corresponding type for all cdef classes

For example

    -    def send(pych, obj):
    +    def send(pychan pych, obj):

Even though Cython allows not to annotate self with type, this makes the
code more clear.
parent 30561db4
......@@ -145,10 +145,10 @@ cdef void __goviac(void *arg) nogil:
# pychan is chan<object>.
@final
cdef class pychan:
def __cinit__(pych, size=0):
def __cinit__(pychan pych, size=0):
pych._ch = _makechan_pyexc(sizeof(PyObject*), size)
def __dealloc__(pych):
def __dealloc__(pychan pych):
# on del: drain buffered channel to decref sent objects.
# verify that the channel is not connected anywhere outside us.
# (if it was present also somewhere else - draining would be incorrect)
......@@ -178,7 +178,7 @@ cdef class pychan:
# send sends object to a receiver.
def send(pych, obj):
def send(pychan pych, obj):
cdef PyObject *_tx = <PyObject*>obj
# increment obj reference count - until received the channel is holding pointer to the object.
......@@ -196,7 +196,7 @@ cdef class pychan:
#
# ok is true - if receive was delivered by a successful send.
# ok is false - if receive is due to channel being closed and empty.
def recv_(pych): # -> (rx, ok)
def recv_(pychan pych): # -> (rx, ok)
cdef PyObject *_rx = NULL
cdef bint ok
......@@ -212,19 +212,19 @@ cdef class pychan:
return (rx, ok)
# recv receives from the channel.
def recv(pych): # -> rx
def recv(pychan pych): # -> rx
rx, _ = pych.recv_() # TODO call recv_ via C
return rx
# close closes sending side of the channel.
def close(pych):
def close(pychan pych):
with nogil:
_chanclose_pyexc(pych._ch)
def __len__(pych):
def __len__(pychan pych):
return _chanlen_pyexc(pych._ch)
def __repr__(pych):
def __repr__(pychan pych):
if pych._ch == NULL:
return "nilchan"
else:
......
......@@ -74,12 +74,12 @@ def pywaitBlocked(pychanop):
# `with pypanicWhenBlocked` hooks into libgolang _blockforever to raise panic with
# "t: blocks forever" instead of blocking.
cdef class pypanicWhenBlocked:
def __enter__(t):
def __enter__(pypanicWhenBlocked t):
global _tblockforever
_tblockforever = _panicblocked
return t
def __exit__(t, typ, val, tb):
def __exit__(pypanicWhenBlocked t, typ, val, tb):
_tblockforever = NULL
cdef void _panicblocked() nogil:
......
......@@ -30,11 +30,11 @@ cdef class PySema:
# FIXME cannot catch/pyreraise panic of .sema ctor
# https://github.com/cython/cython/issues/3165
def acquire(pysema):
def acquire(PySema pysema):
with nogil:
semaacquire_pyexc(&pysema.sema)
def release(pysema):
def release(PySema pysema):
semarelease_pyexc(&pysema.sema)
# with support
......@@ -49,17 +49,17 @@ cdef class PyMutex:
# FIXME cannot catch/pyreraise panic of .mu ctor
# https://github.com/cython/cython/issues/3165
def lock(pymu):
def lock(PyMutex pymu):
with nogil:
mutexlock_pyexc(&pymu.mu)
def unlock(pymu):
def unlock(PyMutex pymu):
mutexunlock_pyexc(&pymu.mu)
# with support
__enter__ = lock
def __exit__(pymu, exc_typ, exc_val, exc_tb):
def __exit__(PyMutex pymu, exc_typ, exc_val, exc_tb):
pymu.unlock()
......
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