Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 091c7b1

Browse files
committed
Merged revisions 71229,71271 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r71229 | matthias.klose | 2009-04-05 14:43:08 +0200 (So, 05 Apr 2009) | 3 lines - Py_DECREF: Add `do { ... } while (0)' to avoid compiler warnings. (avoiding brown paper typo this time) ........ r71271 | matthias.klose | 2009-04-05 23:19:13 +0200 (So, 05 Apr 2009) | 3 lines Issue #1113244: Py_XINCREF, Py_DECREF, Py_XDECREF: Add `do { ... } while (0)' to avoid compiler warnings. ........
1 parent a3d29e8 commit 091c7b1

3 files changed

Lines changed: 14 additions & 11 deletions

File tree

Include/object.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -651,11 +651,13 @@ PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force);
651651
((PyObject*)(op))->ob_refcnt++)
652652

653653
#define Py_DECREF(op) \
654-
if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
655-
--((PyObject*)(op))->ob_refcnt != 0) \
656-
_Py_CHECK_REFCNT(op) \
657-
else \
658-
_Py_Dealloc((PyObject *)(op))
654+
do { \
655+
if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
656+
--((PyObject*)(op))->ob_refcnt != 0) \
657+
_Py_CHECK_REFCNT(op) \
658+
else \
659+
_Py_Dealloc((PyObject *)(op)); \
660+
} while (0)
659661

660662
/* Safely decref `op` and set `op` to NULL, especially useful in tp_clear
661663
* and tp_dealloc implementatons.
@@ -701,8 +703,8 @@ PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force);
701703
} while (0)
702704

703705
/* Macros to use in case the object pointer may be NULL: */
704-
#define Py_XINCREF(op) if ((op) == NULL) ; else Py_INCREF(op)
705-
#define Py_XDECREF(op) if ((op) == NULL) ; else Py_DECREF(op)
706+
#define Py_XINCREF(op) do { if ((op) == NULL) ; else Py_INCREF(op); } while (0)
707+
#define Py_XDECREF(op) do { if ((op) == NULL) ; else Py_DECREF(op); } while (0)
706708

707709
/*
708710
These are provided as conveniences to Python runtime embedders, so that

Misc/NEWS

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 3.1 beta 1?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #1113244: Py_XINCREF, Py_DECREF, Py_XDECREF: Add `do { ... } while (0)'
16+
to avoid compiler warnings.
17+
1518
Library
1619
-------
1720

@@ -78,8 +81,6 @@ Core and Builtins
7881
- Issue #3845: In PyRun_SimpleFileExFlags avoid invalid memory access with
7982
short file names.
8083

81-
- Py_DECREF: Add `do { ... } while (0)' to avoid compiler warnings.
82-
8384
Library
8485
-------
8586

Modules/readline.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,13 +693,13 @@ on_completion_display_matches_hook(char **matches,
693693
r = PyObject_CallFunction(completion_display_matches_hook,
694694
"sOi", matches[0], m, max_length);
695695

696-
Py_DECREF(m), m=NULL;
696+
Py_DECREF(m); m=NULL;
697697

698698
if (r == NULL ||
699699
(r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
700700
goto error;
701701
}
702-
Py_XDECREF(r), r=NULL;
702+
Py_XDECREF(r); r=NULL;
703703

704704
if (0) {
705705
error:

0 commit comments

Comments
 (0)