Cell Objects

“Cell” objects are used to implement variables referenced by multiple scopes.For each such variable, a cell object is created to store the value; the localvariables of each stack frame that references the value contains a reference tothe cells from outer scopes which also use that variable. When the value isaccessed, the value contained in the cell is used instead of the cell objectitself. This de-referencing of the cell object requires support from thegenerated byte-code; these are not automatically de-referenced when accessed.Cell objects are not likely to be useful elsewhere.

typePyCellObject

The C structure used for cell objects.

PyTypeObjectPyCell_Type

The type object corresponding to cell objects.

intPyCell_Check(PyObject*ob)

Return true ifob is a cell object;ob must not beNULL. Thisfunction always succeeds.

PyObject*PyCell_New(PyObject*ob)
Return value: New reference.

Create and return a new cell object containing the valueob. The parameter maybeNULL.

PyObject*PyCell_Get(PyObject*cell)
Return value: New reference.

Return the contents of the cellcell, which can beNULL.Ifcell is not a cell object, returnsNULL with an exception set.

PyObject*PyCell_GET(PyObject*cell)
Return value: Borrowed reference.

Return the contents of the cellcell, but without checking thatcell isnon-NULL and a cell object.

intPyCell_Set(PyObject*cell,PyObject*value)

Set the contents of the cell objectcell tovalue. This releases thereference to any current content of the cell.value may beNULL.cellmust be non-NULL.

On success, return0.Ifcell is not a cell object, set an exception and return-1.

voidPyCell_SET(PyObject*cell,PyObject*value)

Sets the value of the cell objectcell tovalue. No reference counts areadjusted, and no checks are made for safety;cell must be non-NULL and mustbe a cell object.