17db96d56Sopenharmony_ci.. highlight:: c
27db96d56Sopenharmony_ci
37db96d56Sopenharmony_ci.. _cell-objects:
47db96d56Sopenharmony_ci
57db96d56Sopenharmony_ciCell Objects
67db96d56Sopenharmony_ci------------
77db96d56Sopenharmony_ci
87db96d56Sopenharmony_ci"Cell" objects are used to implement variables referenced by multiple scopes.
97db96d56Sopenharmony_ciFor each such variable, a cell object is created to store the value; the local
107db96d56Sopenharmony_civariables of each stack frame that references the value contains a reference to
117db96d56Sopenharmony_cithe cells from outer scopes which also use that variable.  When the value is
127db96d56Sopenharmony_ciaccessed, the value contained in the cell is used instead of the cell object
137db96d56Sopenharmony_ciitself.  This de-referencing of the cell object requires support from the
147db96d56Sopenharmony_cigenerated byte-code; these are not automatically de-referenced when accessed.
157db96d56Sopenharmony_ciCell objects are not likely to be useful elsewhere.
167db96d56Sopenharmony_ci
177db96d56Sopenharmony_ci
187db96d56Sopenharmony_ci.. c:type:: PyCellObject
197db96d56Sopenharmony_ci
207db96d56Sopenharmony_ci   The C structure used for cell objects.
217db96d56Sopenharmony_ci
227db96d56Sopenharmony_ci
237db96d56Sopenharmony_ci.. c:var:: PyTypeObject PyCell_Type
247db96d56Sopenharmony_ci
257db96d56Sopenharmony_ci   The type object corresponding to cell objects.
267db96d56Sopenharmony_ci
277db96d56Sopenharmony_ci
287db96d56Sopenharmony_ci.. c:function:: int PyCell_Check(ob)
297db96d56Sopenharmony_ci
307db96d56Sopenharmony_ci   Return true if *ob* is a cell object; *ob* must not be ``NULL``.  This
317db96d56Sopenharmony_ci   function always succeeds.
327db96d56Sopenharmony_ci
337db96d56Sopenharmony_ci
347db96d56Sopenharmony_ci.. c:function:: PyObject* PyCell_New(PyObject *ob)
357db96d56Sopenharmony_ci
367db96d56Sopenharmony_ci   Create and return a new cell object containing the value *ob*. The parameter may
377db96d56Sopenharmony_ci   be ``NULL``.
387db96d56Sopenharmony_ci
397db96d56Sopenharmony_ci
407db96d56Sopenharmony_ci.. c:function:: PyObject* PyCell_Get(PyObject *cell)
417db96d56Sopenharmony_ci
427db96d56Sopenharmony_ci   Return the contents of the cell *cell*.
437db96d56Sopenharmony_ci
447db96d56Sopenharmony_ci
457db96d56Sopenharmony_ci.. c:function:: PyObject* PyCell_GET(PyObject *cell)
467db96d56Sopenharmony_ci
477db96d56Sopenharmony_ci   Return the contents of the cell *cell*, but without checking that *cell* is
487db96d56Sopenharmony_ci   non-``NULL`` and a cell object.
497db96d56Sopenharmony_ci
507db96d56Sopenharmony_ci
517db96d56Sopenharmony_ci.. c:function:: int PyCell_Set(PyObject *cell, PyObject *value)
527db96d56Sopenharmony_ci
537db96d56Sopenharmony_ci   Set the contents of the cell object *cell* to *value*.  This releases the
547db96d56Sopenharmony_ci   reference to any current content of the cell. *value* may be ``NULL``.  *cell*
557db96d56Sopenharmony_ci   must be non-``NULL``; if it is not a cell object, ``-1`` will be returned.  On
567db96d56Sopenharmony_ci   success, ``0`` will be returned.
577db96d56Sopenharmony_ci
587db96d56Sopenharmony_ci
597db96d56Sopenharmony_ci.. c:function:: void PyCell_SET(PyObject *cell, PyObject *value)
607db96d56Sopenharmony_ci
617db96d56Sopenharmony_ci   Sets the value of the cell object *cell* to *value*.  No reference counts are
627db96d56Sopenharmony_ci   adjusted, and no checks are made for safety; *cell* must be non-``NULL`` and must
637db96d56Sopenharmony_ci   be a cell object.
64