blob: cda6f89a99e9a2dfd1d5ba7bf40f6292f33469b3 [file] [log] [blame]
Guido van Rossum5f820362002-04-03 23:01:45 +00001/* Boolean object interface */
2
Mark Hammond303d05d2002-04-06 03:58:41 +00003#ifndef Py_BOOLOBJECT_H
4#define Py_BOOLOBJECT_H
5#ifdef __cplusplus
6extern "C" {
7#endif
8
9
Mark Hammond91a681d2002-08-12 07:21:58 +000010PyAPI_DATA(PyTypeObject) PyBool_Type;
Guido van Rossum5f820362002-04-03 23:01:45 +000011
Dong-hee Nad905df72020-02-14 02:37:17 +090012#define PyBool_Check(x) Py_IS_TYPE(x, &PyBool_Type)
Guido van Rossum5f820362002-04-03 23:01:45 +000013
14/* Py_False and Py_True are the only two bools in existence.
15Don't forget to apply Py_INCREF() when returning either!!! */
16
17/* Don't use these directly */
Petr Viktorine7cc64e2021-04-23 14:14:00 +020018PyAPI_DATA(struct _longobject) _Py_FalseStruct;
19PyAPI_DATA(struct _longobject) _Py_TrueStruct;
Guido van Rossum5f820362002-04-03 23:01:45 +000020
21/* Use these macros */
Guido van Rossumddefaf32007-01-14 03:31:43 +000022#define Py_False ((PyObject *) &_Py_FalseStruct)
Guido van Rossum5f820362002-04-03 23:01:45 +000023#define Py_True ((PyObject *) &_Py_TrueStruct)
24
Victor Stinner09bbebe2021-04-11 00:17:39 +020025// Test if an object is the True singleton, the same as "x is True" in Python.
26PyAPI_FUNC(int) Py_IsTrue(PyObject *x);
27#define Py_IsTrue(x) Py_Is((x), Py_True)
28
29// Test if an object is the False singleton, the same as "x is False" in Python.
30PyAPI_FUNC(int) Py_IsFalse(PyObject *x);
31#define Py_IsFalse(x) Py_Is((x), Py_False)
32
Brett Cannond05235e2003-10-19 21:19:40 +000033/* Macros for returning Py_True or Py_False, respectively */
Victor Stinner53a03aa2020-11-05 15:02:12 +010034#define Py_RETURN_TRUE return Py_NewRef(Py_True)
35#define Py_RETURN_FALSE return Py_NewRef(Py_False)
Brett Cannond05235e2003-10-19 21:19:40 +000036
Guido van Rossum5f820362002-04-03 23:01:45 +000037/* Function to return a bool from a C long */
Mark Hammond91a681d2002-08-12 07:21:58 +000038PyAPI_FUNC(PyObject *) PyBool_FromLong(long);
Mark Hammond303d05d2002-04-06 03:58:41 +000039
40#ifdef __cplusplus
41}
42#endif
43#endif /* !Py_BOOLOBJECT_H */