Nuitka
The Python compiler
Loading...
Searching...
No Matches
indexes.h
1// Copyright 2025, Kay Hayen, mailto:kay.hayen@gmail.com find license text at end of file
2
3#ifndef __NUITKA_HELPER_INDEXES_H__
4#define __NUITKA_HELPER_INDEXES_H__
5
6/* This file is included from another C file, help IDEs to still parse it on its own. */
7#ifdef __IDE_ONLY__
8#include "nuitka/prelude.h"
9#endif
10
11// Avoid the API version of "PyIndex_Check" with this.
12#if PYTHON_VERSION >= 0x380
13static inline bool Nuitka_Index_Check(PyObject *obj) {
14 PyNumberMethods *tp_as_number = Py_TYPE(obj)->tp_as_number;
15
16 return (tp_as_number != NULL && tp_as_number->nb_index != NULL);
17}
18#else
19#define Nuitka_Index_Check(obj) PyIndex_Check(obj)
20#endif
21
22// Similar to "PyNumber_Index" but "Nuitka_Number_IndexAsLong" could be more relevant
23extern PyObject *Nuitka_Number_Index(PyObject *item);
24
25// In Python 3.10 or higher, the conversion to long is forced, but sometimes we
26// do not care at all, or it should not be done.
27#if PYTHON_VERSION >= 0x3a0
28extern PyObject *Nuitka_Number_IndexAsLong(PyObject *item);
29#else
30#define Nuitka_Number_IndexAsLong(item) Nuitka_Number_Index(item)
31#endif
32
33#endif
34// Part of "Nuitka", an optimizing Python compiler that is compatible and
35// integrates with CPython, but also works on its own.
36//
37// Licensed under the Apache License, Version 2.0 (the "License");
38// you may not use this file except in compliance with the License.
39// You may obtain a copy of the License at
40//
41// http://www.apache.org/licenses/LICENSE-2.0
42//
43// Unless required by applicable law or agreed to in writing, software
44// distributed under the License is distributed on an "AS IS" BASIS,
45// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
46// See the License for the specific language governing permissions and
47// limitations under the License.