Skip to content

Commit 36b791f

Browse files
committed
Simplify code working with func pointers
1 parent 6f93a81 commit 36b791f

File tree

9 files changed

+43
-45
lines changed

9 files changed

+43
-45
lines changed

uvloop/cbhandles.pyx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,16 @@ cdef class Handle:
5757
callback(*args)
5858

5959
elif cb_type == 2:
60-
((<method_t*>self.callback)[0])(self.arg1)
60+
(<method_t>self.callback)(self.arg1)
6161

6262
elif cb_type == 3:
63-
((<method1_t*>self.callback)[0])(
64-
self.arg1, self.arg2)
63+
(<method1_t>self.callback)(self.arg1, self.arg2)
6564

6665
elif cb_type == 4:
67-
((<method2_t*>self.callback)[0])(
68-
self.arg1, self.arg2, self.arg3)
66+
(<method2_t>self.callback)(self.arg1, self.arg2, self.arg3)
6967

7068
elif cb_type == 5:
71-
((<method3_t*>self.callback)[0])(
69+
(<method3_t>self.callback)(
7270
self.arg1, self.arg2, self.arg3, self.arg4)
7371

7472
else:
@@ -130,7 +128,7 @@ cdef class TimerHandle:
130128
self._source_traceback = tb_extract_stack(sys_getframe(0))
131129

132130
self.timer = UVTimer.new(
133-
loop, <method_t*>&self._run, self, delay)
131+
loop, <method_t>self._run, self, delay)
134132

135133
self.timer.start()
136134

@@ -224,7 +222,7 @@ cdef new_Handle(Loop loop, object callback, object args):
224222
return handle
225223

226224

227-
cdef new_MethodHandle(Loop loop, str name, method_t *callback, object ctx):
225+
cdef new_MethodHandle(Loop loop, str name, method_t callback, object ctx):
228226
cdef Handle handle
229227
handle = Handle.__new__(Handle)
230228
handle._set_loop(loop)
@@ -238,7 +236,7 @@ cdef new_MethodHandle(Loop loop, str name, method_t *callback, object ctx):
238236
return handle
239237

240238

241-
cdef new_MethodHandle1(Loop loop, str name, method1_t *callback,
239+
cdef new_MethodHandle1(Loop loop, str name, method1_t callback,
242240
object ctx, object arg):
243241

244242
cdef Handle handle
@@ -254,7 +252,7 @@ cdef new_MethodHandle1(Loop loop, str name, method1_t *callback,
254252

255253
return handle
256254

257-
cdef new_MethodHandle2(Loop loop, str name, method2_t *callback, object ctx,
255+
cdef new_MethodHandle2(Loop loop, str name, method2_t callback, object ctx,
258256
object arg1, object arg2):
259257

260258
cdef Handle handle
@@ -271,7 +269,7 @@ cdef new_MethodHandle2(Loop loop, str name, method2_t *callback, object ctx,
271269

272270
return handle
273271

274-
cdef new_MethodHandle3(Loop loop, str name, method3_t *callback, object ctx,
272+
cdef new_MethodHandle3(Loop loop, str name, method3_t callback, object ctx,
275273
object arg1, object arg2, object arg3):
276274

277275
cdef Handle handle

uvloop/handles/async_.pxd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
cdef class UVAsync(UVHandle):
22
cdef:
3-
method_t* callback
3+
method_t callback
44
object ctx
55

6-
cdef _init(self, Loop loop, method_t* callback, object ctx)
6+
cdef _init(self, Loop loop, method_t callback, object ctx)
77

88
cdef send(self)
99

1010
@staticmethod
11-
cdef UVAsync new(Loop loop, method_t* callback, object ctx)
11+
cdef UVAsync new(Loop loop, method_t callback, object ctx)

uvloop/handles/async_.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@cython.no_gc_clear
22
cdef class UVAsync(UVHandle):
3-
cdef _init(self, Loop loop, method_t* callback, object ctx):
3+
cdef _init(self, Loop loop, method_t callback, object ctx):
44
cdef int err
55

66
self._start_init(loop)
@@ -35,7 +35,7 @@ cdef class UVAsync(UVHandle):
3535
return
3636

3737
@staticmethod
38-
cdef UVAsync new(Loop loop, method_t* callback, object ctx):
38+
cdef UVAsync new(Loop loop, method_t callback, object ctx):
3939
cdef UVAsync handle
4040
handle = UVAsync.__new__(UVAsync)
4141
handle._init(loop, callback, ctx)
@@ -48,7 +48,7 @@ cdef void __uvasync_callback(uv.uv_async_t* handle) with gil:
4848

4949
cdef:
5050
UVAsync async_ = <UVAsync> handle.data
51-
method_t cb = async_.callback[0] # deref
51+
method_t cb = async_.callback
5252
try:
5353
cb(async_.ctx)
5454
except BaseException as ex:

uvloop/handles/basetransport.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ cdef class UVBaseTransport(UVSocketHandle):
2626
self._loop._call_soon_handle(
2727
new_MethodHandle(self._loop,
2828
"UVTransport._call_connection_made",
29-
<method_t*>&self._call_connection_made,
29+
<method_t>self._call_connection_made,
3030
self))
3131

3232
cdef inline _schedule_call_connection_lost(self, exc):
3333
self._loop._call_soon_handle(
3434
new_MethodHandle1(self._loop,
3535
"UVTransport._call_connection_lost",
36-
<method1_t*>&self._call_connection_lost,
36+
<method1_t>self._call_connection_lost,
3737
self, exc))
3838

3939
cdef _fatal_error(self, exc, throw, reason=None):
@@ -139,7 +139,7 @@ cdef class UVBaseTransport(UVSocketHandle):
139139
self._loop._call_soon_handle(
140140
new_MethodHandle(self._loop,
141141
"UVTransport._start_reading",
142-
<method_t*>&self._start_reading,
142+
<method_t>self._start_reading,
143143
self))
144144

145145
if self._waiter is not None:

uvloop/handles/process.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ cdef class UVProcessTransport(UVProcess):
533533
self._loop._call_soon_handle(
534534
new_MethodHandle1(self._loop,
535535
"UVProcessTransport._call_connection_made",
536-
<method1_t*>&self._call_connection_made,
536+
<method1_t>self._call_connection_made,
537537
self, waiter))
538538

539539
@staticmethod
@@ -567,7 +567,7 @@ cdef class UVProcessTransport(UVProcess):
567567
loop._call_soon_handle(
568568
new_MethodHandle1(loop,
569569
"UVProcessTransport._call_connection_made",
570-
<method1_t*>&handle._call_connection_made,
570+
<method1_t>handle._call_connection_made,
571571
handle, waiter))
572572

573573
return handle

uvloop/handles/timer.pxd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
cdef class UVTimer(UVHandle):
22
cdef:
3-
method_t* callback
3+
method_t callback
44
object ctx
55
bint running
66
uint64_t timeout
77

8-
cdef _init(self, Loop loop, method_t* callback, object ctx,
8+
cdef _init(self, Loop loop, method_t callback, object ctx,
99
uint64_t timeout)
1010

1111
cdef stop(self)
1212
cdef start(self)
1313

1414
@staticmethod
15-
cdef UVTimer new(Loop loop, method_t* callback, object ctx,
15+
cdef UVTimer new(Loop loop, method_t callback, object ctx,
1616
uint64_t timeout)

uvloop/handles/timer.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@cython.no_gc_clear
22
cdef class UVTimer(UVHandle):
3-
cdef _init(self, Loop loop, method_t* callback, object ctx,
3+
cdef _init(self, Loop loop, method_t callback, object ctx,
44
uint64_t timeout):
55

66
cdef int err
@@ -58,7 +58,7 @@ cdef class UVTimer(UVHandle):
5858
self.running = 1
5959

6060
@staticmethod
61-
cdef UVTimer new(Loop loop, method_t* callback, object ctx,
61+
cdef UVTimer new(Loop loop, method_t callback, object ctx,
6262
uint64_t timeout):
6363

6464
cdef UVTimer handle
@@ -73,7 +73,7 @@ cdef void __uvtimer_callback(uv.uv_timer_t* handle) with gil:
7373

7474
cdef:
7575
UVTimer timer = <UVTimer> handle.data
76-
method_t cb = timer.callback[0] # deref
76+
method_t cb = timer.callback
7777

7878
timer.running = 0
7979
try:

uvloop/loop.pyx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,23 @@ cdef class Loop:
140140
self._ready_len = 0
141141

142142
self.handler_async = UVAsync.new(
143-
self, <method_t*>&self._on_wake, self)
143+
self, <method_t>self._on_wake, self)
144144

145145
self.handler_idle = UVIdle.new(
146146
self,
147147
new_MethodHandle(
148-
self, "loop._on_idle", <method_t*>&self._on_idle, self))
148+
self, "loop._on_idle", <method_t>self._on_idle, self))
149149

150150
self.handler_sigint = UVSignal.new(
151151
self,
152152
new_MethodHandle(
153-
self, "loop._on_sigint", <method_t*>&self._on_sigint, self),
153+
self, "loop._on_sigint", <method_t>self._on_sigint, self),
154154
uv.SIGINT)
155155

156156
self.handler_sighup = UVSignal.new(
157157
self,
158158
new_MethodHandle(
159-
self, "loop._on_sighup", <method_t*>&self._on_sighup, self),
159+
self, "loop._on_sighup", <method_t>self._on_sighup, self),
160160
uv.SIGHUP)
161161

162162
# Needed to call `UVStream._exec_write` for writes scheduled
@@ -165,7 +165,7 @@ cdef class Loop:
165165
self,
166166
new_MethodHandle(
167167
self, "loop._exec_queued_writes",
168-
<method_t*>&self._exec_queued_writes, self))
168+
<method_t>self._exec_queued_writes, self))
169169

170170
uv.uv_disable_stdio_inheritance()
171171

@@ -662,7 +662,7 @@ cdef class Loop:
662662
handle = new_MethodHandle3(
663663
self,
664664
"Loop._sock_sendall",
665-
<method3_t*>&self._sock_sendall,
665+
<method3_t>self._sock_sendall,
666666
self,
667667
fut, sock, data)
668668

@@ -709,7 +709,7 @@ cdef class Loop:
709709
handle = new_MethodHandle3(
710710
self,
711711
"Loop._sock_connect",
712-
<method3_t*>&self._sock_connect_cb,
712+
<method3_t>self._sock_connect_cb,
713713
self,
714714
fut, sock, address)
715715

@@ -995,7 +995,7 @@ cdef class Loop:
995995
new_MethodHandle1(
996996
self,
997997
"Loop._stop",
998-
<method1_t*>&self._stop,
998+
<method1_t>self._stop,
999999
self,
10001000
None))
10011001

@@ -1784,7 +1784,7 @@ cdef class Loop:
17841784
handle = new_MethodHandle3(
17851785
self,
17861786
"Loop._sock_recv",
1787-
<method3_t*>&self._sock_recv,
1787+
<method3_t>self._sock_recv,
17881788
self,
17891789
fut, sock, n)
17901790

@@ -1834,7 +1834,7 @@ cdef class Loop:
18341834
handle = new_MethodHandle3(
18351835
self,
18361836
"Loop._sock_sendall",
1837-
<method3_t*>&self._sock_sendall,
1837+
<method3_t>self._sock_sendall,
18381838
self,
18391839
fut, sock, data)
18401840

@@ -1863,7 +1863,7 @@ cdef class Loop:
18631863
handle = new_MethodHandle2(
18641864
self,
18651865
"Loop._sock_accept",
1866-
<method2_t*>&self._sock_accept,
1866+
<method2_t>self._sock_accept,
18671867
self,
18681868
fut, sock)
18691869

uvloop/task.pyx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ cdef class BaseTask(BaseFuture):
2121
new_MethodHandle1(
2222
self._loop,
2323
"Task._step",
24-
<method1_t*>&self._fast_step,
24+
<method1_t>self._fast_step,
2525
self,
2626
None))
2727

@@ -46,7 +46,7 @@ cdef class BaseTask(BaseFuture):
4646
new_MethodHandle1(
4747
self._loop,
4848
"Task._step",
49-
<method1_t*>&self._fast_step,
49+
<method1_t>self._fast_step,
5050
self,
5151
ex))
5252

@@ -58,7 +58,7 @@ cdef class BaseTask(BaseFuture):
5858
new_MethodHandle1(
5959
self._loop,
6060
"Task._step",
61-
<method1_t*>&self._fast_step,
61+
<method1_t>self._fast_step,
6262
self,
6363
ex))
6464

@@ -70,7 +70,7 @@ cdef class BaseTask(BaseFuture):
7070
new_MethodHandle1(
7171
self._loop,
7272
"Task._step",
73-
<method1_t*>&self._fast_step,
73+
<method1_t>self._fast_step,
7474
self,
7575
ex))
7676

@@ -80,7 +80,7 @@ cdef class BaseTask(BaseFuture):
8080
new_MethodHandle1(
8181
self._loop,
8282
"Task._step",
83-
<method1_t*>&self._fast_step,
83+
<method1_t>self._fast_step,
8484
self,
8585
ex))
8686

@@ -89,7 +89,7 @@ cdef class BaseTask(BaseFuture):
8989
new_MethodHandle1(
9090
self._loop,
9191
"Task._step",
92-
<method1_t*>&self._fast_step,
92+
<method1_t>self._fast_step,
9393
self,
9494
None))
9595

0 commit comments

Comments
 (0)