File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1663,6 +1663,29 @@ \section{Supporting Cyclic Garbage Collection
16631663 that value should be returned immediately.
16641664\end {ctypedesc }
16651665
1666+ To simplify writing \member {tp_traverse} handlers, a
1667+ \cfunction {Py_VISIT()} is provided:
1668+
1669+ \begin {cfuncdesc }{void}{Py_VISIT}{PyObject *o}
1670+ Call the \var {visit} for \var {o} with \var {arg}. If \var {visit}
1671+ returns a non-zero value, then return it. Using this macro,
1672+ \member {tp_traverse} handlers look like:
1673+
1674+
1675+ \begin {verbatim }
1676+ static int
1677+ my_traverse(Noddy *self, visitproc visit, void *arg)
1678+ {
1679+ Py_VISIT(self->foo);
1680+ Py_VISIT(self->bar);
1681+ return 0;
1682+ }
1683+ \end {verbatim }
1684+
1685+ \versionadded {2.4}
1686+ \end {cfuncdesc }
1687+
1688+
16661689The \member {tp_clear} handler must be of the \ctype {inquiry} type, or
16671690\NULL {} if the object is immutable.
16681691
Original file line number Diff line number Diff line change @@ -302,6 +302,16 @@ PyAPI_FUNC(void) PyObject_GC_Del(void *);
302302 ( (type *) _PyObject_GC_NewVar((typeobj), (n)) )
303303
304304
305+ /* Utility macro to help write tp_traverse functions */
306+ #define Py_VISIT (op ) \
307+ do { \
308+ if (op) { \
309+ int vret = visit((op), arg); \
310+ if (vret) \
311+ return vret; \
312+ } \
313+ } while (0)
314+
305315/* This is here for the sake of backwards compatibility. Extensions that
306316 * use the old GC API will still compile but the objects will not be
307317 * tracked by the GC. */
You can’t perform that action at this time.
0 commit comments