Skip to content

Commit fc923f9

Browse files
committed
handle: Remove __NOHANDLE__; just use NULL
1 parent 2af7b2a commit fc923f9

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

uvloop/handles/handle.pyx

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
cdef __NOHANDLE__ = object()
2-
3-
41
@cython.no_gc_clear
52
cdef class UVHandle:
63
"""A base class for all libuv handles.
@@ -60,7 +57,7 @@ cdef class UVHandle:
6057
# Situations when this is possible include unhandled exceptions,
6158
# errors during Handle.__cinit__/__init__ etc.
6259
if self._inited:
63-
self._handle.data = <void*> __NOHANDLE__
60+
self._handle.data = NULL
6461
uv.uv_close(self._handle, __uv_close_handle_cb) # void; no errors
6562
self._handle = NULL
6663
warnings_warn("unclosed resource {!r}".format(self),
@@ -276,7 +273,7 @@ cdef inline bint __ensure_handle_data(uv.uv_handle_t* handle,
276273
})
277274
return 0
278275

279-
if <object>handle.data is __NOHANDLE__:
276+
if handle.data is NULL:
280277
# The underlying UVHandle object was GCed with an open uv_handle_t.
281278
loop = <Loop>handle.loop.data
282279
loop.call_exception_handler({
@@ -289,20 +286,9 @@ cdef inline bint __ensure_handle_data(uv.uv_handle_t* handle,
289286

290287

291288
cdef void __uv_close_handle_cb(uv.uv_handle_t* handle) with gil:
292-
cdef:
293-
UVHandle h
294-
Loop loop
289+
cdef UVHandle h
295290

296291
if handle.data is NULL:
297-
# Shouldn't happen.
298-
loop = <Loop>handle.loop.data
299-
loop.call_exception_handler({
300-
'message': 'uv_handle_t.data is NULL in close callback'
301-
})
302-
PyMem_Free(handle)
303-
return
304-
305-
if <object>handle.data is __NOHANDLE__:
306292
# The original UVHandle is long dead. Just free the mem of
307293
# the uv_handle_t* handler.
308294
PyMem_Free(handle)
@@ -334,15 +320,14 @@ cdef void __uv_walk_close_all_handles_cb(uv.uv_handle_t* handle, void* arg) with
334320
})
335321
return
336322

337-
if <object>handle.data is __NOHANDLE__:
323+
if handle.data is NULL:
338324
# And this shouldn't happen too.
339325
loop.call_exception_handler({
340-
'message': "handle.data is __NOHANDLE__ yet it's not closing"
326+
'message': "handle.data is NULL yet it's not closing"
341327
})
342328
return
343329

344330
h = <UVHandle>handle.data
345-
346331
if not h._closed:
347332
warnings_warn("unclosed resource {!r}".format(h), ResourceWarning)
348333
h._close()

0 commit comments

Comments
 (0)