Skip to content

Commit 1cd0b74

Browse files
[3.13] gh-141004: Document Py_BUILD_ASSERT* macros (GH-141266) (GH-141270)
gh-141004: Document `Py_BUILD_ASSERT*` macros (GH-141266) (cherry picked from commit 0ac890b) Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
1 parent 2a300e3 commit 1cd0b74

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

Doc/c-api/intro.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,29 @@ complete listing.
245245

246246
.. versionadded:: 3.4
247247

248+
.. c:macro:: Py_BUILD_ASSERT(cond)
249+
250+
Asserts a compile-time condition *cond*, as a statement.
251+
The build will fail if the condition is false or cannot be evaluated at compile time.
252+
253+
For example::
254+
255+
Py_BUILD_ASSERT(sizeof(PyTime_t) == sizeof(int64_t));
256+
257+
.. versionadded:: 3.3
258+
259+
.. c:macro:: Py_BUILD_ASSERT_EXPR(cond)
260+
261+
Asserts a compile-time condition *cond*, as an expression that evaluates to ``0``.
262+
The build will fail if the condition is false or cannot be evaluated at compile time.
263+
264+
For example::
265+
266+
#define foo_to_char(foo) \
267+
((char *)(foo) + Py_BUILD_ASSERT_EXPR(offsetof(struct foo, string) == 0))
268+
269+
.. versionadded:: 3.3
270+
248271
.. c:macro:: PyDoc_STRVAR(name, str)
249272
250273
Creates a variable with name *name* that can be used in docstrings.

Doc/conf.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,6 @@
225225
# Temporary undocumented names.
226226
# In future this list must be empty.
227227
nitpick_ignore += [
228-
# Undocumented public C macros
229-
('c:macro', 'Py_BUILD_ASSERT'),
230-
('c:macro', 'Py_BUILD_ASSERT_EXPR'),
231228
# Do not error nit-picky mode builds when _SubParsersAction.add_parser cannot
232229
# be resolved, as the method is currently undocumented. For context, see
233230
# https://github.com/python/cpython/pull/103289.

0 commit comments

Comments
 (0)