From 468f8a6ee0d83e36795bbab6f20037b0e380f493 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 25 Sep 2019 13:06:16 +0200 Subject: bpo-38140: Document offsets in PyMemberDef (GH-16354) bpo-38140: Document offsets in PyMemberDef Co-Authored-By: Ammar Askar --- Doc/c-api/structures.rst | 13 +++++++++++++ Doc/c-api/type.rst | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Doc/c-api/structures.rst b/Doc/c-api/structures.rst index af79777..b0a1938 100644 --- a/Doc/c-api/structures.rst +++ b/Doc/c-api/structures.rst @@ -346,6 +346,19 @@ Accessing attributes of extension types Only :c:macro:`T_OBJECT` and :c:macro:`T_OBJECT_EX` members can be deleted. (They are set to *NULL*). + .. _pymemberdef-offsets: + + Heap allocated types (created using :c:func:`PyType_FromSpec` or similar), + ``PyMemberDef`` may contain defintitions for the special members + ``__dictoffset__`` and ``__weaklistoffset__``, corresponding to + :c:member:`~PyTypeObject.tp_dictoffset` and + :c:member:`~PyTypeObject.tp_weaklistoffset` in type objects. + These must be defined with ``T_PYSSIZET`` and ``READONLY``, for example:: + + static PyMemberDef spam_type_members[] = { + {"__dictoffset__", T_PYSSIZET, offsetof(Spam_object, dict), READONLY}, + {NULL} /* Sentinel */ + }; .. c:type:: PyGetSetDef diff --git a/Doc/c-api/type.rst b/Doc/c-api/type.rst index ad3e022..36309dd 100644 --- a/Doc/c-api/type.rst +++ b/Doc/c-api/type.rst @@ -188,7 +188,10 @@ The following functions and structs are used to create * :c:member:`~PyTypeObject.tp_subclasses` * :c:member:`~PyTypeObject.tp_weaklist` * :c:member:`~PyTypeObject.tp_vectorcall` - * :c:member:`~PyTypeObject.tp_print` + * :c:member:`~PyTypeObject.tp_weaklistoffset` + (see :ref:`PyMemberDef `) + * :c:member:`~PyTypeObject.tp_dictoffset` + (see :ref:`PyMemberDef `) * :c:member:`~PyBufferProcs.bf_getbuffer` * :c:member:`~PyBufferProcs.bf_releasebuffer` -- cgit v0.12