Nuitka
The Python compiler
Loading...
Searching...
No Matches
checkers.h
1// Copyright 2026, Kay Hayen, mailto:kay.hayen@gmail.com find license text at end of file
2
3#ifndef __NUITKA_CHECKERS_H__
4#define __NUITKA_CHECKERS_H__
5
6// Helper to check that an object is valid and has positive reference count.
7#define CHECK_OBJECT(value) (assert((value) != NULL), assert(Py_REFCNT(value) > 0))
8#define CHECK_OBJECT_X(value) (assert((value) == NULL || Py_REFCNT(value) > 0))
9
10// Helper to check an array of objects with CHECK_OBJECT
11#ifndef __NUITKA_NO_ASSERT__
12#define CHECK_OBJECTS(values, count) \
13 { \
14 for (int i = 0; i < count; i++) { \
15 CHECK_OBJECT((values)[i]); \
16 } \
17 }
18#else
19#define CHECK_OBJECTS(values, count)
20#endif
21
22extern void CHECK_OBJECT_DEEP(PyObject *value);
23extern void CHECK_OBJECT_DEEP_NAMED(char const *name, PyObject *value);
24extern void CHECK_OBJECTS_DEEP(PyObject *const *values, Py_ssize_t size);
25
26#endif
27
28// Part of "Nuitka", an optimizing Python compiler that is compatible and
29// integrates with CPython, but also works on its own.
30//
31// Licensed under the GNU Affero General Public License, Version 3 (the "License");
32// you may not use this file except in compliance with the License.
33// You may obtain a copy of the License at
34//
35// http://www.gnu.org/licenses/agpl.txt
36//
37// Unless required by applicable law or agreed to in writing, software
38// distributed under the License is distributed on an "AS IS" BASIS,
39// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40// See the License for the specific language governing permissions and
41// limitations under the License.