Skip to content

Commit 5980ff2

Browse files
committed
SF bug 994255: Py_RETURN_NONE causes too much warnings
Rewrote Py_RETURN_{NONE, TRUE, FALSE} to expand to comma expressions rather than "do {} while(0)" thingies. The OP complained because he likes using MS /W4 sometimes, and then all his uses of these things generate nuisance warnings about testing a constant expression (in the "while(0)" part). Comma expressions don't have this problem (although it's a lucky accident that comma expressions suffice for these macros!).
1 parent aa1c7ff commit 5980ff2

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Include/boolobject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ PyAPI_DATA(PyIntObject) _Py_ZeroStruct, _Py_TrueStruct;
2424
#define Py_True ((PyObject *) &_Py_TrueStruct)
2525

2626
/* Macros for returning Py_True or Py_False, respectively */
27-
#define Py_RETURN_TRUE do {Py_INCREF(Py_True); return Py_True;} while (0)
28-
#define Py_RETURN_FALSE do {Py_INCREF(Py_False); return Py_False;} while (0)
27+
#define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True
28+
#define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False
2929

3030
/* Function to return a bool from a C long */
3131
PyAPI_FUNC(PyObject *) PyBool_FromLong(long);

Include/object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ PyAPI_DATA(PyObject) _Py_NoneStruct; /* Don't use this directly */
650650
#define Py_None (&_Py_NoneStruct)
651651

652652
/* Macro for returning Py_None from a function */
653-
#define Py_RETURN_NONE do {Py_INCREF(Py_None); return Py_None;} while (0)
653+
#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
654654

655655
/*
656656
Py_NotImplemented is a singleton used to signal that an operation is

0 commit comments

Comments
 (0)