@@ -31,7 +31,7 @@ cdef class _StreamWriteContext:
3131 if self .uv_bufs is not NULL :
3232 PyMem_RawFree(self .uv_bufs)
3333 self .uv_bufs = NULL
34- IF DEBUG :
34+ if UVLOOP_DEBUG :
3535 if self .py_bufs_sml_inuse:
3636 raise RuntimeError (
3737 ' _StreamWriteContext.close: uv_bufs != NULL and '
@@ -42,7 +42,7 @@ cdef class _StreamWriteContext:
4242 PyBuffer_Release(& self .py_bufs[i])
4343 PyMem_RawFree(self .py_bufs)
4444 self .py_bufs = NULL
45- IF DEBUG :
45+ if UVLOOP_DEBUG :
4646 if self .py_bufs_sml_inuse:
4747 raise RuntimeError (
4848 ' _StreamWriteContext.close: py_bufs != NULL and '
@@ -87,7 +87,7 @@ cdef class _StreamWriteContext:
8787 else :
8888 sent -= self .uv_bufs_start[idx].len
8989
90- IF DEBUG :
90+ if UVLOOP_DEBUG :
9191 if sent < 0 :
9292 raise RuntimeError (' fatal: sent < 0 in advance_uv_buf' )
9393
@@ -123,7 +123,7 @@ cdef class _StreamWriteContext:
123123
124124 else :
125125 for buf in buffers:
126- IF DEBUG :
126+ if UVLOOP_DEBUG :
127127 if not isinstance (buf, (bytes, bytearray, memoryview)):
128128 raise RuntimeError (
129129 ' invalid data in writebuf: an instance of '
@@ -180,7 +180,7 @@ cdef class _StreamWriteContext:
180180 ctx.py_bufs_len = py_bufs_len
181181 ctx.req.data = < void * > ctx
182182
183- IF DEBUG :
183+ if UVLOOP_DEBUG :
184184 stream._loop._debug_stream_write_ctx_total += 1
185185 stream._loop._debug_stream_write_ctx_cnt += 1
186186
@@ -191,15 +191,14 @@ cdef class _StreamWriteContext:
191191 ctx.closed = 0
192192 return ctx
193193
194- IF DEBUG :
195- def __dealloc__ ( self ) :
194+ def __dealloc__ ( self ) :
195+ if not self .closed :
196196 # 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' )
202200
201+ if UVLOOP_DEBUG:
203202 if self .stream is not None :
204203 self .stream._loop._debug_stream_write_ctx_cnt -= 1
205204 self .stream = None
@@ -360,7 +359,7 @@ cdef class UVStream(UVBaseTransport):
360359 self ._fatal_error(exc, True )
361360 return
362361
363- IF DEBUG :
362+ if UVLOOP_DEBUG :
364363 self ._loop._debug_stream_write_tries += 1
365364
366365 if < size_t> written == blen:
@@ -392,7 +391,7 @@ cdef class UVStream(UVBaseTransport):
392391 # Then:
393392 # - Try to write all buffered data right now.
394393 all_sent = self ._exec_write()
395- IF DEBUG :
394+ if UVLOOP_DEBUG :
396395 if self ._buffer_size != 0 or self ._buffer != []:
397396 raise RuntimeError (
398397 ' _buffer_size is not 0 after a successful _exec_write' )
@@ -454,7 +453,7 @@ cdef class UVStream(UVBaseTransport):
454453 return True
455454
456455 if sent > 0 :
457- IF DEBUG :
456+ if UVLOOP_DEBUG :
458457 if sent == len (data):
459458 raise RuntimeError (
460459 ' _try_write sent all data and returned '
@@ -704,7 +703,7 @@ cdef void __uv_stream_on_shutdown(uv.uv_shutdown_t* req,
704703 # v0.11. A possible reason for leaving it unchanged is that it
705704 # informs the callee that the handle has been destroyed.
706705
707- IF DEBUG :
706+ if UVLOOP_DEBUG :
708707 stream._loop._debug_stream_shutdown_errors_total += 1
709708
710709 exc = convert_error(status)
@@ -736,13 +735,13 @@ cdef inline void __uv_stream_on_read_impl(uv.uv_stream_t* stream,
736735 # when an error happens by calling uv_read_stop() or uv_close().
737736 # Trying to read from the stream again is undefined.
738737 try :
739- IF DEBUG :
738+ if UVLOOP_DEBUG :
740739 loop._debug_stream_read_eof_total += 1
741740
742741 sc._stop_reading()
743742 sc._on_eof()
744743 except BaseException as ex:
745- IF DEBUG :
744+ if UVLOOP_DEBUG :
746745 loop._debug_stream_read_eof_cb_errors_total += 1
747746
748747 sc._error(ex, False )
@@ -765,7 +764,7 @@ cdef inline void __uv_stream_on_read_impl(uv.uv_stream_t* stream,
765764 # doesn't raise exceptions unless uvloop is built with DEBUG=1,
766765 # we don't need try...finally here.
767766
768- IF DEBUG :
767+ if UVLOOP_DEBUG :
769768 loop._debug_stream_read_errors_total += 1
770769
771770 if sc.__read_error_close:
@@ -780,12 +779,12 @@ cdef inline void __uv_stream_on_read_impl(uv.uv_stream_t* stream,
780779 return
781780
782781 try :
783- IF DEBUG :
782+ if UVLOOP_DEBUG :
784783 loop._debug_stream_read_cb_total += 1
785784
786785 sc._on_read(loop._recv_buffer[:nread])
787786 except BaseException as exc:
788- IF DEBUG :
787+ if UVLOOP_DEBUG :
789788 loop._debug_stream_read_cb_errors_total += 1
790789
791790 sc._error(exc, False )
@@ -805,7 +804,7 @@ cdef inline void __uv_stream_on_write_impl(uv.uv_write_t* req, int status):
805804 return
806805
807806 if status < 0 :
808- IF DEBUG :
807+ if UVLOOP_DEBUG :
809808 stream._loop._debug_stream_write_errors_total += 1
810809
811810 exc = convert_error(status)
@@ -816,7 +815,7 @@ cdef inline void __uv_stream_on_write_impl(uv.uv_write_t* req, int status):
816815 try :
817816 stream._on_write()
818817 except BaseException as exc:
819- IF DEBUG :
818+ if UVLOOP_DEBUG :
820819 stream._loop._debug_stream_write_cb_errors_total += 1
821820
822821 stream._error(exc, False )
@@ -839,7 +838,7 @@ cdef void __uv_stream_on_read(uv.uv_stream_t* stream,
839838
840839cdef void __uv_stream_on_write(uv.uv_write_t* req, int status) with gil:
841840
842- IF DEBUG :
841+ if UVLOOP_DEBUG :
843842 if req.data is NULL :
844843 aio_logger.error(
845844 ' UVStream.write callback called with NULL req.data, status=%r ' ,
0 commit comments