• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Boolean object interface */
2 
3 #ifndef Py_BOOLOBJECT_H
4 #define Py_BOOLOBJECT_H
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
8 
9 
10 // PyBool_Type is declared by object.h
11 
12 #define PyBool_Check(x) Py_IS_TYPE((x), &PyBool_Type)
13 
14 /* Py_False and Py_True are the only two bools in existence. */
15 
16 /* Don't use these directly */
17 PyAPI_DATA(PyLongObject) _Py_FalseStruct;
18 PyAPI_DATA(PyLongObject) _Py_TrueStruct;
19 
20 /* Use these macros */
21 #if defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030D0000
22 #  define Py_False Py_GetConstantBorrowed(Py_CONSTANT_FALSE)
23 #  define Py_True Py_GetConstantBorrowed(Py_CONSTANT_TRUE)
24 #else
25 #  define Py_False _PyObject_CAST(&_Py_FalseStruct)
26 #  define Py_True _PyObject_CAST(&_Py_TrueStruct)
27 #endif
28 
29 // Test if an object is the True singleton, the same as "x is True" in Python.
30 PyAPI_FUNC(int) Py_IsTrue(PyObject *x);
31 #define Py_IsTrue(x) Py_Is((x), Py_True)
32 
33 // Test if an object is the False singleton, the same as "x is False" in Python.
34 PyAPI_FUNC(int) Py_IsFalse(PyObject *x);
35 #define Py_IsFalse(x) Py_Is((x), Py_False)
36 
37 /* Macros for returning Py_True or Py_False, respectively */
38 #define Py_RETURN_TRUE return Py_True
39 #define Py_RETURN_FALSE return Py_False
40 
41 /* Function to return a bool from a C long */
42 PyAPI_FUNC(PyObject *) PyBool_FromLong(long);
43 
44 #ifdef __cplusplus
45 }
46 #endif
47 #endif /* !Py_BOOLOBJECT_H */
48