Skip to content

Commit a3eec03

Browse files
committed
stream/write-ctx: Unbreak debug build
1 parent ee0ccd4 commit a3eec03

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

uvloop/handles/stream.pyx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,31 @@ cdef class _StreamWriteContext:
2323
self.closed = 1
2424
PyBuffer_Release(&self.py_buf) # void
2525
self.req.data = NULL
26-
Py_DECREF(self)
2726
IF not DEBUG:
2827
self.stream = None
28+
Py_DECREF(self)
2929

3030
@staticmethod
3131
cdef _StreamWriteContext new(UVStream stream, object data):
3232
cdef _StreamWriteContext ctx
3333
ctx = _StreamWriteContext.__new__(_StreamWriteContext)
34+
ctx.stream = None
35+
ctx.closed = 1
3436

3537
ctx.req.data = <void*> ctx
3638

3739
PyObject_GetBuffer(data, &ctx.py_buf, PyBUF_SIMPLE)
3840
ctx.uv_buf = uv.uv_buf_init(<char*>ctx.py_buf.buf, ctx.py_buf.len)
3941
ctx.stream = stream
4042

41-
ctx.closed = 0
42-
4343
IF DEBUG:
4444
stream._loop._debug_stream_write_ctx_total += 1
4545
stream._loop._debug_stream_write_ctx_cnt += 1
4646

4747
# Do incref after everything else is done
4848
# (PyObject_GetBuffer for instance may fail with exception)
4949
Py_INCREF(ctx)
50+
ctx.closed = 0
5051
return ctx
5152

5253
IF DEBUG:
@@ -56,9 +57,9 @@ cdef class _StreamWriteContext:
5657
'open _StreamWriteContext is being deallocated')
5758

5859
IF DEBUG:
59-
self.stream._loop._debug_stream_write_ctx_cnt -= 1
60-
61-
self.stream = None
60+
if self.stream is not None:
61+
self.stream._loop._debug_stream_write_ctx_cnt -= 1
62+
self.stream = None
6263

6364

6465
@cython.no_gc_clear

0 commit comments

Comments
 (0)