1
/* Cell object implementation */
6
PyCell_New(PyObject *obj)
10
op = (PyCellObject *)PyObject_GC_New(PyCellObject, &PyCell_Type);
16
_PyObject_GC_TRACK(op);
17
return (PyObject *)op;
21
PyCell_Get(PyObject *op)
23
if (!PyCell_Check(op)) {
24
PyErr_BadInternalCall();
27
Py_XINCREF(((PyCellObject*)op)->ob_ref);
28
return PyCell_GET(op);
32
PyCell_Set(PyObject *op, PyObject *obj)
35
if (!PyCell_Check(op)) {
36
PyErr_BadInternalCall();
39
oldobj = PyCell_GET(op);
47
cell_dealloc(PyCellObject *op)
49
_PyObject_GC_UNTRACK(op);
50
Py_XDECREF(op->ob_ref);
55
cell_compare(PyCellObject *a, PyCellObject *b)
57
/* Py3K warning for comparisons */
58
if (PyErr_WarnPy3k("cell comparisons not supported in 3.x",
63
if (a->ob_ref == NULL) {
64
if (b->ob_ref == NULL)
67
} else if (b->ob_ref == NULL)
69
return PyObject_Compare(a->ob_ref, b->ob_ref);
73
cell_repr(PyCellObject *op)
75
if (op->ob_ref == NULL)
76
return PyString_FromFormat("<cell at %p: empty>", op);
78
return PyString_FromFormat("<cell at %p: %.80s object at %p>",
79
op, op->ob_ref->ob_type->tp_name,
84
cell_traverse(PyCellObject *op, visitproc visit, void *arg)
91
cell_clear(PyCellObject *op)
98
cell_get_contents(PyCellObject *op, void *closure)
100
if (op->ob_ref == NULL)
102
PyErr_SetString(PyExc_ValueError, "Cell is empty");
105
Py_INCREF(op->ob_ref);
109
static PyGetSetDef cell_getsetlist[] = {
110
{"cell_contents", (getter)cell_get_contents, NULL},
111
{NULL} /* sentinel */
114
PyTypeObject PyCell_Type = {
115
PyVarObject_HEAD_INIT(&PyType_Type, 0)
117
sizeof(PyCellObject),
119
(destructor)cell_dealloc, /* tp_dealloc */
123
(cmpfunc)cell_compare, /* tp_compare */
124
(reprfunc)cell_repr, /* tp_repr */
125
0, /* tp_as_number */
126
0, /* tp_as_sequence */
127
0, /* tp_as_mapping */
131
PyObject_GenericGetAttr, /* tp_getattro */
133
0, /* tp_as_buffer */
134
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
136
(traverseproc)cell_traverse, /* tp_traverse */
137
(inquiry)cell_clear, /* tp_clear */
138
0, /* tp_richcompare */
139
0, /* tp_weaklistoffset */
144
cell_getsetlist, /* tp_getset */