9 my_traverse(MyObject
*self
, visitproc visit
, void *arg
)
11 if (self
->container
!= NULL
)
12 return visit(self
->container
, arg
);
18 my_clear(MyObject
*self
)
20 Py_XDECREF(self
->container
);
21 self
->container
= NULL
;
27 my_dealloc(MyObject
*self
)
29 PyObject_GC_UnTrack((PyObject
*) self
);
30 Py_XDECREF(self
->container
);
31 PyObject_GC_Del(self
);
36 PyObject_HEAD_INIT(NULL
)
41 (destructor
)my_dealloc
, /* tp_dealloc */
48 0, /* tp_as_sequence */
49 0, /* tp_as_mapping */
56 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_HAVE_GC
,
58 (traverseproc
)my_traverse
, /* tp_traverse */
59 (inquiry
)my_clear
, /* tp_clear */
60 0, /* tp_richcompare */
61 0, /* tp_weaklistoffset */
64 /* This constructor should be made accessible from Python. */
66 new_object(PyObject
*unused
, PyObject
*args
)
68 PyObject
*container
= NULL
;
69 MyObject
*result
= NULL
;
71 if (PyArg_ParseTuple(args
, "|O:new_object", &container
)) {
72 result
= PyObject_GC_New(MyObject
, &MyObject_Type
);
74 result
->container
= container
;
75 PyObject_GC_Track(result
);
78 return (PyObject
*) result
;