Coverage Report

Created: 2025-07-04 06:49

/src/cpython-install/include/python3.15/cpython/abstract.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef Py_CPYTHON_ABSTRACTOBJECT_H
2
#  error "this header file must not be included directly"
3
#endif
4
5
/* === Object Protocol ================================================== */
6
7
/* Like PyObject_CallMethod(), but expect a _Py_Identifier*
8
   as the method name. */
9
PyAPI_FUNC(PyObject*) _PyObject_CallMethodId(
10
    PyObject *obj,
11
    _Py_Identifier *name,
12
    const char *format, ...);
13
14
/* Convert keyword arguments from the FASTCALL (stack: C array, kwnames: tuple)
15
   format to a Python dictionary ("kwargs" dict).
16
17
   The type of kwnames keys is not checked. The final function getting
18
   arguments is responsible to check if all keys are strings, for example using
19
   PyArg_ParseTupleAndKeywords() or PyArg_ValidateKeywordArguments().
20
21
   Duplicate keys are merged using the last value. If duplicate keys must raise
22
   an exception, the caller is responsible to implement an explicit keys on
23
   kwnames. */
24
PyAPI_FUNC(PyObject*) _PyStack_AsDict(PyObject *const *values, PyObject *kwnames);
25
26
27
/* === Vectorcall protocol (PEP 590) ============================= */
28
29
// PyVectorcall_NARGS() is exported as a function for the stable ABI.
30
// Here (when we are not using the stable ABI), the name is overridden to
31
// call a static inline function for best performance.
32
static inline Py_ssize_t
33
_PyVectorcall_NARGS(size_t n)
34
0
{
35
0
    return n & ~PY_VECTORCALL_ARGUMENTS_OFFSET;
36
0
}
37
#define PyVectorcall_NARGS(n) _PyVectorcall_NARGS(n)
38
39
PyAPI_FUNC(vectorcallfunc) PyVectorcall_Function(PyObject *callable);
40
41
// Backwards compatibility aliases (PEP 590) for API that was provisional
42
// in Python 3.8
43
#define _PyObject_Vectorcall PyObject_Vectorcall
44
#define _PyObject_VectorcallMethod PyObject_VectorcallMethod
45
#define _PyObject_FastCallDict PyObject_VectorcallDict
46
#define _PyVectorcall_Function PyVectorcall_Function
47
#define _PyObject_CallOneArg PyObject_CallOneArg
48
#define _PyObject_CallMethodNoArgs PyObject_CallMethodNoArgs
49
#define _PyObject_CallMethodOneArg PyObject_CallMethodOneArg
50
51
/* Same as PyObject_Vectorcall except that keyword arguments are passed as
52
   dict, which may be NULL if there are no keyword arguments. */
53
PyAPI_FUNC(PyObject *) PyObject_VectorcallDict(
54
    PyObject *callable,
55
    PyObject *const *args,
56
    size_t nargsf,
57
    PyObject *kwargs);
58
59
PyAPI_FUNC(PyObject *) PyObject_CallOneArg(PyObject *func, PyObject *arg);
60
61
static inline PyObject *
62
PyObject_CallMethodNoArgs(PyObject *self, PyObject *name)
63
0
{
64
0
    size_t nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET;
65
0
    return PyObject_VectorcallMethod(name, &self, nargsf, _Py_NULL);
66
0
}
67
68
static inline PyObject *
69
PyObject_CallMethodOneArg(PyObject *self, PyObject *name, PyObject *arg)
70
0
{
71
0
    PyObject *args[2] = {self, arg};
72
0
    size_t nargsf = 2 | PY_VECTORCALL_ARGUMENTS_OFFSET;
73
0
    assert(arg != NULL);
74
0
    return PyObject_VectorcallMethod(name, args, nargsf, _Py_NULL);
75
0
}
76
77
/* Guess the size of object 'o' using len(o) or o.__length_hint__().
78
   If neither of those return a non-negative value, then return the default
79
   value.  If one of the calls fails, this function returns -1. */
80
PyAPI_FUNC(Py_ssize_t) PyObject_LengthHint(PyObject *o, Py_ssize_t);
81
82
/* === Sequence protocol ================================================ */
83
84
/* Assume tp_as_sequence and sq_item exist and that 'i' does not
85
   need to be corrected for a negative index. */
86
#define PySequence_ITEM(o, i)\
87
    ( Py_TYPE(o)->tp_as_sequence->sq_item((o), (i)) )
88
89
/* Return the size of the sequence 'o', assuming that 'o' was returned by
90
   PySequence_Fast and is not NULL. */
91
#define PySequence_Fast_GET_SIZE(o) \
92
    (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o))
93
94
/* Return the 'i'-th element of the sequence 'o', assuming that o was returned
95
   by PySequence_Fast, and that i is within bounds. */
96
#define PySequence_Fast_GET_ITEM(o, i)\
97
     (PyList_Check(o) ? PyList_GET_ITEM((o), (i)) : PyTuple_GET_ITEM((o), (i)))
98
99
/* Return a pointer to the underlying item array for
100
   an object returned by PySequence_Fast */
101
#define PySequence_Fast_ITEMS(sf) \
102
    (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \
103
                      : ((PyTupleObject *)(sf))->ob_item)
104