Nuitka
The Python compiler
Loading...
Searching...
No Matches
sequences.h
1// Copyright 2025, Kay Hayen, mailto:kay.hayen@gmail.com find license text at end of file
2
3#ifndef __NUITKA_HELPER_SEQUENCES_H__
4#define __NUITKA_HELPER_SEQUENCES_H__
5
6// TODO: Provide enhanced form of PySequence_Contains with less overhead as well.
7
8extern bool SEQUENCE_SET_ITEM(PyObject *sequence, Py_ssize_t index, PyObject *value);
9
10extern Py_ssize_t Nuitka_PyObject_Size(PyObject *sequence);
11
12// Our version of "_PyObject_HasLen", a former API function.
13NUITKA_MAY_BE_UNUSED static int Nuitka_PyObject_HasLen(PyObject *o) {
14 return (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_length) ||
15 (Py_TYPE(o)->tp_as_mapping && Py_TYPE(o)->tp_as_mapping->mp_length);
16}
17
18#endif
19
20// Part of "Nuitka", an optimizing Python compiler that is compatible and
21// integrates with CPython, but also works on its own.
22//
23// Licensed under the Apache License, Version 2.0 (the "License");
24// you may not use this file except in compliance with the License.
25// You may obtain a copy of the License at
26//
27// http://www.apache.org/licenses/LICENSE-2.0
28//
29// Unless required by applicable law or agreed to in writing, software
30// distributed under the License is distributed on an "AS IS" BASIS,
31// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32// See the License for the specific language governing permissions and
33// limitations under the License.