Nuitka
The Python compiler
Loading...
Searching...
No Matches
compiled_cell.h
1// Copyright 2026, Kay Hayen, mailto:kay.hayen@gmail.com find license text at end of file
2
3#ifndef __NUITKA_COMPILED_CELL_H__
4#define __NUITKA_COMPILED_CELL_H__
5
6/* This is a clone of the normal PyCell structure. We should keep it binary
7 * compatible, just in case somebody crazy insists on it.
8 */
9
10extern PyTypeObject Nuitka_Cell_Type;
11
12static inline bool Nuitka_Cell_Check(PyObject *object) { return Py_TYPE(object) == &Nuitka_Cell_Type; }
13static inline bool Nuitka_CellOrPyCell_Check(PyObject *object) {
14 return Nuitka_Cell_Check(object) || PyCell_Check(object);
15}
16
18 /* Python object folklore: */
19 PyObject_HEAD
20
21 /* Content of the cell or NULL when empty */
22 PyObject *ob_ref;
23};
24
25// Create cell with out value, and with or without reference given.
26extern struct Nuitka_CellObject *Nuitka_Cell_NewEmpty(void);
27extern struct Nuitka_CellObject *Nuitka_Cell_New0(PyObject *value);
28extern struct Nuitka_CellObject *Nuitka_Cell_New1(PyObject *value);
29
30// Check stuff while accessing a compile cell in debug mode.
31#ifdef __NUITKA_NO_ASSERT__
32#define Nuitka_Cell_GET(cell) (((struct Nuitka_CellObject *)(cell))->ob_ref)
33#else
34#define Nuitka_Cell_GET(cell) \
35 (CHECK_OBJECT(cell), assert(Nuitka_Cell_Check((PyObject *)cell)), (((struct Nuitka_CellObject *)(cell))->ob_ref))
36#endif
37
38NUITKA_MAY_BE_UNUSED static inline PyObject *Nuitka_CellOrPyCell_GET(PyObject *cell) {
39 CHECK_OBJECT(cell);
40 assert(Nuitka_CellOrPyCell_Check(cell));
41
42 return ((struct Nuitka_CellObject *)cell)->ob_ref;
43}
44
45#if _DEBUG_REFCOUNTS
46extern int count_active_Nuitka_Cell_Type;
47extern int count_allocated_Nuitka_Cell_Type;
48extern int count_released_Nuitka_Cell_Type;
49#endif
50
51NUITKA_MAY_BE_UNUSED static inline void Nuitka_Cell_SET(struct Nuitka_CellObject *cell_object, PyObject *value) {
52 CHECK_OBJECT_X(value);
53 CHECK_OBJECT(cell_object);
54
55 assert(Nuitka_Cell_Check((PyObject *)cell_object));
56 cell_object->ob_ref = value;
57}
58
59#endif
60
61// Part of "Nuitka", an optimizing Python compiler that is compatible and
62// integrates with CPython, but also works on its own.
63//
64// Licensed under the GNU Affero General Public License, Version 3 (the "License");
65// you may not use this file except in compliance with the License.
66// You may obtain a copy of the License at
67//
68// http://www.gnu.org/licenses/agpl.txt
69//
70// Unless required by applicable law or agreed to in writing, software
71// distributed under the License is distributed on an "AS IS" BASIS,
72// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
73// See the License for the specific language governing permissions and
74// limitations under the License.
Definition compiled_cell.h:17