Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 1 | .. highlightlang:: c |
| 2 | |
| 3 | .. _boolobjects: |
| 4 | |
| 5 | Boolean Objects |
| 6 | --------------- |
| 7 | |
| 8 | Booleans in Python are implemented as a subclass of integers. There are only |
| 9 | two booleans, :const:`Py_False` and :const:`Py_True`. As such, the normal |
| 10 | creation and deletion functions don't apply to booleans. The following macros |
| 11 | are available, however. |
| 12 | |
| 13 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame^] | 14 | .. c:function:: int PyBool_Check(PyObject *o) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 15 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame^] | 16 | Return true if *o* is of type :c:data:`PyBool_Type`. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 17 | |
| 18 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame^] | 19 | .. c:var:: PyObject* Py_False |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 20 | |
| 21 | The Python ``False`` object. This object has no methods. It needs to be |
| 22 | treated just like any other object with respect to reference counts. |
| 23 | |
| 24 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame^] | 25 | .. c:var:: PyObject* Py_True |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 26 | |
| 27 | The Python ``True`` object. This object has no methods. It needs to be treated |
| 28 | just like any other object with respect to reference counts. |
| 29 | |
| 30 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame^] | 31 | .. c:macro:: Py_RETURN_FALSE |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 32 | |
| 33 | Return :const:`Py_False` from a function, properly incrementing its reference |
| 34 | count. |
| 35 | |
| 36 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame^] | 37 | .. c:macro:: Py_RETURN_TRUE |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 38 | |
| 39 | Return :const:`Py_True` from a function, properly incrementing its reference |
| 40 | count. |
| 41 | |
| 42 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame^] | 43 | .. c:function:: PyObject* PyBool_FromLong(long v) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 44 | |
| 45 | Return a new reference to :const:`Py_True` or :const:`Py_False` depending on the |
| 46 | truth value of *v*. |