Nuitka
The Python compiler
Loading...
Searching...
No Matches
compiled_cell.h
1// Copyright 2025, 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; }
13
15 /* Python object folklore: */
16 PyObject_HEAD
17
18 /* Content of the cell or NULL when empty */
19 PyObject *ob_ref;
20};
21
22// Create cell with out value, and with or without reference given.
23extern struct Nuitka_CellObject *Nuitka_Cell_NewEmpty(void);
24extern struct Nuitka_CellObject *Nuitka_Cell_New0(PyObject *value);
25extern struct Nuitka_CellObject *Nuitka_Cell_New1(PyObject *value);
26
27// Check stuff while accessing a compile cell in debug mode.
28#ifdef __NUITKA_NO_ASSERT__
29#define Nuitka_Cell_GET(cell) (((struct Nuitka_CellObject *)(cell))->ob_ref)
30#else
31#define Nuitka_Cell_GET(cell) \
32 (CHECK_OBJECT(cell), assert(Nuitka_Cell_Check((PyObject *)cell)), (((struct Nuitka_CellObject *)(cell))->ob_ref))
33#endif
34
35#if _DEBUG_REFCOUNTS
36extern int count_active_Nuitka_Cell_Type;
37extern int count_allocated_Nuitka_Cell_Type;
38extern int count_released_Nuitka_Cell_Type;
39#endif
40
41NUITKA_MAY_BE_UNUSED static inline void Nuitka_Cell_SET(struct Nuitka_CellObject *cell_object, PyObject *value) {
42 CHECK_OBJECT_X(value);
43 CHECK_OBJECT(cell_object);
44
45 assert(Nuitka_Cell_Check((PyObject *)cell_object));
46 cell_object->ob_ref = value;
47}
48
49#endif
50
51// Part of "Nuitka", an optimizing Python compiler that is compatible and
52// integrates with CPython, but also works on its own.
53//
54// Licensed under the Apache License, Version 2.0 (the "License");
55// you may not use this file except in compliance with the License.
56// You may obtain a copy of the License at
57//
58// http://www.apache.org/licenses/LICENSE-2.0
59//
60// Unless required by applicable law or agreed to in writing, software
61// distributed under the License is distributed on an "AS IS" BASIS,
62// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
63// See the License for the specific language governing permissions and
64// limitations under the License.
Definition compiled_cell.h:14