@@ -31,7 +31,7 @@ cdef class _StreamWriteContext:
31
31
if self .uv_bufs is not NULL :
32
32
PyMem_RawFree(self .uv_bufs)
33
33
self .uv_bufs = NULL
34
- IF DEBUG :
34
+ if UVLOOP_DEBUG :
35
35
if self .py_bufs_sml_inuse:
36
36
raise RuntimeError (
37
37
' _StreamWriteContext.close: uv_bufs != NULL and '
@@ -42,7 +42,7 @@ cdef class _StreamWriteContext:
42
42
PyBuffer_Release(& self .py_bufs[i])
43
43
PyMem_RawFree(self .py_bufs)
44
44
self .py_bufs = NULL
45
- IF DEBUG :
45
+ if UVLOOP_DEBUG :
46
46
if self .py_bufs_sml_inuse:
47
47
raise RuntimeError (
48
48
' _StreamWriteContext.close: py_bufs != NULL and '
@@ -87,7 +87,7 @@ cdef class _StreamWriteContext:
87
87
else :
88
88
sent -= self .uv_bufs_start[idx].len
89
89
90
- IF DEBUG :
90
+ if UVLOOP_DEBUG :
91
91
if sent < 0 :
92
92
raise RuntimeError (' fatal: sent < 0 in advance_uv_buf' )
93
93
@@ -123,7 +123,7 @@ cdef class _StreamWriteContext:
123
123
124
124
else :
125
125
for buf in buffers:
126
- IF DEBUG :
126
+ if UVLOOP_DEBUG :
127
127
if not isinstance (buf, (bytes, bytearray, memoryview)):
128
128
raise RuntimeError (
129
129
' invalid data in writebuf: an instance of '
@@ -180,7 +180,7 @@ cdef class _StreamWriteContext:
180
180
ctx.py_bufs_len = py_bufs_len
181
181
ctx.req.data = < void * > ctx
182
182
183
- IF DEBUG :
183
+ if UVLOOP_DEBUG :
184
184
stream._loop._debug_stream_write_ctx_total += 1
185
185
stream._loop._debug_stream_write_ctx_cnt += 1
186
186
@@ -191,15 +191,14 @@ cdef class _StreamWriteContext:
191
191
ctx.closed = 0
192
192
return ctx
193
193
194
- IF DEBUG :
195
- def __dealloc__ ( self ) :
194
+ def __dealloc__ ( self ) :
195
+ if not self .closed :
196
196
# Because we do an INCREF in _StreamWriteContext.new,
197
- # __dealloc__ shouldn't ever happen with `self.closed == 0`
198
-
199
- if not self .closed:
200
- raise RuntimeError (
201
- ' open _StreamWriteContext is being deallocated' )
197
+ # __dealloc__ shouldn't ever happen with `self.closed == 1`
198
+ raise RuntimeError (
199
+ ' open _StreamWriteContext is being deallocated' )
202
200
201
+ if UVLOOP_DEBUG:
203
202
if self .stream is not None :
204
203
self .stream._loop._debug_stream_write_ctx_cnt -= 1
205
204
self .stream = None
@@ -360,7 +359,7 @@ cdef class UVStream(UVBaseTransport):
360
359
self ._fatal_error(exc, True )
361
360
return
362
361
363
- IF DEBUG :
362
+ if UVLOOP_DEBUG :
364
363
self ._loop._debug_stream_write_tries += 1
365
364
366
365
if < size_t> written == blen:
@@ -392,7 +391,7 @@ cdef class UVStream(UVBaseTransport):
392
391
# Then:
393
392
# - Try to write all buffered data right now.
394
393
all_sent = self ._exec_write()
395
- IF DEBUG :
394
+ if UVLOOP_DEBUG :
396
395
if self ._buffer_size != 0 or self ._buffer != []:
397
396
raise RuntimeError (
398
397
' _buffer_size is not 0 after a successful _exec_write' )
@@ -454,7 +453,7 @@ cdef class UVStream(UVBaseTransport):
454
453
return True
455
454
456
455
if sent > 0 :
457
- IF DEBUG :
456
+ if UVLOOP_DEBUG :
458
457
if sent == len (data):
459
458
raise RuntimeError (
460
459
' _try_write sent all data and returned '
@@ -704,7 +703,7 @@ cdef void __uv_stream_on_shutdown(uv.uv_shutdown_t* req,
704
703
# v0.11. A possible reason for leaving it unchanged is that it
705
704
# informs the callee that the handle has been destroyed.
706
705
707
- IF DEBUG :
706
+ if UVLOOP_DEBUG :
708
707
stream._loop._debug_stream_shutdown_errors_total += 1
709
708
710
709
exc = convert_error(status)
@@ -736,13 +735,13 @@ cdef inline void __uv_stream_on_read_impl(uv.uv_stream_t* stream,
736
735
# when an error happens by calling uv_read_stop() or uv_close().
737
736
# Trying to read from the stream again is undefined.
738
737
try :
739
- IF DEBUG :
738
+ if UVLOOP_DEBUG :
740
739
loop._debug_stream_read_eof_total += 1
741
740
742
741
sc._stop_reading()
743
742
sc._on_eof()
744
743
except BaseException as ex:
745
- IF DEBUG :
744
+ if UVLOOP_DEBUG :
746
745
loop._debug_stream_read_eof_cb_errors_total += 1
747
746
748
747
sc._error(ex, False )
@@ -765,7 +764,7 @@ cdef inline void __uv_stream_on_read_impl(uv.uv_stream_t* stream,
765
764
# doesn't raise exceptions unless uvloop is built with DEBUG=1,
766
765
# we don't need try...finally here.
767
766
768
- IF DEBUG :
767
+ if UVLOOP_DEBUG :
769
768
loop._debug_stream_read_errors_total += 1
770
769
771
770
if sc.__read_error_close:
@@ -780,12 +779,12 @@ cdef inline void __uv_stream_on_read_impl(uv.uv_stream_t* stream,
780
779
return
781
780
782
781
try :
783
- IF DEBUG :
782
+ if UVLOOP_DEBUG :
784
783
loop._debug_stream_read_cb_total += 1
785
784
786
785
sc._on_read(loop._recv_buffer[:nread])
787
786
except BaseException as exc:
788
- IF DEBUG :
787
+ if UVLOOP_DEBUG :
789
788
loop._debug_stream_read_cb_errors_total += 1
790
789
791
790
sc._error(exc, False )
@@ -805,7 +804,7 @@ cdef inline void __uv_stream_on_write_impl(uv.uv_write_t* req, int status):
805
804
return
806
805
807
806
if status < 0 :
808
- IF DEBUG :
807
+ if UVLOOP_DEBUG :
809
808
stream._loop._debug_stream_write_errors_total += 1
810
809
811
810
exc = convert_error(status)
@@ -816,7 +815,7 @@ cdef inline void __uv_stream_on_write_impl(uv.uv_write_t* req, int status):
816
815
try :
817
816
stream._on_write()
818
817
except BaseException as exc:
819
- IF DEBUG :
818
+ if UVLOOP_DEBUG :
820
819
stream._loop._debug_stream_write_cb_errors_total += 1
821
820
822
821
stream._error(exc, False )
@@ -839,7 +838,7 @@ cdef void __uv_stream_on_read(uv.uv_stream_t* stream,
839
838
840
839
cdef void __uv_stream_on_write(uv.uv_write_t* req, int status) with gil:
841
840
842
- IF DEBUG :
841
+ if UVLOOP_DEBUG :
843
842
if req.data is NULL :
844
843
aio_logger.error(
845
844
' UVStream.write callback called with NULL req.data, status=%r ' ,
0 commit comments