-
-
Notifications
You must be signed in to change notification settings - Fork 34k
gh-141004: Document remaining pyport.h utility macros
#144279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ZeroIntensity
wants to merge
17
commits into
python:main
Choose a base branch
from
ZeroIntensity:document-more-macros
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+96
−9
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
85d1c40
Document Py_ALIGNED
ZeroIntensity a0f0bda
Document Py_ARITHMETIC_RIGHT_SHIFT
ZeroIntensity 0389e16
Add versionchanged.
ZeroIntensity 38ed1e2
Document Py_CAN_START_THREADS
ZeroIntensity fbb93ab
Add versionadded.
ZeroIntensity 9785f84
Document Py_FORCE_EXPANSION
ZeroIntensity 5d84b69
Document Py_GCC_ATTRIBUTE.
ZeroIntensity fa005af
Document Py_LL and Py_ULL.
ZeroIntensity 2630329
Document Py_SAFE_DOWNCAST.
ZeroIntensity d912569
Document Py_VA_COPY.
ZeroIntensity 8437710
Fix Sphinx errors.
ZeroIntensity 920ead5
Fix more stupid Sphinx problems.
ZeroIntensity ed7c53d
Fix my checker script.
ZeroIntensity 62ac248
Apply suggestions from code review
ZeroIntensity c1ef33d
Fix warnings.
ZeroIntensity efb0c72
Add a backwards compatibility note.
ZeroIntensity bc735a6
Remove sentence about older versions.
ZeroIntensity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,6 +167,35 @@ | |
|
|
||
| .. versionadded:: 3.3 | ||
|
|
||
| .. c:macro:: Py_ALIGNED(num) | ||
|
|
||
| Specify alignment to *num* bytes on compilers that support it. | ||
|
|
||
| Consider using the C11 standard ``_Alignas`` specifier over this macro. | ||
|
|
||
| .. c:macro:: Py_ARITHMETIC_RIGHT_SHIFT(type, integer, positions) | ||
|
|
||
| Similar to ``integer >> positions``, but forces sign extension, as the C | ||
| standard does not define whether a right-shift of a signed integer will | ||
| perform sign extension or a zero-fill. | ||
|
|
||
| *integer* should be any signed integer type. | ||
| *positions* is the number of positions to shift to the right. | ||
|
|
||
| Both *integer* and *positions* can be evaluated more than once; | ||
| consequently, avoid directly passing a function call or some other | ||
| expensive operation to this macro. Instead, store the result as a | ||
| variable and then pass it. | ||
|
|
||
| *type* is unused and only kept for backwards compatibility. Historically, | ||
| *type* was used to cast *integer*. | ||
|
|
||
| .. versionchanged:: 3.1 | ||
|
|
||
| This macro is now valid for all signed integer types, not just those for | ||
| which ``unsigned type`` is legal. As a result, *type* is no longer | ||
| used. | ||
|
|
||
| .. c:macro:: Py_ALWAYS_INLINE | ||
|
|
||
| Ask the compiler to always inline a static inline function. The compiler can | ||
|
|
@@ -189,6 +218,15 @@ | |
|
|
||
| .. versionadded:: 3.11 | ||
|
|
||
| .. c:macro:: Py_CAN_START_THREADS | ||
|
|
||
| If this macro is defined, then the current system is able to start threads. | ||
|
|
||
| Currently, all systems supported by CPython (per :pep:`11`), with the | ||
| exception of some WebAssembly platforms, support starting threads. | ||
|
|
||
| .. versionadded:: 3.13 | ||
|
|
||
| .. c:macro:: Py_CHARMASK(c) | ||
|
|
||
| Argument must be a character or an integer in the range [-128, 127] or [0, | ||
|
|
@@ -206,11 +244,35 @@ | |
| .. versionchanged:: 3.8 | ||
| MSVC support was added. | ||
|
|
||
| .. c:macro:: Py_FORCE_EXPANSION(X) | ||
|
|
||
| This is equivalent to ``X``, which is useful for token-pasting in | ||
| macros, as macro expansions in *X* are forcefully evaluated by the | ||
| preprocessor. | ||
|
|
||
| .. c:macro:: Py_GCC_ATTRIBUTE(name) | ||
|
|
||
| Use a GCC attribute *name*, hiding it from compilers that don't support GCC | ||
| attributes (such as MSVC). | ||
|
|
||
| This expands to ``__attribute__((name))`` on a GCC compiler, and expands | ||
| to nothing on compilers that don't support GCC attributes. | ||
|
|
||
| .. c:macro:: Py_GETENV(s) | ||
|
|
||
| Like ``getenv(s)``, but returns ``NULL`` if :option:`-E` was passed on the | ||
| command line (see :c:member:`PyConfig.use_environment`). | ||
|
|
||
| .. c:macro:: Py_LL(number) | ||
|
|
||
| Use *number* as a ``long long`` integer literal. | ||
|
|
||
| This usally expands to *number* followed by ``LL``, but will expand to some | ||
| compiler-specific suffixes (such as ``I64``) on older compilers. | ||
|
|
||
| In modern versions of Python, this macro is not very useful, as C99 and | ||
| later require the ``LL`` suffix to be valid for an integer. | ||
|
|
||
| .. c:macro:: Py_LOCAL(type) | ||
|
|
||
| Declare a function returning the specified *type* using a fast-calling | ||
|
|
@@ -268,13 +330,37 @@ | |
|
|
||
| .. versionadded:: 3.11 | ||
|
|
||
| .. c:macro:: Py_SAFE_DOWNCAST(value, larger, smaller) | ||
|
|
||
| Cast *value* to type *smaller* from type *larger*, validating that no | ||
| information was lost. | ||
|
|
||
| On release builds of Python, this is roughly equivalent to | ||
|
Check warning on line 338 in Doc/c-api/intro.rst
|
||
| :c:expr:`(smaller) value` (in C++, ``static_cast<smaller>(value)`` will be | ||
| used instead). | ||
|
|
||
| On debug builds (implying that :c:macro:`Py_DEBUG` is defined), this asserts | ||
| that no information was lost with the cast from *larger* to *smaller*. | ||
|
|
||
| *value*, *larger*, and *smaller* may all be evaluated more than once in the | ||
| expression; consequently, do not pass an expensive operation directly to | ||
| this macro. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expressions with side effects (ex: |
||
|
|
||
| .. c:macro:: Py_STRINGIFY(x) | ||
|
|
||
| Convert ``x`` to a C string. E.g. ``Py_STRINGIFY(123)`` returns | ||
| ``"123"``. | ||
|
|
||
| .. versionadded:: 3.4 | ||
|
|
||
| .. c:macro:: Py_ULL(number) | ||
|
|
||
| Similar to :c:macro:`Py_LL`, but *number* will be an ``unsigned long long`` | ||
| literal instead. This is done by appending ``U`` to the result of ``Py_LL``. | ||
|
|
||
| In modern versions of Python, this macro is not very useful, as C99 and | ||
| later require the ``ULL``/``LLU`` suffixes to be valid for an integer. | ||
|
|
||
| .. c:macro:: Py_UNREACHABLE() | ||
|
|
||
| Use this when you have a code path that cannot be reached by design. | ||
|
|
@@ -415,6 +501,16 @@ | |
| This macro is intended for defining CPython's C API itself; | ||
| extension modules should not use it for their own symbols. | ||
|
|
||
| .. c:macro:: Py_VA_COPY | ||
|
|
||
| This is a :term:`soft deprecated` alias to the C99-standard ``va_copy`` | ||
| function. | ||
|
|
||
| Historically, this would use a compiler-specific method to copy a ``va_list``. | ||
|
|
||
| .. versionchanged:: 3.6 | ||
| This is now an alias to ``va_copy``. | ||
|
|
||
|
|
||
| .. _api-objects: | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It emits a warning:
I suggest to avoid c:expr: