@@ -122,9 +122,71 @@ \section{Allocating Objects on the Heap
122122
123123\section {Common Object Structures \label {common-structs } }
124124
125- PyObject, PyVarObject
125+ There are a large number of structures which are used in the
126+ definition of object types for Python. This section describes these
127+ structures and how they are used.
128+
129+ All Python objects ultimately share a small number of fields at the
130+ beginning of the object's representation in memory. These are
131+ represented by the \ctype {PyObject} and \ctype {PyVarObject} types,
132+ which are defined, in turn, by the expansions of some macros also
133+ used, whether directly or indirectly, in the definition of all other
134+ Python objects.
135+
136+ \begin {ctypedesc }{PyObject}
137+ All object types are extensions of this type. This is a type which
138+ contains the information Python needs to treat a pointer to an
139+ object as an object. In a normal `` release'' build, it contains
140+ only the objects reference count and a pointer to the corresponding
141+ type object. It corresponds to the fields defined by the
142+ expansion of the \code {PyObject_VAR_HEAD} macro.
143+ \end {ctypedesc }
144+
145+ \begin {ctypedesc }{PyVarObject}
146+ This is an extension of \ctype {PyObject} that adds the
147+ \member {ob_size} field. This is only used for objects that have
148+ some notion of \emph {length }. This type does not often appear in
149+ the Python/C API. It corresponds to the fields defined by the
150+ expansion of the \code {PyObject_VAR_HEAD} macro.
151+ \end {ctypedesc }
126152
127- PyObject_HEAD, PyObject_HEAD_INIT, PyObject_VAR_HEAD
153+ These macros are used in the definition of \ctype {PyObject} and
154+ \ctype {PyVarObject}:
155+
156+ \begin {csimplemacrodesc }{PyObject_HEAD}
157+ This is a macro which expands to the declarations of the fields of
158+ the \ctype {PyObject} type; it is used when declaring new types which
159+ represent objects without a varying length. The specific fields it
160+ expands to depends on the definition of
161+ \csimplemacro {Py_TRACE_REFS}. By default, that macro is not
162+ defined, and \csimplemacro {PyObject_HEAD} expands to:
163+ \begin {verbatim }
164+ int ob_refcnt;
165+ PyTypeObject *ob_type;
166+ \end {verbatim }
167+ When \csimplemacro {Py_TRACE_REFS} is defined, it expands to:
168+ \begin {verbatim }
169+ PyObject *_ob_next, *_ob_prev;
170+ int ob_refcnt;
171+ PyTypeObject *ob_type;
172+ \end {verbatim }
173+ \end {csimplemacrodesc }
174+
175+ \begin {csimplemacrodesc }{PyObject_VAR_HEAD}
176+ This is a macro which expands to the declarations of the fields of
177+ the \ctype {PyVarObject} type; it is used when declaring new types which
178+ represent objects with a length that varies from instance to
179+ instance. This macro always expands to:
180+ \begin {verbatim }
181+ PyObject_HEAD
182+ int ob_size;
183+ \end {verbatim }
184+ Note that \csimplemacro {PyObject_HEAD} is part of the expansion, and
185+ that it's own expansion varies depending on the definition of
186+ \csimplemacro {Py_TRACE_REFS}.
187+ \end {csimplemacrodesc }
188+
189+ PyObject_HEAD_INIT
128190
129191Typedefs:
130192unaryfunc, binaryfunc, ternaryfunc, inquiry, coercion, intargfunc,
@@ -134,6 +196,11 @@ \section{Common Object Structures \label{common-structs}}
134196
135197\begin {ctypedesc }{PyCFunction}
136198 Type of the functions used to implement most Python callables in C.
199+ Functions of this type take two \ctype {PyObject*} parameters and
200+ return one such value. If the return value is \NULL , an exception
201+ shall have been set. If not \NULL , the return value is interpreted
202+ as the return value of the function as exposed in Python. The
203+ function must return a new reference.
137204\end {ctypedesc }
138205
139206\begin {ctypedesc }{PyMethodDef}
0 commit comments