16#include "nuitka/prelude.h"
20int count_active_Nuitka_Cell_Type;
21int count_allocated_Nuitka_Cell_Type;
22int count_released_Nuitka_Cell_Type;
26#define MAX_CELL_FREE_LIST_COUNT 1000
28static int free_list_cells_count = 0;
32 count_active_Nuitka_Cell_Type -= 1;
33 count_released_Nuitka_Cell_Type += 1;
36 Nuitka_GC_UnTrack(cell);
37 Py_XDECREF(cell->ob_ref);
39 releaseToFreeList(free_list_cells, cell, MAX_CELL_FREE_LIST_COUNT);
42#if PYTHON_VERSION < 0x300
43static int Nuitka_Cell_tp_compare(PyObject *a, PyObject *b) {
48 if (cell_a->ob_ref == NULL) {
49 if (cell_b->ob_ref == NULL) {
56 if (cell_b->ob_ref == NULL) {
60 return PyObject_Compare(cell_a->ob_ref, cell_b->ob_ref);
63#define Nuitka_Cell_tp_compare (NULL)
65static PyObject *Nuitka_Cell_tp_richcompare(PyObject *a, PyObject *b,
int op) {
71 if (unlikely(!Nuitka_Cell_Check(a) || !Nuitka_Cell_Check(b))) {
72 result = Py_NotImplemented;
83 if (a != NULL && b != NULL) {
86 return RICH_COMPARE_EQ_OBJECT_OBJECT_OBJECT(a, b);
88 return RICH_COMPARE_NE_OBJECT_OBJECT_OBJECT(a, b);
90 return RICH_COMPARE_LE_OBJECT_OBJECT_OBJECT(a, b);
92 return RICH_COMPARE_GE_OBJECT_OBJECT_OBJECT(a, b);
94 return RICH_COMPARE_LT_OBJECT_OBJECT_OBJECT(a, b);
96 return RICH_COMPARE_GT_OBJECT_OBJECT_OBJECT(a, b);
103 int res = (b == NULL) - (a == NULL);
106 result = BOOL_FROM(res == 0);
109 result = BOOL_FROM(res != 0);
112 result = BOOL_FROM(res <= 0);
115 result = BOOL_FROM(res >= 0);
118 result = BOOL_FROM(res < 0);
121 result = BOOL_FROM(res > 0);
128 Py_INCREF_IMMORTAL(result);
134 if (cell->ob_ref == NULL) {
135 return Nuitka_String_FromFormat(
"<compiled_cell at %p: empty>", cell);
137 return Nuitka_String_FromFormat(
"<compiled_cell at %p: %s object at %p>", cell, cell->ob_ref->ob_type->tp_name,
142static int Nuitka_Cell_tp_traverse(
struct Nuitka_CellObject *cell, visitproc visit,
void *arg) {
143 Py_VISIT(cell->ob_ref);
149 Py_CLEAR(cell->ob_ref);
154static PyObject *Nuitka_Cell_get_contents(PyObject *self,
void *data) {
156 if (unlikely(cell->ob_ref == NULL)) {
157 PyThreadState *tstate = PyThreadState_GET();
159 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ValueError,
"Cell is empty");
163 Py_INCREF(cell->ob_ref);
167#if PYTHON_VERSION >= 0x370
168static int Nuitka_Cell_set_contents(PyObject *self, PyObject *value,
void *data) {
170 PyObject *old = cell->ob_ref;
172 if (old != NULL && value == NULL) {
173 PyThreadState *tstate = PyThreadState_GET();
175 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_RuntimeError,
176 "cell_contents cannot be used to delete values Nuitka");
180 cell->ob_ref = value;
188static PyGetSetDef Nuitka_Cell_tp_getset[] = {
189#if PYTHON_VERSION < 0x370
190 {(
char *)
"cell_contents", Nuitka_Cell_get_contents, NULL, NULL},
192 {(
char *)
"cell_contents", Nuitka_Cell_get_contents, Nuitka_Cell_set_contents, NULL},
196PyTypeObject Nuitka_Cell_Type = {
197 PyVarObject_HEAD_INIT(NULL, 0)
"compiled_cell",
200 (destructor)Nuitka_Cell_tp_dealloc,
204 Nuitka_Cell_tp_compare,
205 (reprfunc)Nuitka_Cell_tp_repr,
215 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
217 (traverseproc)Nuitka_Cell_tp_traverse,
218 (inquiry)Nuitka_Cell_tp_clear,
219#if PYTHON_VERSION < 0x300
222 Nuitka_Cell_tp_richcompare,
229 Nuitka_Cell_tp_getset,
232void _initCompiledCellType(
void) { Nuitka_PyType_Ready(&Nuitka_Cell_Type, NULL,
true,
false,
false,
false,
false); }
236 count_active_Nuitka_Cell_Type += 1;
237 count_allocated_Nuitka_Cell_Type += 1;
242 allocateFromFreeListFixed(free_list_cells,
struct Nuitka_CellObject, Nuitka_Cell_Type);
244 result->ob_ref = NULL;
246 Nuitka_GC_Track(result);
253 count_active_Nuitka_Cell_Type += 1;
254 count_allocated_Nuitka_Cell_Type += 1;
260 allocateFromFreeListFixed(free_list_cells,
struct Nuitka_CellObject, Nuitka_Cell_Type);
262 result->ob_ref = value;
265 Nuitka_GC_Track(result);
272 count_active_Nuitka_Cell_Type += 1;
273 count_allocated_Nuitka_Cell_Type += 1;
279 allocateFromFreeListFixed(free_list_cells,
struct Nuitka_CellObject, Nuitka_Cell_Type);
281 result->ob_ref = value;
283 Nuitka_GC_Track(result);
Definition compiled_cell.h:14