Others of a more general utility are defined here. This is not necessarily a
complete listing.
-.. c:macro:: Py_UNREACHABLE()
+.. c:macro:: Py_ABS(x)
- Use this when you have a code path that cannot be reached by design.
- For example, in the ``default:`` clause in a ``switch`` statement for which
- all possible values are covered in ``case`` statements. Use this in places
- where you might be tempted to put an ``assert(0)`` or ``abort()`` call.
+ Return the absolute value of ``x``.
- In release mode, the macro helps the compiler to optimize the code, and
- avoids a warning about unreachable code. For example, the macro is
- implemented with ``__builtin_unreachable()`` on GCC in release mode.
+ .. versionadded:: 3.3
- A use for ``Py_UNREACHABLE()`` is following a call a function that
- never returns but that is not declared :c:macro:`_Py_NO_RETURN`.
+.. c:macro:: Py_CHARMASK(c)
- If a code path is very unlikely code but can be reached under exceptional
- case, this macro must not be used. For example, under low memory condition
- or if a system call returns a value out of the expected range. In this
- case, it's better to report the error to the caller. If the error cannot
- be reported to caller, :c:func:`Py_FatalError` can be used.
+ Argument must be a character or an integer in the range [-128, 127] or [0,
+ 255]. This macro returns ``c`` cast to an ``unsigned char``.
- .. versionadded:: 3.7
+.. c:macro:: Py_DEPRECATED(version)
-.. c:macro:: Py_ABS(x)
+ Use this for deprecated declarations. The macro must be placed before the
+ symbol name.
- Return the absolute value of ``x``.
+ Example::
+
+ Py_DEPRECATED(3.8) PyAPI_FUNC(int) Py_OldFunction(void);
+
+ .. versionchanged:: 3.8
+ MSVC support was added.
+
+.. c:macro:: Py_GETENV(s)
+
+ Like ``getenv(s)``, but returns ``NULL`` if :option:`-E` was passed on the
+ command line (i.e. if ``Py_IgnoreEnvironmentFlag`` is set).
+
+.. c:macro:: Py_MAX(x, y)
+
+ Return the maximum value between ``x`` and ``y``.
.. versionadded:: 3.3
+.. c:macro:: Py_MEMBER_SIZE(type, member)
+
+ Return the size of a structure (``type``) ``member`` in bytes.
+
+ .. versionadded:: 3.6
+
.. c:macro:: Py_MIN(x, y)
Return the minimum value between ``x`` and ``y``.
.. versionadded:: 3.3
-.. c:macro:: Py_MAX(x, y)
+.. c:macro:: Py_NO_INLINE
- Return the maximum value between ``x`` and ``y``.
+ Disable inlining on a function. For example, it reduces the C stack
+ consumption: useful on LTO+PGO builds which heavily inline code (see
+ :issue:`33720`).
- .. versionadded:: 3.3
+ Usage::
+
+ Py_NO_INLINE static int random(void) { return 4; }
+
+ .. versionadded:: 3.11
.. c:macro:: Py_STRINGIFY(x)
.. versionadded:: 3.4
-.. c:macro:: Py_MEMBER_SIZE(type, member)
-
- Return the size of a structure (``type``) ``member`` in bytes.
+.. c:macro:: Py_UNREACHABLE()
- .. versionadded:: 3.6
+ Use this when you have a code path that cannot be reached by design.
+ For example, in the ``default:`` clause in a ``switch`` statement for which
+ all possible values are covered in ``case`` statements. Use this in places
+ where you might be tempted to put an ``assert(0)`` or ``abort()`` call.
-.. c:macro:: Py_CHARMASK(c)
+ In release mode, the macro helps the compiler to optimize the code, and
+ avoids a warning about unreachable code. For example, the macro is
+ implemented with ``__builtin_unreachable()`` on GCC in release mode.
- Argument must be a character or an integer in the range [-128, 127] or [0,
- 255]. This macro returns ``c`` cast to an ``unsigned char``.
+ A use for ``Py_UNREACHABLE()`` is following a call a function that
+ never returns but that is not declared :c:macro:`_Py_NO_RETURN`.
-.. c:macro:: Py_GETENV(s)
+ If a code path is very unlikely code but can be reached under exceptional
+ case, this macro must not be used. For example, under low memory condition
+ or if a system call returns a value out of the expected range. In this
+ case, it's better to report the error to the caller. If the error cannot
+ be reported to caller, :c:func:`Py_FatalError` can be used.
- Like ``getenv(s)``, but returns ``NULL`` if :option:`-E` was passed on the
- command line (i.e. if ``Py_IgnoreEnvironmentFlag`` is set).
+ .. versionadded:: 3.7
.. c:macro:: Py_UNUSED(arg)
.. versionadded:: 3.4
-.. c:macro:: Py_DEPRECATED(version)
-
- Use this for deprecated declarations. The macro must be placed before the
- symbol name.
-
- Example::
-
- Py_DEPRECATED(3.8) PyAPI_FUNC(int) Py_OldFunction(void);
-
- .. versionchanged:: 3.8
- MSVC support was added.
-
.. c:macro:: PyDoc_STRVAR(name, str)
Creates a variable with name ``name`` that can be used in docstrings.
{NULL, NULL}
};
+
.. _api-objects:
Objects, Types and Reference Counts