Skip to content

Commit a81ffeb

Browse files
author
georg.brandl
committed
Previously, Python code had no easy way to access the contents of a
cell object. Now, a ``cell_contents`` attribute has been added (closes patch #1170323). git-svn-id: http://svn.python.org/projects/python/trunk@43131 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent d6e1993 commit a81ffeb

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ What's New in Python 2.5 alpha 1?
1212
Core and builtins
1313
-----------------
1414

15+
- Previously, Python code had no easy way to access the contents of a
16+
cell object. Now, a ``cell_contents`` attribute has been added
17+
(closes patch #1170323).
18+
1519
- Patch #1123430: Python's small-object allocator now returns an arena to
1620
the system ``free()`` when all memory within an arena becomes unused
1721
again. Prior to Python 2.5, arenas (256KB chunks of memory) were never

Objects/cellobject.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ cell_clear(PyCellObject *op)
8686
return 0;
8787
}
8888

89+
static PyObject *
90+
cell_get_contents(PyCellObject *op, void *closure)
91+
{
92+
Py_XINCREF(op->ob_ref);
93+
return op->ob_ref;
94+
}
95+
96+
static PyGetSetDef cell_getsetlist[] = {
97+
{"cell_contents", (getter)cell_get_contents, NULL},
98+
{NULL} /* sentinel */
99+
};
100+
89101
PyTypeObject PyCell_Type = {
90102
PyObject_HEAD_INIT(&PyType_Type)
91103
0,
@@ -111,4 +123,11 @@ PyTypeObject PyCell_Type = {
111123
0, /* tp_doc */
112124
(traverseproc)cell_traverse, /* tp_traverse */
113125
(inquiry)cell_clear, /* tp_clear */
126+
0, /* tp_richcompare */
127+
0, /* tp_weaklistoffset */
128+
0, /* tp_iter */
129+
0, /* tp_iternext */
130+
0, /* tp_methods */
131+
0, /* tp_members */
132+
cell_getsetlist, /* tp_getset */
114133
};

0 commit comments

Comments
 (0)