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