Skip to content

Commit d05235e

Browse files
committed
Defined macros Py_RETURN_(TRUE|FALSE|NONE) as helper functions for returning
the specified value. All three Py_INCREF the singleton and then return it.
1 parent 52da449 commit d05235e

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Include/boolobject.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ PyAPI_DATA(PyIntObject) _Py_ZeroStruct, _Py_TrueStruct;
2323
#define Py_False ((PyObject *) &_Py_ZeroStruct)
2424
#define Py_True ((PyObject *) &_Py_TrueStruct)
2525

26+
/* Macros for returning Py_True or Py_False, respectively */
27+
#define Py_RETURN_TRUE Py_INCREF(Py_True); return Py_True;
28+
#define Py_RETURN_FALSE Py_INCREF(Py_False); return Py_False;
29+
2630
/* Function to return a bool from a C long */
2731
PyAPI_FUNC(PyObject *) PyBool_FromLong(long);
2832

Include/object.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,9 @@ Don't forget to apply Py_INCREF() when returning this value!!!
633633
PyAPI_DATA(PyObject) _Py_NoneStruct; /* Don't use this directly */
634634
#define Py_None (&_Py_NoneStruct)
635635

636+
/* Macro for returning Py_None from a function */
637+
#define Py_RETURN_NONE Py_INCREF(Py_None); return Py_None;
638+
636639
/*
637640
Py_NotImplemented is a singleton used to signal that an operation is
638641
not implemented for a given type combination.

0 commit comments

Comments
 (0)