@@ -10,29 +10,112 @@ extern "C" {
1010
1111#include "pycore_pystate.h" // _PyThreadState_GET()
1212
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 (
1434 PyThreadState * tstate ,
1535 PyObject * callable ,
1636 PyObject * obj ,
1737 PyObject * args ,
1838 PyObject * kwargs );
1939
20- PyAPI_FUNC ( PyObject * ) _PyObject_FastCallDictTstate (
40+ extern PyObject * _PyObject_FastCallDictTstate (
2141 PyThreadState * tstate ,
2242 PyObject * callable ,
2343 PyObject * const * args ,
2444 size_t nargsf ,
2545 PyObject * kwargs );
2646
27- PyAPI_FUNC ( PyObject * ) _PyObject_Call (
47+ extern PyObject * _PyObject_Call (
2848 PyThreadState * tstate ,
2949 PyObject * callable ,
3050 PyObject * args ,
3151 PyObject * kwargs );
3252
3353extern PyObject * _PyObject_CallMethodFormat (
34- PyThreadState * tstate , PyObject * callable , const char * format , ...);
54+ PyThreadState * tstate ,
55+ PyObject * callable ,
56+ const char * format ,
57+ ...);
3558
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 );
36119
37120// Static inline variant of public PyVectorcall_Function().
38121static inline vectorcallfunc
@@ -110,22 +193,26 @@ _PyObject_CallNoArgs(PyObject *func) {
110193
111194
112195static 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 )
114198{
115199 EVAL_CALL_STAT_INC_IF_FUNCTION (EVAL_CALL_API , func );
116200 return _PyObject_VectorcallTstate (tstate , func , args , (size_t )nargs , NULL );
117201}
118202
119- PyObject * const *
203+ extern PyObject * const *
120204_PyStack_UnpackDict (PyThreadState * tstate ,
121205 PyObject * const * args , Py_ssize_t nargs ,
122206 PyObject * kwargs , PyObject * * p_kwnames );
123207
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 ,
126211 PyObject * kwnames );
127212
128- void _PyStack_UnpackDict_FreeNoDecRef (PyObject * const * stack , PyObject * kwnames );
213+ extern void _PyStack_UnpackDict_FreeNoDecRef (
214+ PyObject * const * stack ,
215+ PyObject * kwnames );
129216
130217#ifdef __cplusplus
131218}
0 commit comments