Guido van Rossum | 5f82036 | 2002-04-03 23:01:45 +0000 | [diff] [blame] | 1 | /* Boolean object interface */ |
| 2 | |
Mark Hammond | 303d05d | 2002-04-06 03:58:41 +0000 | [diff] [blame] | 3 | #ifndef Py_BOOLOBJECT_H |
| 4 | #define Py_BOOLOBJECT_H |
| 5 | #ifdef __cplusplus |
| 6 | extern "C" { |
| 7 | #endif |
| 8 | |
| 9 | |
Guido van Rossum | 5f82036 | 2002-04-03 23:01:45 +0000 | [diff] [blame] | 10 | typedef PyIntObject PyBoolObject; |
| 11 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 12 | PyAPI_DATA(PyTypeObject) PyBool_Type; |
Guido van Rossum | 5f82036 | 2002-04-03 23:01:45 +0000 | [diff] [blame] | 13 | |
Christian Heimes | e93237d | 2007-12-19 02:37:44 +0000 | [diff] [blame] | 14 | #define PyBool_Check(x) (Py_TYPE(x) == &PyBool_Type) |
Guido van Rossum | 5f82036 | 2002-04-03 23:01:45 +0000 | [diff] [blame] | 15 | |
| 16 | /* Py_False and Py_True are the only two bools in existence. |
| 17 | Don't forget to apply Py_INCREF() when returning either!!! */ |
| 18 | |
| 19 | /* Don't use these directly */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 20 | PyAPI_DATA(PyIntObject) _Py_ZeroStruct, _Py_TrueStruct; |
Guido van Rossum | 5f82036 | 2002-04-03 23:01:45 +0000 | [diff] [blame] | 21 | |
| 22 | /* Use these macros */ |
| 23 | #define Py_False ((PyObject *) &_Py_ZeroStruct) |
| 24 | #define Py_True ((PyObject *) &_Py_TrueStruct) |
| 25 | |
Brett Cannon | d05235e | 2003-10-19 21:19:40 +0000 | [diff] [blame] | 26 | /* Macros for returning Py_True or Py_False, respectively */ |
Tim Peters | 5980ff2 | 2004-07-22 01:46:43 +0000 | [diff] [blame] | 27 | #define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True |
| 28 | #define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False |
Brett Cannon | d05235e | 2003-10-19 21:19:40 +0000 | [diff] [blame] | 29 | |
Guido van Rossum | 5f82036 | 2002-04-03 23:01:45 +0000 | [diff] [blame] | 30 | /* Function to return a bool from a C long */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 31 | PyAPI_FUNC(PyObject *) PyBool_FromLong(long); |
Mark Hammond | 303d05d | 2002-04-06 03:58:41 +0000 | [diff] [blame] | 32 | |
| 33 | #ifdef __cplusplus |
| 34 | } |
| 35 | #endif |
| 36 | #endif /* !Py_BOOLOBJECT_H */ |