Cell 对象

“Cell”对象用于实现由多个作用域引用的变量。 对于每个这样的变量,一个“Cell”对象为了存储该值而被创建;引用该值的每个堆栈框架的局部变量包含同样使用该变量的对外部作用域的“Cell”引用。 访问该值时,将使用“Cell”中包含的值而不是单元格对象本身。 这种对“Cell”对象的非关联化的引用需要支持生成的字节码;访问时不会自动非关联化这些内容。 “Cell”对象在其他地方可能不太有用。



PyTypeObject PyCell_Type

与 Cell 对象对应的类型对​​象。

int PyCell_Check(ob)

Return true if ob is a cell object; ob must not be NULL.

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

Create and return a new cell object containing the value ob. The parameter may be NULL.

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

返回 cell 对象 cell 的内容。

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

Return the contents of the cell cell, but without checking that cell is non-NULL and a cell object.

int PyCell_Set(PyObject *cell, PyObject *value)

Set the contents of the cell object cell to value. This releases the reference to any current content of the cell. value may be NULL. cell must be non-NULL; if it is not a cell object, -1 will be returned. On success, 0 will be returned.

void PyCell_SET(PyObject *cell, PyObject *value)

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