]> granicus.if.org Git - python/commitdiff
bpo-38140: Document offsets in PyMemberDef (GH-16354)
authorPetr Viktorin <encukou@gmail.com>
Wed, 25 Sep 2019 11:06:16 +0000 (13:06 +0200)
committerGitHub <noreply@github.com>
Wed, 25 Sep 2019 11:06:16 +0000 (13:06 +0200)
bpo-38140: Document offsets in PyMemberDef

Co-Authored-By: Ammar Askar <ammar_askar@hotmail.com>
Doc/c-api/structures.rst
Doc/c-api/type.rst

index af797778ce6334efb59c6fdbe69cd18efe23698f..b0a193876c537f3abf74f63fdaf122f3557ecedb 100644 (file)
@@ -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
 
index ad3e022d42ca1747a51a19ceaf9316dc8165e98e..36309dd5254a3a510f03daa6a8a95db5faa08fe1 100644 (file)
@@ -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 <pymemberdef-offsets>`)
+      * :c:member:`~PyTypeObject.tp_dictoffset`
+        (see :ref:`PyMemberDef <pymemberdef-offsets>`)
       * :c:member:`~PyBufferProcs.bf_getbuffer`
       * :c:member:`~PyBufferProcs.bf_releasebuffer`