@@ -10,29 +10,112 @@ extern "C" {
10
10
11
11
#include "pycore_pystate.h" // _PyThreadState_GET()
12
12
13
- PyAPI_FUNC (PyObject * ) _PyObject_Call_Prepend (
13
+ // Export for shared stdlib extensions like the math extension,
14
+ // function used via inlined _PyObject_VectorcallTstate() function.
15
+ PyAPI_FUNC (PyObject * ) _Py_CheckFunctionResult (
16
+ PyThreadState * tstate ,
17
+ PyObject * callable ,
18
+ PyObject * result ,
19
+ const char * where );
20
+
21
+ /* Convert keyword arguments from the FASTCALL (stack: C array, kwnames: tuple)
22
+ format to a Python dictionary ("kwargs" dict).
23
+
24
+ The type of kwnames keys is not checked. The final function getting
25
+ arguments is responsible to check if all keys are strings, for example using
26
+ PyArg_ParseTupleAndKeywords() or PyArg_ValidateKeywordArguments().
27
+
28
+ Duplicate keys are merged using the last value. If duplicate keys must raise
29
+ an exception, the caller is responsible to implement an explicit keys on
30
+ kwnames. */
31
+ extern PyObject * _PyStack_AsDict (PyObject * const * values , PyObject * kwnames );
32
+
33
+ extern PyObject * _PyObject_Call_Prepend (
14
34
PyThreadState * tstate ,
15
35
PyObject * callable ,
16
36
PyObject * obj ,
17
37
PyObject * args ,
18
38
PyObject * kwargs );
19
39
20
- PyAPI_FUNC ( PyObject * ) _PyObject_FastCallDictTstate (
40
+ extern PyObject * _PyObject_FastCallDictTstate (
21
41
PyThreadState * tstate ,
22
42
PyObject * callable ,
23
43
PyObject * const * args ,
24
44
size_t nargsf ,
25
45
PyObject * kwargs );
26
46
27
- PyAPI_FUNC ( PyObject * ) _PyObject_Call (
47
+ extern PyObject * _PyObject_Call (
28
48
PyThreadState * tstate ,
29
49
PyObject * callable ,
30
50
PyObject * args ,
31
51
PyObject * kwargs );
32
52
33
53
extern PyObject * _PyObject_CallMethodFormat (
34
- PyThreadState * tstate , PyObject * callable , const char * format , ...);
54
+ PyThreadState * tstate ,
55
+ PyObject * callable ,
56
+ const char * format ,
57
+ ...);
35
58
59
+ // Export for shared stdlib extensions like the array extension
60
+ PyAPI_FUNC (PyObject * ) _PyObject_CallMethod (
61
+ PyObject * obj ,
62
+ PyObject * name ,
63
+ const char * format , ...);
64
+
65
+ /* Like PyObject_CallMethod(), but expect a _Py_Identifier*
66
+ as the method name. */
67
+ extern PyObject * _PyObject_CallMethodId (
68
+ PyObject * obj ,
69
+ _Py_Identifier * name ,
70
+ const char * format , ...);
71
+
72
+ extern PyObject * _PyObject_CallMethodIdObjArgs (
73
+ PyObject * obj ,
74
+ _Py_Identifier * name ,
75
+ ...);
76
+
77
+ static inline PyObject *
78
+ _PyObject_VectorcallMethodId (
79
+ _Py_Identifier * name , PyObject * const * args ,
80
+ size_t nargsf , PyObject * kwnames )
81
+ {
82
+ PyObject * oname = _PyUnicode_FromId (name ); /* borrowed */
83
+ if (!oname ) {
84
+ return _Py_NULL ;
85
+ }
86
+ return PyObject_VectorcallMethod (oname , args , nargsf , kwnames );
87
+ }
88
+
89
+ static inline PyObject *
90
+ _PyObject_CallMethodIdNoArgs (PyObject * self , _Py_Identifier * name )
91
+ {
92
+ size_t nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET ;
93
+ return _PyObject_VectorcallMethodId (name , & self , nargsf , _Py_NULL );
94
+ }
95
+
96
+ static inline PyObject *
97
+ _PyObject_CallMethodIdOneArg (PyObject * self , _Py_Identifier * name , PyObject * arg )
98
+ {
99
+ PyObject * args [2 ] = {self , arg };
100
+ size_t nargsf = 2 | PY_VECTORCALL_ARGUMENTS_OFFSET ;
101
+ assert (arg != NULL );
102
+ return _PyObject_VectorcallMethodId (name , args , nargsf , _Py_NULL );
103
+ }
104
+
105
+
106
+ /* === Vectorcall protocol (PEP 590) ============================= */
107
+
108
+ // Call callable using tp_call. Arguments are like PyObject_Vectorcall()
109
+ // or PyObject_FastCallDict() (both forms are supported),
110
+ // except that nargs is plainly the number of arguments without flags.
111
+ //
112
+ // Export for shared stdlib extensions like the math extension,
113
+ // function used via inlined _PyObject_VectorcallTstate() function.
114
+ PyAPI_FUNC (PyObject * ) _PyObject_MakeTpCall (
115
+ PyThreadState * tstate ,
116
+ PyObject * callable ,
117
+ PyObject * const * args , Py_ssize_t nargs ,
118
+ PyObject * keywords );
36
119
37
120
// Static inline variant of public PyVectorcall_Function().
38
121
static inline vectorcallfunc
@@ -110,22 +193,26 @@ _PyObject_CallNoArgs(PyObject *func) {
110
193
111
194
112
195
static inline PyObject *
113
- _PyObject_FastCallTstate (PyThreadState * tstate , PyObject * func , PyObject * const * args , Py_ssize_t nargs )
196
+ _PyObject_FastCallTstate (PyThreadState * tstate , PyObject * func ,
197
+ PyObject * const * args , Py_ssize_t nargs )
114
198
{
115
199
EVAL_CALL_STAT_INC_IF_FUNCTION (EVAL_CALL_API , func );
116
200
return _PyObject_VectorcallTstate (tstate , func , args , (size_t )nargs , NULL );
117
201
}
118
202
119
- PyObject * const *
203
+ extern PyObject * const *
120
204
_PyStack_UnpackDict (PyThreadState * tstate ,
121
205
PyObject * const * args , Py_ssize_t nargs ,
122
206
PyObject * kwargs , PyObject * * p_kwnames );
123
207
124
- void
125
- _PyStack_UnpackDict_Free (PyObject * const * stack , Py_ssize_t nargs ,
208
+ extern void _PyStack_UnpackDict_Free (
209
+ PyObject * const * stack ,
210
+ Py_ssize_t nargs ,
126
211
PyObject * kwnames );
127
212
128
- void _PyStack_UnpackDict_FreeNoDecRef (PyObject * const * stack , PyObject * kwnames );
213
+ extern void _PyStack_UnpackDict_FreeNoDecRef (
214
+ PyObject * const * stack ,
215
+ PyObject * kwnames );
129
216
130
217
#ifdef __cplusplus
131
218
}
0 commit comments