Cell 物件

"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 local variables of each stack frame that references the value contain a reference to the cells from outer scopes which also use that variable. When the value is accessed, the value contained in the cell is used instead of the cell object itself. This de-referencing of the cell object requires support from the generated byte-code; these are not automatically de-referenced when accessed. Cell objects are not likely to be useful elsewhere.

type PyCellObject

Cell 物件所用之 C 結構。

PyTypeObject PyCell_Type

對應 cell 物件的物件型別。

int PyCell_Check(PyObject *ob)

如果 ob 是一個 cell 物件則回傳真值;ob 必須不為 NULL。此函式總是會成功執行。

PyObject *PyCell_New(PyObject *ob)
回傳值:新的參照。

建立並回傳一個包含 ob 的新 cell 物件。參數可以為 NULL

PyObject *PyCell_Get(PyObject *cell)
回傳值:新的參照。

回傳 cell 物件 cell 的內容,其可能為 NULL。如果 cell 不是一個 cell 物件,則將回傳 NULL 並設定例外。

PyObject *PyCell_GET(PyObject *cell)
回傳值:借用參照。

回傳 cell 物件 cell 的內容,但是不檢查 cell 是否非 NULL 並且為一個 cell 物件。

int PyCell_Set(PyObject *cell, PyObject *value)

將 cell 物件 cell 的內容設為 value。這將釋放任何對 cell 物件目前內容的參照。value 可以為 NULLcell 必須不為 NULL

在成功時回傳 0。如果 cell 不是一個 cell 物件,則將設定例外並回傳 -1

void PyCell_SET(PyObject *cell, PyObject *value)

將 cell 物件 cell 的值設為 value。不會調整參照計數,並且不會進行任何安全檢查;cell 必須為非 NULL 並且為一個 cell 物件。