Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 200 additions & 0 deletions Doc/c-api/typeobj.rst

Large diffs are not rendered by default.

153 changes: 153 additions & 0 deletions Doc/data/stable_abi.dat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Doc/library/functools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ The :mod:`functools` module defines the following functions:
def factorial(n):
return n * factorial(n-1) if n else 1

>>> factorial(10) # no previously cached result, makes 11 recursive calls
>>> factorial(10) # no previously cached result, makes 11 recursive calls
3628800
>>> factorial(5) # just looks up cached value result
>>> factorial(5) # no new calls, just returns the cached result
120
>>> factorial(12) # makes two new recursive calls, the other 10 are cached
>>> factorial(12) # two new recursive calls, factorial(10) is cached
479001600

The cache is threadsafe so that the wrapped function can be used in
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/string.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.. module:: string
:synopsis: Common string operations.

**Source code:** :source:`Lib/string.py`
**Source code:** :source:`Lib/string/__init__.py`

--------------

Expand Down
1 change: 0 additions & 1 deletion Doc/tools/.nitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Doc/c-api/init_config.rst
Doc/c-api/intro.rst
Doc/c-api/module.rst
Doc/c-api/stable.rst
Doc/c-api/type.rst
Doc/c-api/typeobj.rst
Doc/library/ast.rst
Doc/library/asyncio-extending.rst
Expand Down
76 changes: 72 additions & 4 deletions Doc/tools/extensions/c_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ def add_annotations(app: Sphinx, doctree: nodes.document) -> None:
node.insert(0, annotation)


def _stable_abi_annotation(record: StableABIEntry) -> nodes.emphasis:
def _stable_abi_annotation(
record: StableABIEntry,
is_corresponding_slot: bool = False,
) -> nodes.emphasis:
"""Create the Stable ABI annotation.

These have two forms:
Expand All @@ -168,9 +171,28 @@ def _stable_abi_annotation(record: StableABIEntry) -> nodes.emphasis:
... all of which can have "since version X.Y" appended.
"""
stable_added = record.added
message = sphinx_gettext("Part of the")
message = message.center(len(message) + 2)
emph_node = nodes.emphasis(message, message, classes=["stableabi"])
emph_node = nodes.emphasis('', '', classes=["stableabi"])
if is_corresponding_slot:
# See "Type slot annotations" in add_annotations
ref_node = addnodes.pending_xref(
"slot ID",
refdomain="c",
reftarget="PyType_Slot",
reftype="type",
refexplicit="True",
)
ref_node += nodes.Text(sphinx_gettext("slot ID"))

message = sphinx_gettext("The corresponding")
emph_node += nodes.Text(" " + message + " ")
emph_node += ref_node
emph_node += nodes.Text(" ")
emph_node += nodes.literal(record.name, record.name)
message = sphinx_gettext("is part of the")
emph_node += nodes.Text(" " + message + " ")
else:
message = sphinx_gettext("Part of the")
emph_node += nodes.Text(" " + message + " ")
ref_node = addnodes.pending_xref(
"Stable ABI",
refdomain="std",
Expand Down Expand Up @@ -265,6 +287,51 @@ def run(self) -> list[nodes.Node]:
return [node]


class CorrespondingTypeSlot(SphinxDirective):
"""Type slot annotations

Docs for these are with the corresponding field, for example,
"Py_tp_repr" is documented under "PyTypeObject.tp_repr", with
only a stable ABI note mentioning "Py_tp_repr" (and linking to
docs on how this works).

If there is no corresponding field, these should be documented as normal
macros.
"""

has_content = False

required_arguments = 1
optional_arguments = 0

def run(self) -> list[nodes.Node]:
name = self.arguments[0]
state = self.env.domaindata["c_annotations"]
stable_abi_data = state["stable_abi_data"]

try:
record = stable_abi_data[name]
except LookupError as err:
raise LookupError(
f"{name} is not part of stable ABI. "
+ "Document it as `c:macro::` rather than "
+ "`corresponding-type-slot::`."
) from err

annotation = _stable_abi_annotation(record, is_corresponding_slot=True)

node = nodes.paragraph()
content = [
".. c:namespace:: NULL",
"",
".. c:macro:: " + name,
" :no-typesetting:",
]
self.state.nested_parse(StringList(content), 0, node)
node.insert(0, annotation)
return [node]


def init_annotations(app: Sphinx) -> None:
# Using domaindata is a bit hack-ish,
# but allows storing state without a global variable or closure.
Expand All @@ -281,6 +348,7 @@ def setup(app: Sphinx) -> ExtensionMetadata:
app.add_config_value("refcount_file", "", "env", types={str})
app.add_config_value("stable_abi_file", "", "env", types={str})
app.add_directive("limited-api-list", LimitedAPIList)
app.add_directive("corresponding-type-slot", CorrespondingTypeSlot)
app.connect("builder-inited", init_annotations)
app.connect("doctree-read", add_annotations)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
When building the JIT, match the jit_stencils filename expectations in
Makefile with the generator script. This avoid needless JIT recompilation
during ``make install``.
4 changes: 4 additions & 0 deletions Misc/stable_abi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2306,6 +2306,10 @@
added = '3.11'
[function.PyMemoryView_FromBuffer]
added = '3.11'
[const.Py_bf_getbuffer]
added = '3.11'
[const.Py_bf_releasebuffer]
added = '3.11'

# Constants for Py_buffer API added to this list in Python 3.11.1 (https://github.com/python/cpython/issues/98680)
# (they were available with 3.11.0)
Expand Down
2 changes: 1 addition & 1 deletion Tools/build/stable_abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def sort_key(item):
'data': 'data',
'struct': 'type',
'macro': 'macro',
# 'const': 'const', # all undocumented
'const': 'macro',
'typedef': 'type',
}

Expand Down
4 changes: 2 additions & 2 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -8219,10 +8219,10 @@ AS_VAR_IF([enable_experimental_jit], [no],
JIT_STENCILS_H="jit_stencils-x86_64-pc-windows-msvc.h"
;;
aarch64-*-linux-gnu)
JIT_STENCILS_H="jit_stencils-$host.h"
JIT_STENCILS_H="jit_stencils-aarch64-unknown-linux-gnu.h"
;;
x86_64-*-linux-gnu)
JIT_STENCILS_H="jit_stencils-$host.h"
JIT_STENCILS_H="jit_stencils-x86_64-unknown-linux-gnu.h"
;;
esac])

Expand Down
Loading