#include "pycore_modsupport.h" // _PyArg_NoKeywords()
#include "pycore_object.h"
+#define _PyCell_CAST(op) _Py_CAST(PyCellObject*, (op))
+
PyObject *
PyCell_New(PyObject *obj)
{
}
static void
-cell_dealloc(PyCellObject *op)
+cell_dealloc(PyObject *self)
{
+ PyCellObject *op = _PyCell_CAST(self);
_PyObject_GC_UNTRACK(op);
Py_XDECREF(op->ob_ref);
PyObject_GC_Del(op);
}
static PyObject *
-cell_repr(PyCellObject *op)
+cell_repr(PyObject *self)
{
- if (op->ob_ref == NULL)
+ PyCellObject *op = _PyCell_CAST(self);
+ if (op->ob_ref == NULL) {
return PyUnicode_FromFormat("<cell at %p: empty>", op);
+ }
return PyUnicode_FromFormat("<cell at %p: %.80s object at %p>",
op, Py_TYPE(op->ob_ref)->tp_name,
}
static int
-cell_traverse(PyCellObject *op, visitproc visit, void *arg)
+cell_traverse(PyObject *self, visitproc visit, void *arg)
{
+ PyCellObject *op = _PyCell_CAST(self);
Py_VISIT(op->ob_ref);
return 0;
}
static int
-cell_clear(PyCellObject *op)
+cell_clear(PyObject *self)
{
+ PyCellObject *op = _PyCell_CAST(self);
Py_CLEAR(op->ob_ref);
return 0;
}
static PyObject *
-cell_get_contents(PyCellObject *op, void *closure)
+cell_get_contents(PyObject *self, void *closure)
{
- if (op->ob_ref == NULL)
- {
+ PyCellObject *op = _PyCell_CAST(self);
+ if (op->ob_ref == NULL) {
PyErr_SetString(PyExc_ValueError, "Cell is empty");
return NULL;
}
}
static int
-cell_set_contents(PyCellObject *op, PyObject *obj, void *Py_UNUSED(ignored))
+cell_set_contents(PyObject *self, PyObject *obj, void *Py_UNUSED(ignored))
{
+ PyCellObject *op = _PyCell_CAST(self);
Py_XSETREF(op->ob_ref, Py_XNewRef(obj));
return 0;
}
static PyGetSetDef cell_getsetlist[] = {
- {"cell_contents", (getter)cell_get_contents,
- (setter)cell_set_contents, NULL},
+ {"cell_contents", cell_get_contents, cell_set_contents, NULL},
{NULL} /* sentinel */
};
"cell",
sizeof(PyCellObject),
0,
- (destructor)cell_dealloc, /* tp_dealloc */
+ cell_dealloc, /* tp_dealloc */
0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_as_async */
- (reprfunc)cell_repr, /* tp_repr */
+ cell_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
cell_new_doc, /* tp_doc */
- (traverseproc)cell_traverse, /* tp_traverse */
- (inquiry)cell_clear, /* tp_clear */
+ cell_traverse, /* tp_traverse */
+ cell_clear, /* tp_clear */
cell_richcompare, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
- (newfunc)cell_new, /* tp_new */
+ cell_new, /* tp_new */
0, /* tp_free */
};