mirror of https://github.com/MagicStack/uvloop.git
Simplify code working with func pointers
This commit is contained in:
parent
6f93a8131d
commit
36b791f6b1
|
@ -57,18 +57,16 @@ cdef class Handle:
|
|||
callback(*args)
|
||||
|
||||
elif cb_type == 2:
|
||||
((<method_t*>self.callback)[0])(self.arg1)
|
||||
(<method_t>self.callback)(self.arg1)
|
||||
|
||||
elif cb_type == 3:
|
||||
((<method1_t*>self.callback)[0])(
|
||||
self.arg1, self.arg2)
|
||||
(<method1_t>self.callback)(self.arg1, self.arg2)
|
||||
|
||||
elif cb_type == 4:
|
||||
((<method2_t*>self.callback)[0])(
|
||||
self.arg1, self.arg2, self.arg3)
|
||||
(<method2_t>self.callback)(self.arg1, self.arg2, self.arg3)
|
||||
|
||||
elif cb_type == 5:
|
||||
((<method3_t*>self.callback)[0])(
|
||||
(<method3_t>self.callback)(
|
||||
self.arg1, self.arg2, self.arg3, self.arg4)
|
||||
|
||||
else:
|
||||
|
@ -130,7 +128,7 @@ cdef class TimerHandle:
|
|||
self._source_traceback = tb_extract_stack(sys_getframe(0))
|
||||
|
||||
self.timer = UVTimer.new(
|
||||
loop, <method_t*>&self._run, self, delay)
|
||||
loop, <method_t>self._run, self, delay)
|
||||
|
||||
self.timer.start()
|
||||
|
||||
|
@ -224,7 +222,7 @@ cdef new_Handle(Loop loop, object callback, object args):
|
|||
return handle
|
||||
|
||||
|
||||
cdef new_MethodHandle(Loop loop, str name, method_t *callback, object ctx):
|
||||
cdef new_MethodHandle(Loop loop, str name, method_t callback, object ctx):
|
||||
cdef Handle handle
|
||||
handle = Handle.__new__(Handle)
|
||||
handle._set_loop(loop)
|
||||
|
@ -238,7 +236,7 @@ cdef new_MethodHandle(Loop loop, str name, method_t *callback, object ctx):
|
|||
return handle
|
||||
|
||||
|
||||
cdef new_MethodHandle1(Loop loop, str name, method1_t *callback,
|
||||
cdef new_MethodHandle1(Loop loop, str name, method1_t callback,
|
||||
object ctx, object arg):
|
||||
|
||||
cdef Handle handle
|
||||
|
@ -254,7 +252,7 @@ cdef new_MethodHandle1(Loop loop, str name, method1_t *callback,
|
|||
|
||||
return handle
|
||||
|
||||
cdef new_MethodHandle2(Loop loop, str name, method2_t *callback, object ctx,
|
||||
cdef new_MethodHandle2(Loop loop, str name, method2_t callback, object ctx,
|
||||
object arg1, object arg2):
|
||||
|
||||
cdef Handle handle
|
||||
|
@ -271,7 +269,7 @@ cdef new_MethodHandle2(Loop loop, str name, method2_t *callback, object ctx,
|
|||
|
||||
return handle
|
||||
|
||||
cdef new_MethodHandle3(Loop loop, str name, method3_t *callback, object ctx,
|
||||
cdef new_MethodHandle3(Loop loop, str name, method3_t callback, object ctx,
|
||||
object arg1, object arg2, object arg3):
|
||||
|
||||
cdef Handle handle
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
cdef class UVAsync(UVHandle):
|
||||
cdef:
|
||||
method_t* callback
|
||||
method_t callback
|
||||
object ctx
|
||||
|
||||
cdef _init(self, Loop loop, method_t* callback, object ctx)
|
||||
cdef _init(self, Loop loop, method_t callback, object ctx)
|
||||
|
||||
cdef send(self)
|
||||
|
||||
@staticmethod
|
||||
cdef UVAsync new(Loop loop, method_t* callback, object ctx)
|
||||
cdef UVAsync new(Loop loop, method_t callback, object ctx)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
@cython.no_gc_clear
|
||||
cdef class UVAsync(UVHandle):
|
||||
cdef _init(self, Loop loop, method_t* callback, object ctx):
|
||||
cdef _init(self, Loop loop, method_t callback, object ctx):
|
||||
cdef int err
|
||||
|
||||
self._start_init(loop)
|
||||
|
@ -35,7 +35,7 @@ cdef class UVAsync(UVHandle):
|
|||
return
|
||||
|
||||
@staticmethod
|
||||
cdef UVAsync new(Loop loop, method_t* callback, object ctx):
|
||||
cdef UVAsync new(Loop loop, method_t callback, object ctx):
|
||||
cdef UVAsync handle
|
||||
handle = UVAsync.__new__(UVAsync)
|
||||
handle._init(loop, callback, ctx)
|
||||
|
@ -48,7 +48,7 @@ cdef void __uvasync_callback(uv.uv_async_t* handle) with gil:
|
|||
|
||||
cdef:
|
||||
UVAsync async_ = <UVAsync> handle.data
|
||||
method_t cb = async_.callback[0] # deref
|
||||
method_t cb = async_.callback
|
||||
try:
|
||||
cb(async_.ctx)
|
||||
except BaseException as ex:
|
||||
|
|
|
@ -26,14 +26,14 @@ cdef class UVBaseTransport(UVSocketHandle):
|
|||
self._loop._call_soon_handle(
|
||||
new_MethodHandle(self._loop,
|
||||
"UVTransport._call_connection_made",
|
||||
<method_t*>&self._call_connection_made,
|
||||
<method_t>self._call_connection_made,
|
||||
self))
|
||||
|
||||
cdef inline _schedule_call_connection_lost(self, exc):
|
||||
self._loop._call_soon_handle(
|
||||
new_MethodHandle1(self._loop,
|
||||
"UVTransport._call_connection_lost",
|
||||
<method1_t*>&self._call_connection_lost,
|
||||
<method1_t>self._call_connection_lost,
|
||||
self, exc))
|
||||
|
||||
cdef _fatal_error(self, exc, throw, reason=None):
|
||||
|
@ -139,7 +139,7 @@ cdef class UVBaseTransport(UVSocketHandle):
|
|||
self._loop._call_soon_handle(
|
||||
new_MethodHandle(self._loop,
|
||||
"UVTransport._start_reading",
|
||||
<method_t*>&self._start_reading,
|
||||
<method_t>self._start_reading,
|
||||
self))
|
||||
|
||||
if self._waiter is not None:
|
||||
|
|
|
@ -533,7 +533,7 @@ cdef class UVProcessTransport(UVProcess):
|
|||
self._loop._call_soon_handle(
|
||||
new_MethodHandle1(self._loop,
|
||||
"UVProcessTransport._call_connection_made",
|
||||
<method1_t*>&self._call_connection_made,
|
||||
<method1_t>self._call_connection_made,
|
||||
self, waiter))
|
||||
|
||||
@staticmethod
|
||||
|
@ -567,7 +567,7 @@ cdef class UVProcessTransport(UVProcess):
|
|||
loop._call_soon_handle(
|
||||
new_MethodHandle1(loop,
|
||||
"UVProcessTransport._call_connection_made",
|
||||
<method1_t*>&handle._call_connection_made,
|
||||
<method1_t>handle._call_connection_made,
|
||||
handle, waiter))
|
||||
|
||||
return handle
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
cdef class UVTimer(UVHandle):
|
||||
cdef:
|
||||
method_t* callback
|
||||
method_t callback
|
||||
object ctx
|
||||
bint running
|
||||
uint64_t timeout
|
||||
|
||||
cdef _init(self, Loop loop, method_t* callback, object ctx,
|
||||
cdef _init(self, Loop loop, method_t callback, object ctx,
|
||||
uint64_t timeout)
|
||||
|
||||
cdef stop(self)
|
||||
cdef start(self)
|
||||
|
||||
@staticmethod
|
||||
cdef UVTimer new(Loop loop, method_t* callback, object ctx,
|
||||
cdef UVTimer new(Loop loop, method_t callback, object ctx,
|
||||
uint64_t timeout)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
@cython.no_gc_clear
|
||||
cdef class UVTimer(UVHandle):
|
||||
cdef _init(self, Loop loop, method_t* callback, object ctx,
|
||||
cdef _init(self, Loop loop, method_t callback, object ctx,
|
||||
uint64_t timeout):
|
||||
|
||||
cdef int err
|
||||
|
@ -58,7 +58,7 @@ cdef class UVTimer(UVHandle):
|
|||
self.running = 1
|
||||
|
||||
@staticmethod
|
||||
cdef UVTimer new(Loop loop, method_t* callback, object ctx,
|
||||
cdef UVTimer new(Loop loop, method_t callback, object ctx,
|
||||
uint64_t timeout):
|
||||
|
||||
cdef UVTimer handle
|
||||
|
@ -73,7 +73,7 @@ cdef void __uvtimer_callback(uv.uv_timer_t* handle) with gil:
|
|||
|
||||
cdef:
|
||||
UVTimer timer = <UVTimer> handle.data
|
||||
method_t cb = timer.callback[0] # deref
|
||||
method_t cb = timer.callback
|
||||
|
||||
timer.running = 0
|
||||
try:
|
||||
|
|
|
@ -140,23 +140,23 @@ cdef class Loop:
|
|||
self._ready_len = 0
|
||||
|
||||
self.handler_async = UVAsync.new(
|
||||
self, <method_t*>&self._on_wake, self)
|
||||
self, <method_t>self._on_wake, self)
|
||||
|
||||
self.handler_idle = UVIdle.new(
|
||||
self,
|
||||
new_MethodHandle(
|
||||
self, "loop._on_idle", <method_t*>&self._on_idle, self))
|
||||
self, "loop._on_idle", <method_t>self._on_idle, self))
|
||||
|
||||
self.handler_sigint = UVSignal.new(
|
||||
self,
|
||||
new_MethodHandle(
|
||||
self, "loop._on_sigint", <method_t*>&self._on_sigint, self),
|
||||
self, "loop._on_sigint", <method_t>self._on_sigint, self),
|
||||
uv.SIGINT)
|
||||
|
||||
self.handler_sighup = UVSignal.new(
|
||||
self,
|
||||
new_MethodHandle(
|
||||
self, "loop._on_sighup", <method_t*>&self._on_sighup, self),
|
||||
self, "loop._on_sighup", <method_t>self._on_sighup, self),
|
||||
uv.SIGHUP)
|
||||
|
||||
# Needed to call `UVStream._exec_write` for writes scheduled
|
||||
|
@ -165,7 +165,7 @@ cdef class Loop:
|
|||
self,
|
||||
new_MethodHandle(
|
||||
self, "loop._exec_queued_writes",
|
||||
<method_t*>&self._exec_queued_writes, self))
|
||||
<method_t>self._exec_queued_writes, self))
|
||||
|
||||
uv.uv_disable_stdio_inheritance()
|
||||
|
||||
|
@ -662,7 +662,7 @@ cdef class Loop:
|
|||
handle = new_MethodHandle3(
|
||||
self,
|
||||
"Loop._sock_sendall",
|
||||
<method3_t*>&self._sock_sendall,
|
||||
<method3_t>self._sock_sendall,
|
||||
self,
|
||||
fut, sock, data)
|
||||
|
||||
|
@ -709,7 +709,7 @@ cdef class Loop:
|
|||
handle = new_MethodHandle3(
|
||||
self,
|
||||
"Loop._sock_connect",
|
||||
<method3_t*>&self._sock_connect_cb,
|
||||
<method3_t>self._sock_connect_cb,
|
||||
self,
|
||||
fut, sock, address)
|
||||
|
||||
|
@ -995,7 +995,7 @@ cdef class Loop:
|
|||
new_MethodHandle1(
|
||||
self,
|
||||
"Loop._stop",
|
||||
<method1_t*>&self._stop,
|
||||
<method1_t>self._stop,
|
||||
self,
|
||||
None))
|
||||
|
||||
|
@ -1784,7 +1784,7 @@ cdef class Loop:
|
|||
handle = new_MethodHandle3(
|
||||
self,
|
||||
"Loop._sock_recv",
|
||||
<method3_t*>&self._sock_recv,
|
||||
<method3_t>self._sock_recv,
|
||||
self,
|
||||
fut, sock, n)
|
||||
|
||||
|
@ -1834,7 +1834,7 @@ cdef class Loop:
|
|||
handle = new_MethodHandle3(
|
||||
self,
|
||||
"Loop._sock_sendall",
|
||||
<method3_t*>&self._sock_sendall,
|
||||
<method3_t>self._sock_sendall,
|
||||
self,
|
||||
fut, sock, data)
|
||||
|
||||
|
@ -1863,7 +1863,7 @@ cdef class Loop:
|
|||
handle = new_MethodHandle2(
|
||||
self,
|
||||
"Loop._sock_accept",
|
||||
<method2_t*>&self._sock_accept,
|
||||
<method2_t>self._sock_accept,
|
||||
self,
|
||||
fut, sock)
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ cdef class BaseTask(BaseFuture):
|
|||
new_MethodHandle1(
|
||||
self._loop,
|
||||
"Task._step",
|
||||
<method1_t*>&self._fast_step,
|
||||
<method1_t>self._fast_step,
|
||||
self,
|
||||
None))
|
||||
|
||||
|
@ -46,7 +46,7 @@ cdef class BaseTask(BaseFuture):
|
|||
new_MethodHandle1(
|
||||
self._loop,
|
||||
"Task._step",
|
||||
<method1_t*>&self._fast_step,
|
||||
<method1_t>self._fast_step,
|
||||
self,
|
||||
ex))
|
||||
|
||||
|
@ -58,7 +58,7 @@ cdef class BaseTask(BaseFuture):
|
|||
new_MethodHandle1(
|
||||
self._loop,
|
||||
"Task._step",
|
||||
<method1_t*>&self._fast_step,
|
||||
<method1_t>self._fast_step,
|
||||
self,
|
||||
ex))
|
||||
|
||||
|
@ -70,7 +70,7 @@ cdef class BaseTask(BaseFuture):
|
|||
new_MethodHandle1(
|
||||
self._loop,
|
||||
"Task._step",
|
||||
<method1_t*>&self._fast_step,
|
||||
<method1_t>self._fast_step,
|
||||
self,
|
||||
ex))
|
||||
|
||||
|
@ -80,7 +80,7 @@ cdef class BaseTask(BaseFuture):
|
|||
new_MethodHandle1(
|
||||
self._loop,
|
||||
"Task._step",
|
||||
<method1_t*>&self._fast_step,
|
||||
<method1_t>self._fast_step,
|
||||
self,
|
||||
ex))
|
||||
|
||||
|
@ -89,7 +89,7 @@ cdef class BaseTask(BaseFuture):
|
|||
new_MethodHandle1(
|
||||
self._loop,
|
||||
"Task._step",
|
||||
<method1_t*>&self._fast_step,
|
||||
<method1_t>self._fast_step,
|
||||
self,
|
||||
None))
|
||||
|
||||
|
|
Loading…
Reference in New Issue