1
- cdef __NOHANDLE__ = object ()
2
-
3
-
4
1
@cython.no_gc_clear
5
2
cdef class UVHandle:
6
3
""" A base class for all libuv handles.
@@ -60,7 +57,7 @@ cdef class UVHandle:
60
57
# Situations when this is possible include unhandled exceptions,
61
58
# errors during Handle.__cinit__/__init__ etc.
62
59
if self ._inited:
63
- self ._handle.data = < void * > __NOHANDLE__
60
+ self ._handle.data = NULL
64
61
uv.uv_close(self ._handle, __uv_close_handle_cb) # void; no errors
65
62
self ._handle = NULL
66
63
warnings_warn(" unclosed resource {!r}" .format(self ),
@@ -276,7 +273,7 @@ cdef inline bint __ensure_handle_data(uv.uv_handle_t* handle,
276
273
})
277
274
return 0
278
275
279
- if < object > handle.data is __NOHANDLE__ :
276
+ if handle.data is NULL :
280
277
# The underlying UVHandle object was GCed with an open uv_handle_t.
281
278
loop = < Loop> handle.loop.data
282
279
loop.call_exception_handler({
@@ -289,20 +286,9 @@ cdef inline bint __ensure_handle_data(uv.uv_handle_t* handle,
289
286
290
287
291
288
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
295
290
296
291
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__:
306
292
# The original UVHandle is long dead. Just free the mem of
307
293
# the uv_handle_t* handler.
308
294
PyMem_Free(handle)
@@ -334,15 +320,14 @@ cdef void __uv_walk_close_all_handles_cb(uv.uv_handle_t* handle, void* arg) with
334
320
})
335
321
return
336
322
337
- if < object > handle.data is __NOHANDLE__ :
323
+ if handle.data is NULL :
338
324
# And this shouldn't happen too.
339
325
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"
341
327
})
342
328
return
343
329
344
330
h = < UVHandle> handle.data
345
-
346
331
if not h._closed:
347
332
warnings_warn(" unclosed resource {!r}" .format(h), ResourceWarning)
348
333
h._close()
0 commit comments