blob: 8408f7e398db7b63e99e77fe578d271100f7d0e3 [file] [log] [blame]
Stéphane Wirtelcbb64842019-05-17 11:55:34 +02001.. highlight:: c
Georg Brandl54a3faa2008-01-20 09:30:57 +00002
3.. _cell-objects:
4
5Cell Objects
6------------
7
8"Cell" objects are used to implement variables referenced by multiple scopes.
9For each such variable, a cell object is created to store the value; the local
10variables of each stack frame that references the value contains a reference to
11the cells from outer scopes which also use that variable. When the value is
12accessed, the value contained in the cell is used instead of the cell object
13itself. This de-referencing of the cell object requires support from the
14generated byte-code; these are not automatically de-referenced when accessed.
15Cell objects are not likely to be useful elsewhere.
16
17
Georg Brandl60203b42010-10-06 10:11:56 +000018.. c:type:: PyCellObject
Georg Brandl54a3faa2008-01-20 09:30:57 +000019
20 The C structure used for cell objects.
21
22
Georg Brandl60203b42010-10-06 10:11:56 +000023.. c:var:: PyTypeObject PyCell_Type
Georg Brandl54a3faa2008-01-20 09:30:57 +000024
25 The type object corresponding to cell objects.
26
27
Georg Brandl60203b42010-10-06 10:11:56 +000028.. c:function:: int PyCell_Check(ob)
Georg Brandl54a3faa2008-01-20 09:30:57 +000029
Serhiy Storchaka25fc0882019-10-30 12:03:20 +020030 Return true if *ob* is a cell object; *ob* must not be ``NULL``.
Georg Brandl54a3faa2008-01-20 09:30:57 +000031
32
Georg Brandl60203b42010-10-06 10:11:56 +000033.. c:function:: PyObject* PyCell_New(PyObject *ob)
Georg Brandl54a3faa2008-01-20 09:30:57 +000034
35 Create and return a new cell object containing the value *ob*. The parameter may
Serhiy Storchaka25fc0882019-10-30 12:03:20 +020036 be ``NULL``.
Georg Brandl54a3faa2008-01-20 09:30:57 +000037
38
Georg Brandl60203b42010-10-06 10:11:56 +000039.. c:function:: PyObject* PyCell_Get(PyObject *cell)
Georg Brandl54a3faa2008-01-20 09:30:57 +000040
41 Return the contents of the cell *cell*.
42
43
Georg Brandl60203b42010-10-06 10:11:56 +000044.. c:function:: PyObject* PyCell_GET(PyObject *cell)
Georg Brandl54a3faa2008-01-20 09:30:57 +000045
46 Return the contents of the cell *cell*, but without checking that *cell* is
Serhiy Storchaka25fc0882019-10-30 12:03:20 +020047 non-``NULL`` and a cell object.
Georg Brandl54a3faa2008-01-20 09:30:57 +000048
49
Georg Brandl60203b42010-10-06 10:11:56 +000050.. c:function:: int PyCell_Set(PyObject *cell, PyObject *value)
Georg Brandl54a3faa2008-01-20 09:30:57 +000051
52 Set the contents of the cell object *cell* to *value*. This releases the
Serhiy Storchaka25fc0882019-10-30 12:03:20 +020053 reference to any current content of the cell. *value* may be ``NULL``. *cell*
54 must be non-``NULL``; if it is not a cell object, ``-1`` will be returned. On
Georg Brandl54a3faa2008-01-20 09:30:57 +000055 success, ``0`` will be returned.
56
57
Georg Brandl60203b42010-10-06 10:11:56 +000058.. c:function:: void PyCell_SET(PyObject *cell, PyObject *value)
Georg Brandl54a3faa2008-01-20 09:30:57 +000059
60 Sets the value of the cell object *cell* to *value*. No reference counts are
Serhiy Storchaka25fc0882019-10-30 12:03:20 +020061 adjusted, and no checks are made for safety; *cell* must be non-``NULL`` and must
Georg Brandl54a3faa2008-01-20 09:30:57 +000062 be a cell object.