summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-10-14 19:53:04 (GMT)
committerGitHub <noreply@github.com>2021-10-14 19:53:04 (GMT)
commit3cc56c828d2d8f8659ea49447234bf0d2b87cd64 (patch)
tree7f204eb39062037d3575d407fda18825e314dd7e /Objects
parent39aa98346d5dd8ac591a7cafb467af21c53f1e5d (diff)
downloadcpython-3cc56c828d2d8f8659ea49447234bf0d2b87cd64.zip
cpython-3cc56c828d2d8f8659ea49447234bf0d2b87cd64.tar.gz
cpython-3cc56c828d2d8f8659ea49447234bf0d2b87cd64.tar.bz2
bpo-45439: Move _PyObject_VectorcallTstate() to pycore_call.h (GH-28893)
* Move _PyObject_VectorcallTstate() and _PyObject_FastCallTstate() to pycore_call.h (internal C API). * Convert PyObject_CallOneArg(), PyObject_Vectorcall(), _PyObject_FastCall() and PyVectorcall_Function() static inline functions to regular functions. * Add _PyVectorcall_FunctionInline() static inline function. * PyObject_Vectorcall(), _PyObject_FastCall(), and PyObject_CallOneArg() now call _PyThreadState_GET() rather than PyThreadState_Get().
Diffstat (limited to 'Objects')
-rw-r--r--Objects/call.c47
-rw-r--r--Objects/classobject.c1
2 files changed, 43 insertions, 5 deletions
diff --git a/Objects/call.c b/Objects/call.c
index cfcd422..5e55518 100644
--- a/Objects/call.c
+++ b/Objects/call.c
@@ -109,8 +109,7 @@ _Py_CheckSlotResult(PyObject *obj, const char *slot_name, int success)
PyObject *
PyObject_CallNoArgs(PyObject *func)
{
- PyThreadState *tstate = _PyThreadState_GET();
- return _PyObject_CallNoArgsTstate(tstate, func);
+ return _PyObject_CallNoArgs(func);
}
@@ -131,7 +130,7 @@ _PyObject_FastCallDictTstate(PyThreadState *tstate, PyObject *callable,
assert(nargs == 0 || args != NULL);
assert(kwargs == NULL || PyDict_Check(kwargs));
- vectorcallfunc func = PyVectorcall_Function(callable);
+ vectorcallfunc func = _PyVectorcall_Function(callable);
if (func == NULL) {
/* Use tp_call instead */
return _PyObject_MakeTpCall(tstate, callable, args, nargs, kwargs);
@@ -225,6 +224,13 @@ _PyObject_MakeTpCall(PyThreadState *tstate, PyObject *callable,
}
+vectorcallfunc
+PyVectorcall_Function(PyObject *callable)
+{
+ return _PyVectorcall_FunctionInline(callable);
+}
+
+
static PyObject *
_PyVectorcall_Call(PyThreadState *tstate, vectorcallfunc func,
PyObject *callable, PyObject *tuple, PyObject *kwargs)
@@ -260,7 +266,7 @@ PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs)
{
PyThreadState *tstate = _PyThreadState_GET();
- /* get vectorcallfunc as in PyVectorcall_Function, but without
+ /* get vectorcallfunc as in _PyVectorcall_Function, but without
* the Py_TPFLAGS_HAVE_VECTORCALL check */
Py_ssize_t offset = Py_TYPE(callable)->tp_vectorcall_offset;
if (offset <= 0) {
@@ -285,6 +291,24 @@ PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs)
PyObject *
+PyObject_Vectorcall(PyObject *callable, PyObject *const *args,
+ size_t nargsf, PyObject *kwnames)
+{
+ PyThreadState *tstate = _PyThreadState_GET();
+ return _PyObject_VectorcallTstate(tstate, callable,
+ args, nargsf, kwnames);
+}
+
+
+PyObject *
+_PyObject_FastCall(PyObject *func, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyThreadState *tstate = _PyThreadState_GET();
+ return _PyObject_FastCallTstate(tstate, func, args, nargs);
+}
+
+
+PyObject *
_PyObject_Call(PyThreadState *tstate, PyObject *callable,
PyObject *args, PyObject *kwargs)
{
@@ -298,7 +322,7 @@ _PyObject_Call(PyThreadState *tstate, PyObject *callable,
assert(PyTuple_Check(args));
assert(kwargs == NULL || PyDict_Check(kwargs));
- vectorcallfunc vector_func = PyVectorcall_Function(callable);
+ vectorcallfunc vector_func = _PyVectorcall_Function(callable);
if (vector_func != NULL) {
return _PyVectorcall_Call(tstate, vector_func, callable, args, kwargs);
}
@@ -339,6 +363,19 @@ PyCFunction_Call(PyObject *callable, PyObject *args, PyObject *kwargs)
}
+PyObject *
+PyObject_CallOneArg(PyObject *func, PyObject *arg)
+{
+ assert(arg != NULL);
+ PyObject *_args[2];
+ PyObject **args = _args + 1; // For PY_VECTORCALL_ARGUMENTS_OFFSET
+ args[0] = arg;
+ PyThreadState *tstate = _PyThreadState_GET();
+ size_t nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET;
+ return _PyObject_VectorcallTstate(tstate, func, args, nargsf, NULL);
+}
+
+
/* --- PyFunction call functions ---------------------------------- */
PyObject *
diff --git a/Objects/classobject.c b/Objects/classobject.c
index af73be3..9d4fc99 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -1,6 +1,7 @@
/* Class object implementation (dead now except for methods) */
#include "Python.h"
+#include "pycore_call.h" // _PyObject_VectorcallTstate()
#include "pycore_object.h"
#include "pycore_pyerrors.h"
#include "pycore_pystate.h" // _PyThreadState_GET()