1 /* Cell object implementation */
6 PyCell_New(PyObject
*obj
)
10 op
= (PyCellObject
*)PyObject_GC_New(PyCellObject
, &PyCell_Type
);
14 _PyObject_GC_TRACK(op
);
15 return (PyObject
*)op
;
19 PyCell_Get(PyObject
*op
)
21 if (!PyCell_Check(op
)) {
22 PyErr_BadInternalCall();
25 Py_XINCREF(((PyCellObject
*)op
)->ob_ref
);
26 return PyCell_GET(op
);
30 PyCell_Set(PyObject
*op
, PyObject
*obj
)
32 if (!PyCell_Check(op
)) {
33 PyErr_BadInternalCall();
36 Py_XDECREF(((PyCellObject
*)op
)->ob_ref
);
43 cell_dealloc(PyCellObject
*op
)
45 _PyObject_GC_UNTRACK(op
);
46 Py_XDECREF(op
->ob_ref
);
51 cell_compare(PyCellObject
*a
, PyCellObject
*b
)
53 if (a
->ob_ref
== NULL
) {
54 if (b
->ob_ref
== NULL
)
57 } else if (b
->ob_ref
== NULL
)
59 return PyObject_Compare(a
->ob_ref
, b
->ob_ref
);
63 cell_repr(PyCellObject
*op
)
65 if (op
->ob_ref
== NULL
)
66 return PyString_FromFormat("<cell at %p: empty>", op
);
68 return PyString_FromFormat("<cell at %p: %.80s object at %p>",
69 op
, op
->ob_ref
->ob_type
->tp_name
,
74 cell_traverse(PyCellObject
*op
, visitproc visit
, void *arg
)
77 return visit(op
->ob_ref
, arg
);
82 cell_clear(PyCellObject
*op
)
84 Py_XDECREF(op
->ob_ref
);
90 cell_get_contents(PyCellObject
*op
, void *closure
)
92 Py_XINCREF(op
->ob_ref
);
96 static PyGetSetDef cell_getsetlist
[] = {
97 {"cell_contents", (getter
)cell_get_contents
, NULL
},
101 PyTypeObject PyCell_Type
= {
102 PyObject_HEAD_INIT(&PyType_Type
)
105 sizeof(PyCellObject
),
107 (destructor
)cell_dealloc
, /* tp_dealloc */
111 (cmpfunc
)cell_compare
, /* tp_compare */
112 (reprfunc
)cell_repr
, /* tp_repr */
113 0, /* tp_as_number */
114 0, /* tp_as_sequence */
115 0, /* tp_as_mapping */
119 PyObject_GenericGetAttr
, /* tp_getattro */
121 0, /* tp_as_buffer */
122 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_HAVE_GC
,/* tp_flags */
124 (traverseproc
)cell_traverse
, /* tp_traverse */
125 (inquiry
)cell_clear
, /* tp_clear */
126 0, /* tp_richcompare */
127 0, /* tp_weaklistoffset */
132 cell_getsetlist
, /* tp_getset */