summaryrefslogtreecommitdiffstats
path: root/Objects/cellobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/cellobject.c')
-rw-r--r--Objects/cellobject.c94
1 files changed, 20 insertions, 74 deletions
diff --git a/Objects/cellobject.c b/Objects/cellobject.c
index 911cf52..c206684 100644
--- a/Objects/cellobject.c
+++ b/Objects/cellobject.c
@@ -1,9 +1,6 @@
/* Cell object implementation */
#include "Python.h"
-#include "pycore_object.h"
-#include "pycore_pymem.h"
-#include "pycore_pystate.h"
PyObject *
PyCell_New(PyObject *obj)
@@ -20,37 +17,6 @@ PyCell_New(PyObject *obj)
return (PyObject *)op;
}
-PyDoc_STRVAR(cell_new_doc,
-"cell([contents])\n"
-"--\n"
-"\n"
-"Create a new cell object.\n"
-"\n"
-" contents\n"
-" the contents of the cell. If not specified, the cell will be empty,\n"
-" and \n further attempts to access its cell_contents attribute will\n"
-" raise a ValueError.");
-
-
-static PyObject *
-cell_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
-{
- PyObject *return_value = NULL;
- PyObject *obj = NULL;
-
- if (!_PyArg_NoKeywords("cell", kwargs)) {
- goto exit;
- }
- /* min = 0: we allow the cell to be empty */
- if (!PyArg_UnpackTuple(args, "cell", 0, 1, &obj)) {
- goto exit;
- }
- return_value = PyCell_New(obj);
-
-exit:
- return return_value;
-}
-
PyObject *
PyCell_Get(PyObject *op)
{
@@ -85,33 +51,31 @@ cell_dealloc(PyCellObject *op)
PyObject_GC_Del(op);
}
-static PyObject *
-cell_richcompare(PyObject *a, PyObject *b, int op)
+static int
+cell_compare(PyCellObject *a, PyCellObject *b)
{
- /* neither argument should be NULL, unless something's gone wrong */
- assert(a != NULL && b != NULL);
-
- /* both arguments should be instances of PyCellObject */
- if (!PyCell_Check(a) || !PyCell_Check(b)) {
- Py_RETURN_NOTIMPLEMENTED;
+ /* Py3K warning for comparisons */
+ if (PyErr_WarnPy3k("cell comparisons not supported in 3.x",
+ 1) < 0) {
+ return -2;
}
- /* compare cells by contents; empty cells come before anything else */
- a = ((PyCellObject *)a)->ob_ref;
- b = ((PyCellObject *)b)->ob_ref;
- if (a != NULL && b != NULL)
- return PyObject_RichCompare(a, b, op);
-
- Py_RETURN_RICHCOMPARE(b == NULL, a == NULL, op);
+ if (a->ob_ref == NULL) {
+ if (b->ob_ref == NULL)
+ return 0;
+ return -1;
+ } else if (b->ob_ref == NULL)
+ return 1;
+ return PyObject_Compare(a->ob_ref, b->ob_ref);
}
static PyObject *
cell_repr(PyCellObject *op)
{
if (op->ob_ref == NULL)
- return PyUnicode_FromFormat("<cell at %p: empty>", op);
+ return PyString_FromFormat("<cell at %p: empty>", op);
- return PyUnicode_FromFormat("<cell at %p: %.80s object at %p>",
+ return PyString_FromFormat("<cell at %p: %.80s object at %p>",
op, op->ob_ref->ob_type->tp_name,
op->ob_ref);
}
@@ -142,17 +106,8 @@ cell_get_contents(PyCellObject *op, void *closure)
return op->ob_ref;
}
-static int
-cell_set_contents(PyCellObject *op, PyObject *obj, void *Py_UNUSED(ignored))
-{
- Py_XINCREF(obj);
- Py_XSETREF(op->ob_ref, obj);
- return 0;
-}
-
static PyGetSetDef cell_getsetlist[] = {
- {"cell_contents", (getter)cell_get_contents,
- (setter)cell_set_contents, NULL},
+ {"cell_contents", (getter)cell_get_contents, NULL},
{NULL} /* sentinel */
};
@@ -162,10 +117,10 @@ PyTypeObject PyCell_Type = {
sizeof(PyCellObject),
0,
(destructor)cell_dealloc, /* tp_dealloc */
- 0, /* tp_vectorcall_offset */
+ 0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
- 0, /* tp_as_async */
+ (cmpfunc)cell_compare, /* tp_compare */
(reprfunc)cell_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
@@ -177,23 +132,14 @@ PyTypeObject PyCell_Type = {
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
- cell_new_doc, /* tp_doc */
+ 0, /* tp_doc */
(traverseproc)cell_traverse, /* tp_traverse */
(inquiry)cell_clear, /* tp_clear */
- cell_richcompare, /* tp_richcompare */
+ 0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
cell_getsetlist, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- (newfunc)cell_new, /* tp_new */
- 0, /* tp_free */
};