Debian Codegraph @

Doc/c-api/cell.rst

raw
1 .. highlight:: c
2
3 .. _cell-objects:
4
5 Cell Objects
6 ------------
7
8 "Cell" objects are used to implement variables referenced by multiple scopes.
9 For each such variable, a cell object is created to store the value; the local
10 variables of each stack frame that references the value contain a reference to
11 the cells from outer scopes which also use that variable. When the value is
12 accessed, the value contained in the cell is used instead of the cell object
13 itself. This de-referencing of the cell object requires support from the
14 generated byte-code; these are not automatically de-referenced when accessed.
15 Cell objects are not likely to be useful elsewhere.
16
17
18 .. c:type:: PyCellObject
19
20 The C structure used for cell objects.
21
22
23 .. c:var:: PyTypeObject PyCell_Type
24
25 The type object corresponding to cell objects.
26
27
28 .. c:function:: int PyCell_Check(PyObject *ob)
29
30 Return true if *ob* is a cell object; *ob* must not be ``NULL``. This
31 function always succeeds.
32
33
34 .. c:function:: PyObject* PyCell_New(PyObject *ob)
35
36 Create and return a new cell object containing the value *ob*. The parameter may
37 be ``NULL``.
38
39
40 .. c:function:: PyObject* PyCell_Get(PyObject *cell)
41
42 Return the contents of the cell *cell*, which can be ``NULL``.
43 If *cell* is not a cell object, returns ``NULL`` with an exception set.
44
45
46 .. c:function:: PyObject* PyCell_GET(PyObject *cell)
47
48 Return the contents of the cell *cell*, but without checking that *cell* is
49 non-``NULL`` and a cell object.
50
51
52 .. c:function:: int PyCell_Set(PyObject *cell, PyObject *value)
53
54 Set the contents of the cell object *cell* to *value*. This releases the
55 reference to any current content of the cell. *value* may be ``NULL``. *cell*
56 must be non-``NULL``.
57
58 On success, return ``0``.
59 If *cell* is not a cell object, set an exception and return ``-1``.
60
61
62 .. c:function:: void PyCell_SET(PyObject *cell, PyObject *value)
63
64 Sets the value of the cell object *cell* to *value*. No reference counts are
65 adjusted, and no checks are made for safety; *cell* must be non-``NULL`` and must
66 be a cell object.