mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-138189: Link references to type slots (GH-141410)
Link references to type slots
This commit is contained in:
parent
a52c39e260
commit
4695ec109d
4 changed files with 13 additions and 15 deletions
|
|
@ -698,14 +698,12 @@ The following flags can be used with :c:member:`PyMemberDef.flags`:
|
||||||
entry indicates an offset from the subclass-specific data, rather than
|
entry indicates an offset from the subclass-specific data, rather than
|
||||||
from ``PyObject``.
|
from ``PyObject``.
|
||||||
|
|
||||||
Can only be used as part of :c:member:`Py_tp_members <PyTypeObject.tp_members>`
|
Can only be used as part of the :c:data:`Py_tp_members`
|
||||||
:c:type:`slot <PyType_Slot>` when creating a class using negative
|
:c:type:`slot <PyType_Slot>` when creating a class using negative
|
||||||
:c:member:`~PyType_Spec.basicsize`.
|
:c:member:`~PyType_Spec.basicsize`.
|
||||||
It is mandatory in that case.
|
It is mandatory in that case.
|
||||||
|
When setting :c:member:`~PyTypeObject.tp_members` from the slot during
|
||||||
This flag is only used in :c:type:`PyType_Slot`.
|
class creation, Python clears the flag and sets
|
||||||
When setting :c:member:`~PyTypeObject.tp_members` during
|
|
||||||
class creation, Python clears it and sets
|
|
||||||
:c:member:`PyMemberDef.offset` to the offset from the ``PyObject`` struct.
|
:c:member:`PyMemberDef.offset` to the offset from the ``PyObject`` struct.
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
|
|
|
||||||
|
|
@ -383,8 +383,8 @@ The following functions and structs are used to create
|
||||||
|
|
||||||
The *bases* argument can be used to specify base classes; it can either
|
The *bases* argument can be used to specify base classes; it can either
|
||||||
be only one class or a tuple of classes.
|
be only one class or a tuple of classes.
|
||||||
If *bases* is ``NULL``, the *Py_tp_bases* slot is used instead.
|
If *bases* is ``NULL``, the :c:data:`Py_tp_bases` slot is used instead.
|
||||||
If that also is ``NULL``, the *Py_tp_base* slot is used instead.
|
If that also is ``NULL``, the :c:data:`Py_tp_base` slot is used instead.
|
||||||
If that also is ``NULL``, the new type derives from :class:`object`.
|
If that also is ``NULL``, the new type derives from :class:`object`.
|
||||||
|
|
||||||
The *module* argument can be used to record the module in which the new
|
The *module* argument can be used to record the module in which the new
|
||||||
|
|
@ -590,9 +590,9 @@ The following functions and structs are used to create
|
||||||
:c:type:`PyAsyncMethods` with an added ``Py_`` prefix.
|
:c:type:`PyAsyncMethods` with an added ``Py_`` prefix.
|
||||||
For example, use:
|
For example, use:
|
||||||
|
|
||||||
* ``Py_tp_dealloc`` to set :c:member:`PyTypeObject.tp_dealloc`
|
* :c:data:`Py_tp_dealloc` to set :c:member:`PyTypeObject.tp_dealloc`
|
||||||
* ``Py_nb_add`` to set :c:member:`PyNumberMethods.nb_add`
|
* :c:data:`Py_nb_add` to set :c:member:`PyNumberMethods.nb_add`
|
||||||
* ``Py_sq_length`` to set :c:member:`PySequenceMethods.sq_length`
|
* :c:data:`Py_sq_length` to set :c:member:`PySequenceMethods.sq_length`
|
||||||
|
|
||||||
An additional slot is supported that does not correspond to a
|
An additional slot is supported that does not correspond to a
|
||||||
:c:type:`!PyTypeObject` struct field:
|
:c:type:`!PyTypeObject` struct field:
|
||||||
|
|
@ -611,7 +611,7 @@ The following functions and structs are used to create
|
||||||
|
|
||||||
If it is not possible to switch to a ``MANAGED`` flag (for example,
|
If it is not possible to switch to a ``MANAGED`` flag (for example,
|
||||||
for vectorcall or to support Python older than 3.12), specify the
|
for vectorcall or to support Python older than 3.12), specify the
|
||||||
offset in :c:member:`Py_tp_members <PyTypeObject.tp_members>`.
|
offset in :c:data:`Py_tp_members`.
|
||||||
See :ref:`PyMemberDef documentation <pymemberdef-offsets>`
|
See :ref:`PyMemberDef documentation <pymemberdef-offsets>`
|
||||||
for details.
|
for details.
|
||||||
|
|
||||||
|
|
@ -639,7 +639,7 @@ The following functions and structs are used to create
|
||||||
|
|
||||||
.. versionchanged:: 3.14
|
.. versionchanged:: 3.14
|
||||||
The field :c:member:`~PyTypeObject.tp_vectorcall` can now set
|
The field :c:member:`~PyTypeObject.tp_vectorcall` can now set
|
||||||
using ``Py_tp_vectorcall``. See the field's documentation
|
using :c:data:`Py_tp_vectorcall`. See the field's documentation
|
||||||
for details.
|
for details.
|
||||||
|
|
||||||
.. c:member:: void *pfunc
|
.. c:member:: void *pfunc
|
||||||
|
|
@ -649,7 +649,7 @@ The following functions and structs are used to create
|
||||||
|
|
||||||
*pfunc* values may not be ``NULL``, except for the following slots:
|
*pfunc* values may not be ``NULL``, except for the following slots:
|
||||||
|
|
||||||
* ``Py_tp_doc``
|
* :c:data:`Py_tp_doc`
|
||||||
* :c:data:`Py_tp_token` (for clarity, prefer :c:data:`Py_TP_USE_SPEC`
|
* :c:data:`Py_tp_token` (for clarity, prefer :c:data:`Py_TP_USE_SPEC`
|
||||||
rather than ``NULL``)
|
rather than ``NULL``)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2273,7 +2273,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
|
||||||
This field should be set to ``NULL`` and treated as read-only.
|
This field should be set to ``NULL`` and treated as read-only.
|
||||||
Python will fill it in when the type is :c:func:`initialized <PyType_Ready>`.
|
Python will fill it in when the type is :c:func:`initialized <PyType_Ready>`.
|
||||||
|
|
||||||
For dynamically created classes, the ``Py_tp_bases``
|
For dynamically created classes, the :c:data:`Py_tp_bases`
|
||||||
:c:type:`slot <PyType_Slot>` can be used instead of the *bases* argument
|
:c:type:`slot <PyType_Slot>` can be used instead of the *bases* argument
|
||||||
of :c:func:`PyType_FromSpecWithBases`.
|
of :c:func:`PyType_FromSpecWithBases`.
|
||||||
The argument form is preferred.
|
The argument form is preferred.
|
||||||
|
|
|
||||||
|
|
@ -353,7 +353,7 @@ garbage collection protocol.
|
||||||
That is, heap types should:
|
That is, heap types should:
|
||||||
|
|
||||||
- Have the :c:macro:`Py_TPFLAGS_HAVE_GC` flag.
|
- Have the :c:macro:`Py_TPFLAGS_HAVE_GC` flag.
|
||||||
- Define a traverse function using ``Py_tp_traverse``, which
|
- Define a traverse function using :c:data:`Py_tp_traverse`, which
|
||||||
visits the type (e.g. using ``Py_VISIT(Py_TYPE(self))``).
|
visits the type (e.g. using ``Py_VISIT(Py_TYPE(self))``).
|
||||||
|
|
||||||
Please refer to the documentation of
|
Please refer to the documentation of
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue