Skip to content

Commit 4d231bc

Browse files
authored
bpo-38644: Add _PyObject_Call() (GH-17089)
* Add pycore_call.h internal header file. * Add _PyObject_Call(): PyObject_Call() with tstate * Add _PyObject_CallNoArgTstate(): _PyObject_CallNoArg() with tstate * Add _PyObject_FastCallDictTstate(): _PyObject_FastCallDict() with tstate * _PyObject_Call_Prepend() now takes tstate * Replace _PyObject_FastCall() calls with _PyObject_VectorcallTstate() calls
1 parent b9e6812 commit 4d231bc

File tree

10 files changed

+216
-137
lines changed

10 files changed

+216
-137
lines changed

Include/cpython/abstract.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,17 @@ PyAPI_FUNC(PyObject *) PyVectorcall_Call(PyObject *callable, PyObject *tuple, Py
137137
static inline PyObject *
138138
_PyObject_FastCall(PyObject *func, PyObject *const *args, Py_ssize_t nargs)
139139
{
140-
return _PyObject_Vectorcall(func, args, (size_t)nargs, NULL);
140+
PyThreadState *tstate = PyThreadState_GET();
141+
return _PyObject_VectorcallTstate(tstate, func, args, (size_t)nargs, NULL);
141142
}
142143

143144
/* Call a callable without any arguments
144145
Private static inline function variant of public function
145146
PyObject_CallNoArgs(). */
146147
static inline PyObject *
147148
_PyObject_CallNoArg(PyObject *func) {
148-
return _PyObject_Vectorcall(func, NULL, 0, NULL);
149+
PyThreadState *tstate = PyThreadState_GET();
150+
return _PyObject_VectorcallTstate(tstate, func, NULL, 0, NULL);
149151
}
150152

151153
static inline PyObject *
@@ -155,16 +157,11 @@ _PyObject_CallOneArg(PyObject *func, PyObject *arg)
155157
PyObject *_args[2];
156158
PyObject **args = _args + 1; // For PY_VECTORCALL_ARGUMENTS_OFFSET
157159
args[0] = arg;
158-
return _PyObject_Vectorcall(func, args,
159-
1 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
160+
PyThreadState *tstate = PyThreadState_GET();
161+
size_t nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET;
162+
return _PyObject_VectorcallTstate(tstate, func, args, nargsf, NULL);
160163
}
161164

162-
PyAPI_FUNC(PyObject *) _PyObject_Call_Prepend(
163-
PyObject *callable,
164-
PyObject *obj,
165-
PyObject *args,
166-
PyObject *kwargs);
167-
168165
PyAPI_FUNC(PyObject *) _PyObject_VectorcallMethod(
169166
PyObject *name, PyObject *const *args,
170167
size_t nargsf, PyObject *kwnames);

Include/internal/pycore_call.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef Py_INTERNAL_CALL_H
2+
#define Py_INTERNAL_CALL_H
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#ifndef Py_BUILD_CORE
8+
# error "this header requires Py_BUILD_CORE define"
9+
#endif
10+
11+
PyAPI_FUNC(PyObject *) _PyObject_Call_Prepend(
12+
PyThreadState *tstate,
13+
PyObject *callable,
14+
PyObject *obj,
15+
PyObject *args,
16+
PyObject *kwargs);
17+
18+
PyAPI_FUNC(PyObject *) _PyObject_FastCallDictTstate(
19+
PyThreadState *tstate,
20+
PyObject *callable,
21+
PyObject *const *args,
22+
size_t nargsf,
23+
PyObject *kwargs);
24+
25+
PyAPI_FUNC(PyObject *) _PyObject_Call(
26+
PyThreadState *tstate,
27+
PyObject *callable,
28+
PyObject *args,
29+
PyObject *kwargs);
30+
31+
static inline PyObject *
32+
_PyObject_CallNoArgTstate(PyThreadState *tstate, PyObject *func) {
33+
return _PyObject_VectorcallTstate(tstate, func, NULL, 0, NULL);
34+
}
35+
36+
#ifdef __cplusplus
37+
}
38+
#endif
39+
#endif /* !Py_INTERNAL_CALL_H */

Makefile.pre.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,7 @@ PYTHON_HEADERS= \
10761076
\
10771077
$(srcdir)/Include/internal/pycore_accu.h \
10781078
$(srcdir)/Include/internal/pycore_atomic.h \
1079+
$(srcdir)/Include/internal/pycore_call.h \
10791080
$(srcdir)/Include/internal/pycore_ceval.h \
10801081
$(srcdir)/Include/internal/pycore_code.h \
10811082
$(srcdir)/Include/internal/pycore_condvar.h \

0 commit comments

Comments
 (0)