summaryrefslogtreecommitdiffstats
path: root/Doc/c-api/intro.rst
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-09-03 14:44:02 (GMT)
committerGitHub <noreply@github.com>2021-09-03 14:44:02 (GMT)
commit7974c30b9fd84fa56ea1515ed2c08b38edf1a383 (patch)
tree2d638f338e1e6f90765fa731ff27ef6265524723 /Doc/c-api/intro.rst
parentbe9de8721d63b9d8e032d508069daf88c06542c6 (diff)
downloadcpython-7974c30b9fd84fa56ea1515ed2c08b38edf1a383.zip
cpython-7974c30b9fd84fa56ea1515ed2c08b38edf1a383.tar.gz
cpython-7974c30b9fd84fa56ea1515ed2c08b38edf1a383.tar.bz2
bpo-45094: Add Py_NO_INLINE macro (GH-28140)
* Rename _Py_NO_INLINE macro to Py_NO_INLINE: make it public and document it. * Sort macros in the C API documentation.
Diffstat (limited to 'Doc/c-api/intro.rst')
-rw-r--r--Doc/c-api/intro.rst99
1 files changed, 56 insertions, 43 deletions
diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst
index 2d85d30..83824bb 100644
--- a/Doc/c-api/intro.rst
+++ b/Doc/c-api/intro.rst
@@ -105,45 +105,63 @@ defined closer to where they are useful (e.g. :c:macro:`Py_RETURN_NONE`).
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)
@@ -152,21 +170,27 @@ complete listing.
.. 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)
@@ -175,18 +199,6 @@ complete listing.
.. 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.
@@ -221,6 +233,7 @@ complete listing.
{NULL, NULL}
};
+
.. _api-objects:
Objects, Types and Reference Counts