Skip to content

Commit d8a2b8a

Browse files
[3.14] gh-141004: Document Py_BUILD_ASSERT* macros (GH-141266) (GH-141269)
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 f982118 commit d8a2b8a

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
@@ -233,6 +233,29 @@ complete listing.
233233

234234
.. versionadded:: 3.4
235235

236+
.. c:macro:: Py_BUILD_ASSERT(cond)
237+
238+
Asserts a compile-time condition *cond*, as a statement.
239+
The build will fail if the condition is false or cannot be evaluated at compile time.
240+
241+
For example::
242+
243+
Py_BUILD_ASSERT(sizeof(PyTime_t) == sizeof(int64_t));
244+
245+
.. versionadded:: 3.3
246+
247+
.. c:macro:: Py_BUILD_ASSERT_EXPR(cond)
248+
249+
Asserts a compile-time condition *cond*, as an expression that evaluates to ``0``.
250+
The build will fail if the condition is false or cannot be evaluated at compile time.
251+
252+
For example::
253+
254+
#define foo_to_char(foo) \
255+
((char *)(foo) + Py_BUILD_ASSERT_EXPR(offsetof(struct foo, string) == 0))
256+
257+
.. versionadded:: 3.3
258+
236259
.. c:macro:: PyDoc_STRVAR(name, str)
237260
238261
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
@@ -226,9 +226,6 @@
226226
# Temporary undocumented names.
227227
# In future this list must be empty.
228228
nitpick_ignore += [
229-
# Undocumented public C macros
230-
('c:macro', 'Py_BUILD_ASSERT'),
231-
('c:macro', 'Py_BUILD_ASSERT_EXPR'),
232229
# Do not error nit-picky mode builds when _SubParsersAction.add_parser cannot
233230
# be resolved, as the method is currently undocumented. For context, see
234231
# https://github.com/python/cpython/pull/103289.

0 commit comments

Comments
 (0)