]> granicus.if.org Git - python/commitdiff
Modified the Py_RETURN_* macros by having the statements surrounded by {} in
authorBrett Cannon <bcannon@gmail.com>
Sun, 19 Oct 2003 21:31:43 +0000 (21:31 +0000)
committerBrett Cannon <bcannon@gmail.com>
Sun, 19 Oct 2003 21:31:43 +0000 (21:31 +0000)
order to prevent any unexpected surprises from someone using them in a
conditional without using curly braces (e.g., ``if (foo) Py_RETURN_TRUE``.

Include/boolobject.h
Include/object.h
Misc/NEWS

index 7c4939b239616b1cd2fa9b1d7788d9c07d701556..aa5230a2e69732dad3985da0f5fc32cecdcc9a21 100644 (file)
@@ -24,8 +24,8 @@ PyAPI_DATA(PyIntObject) _Py_ZeroStruct, _Py_TrueStruct;
 #define Py_True ((PyObject *) &_Py_TrueStruct)
 
 /* Macros for returning Py_True or Py_False, respectively */
-#define Py_RETURN_TRUE Py_INCREF(Py_True); return Py_True;
-#define Py_RETURN_FALSE Py_INCREF(Py_False); return Py_False;
+#define Py_RETURN_TRUE {Py_INCREF(Py_True); return Py_True;}
+#define Py_RETURN_FALSE {Py_INCREF(Py_False); return Py_False;}
 
 /* Function to return a bool from a C long */
 PyAPI_FUNC(PyObject *) PyBool_FromLong(long);
index 8fdd4dc94e048ce96079bfd4bf7553a36b8baa38..10334456f5c4758d12760da1d7f2fc8a12def7b6 100644 (file)
@@ -634,7 +634,7 @@ PyAPI_DATA(PyObject) _Py_NoneStruct; /* Don't use this directly */
 #define Py_None (&_Py_NoneStruct)
 
 /* Macro for returning Py_None from a function */
-#define Py_RETURN_NONE Py_INCREF(Py_None); return Py_None;
+#define Py_RETURN_NONE {Py_INCREF(Py_None); return Py_None;}
 
 /*
 Py_NotImplemented is a singleton used to signal that an operation is
index 87a82e97e2c9699d63f8db4287c3a7f485f50baf..52ed529e2ee4618f9b552fb452a8b9d81a538e2a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -155,6 +155,9 @@ Build
 C API
 -----
 
+- Added three new macros: Py_RETURN_NONE, Py_RETURN_TRUE, and Py_RETURN_FALSE.
+  Each return the singleton they mention after Py_INCREF()ing them.
+
 - Added a new function, PyTuple_Pack(n, ...) for constructing tuples from a
   variable length argument list of Python objects without having to invoke
   the more complex machinery of Py_BuildValue().  PyTuple_Pack(3, a, b, c)