Skip to content

Commit a836c71

Browse files
committed
update based on review
1 parent 7195743 commit a836c71

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

Modules/_winapi.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ overlapped_dealloc(OverlappedObject *self)
153153
if (self->write_buffer.obj)
154154
PyBuffer_Release(&self->write_buffer);
155155
Py_CLEAR(self->read_buffer);
156-
PyObject_Del(self);
156+
PyTypeObject *tp = PY_TYPE(self);
157+
tp->tp_free(self);
158+
Py_DECREF(tp);
157159
}
158160

159161
/*[clinic input]
@@ -336,10 +338,8 @@ static PyType_Spec winapi_overlapped_type_spec = {
336338
static OverlappedObject *
337339
new_overlapped(PyObject *module, HANDLE handle)
338340
{
339-
OverlappedObject *self;
340-
341341
WinApiState *st = winapi_get_state(module);
342-
self = PyObject_New(OverlappedObject, st->overlapped_type);
342+
OverlappedObject *self = PyObject_New(OverlappedObject, st->overlapped_type);
343343
if (!self)
344344
return NULL;
345345

@@ -1910,14 +1910,15 @@ static PyMethodDef winapi_functions[] = {
19101910
{NULL, NULL}
19111911
};
19121912

1913-
#define WINAPI_CONSTANT(fmt, con) { \
1914-
PyObject *value = Py_BuildValue(fmt, con); \
1915-
if (PyDict_SetItemString(d, #con, value) < 0) { \
1913+
#define WINAPI_CONSTANT(fmt, con) \
1914+
do { \
1915+
PyObject *value = Py_BuildValue(fmt, con); \
1916+
if (PyDict_SetItemString(d, #con, value) < 0) { \
1917+
Py_DECREF(value); \
1918+
return -1; \
1919+
} \
19161920
Py_DECREF(value); \
1917-
return -1; \
1918-
} \
1919-
Py_DECREF(value); \
1920-
}
1921+
} while (0)
19211922

19221923
static int winapi_exec(PyObject *m)
19231924
{
@@ -1928,9 +1929,7 @@ static int winapi_exec(PyObject *m)
19281929
return -1;
19291930
}
19301931

1931-
Py_INCREF(st->overlapped_type);
19321932
if (PyModule_AddType(m, st->overlapped_type) < 0) {
1933-
Py_DECREF(st->overlapped_type);
19341933
return -1;
19351934
}
19361935

0 commit comments

Comments
 (0)