gh-106023: Update code using _PyObject_FastCall() (#106257)

Replace _PyObject_FastCall() calls with PyObject_Vectorcall().
This commit is contained in:
Victor Stinner 2023-06-30 03:05:01 +02:00 committed by GitHub
parent e7bc8d1636
commit 8c5f74fc89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 434 additions and 453 deletions

View file

@ -8,7 +8,6 @@
#include "Python.h"
#include "pycore_abstract.h" // _PyIndex_Check()
#include "pycore_call.h" // _PyObject_FastCallDictTstate()
#include "pycore_ceval.h" // _PyEval_SignalAsyncExc()
#include "pycore_code.h"
#include "pycore_function.h"

View file

@ -4,7 +4,7 @@
#include "Python.h"
#include "pycore_abstract.h" // _PyIndex_Check()
#include "pycore_call.h" // _PyObject_FastCallDictTstate()
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_ceval.h" // _PyEval_SignalAsyncExc()
#include "pycore_code.h"
#include "pycore_function.h"
@ -2431,40 +2431,37 @@ static PyObject *
import_name(PyThreadState *tstate, _PyInterpreterFrame *frame,
PyObject *name, PyObject *fromlist, PyObject *level)
{
PyObject *import_func, *res;
PyObject* stack[5];
import_func = _PyDict_GetItemWithError(frame->f_builtins, &_Py_ID(__import__));
PyObject *import_func = _PyDict_GetItemWithError(frame->f_builtins,
&_Py_ID(__import__));
if (import_func == NULL) {
if (!_PyErr_Occurred(tstate)) {
_PyErr_SetString(tstate, PyExc_ImportError, "__import__ not found");
}
return NULL;
}
PyObject *locals = frame->f_locals;
if (locals == NULL) {
locals = Py_None;
}
/* Fast path for not overloaded __import__. */
if (_PyImport_IsDefaultImportFunc(tstate->interp, import_func)) {
int ilevel = _PyLong_AsInt(level);
if (ilevel == -1 && _PyErr_Occurred(tstate)) {
return NULL;
}
res = PyImport_ImportModuleLevelObject(
return PyImport_ImportModuleLevelObject(
name,
frame->f_globals,
locals == NULL ? Py_None :locals,
locals,
fromlist,
ilevel);
return res;
}
PyObject* args[5] = {name, frame->f_globals, locals, fromlist, level};
Py_INCREF(import_func);
stack[0] = name;
stack[1] = frame->f_globals;
stack[2] = locals == NULL ? Py_None : locals;
stack[3] = fromlist;
stack[4] = level;
res = _PyObject_FastCall(import_func, stack, 5);
PyObject *res = PyObject_Vectorcall(import_func, args, 5, NULL);
Py_DECREF(import_func);
return res;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -834,11 +834,8 @@ _PyErr_PrintEx(PyThreadState *tstate, int set_sys_last_vars)
_PyErr_WriteUnraisableMsg("in audit hook", NULL);
}
if (hook) {
PyObject* stack[3];
stack[0] = typ;
stack[1] = exc;
stack[2] = tb;
PyObject *result = _PyObject_FastCall(hook, stack, 3);
PyObject* args[3] = {typ, exc, tb};
PyObject *result = PyObject_Vectorcall(hook, args, 3, NULL);
if (result == NULL) {
handle_system_exit();

View file

@ -268,7 +268,7 @@ sys_audit_tstate(PyThreadState *ts, const char *event,
PyThreadState_LeaveTracing(ts);
}
PyObject* args[2] = {eventName, eventArgs};
o = _PyObject_FastCallTstate(ts, hook, args, 2);
o = _PyObject_VectorcallTstate(ts, hook, args, 2, NULL);
if (canTrace) {
PyThreadState_EnterTracing(ts);
}