mirror of https://github.com/python/cpython
gh-106023: Update code using _PyObject_FastCall() (#106257)
Replace _PyObject_FastCall() calls with PyObject_Vectorcall().
This commit is contained in:
parent
e7bc8d1636
commit
8c5f74fc89
|
@ -882,7 +882,6 @@ LOCAL(PyObject *)
|
|||
deepcopy(elementtreestate *st, PyObject *object, PyObject *memo)
|
||||
{
|
||||
/* do a deep copy of the given object */
|
||||
PyObject *stack[2];
|
||||
|
||||
/* Fast paths */
|
||||
if (object == Py_None || PyUnicode_CheckExact(object)) {
|
||||
|
@ -917,9 +916,8 @@ deepcopy(elementtreestate *st, PyObject *object, PyObject *memo)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
stack[0] = object;
|
||||
stack[1] = memo;
|
||||
return _PyObject_FastCall(st->deepcopy_obj, stack, 2);
|
||||
PyObject *args[2] = {object, memo};
|
||||
return PyObject_Vectorcall(st->deepcopy_obj, args, 2, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2852,14 +2850,14 @@ treebuilder_handle_pi(TreeBuilderObject* self, PyObject* target, PyObject* text)
|
|||
{
|
||||
PyObject* pi;
|
||||
PyObject* this;
|
||||
PyObject* stack[2] = {target, text};
|
||||
|
||||
if (treebuilder_flush_data(self) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (self->pi_factory) {
|
||||
pi = _PyObject_FastCall(self->pi_factory, stack, 2);
|
||||
PyObject* args[2] = {target, text};
|
||||
pi = PyObject_Vectorcall(self->pi_factory, args, 2, NULL);
|
||||
if (!pi) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -3372,7 +3370,6 @@ expat_start_ns_handler(XMLParserObject* self, const XML_Char* prefix_in,
|
|||
PyObject* res = NULL;
|
||||
PyObject* uri;
|
||||
PyObject* prefix;
|
||||
PyObject* stack[2];
|
||||
|
||||
if (PyErr_Occurred())
|
||||
return;
|
||||
|
@ -3411,9 +3408,8 @@ expat_start_ns_handler(XMLParserObject* self, const XML_Char* prefix_in,
|
|||
return;
|
||||
}
|
||||
|
||||
stack[0] = prefix;
|
||||
stack[1] = uri;
|
||||
res = _PyObject_FastCall(self->handle_start_ns, stack, 2);
|
||||
PyObject* args[2] = {prefix, uri};
|
||||
res = PyObject_Vectorcall(self->handle_start_ns, args, 2, NULL);
|
||||
Py_DECREF(uri);
|
||||
Py_DECREF(prefix);
|
||||
}
|
||||
|
@ -3551,7 +3547,6 @@ expat_pi_handler(XMLParserObject* self, const XML_Char* target_in,
|
|||
PyObject* pi_target;
|
||||
PyObject* data;
|
||||
PyObject* res;
|
||||
PyObject* stack[2];
|
||||
|
||||
if (PyErr_Occurred())
|
||||
return;
|
||||
|
@ -3581,9 +3576,8 @@ expat_pi_handler(XMLParserObject* self, const XML_Char* target_in,
|
|||
if (!data)
|
||||
goto error;
|
||||
|
||||
stack[0] = pi_target;
|
||||
stack[1] = data;
|
||||
res = _PyObject_FastCall(self->handle_pi, stack, 2);
|
||||
PyObject* args[2] = {pi_target, data};
|
||||
res = PyObject_Vectorcall(self->handle_pi, args, 2, NULL);
|
||||
Py_XDECREF(res);
|
||||
Py_DECREF(data);
|
||||
Py_DECREF(pi_target);
|
||||
|
|
|
@ -594,21 +594,15 @@ keyobject_call(keyobject *ko, PyObject *args, PyObject *kwds)
|
|||
static PyObject *
|
||||
keyobject_richcompare(PyObject *ko, PyObject *other, int op)
|
||||
{
|
||||
PyObject *res;
|
||||
PyObject *x;
|
||||
PyObject *y;
|
||||
PyObject *compare;
|
||||
PyObject *answer;
|
||||
PyObject* stack[2];
|
||||
|
||||
if (!Py_IS_TYPE(other, Py_TYPE(ko))) {
|
||||
PyErr_Format(PyExc_TypeError, "other argument must be K instance");
|
||||
return NULL;
|
||||
}
|
||||
compare = ((keyobject *) ko)->cmp;
|
||||
|
||||
PyObject *compare = ((keyobject *) ko)->cmp;
|
||||
assert(compare != NULL);
|
||||
x = ((keyobject *) ko)->object;
|
||||
y = ((keyobject *) other)->object;
|
||||
PyObject *x = ((keyobject *) ko)->object;
|
||||
PyObject *y = ((keyobject *) other)->object;
|
||||
if (!x || !y){
|
||||
PyErr_Format(PyExc_AttributeError, "object");
|
||||
return NULL;
|
||||
|
@ -617,14 +611,13 @@ keyobject_richcompare(PyObject *ko, PyObject *other, int op)
|
|||
/* Call the user's comparison function and translate the 3-way
|
||||
* result into true or false (or error).
|
||||
*/
|
||||
stack[0] = x;
|
||||
stack[1] = y;
|
||||
res = _PyObject_FastCall(compare, stack, 2);
|
||||
PyObject* args[2] = {x, y};
|
||||
PyObject *res = PyObject_Vectorcall(compare, args, 2, NULL);
|
||||
if (res == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
answer = PyObject_RichCompare(res, _PyLong_GetZero(), op);
|
||||
PyObject *answer = PyObject_RichCompare(res, _PyLong_GetZero(), op);
|
||||
Py_DECREF(res);
|
||||
return answer;
|
||||
}
|
||||
|
|
|
@ -10013,7 +10013,8 @@ static int
|
|||
type_new_init_subclass(PyTypeObject *type, PyObject *kwds)
|
||||
{
|
||||
PyObject *args[2] = {(PyObject *)type, (PyObject *)type};
|
||||
PyObject *super = _PyObject_FastCall((PyObject *)&PySuper_Type, args, 2);
|
||||
PyObject *super = PyObject_Vectorcall((PyObject *)&PySuper_Type,
|
||||
args, 2, NULL);
|
||||
if (super == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -465,7 +465,6 @@ _PyPegen_new_identifier(Parser *p, const char *n)
|
|||
identifier; if so, normalize to NFKC. */
|
||||
if (!PyUnicode_IS_ASCII(id))
|
||||
{
|
||||
PyObject *id2;
|
||||
if (!init_normalization(p))
|
||||
{
|
||||
Py_DECREF(id);
|
||||
|
@ -478,12 +477,13 @@ _PyPegen_new_identifier(Parser *p, const char *n)
|
|||
goto error;
|
||||
}
|
||||
PyObject *args[2] = {form, id};
|
||||
id2 = _PyObject_FastCall(p->normalize, args, 2);
|
||||
PyObject *id2 = PyObject_Vectorcall(p->normalize, args, 2, NULL);
|
||||
Py_DECREF(id);
|
||||
Py_DECREF(form);
|
||||
if (!id2) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!PyUnicode_Check(id2))
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue