Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bed6891

Browse files
committed
Issue #23710: Update PyObject_HEAD documentation
Since PEP 3123, PyObject_HEAD only has one field named ob_base. Users now need to use the Py_TYPE macro instead of self->ob_type. Initial patch by Ammar Askar.
1 parent 9de620e commit bed6891

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

Doc/extending/newtypes.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,15 @@ The first bit that will be new is::
5252
} noddy_NoddyObject;
5353

5454
This is what a Noddy object will contain---in this case, nothing more than what
55-
every Python object contains---a refcount and a pointer to a type object.
56-
These are the fields the ``PyObject_HEAD`` macro brings in. The reason for the
57-
macro is to standardize the layout and to enable special debugging fields in
58-
debug builds. Note that there is no semicolon after the ``PyObject_HEAD``
59-
macro; one is included in the macro definition. Be wary of adding one by
55+
every Python object contains---a field called ``ob_base`` of type
56+
:c:type:`PyObject`. :c:type:`PyObject` in turn, contains an ``ob_refcnt``
57+
field and a pointer to a type object. These can be accessed using the macros
58+
:c:macro:`Py_REFCNT` and :c:macro:`Py_TYPE` respectively. These are the fields
59+
the :c:macro:`PyObject_HEAD` macro brings in. The reason for the macro is to
60+
standardize the layout and to enable special debugging fields in debug builds.
61+
62+
Note that there is no semicolon after the :c:macro:`PyObject_HEAD` macro;
63+
one is included in the macro definition. Be wary of adding one by
6064
accident; it's easy to do from habit, and your compiler might not complain,
6165
but someone else's probably will! (On Windows, MSVC is known to call this an
6266
error and refuse to compile the code.)

0 commit comments

Comments
 (0)