diff --git a/Include/object.h b/Include/object.h index b02689cc4a6..a5f769e6247 100644 --- a/Include/object.h +++ b/Include/object.h @@ -746,11 +746,13 @@ PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force); ((PyObject*)(op))->ob_refcnt++) #define Py_DECREF(op) \ - if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \ - --((PyObject*)(op))->ob_refcnt != 0) \ - _Py_CHECK_REFCNT(op) \ - else \ - _Py_Dealloc((PyObject *)(op)) + do { \ + if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \ + --((PyObject*)(op))->ob_refcnt != 0) \ + _Py_CHECK_REFCNT(op) \ + else \ + _Py_Dealloc((PyObject *)(op)) \ + } while (0) /* Safely decref `op` and set `op` to NULL, especially useful in tp_clear * and tp_dealloc implementatons. diff --git a/Misc/NEWS b/Misc/NEWS index 09190a0b900..4ca5e26c76e 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -92,6 +92,8 @@ Core and Builtins - Issue #3845: In PyRun_SimpleFileExFlags avoid invalid memory access with short file names. +- Py_DECREF: Add `do { ... } while (0)' to avoid compiler warnings. + Library -------