Issue 7004: Py_RETURN_BOOL() convenience macro (original) (raw)

Created on 2009-09-27 00:04 by jon, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Py_RETURN_BOOL.patch jon,2009-09-27 00:04 Py_RETURN_BOOL implementation
Py_RETURN_BOOL.examples.patch jon,2009-09-27 00:06 Py_RETURN_BOOL examples
Py_RETURN_BOOL.doc.patch jon,2009-09-27 00:12 Py_RETURN_BOOL documentation
Messages (6)
msg93164 - (view) Author: Jon Parise (jon) Date: 2009-09-27 00:04
I've sometimes found it useful to define a convenience macro named Py_RETURN_BOOL(x) which is essentially: #define Py_RETURN_BOOL(x) if (x) Py_RETURN_TRUE; else Py_RETURN_FALSE It's useful for implementing functions which return Boolean values based on simple conditions. I think it's readable and doesn't detract from regular program flow, although it does hide the condition behind a macro, which detracts a bit from the code's debug-ability.
msg93165 - (view) Author: Jon Parise (jon) Date: 2009-09-27 00:06
Also attached is a short set of examples of how this macro could be used in the Python source tree.
msg93166 - (view) Author: Jon Parise (jon) Date: 2009-09-27 00:12
Also attached is a small documentation patch.
msg93169 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-09-27 07:26
-1. What's wrong with writing return PyBool_FromLong(x);
msg93170 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-09-27 14:10
I agree with Martin; PyBool_FromLong is sufficient.
msg93186 - (view) Author: Jon Parise (jon) Date: 2009-09-27 21:30
I agree, as well. I didn't consider PyBool_FromLong() because I was expecting to solve the problem using a macro, but that is clearly not the best approach here (insignificant function call overhead aside).
History
Date User Action Args
2022-04-11 14:56:53 admin set github: 51253
2009-09-27 21:30:11 jon set messages: +
2009-09-27 14:10:47 benjamin.peterson set status: open -> closednosy: + benjamin.petersonmessages: + resolution: rejected
2009-09-27 07:26:01 loewis set nosy: + loewismessages: +
2009-09-27 00:12:07 jon set files: + Py_RETURN_BOOL.doc.patchmessages: +
2009-09-27 00:06:12 jon set files: + Py_RETURN_BOOL.examples.patchmessages: +
2009-09-27 00:04:58 jon create