Skip to content

Commit 26b3a7b

Browse files
committed
Modified the Py_RETURN_* macros by having the statements surrounded by {} in
order to prevent any unexpected surprises from someone using them in a conditional without using curly braces (e.g., ``if (foo) Py_RETURN_TRUE``.
1 parent d05235e commit 26b3a7b

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-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 Py_INCREF(Py_True); return Py_True;
28-
#define Py_RETURN_FALSE Py_INCREF(Py_False); return Py_False;
27+
#define Py_RETURN_TRUE {Py_INCREF(Py_True); return Py_True;}
28+
#define Py_RETURN_FALSE {Py_INCREF(Py_False); return 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
@@ -634,7 +634,7 @@ PyAPI_DATA(PyObject) _Py_NoneStruct; /* Don't use this directly */
634634
#define Py_None (&_Py_NoneStruct)
635635

636636
/* Macro for returning Py_None from a function */
637-
#define Py_RETURN_NONE Py_INCREF(Py_None); return Py_None;
637+
#define Py_RETURN_NONE {Py_INCREF(Py_None); return Py_None;}
638638

639639
/*
640640
Py_NotImplemented is a singleton used to signal that an operation is

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ Build
155155
C API
156156
-----
157157

158+
- Added three new macros: Py_RETURN_NONE, Py_RETURN_TRUE, and Py_RETURN_FALSE.
159+
Each return the singleton they mention after Py_INCREF()ing them.
160+
158161
- Added a new function, PyTuple_Pack(n, ...) for constructing tuples from a
159162
variable length argument list of Python objects without having to invoke
160163
the more complex machinery of Py_BuildValue(). PyTuple_Pack(3, a, b, c)

0 commit comments

Comments
 (0)