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)
|
deepcopy(elementtreestate *st, PyObject *object, PyObject *memo)
|
||||||
{
|
{
|
||||||
/* do a deep copy of the given object */
|
/* do a deep copy of the given object */
|
||||||
PyObject *stack[2];
|
|
||||||
|
|
||||||
/* Fast paths */
|
/* Fast paths */
|
||||||
if (object == Py_None || PyUnicode_CheckExact(object)) {
|
if (object == Py_None || PyUnicode_CheckExact(object)) {
|
||||||
|
@ -917,9 +916,8 @@ deepcopy(elementtreestate *st, PyObject *object, PyObject *memo)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
stack[0] = object;
|
PyObject *args[2] = {object, memo};
|
||||||
stack[1] = memo;
|
return PyObject_Vectorcall(st->deepcopy_obj, args, 2, NULL);
|
||||||
return _PyObject_FastCall(st->deepcopy_obj, stack, 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2852,14 +2850,14 @@ treebuilder_handle_pi(TreeBuilderObject* self, PyObject* target, PyObject* text)
|
||||||
{
|
{
|
||||||
PyObject* pi;
|
PyObject* pi;
|
||||||
PyObject* this;
|
PyObject* this;
|
||||||
PyObject* stack[2] = {target, text};
|
|
||||||
|
|
||||||
if (treebuilder_flush_data(self) < 0) {
|
if (treebuilder_flush_data(self) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->pi_factory) {
|
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) {
|
if (!pi) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -3372,7 +3370,6 @@ expat_start_ns_handler(XMLParserObject* self, const XML_Char* prefix_in,
|
||||||
PyObject* res = NULL;
|
PyObject* res = NULL;
|
||||||
PyObject* uri;
|
PyObject* uri;
|
||||||
PyObject* prefix;
|
PyObject* prefix;
|
||||||
PyObject* stack[2];
|
|
||||||
|
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred())
|
||||||
return;
|
return;
|
||||||
|
@ -3411,9 +3408,8 @@ expat_start_ns_handler(XMLParserObject* self, const XML_Char* prefix_in,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stack[0] = prefix;
|
PyObject* args[2] = {prefix, uri};
|
||||||
stack[1] = uri;
|
res = PyObject_Vectorcall(self->handle_start_ns, args, 2, NULL);
|
||||||
res = _PyObject_FastCall(self->handle_start_ns, stack, 2);
|
|
||||||
Py_DECREF(uri);
|
Py_DECREF(uri);
|
||||||
Py_DECREF(prefix);
|
Py_DECREF(prefix);
|
||||||
}
|
}
|
||||||
|
@ -3551,7 +3547,6 @@ expat_pi_handler(XMLParserObject* self, const XML_Char* target_in,
|
||||||
PyObject* pi_target;
|
PyObject* pi_target;
|
||||||
PyObject* data;
|
PyObject* data;
|
||||||
PyObject* res;
|
PyObject* res;
|
||||||
PyObject* stack[2];
|
|
||||||
|
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred())
|
||||||
return;
|
return;
|
||||||
|
@ -3581,9 +3576,8 @@ expat_pi_handler(XMLParserObject* self, const XML_Char* target_in,
|
||||||
if (!data)
|
if (!data)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
stack[0] = pi_target;
|
PyObject* args[2] = {pi_target, data};
|
||||||
stack[1] = data;
|
res = PyObject_Vectorcall(self->handle_pi, args, 2, NULL);
|
||||||
res = _PyObject_FastCall(self->handle_pi, stack, 2);
|
|
||||||
Py_XDECREF(res);
|
Py_XDECREF(res);
|
||||||
Py_DECREF(data);
|
Py_DECREF(data);
|
||||||
Py_DECREF(pi_target);
|
Py_DECREF(pi_target);
|
||||||
|
|
|
@ -594,21 +594,15 @@ keyobject_call(keyobject *ko, PyObject *args, PyObject *kwds)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
keyobject_richcompare(PyObject *ko, PyObject *other, int op)
|
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))) {
|
if (!Py_IS_TYPE(other, Py_TYPE(ko))) {
|
||||||
PyErr_Format(PyExc_TypeError, "other argument must be K instance");
|
PyErr_Format(PyExc_TypeError, "other argument must be K instance");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
compare = ((keyobject *) ko)->cmp;
|
|
||||||
|
PyObject *compare = ((keyobject *) ko)->cmp;
|
||||||
assert(compare != NULL);
|
assert(compare != NULL);
|
||||||
x = ((keyobject *) ko)->object;
|
PyObject *x = ((keyobject *) ko)->object;
|
||||||
y = ((keyobject *) other)->object;
|
PyObject *y = ((keyobject *) other)->object;
|
||||||
if (!x || !y){
|
if (!x || !y){
|
||||||
PyErr_Format(PyExc_AttributeError, "object");
|
PyErr_Format(PyExc_AttributeError, "object");
|
||||||
return NULL;
|
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
|
/* Call the user's comparison function and translate the 3-way
|
||||||
* result into true or false (or error).
|
* result into true or false (or error).
|
||||||
*/
|
*/
|
||||||
stack[0] = x;
|
PyObject* args[2] = {x, y};
|
||||||
stack[1] = y;
|
PyObject *res = PyObject_Vectorcall(compare, args, 2, NULL);
|
||||||
res = _PyObject_FastCall(compare, stack, 2);
|
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
answer = PyObject_RichCompare(res, _PyLong_GetZero(), op);
|
PyObject *answer = PyObject_RichCompare(res, _PyLong_GetZero(), op);
|
||||||
Py_DECREF(res);
|
Py_DECREF(res);
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10013,7 +10013,8 @@ static int
|
||||||
type_new_init_subclass(PyTypeObject *type, PyObject *kwds)
|
type_new_init_subclass(PyTypeObject *type, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PyObject *args[2] = {(PyObject *)type, (PyObject *)type};
|
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) {
|
if (super == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -465,7 +465,6 @@ _PyPegen_new_identifier(Parser *p, const char *n)
|
||||||
identifier; if so, normalize to NFKC. */
|
identifier; if so, normalize to NFKC. */
|
||||||
if (!PyUnicode_IS_ASCII(id))
|
if (!PyUnicode_IS_ASCII(id))
|
||||||
{
|
{
|
||||||
PyObject *id2;
|
|
||||||
if (!init_normalization(p))
|
if (!init_normalization(p))
|
||||||
{
|
{
|
||||||
Py_DECREF(id);
|
Py_DECREF(id);
|
||||||
|
@ -478,12 +477,13 @@ _PyPegen_new_identifier(Parser *p, const char *n)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
PyObject *args[2] = {form, id};
|
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(id);
|
||||||
Py_DECREF(form);
|
Py_DECREF(form);
|
||||||
if (!id2) {
|
if (!id2) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PyUnicode_Check(id2))
|
if (!PyUnicode_Check(id2))
|
||||||
{
|
{
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "pycore_abstract.h" // _PyIndex_Check()
|
#include "pycore_abstract.h" // _PyIndex_Check()
|
||||||
#include "pycore_call.h" // _PyObject_FastCallDictTstate()
|
|
||||||
#include "pycore_ceval.h" // _PyEval_SignalAsyncExc()
|
#include "pycore_ceval.h" // _PyEval_SignalAsyncExc()
|
||||||
#include "pycore_code.h"
|
#include "pycore_code.h"
|
||||||
#include "pycore_function.h"
|
#include "pycore_function.h"
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "pycore_abstract.h" // _PyIndex_Check()
|
#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_ceval.h" // _PyEval_SignalAsyncExc()
|
||||||
#include "pycore_code.h"
|
#include "pycore_code.h"
|
||||||
#include "pycore_function.h"
|
#include "pycore_function.h"
|
||||||
|
@ -2431,40 +2431,37 @@ static PyObject *
|
||||||
import_name(PyThreadState *tstate, _PyInterpreterFrame *frame,
|
import_name(PyThreadState *tstate, _PyInterpreterFrame *frame,
|
||||||
PyObject *name, PyObject *fromlist, PyObject *level)
|
PyObject *name, PyObject *fromlist, PyObject *level)
|
||||||
{
|
{
|
||||||
PyObject *import_func, *res;
|
PyObject *import_func = _PyDict_GetItemWithError(frame->f_builtins,
|
||||||
PyObject* stack[5];
|
&_Py_ID(__import__));
|
||||||
|
|
||||||
import_func = _PyDict_GetItemWithError(frame->f_builtins, &_Py_ID(__import__));
|
|
||||||
if (import_func == NULL) {
|
if (import_func == NULL) {
|
||||||
if (!_PyErr_Occurred(tstate)) {
|
if (!_PyErr_Occurred(tstate)) {
|
||||||
_PyErr_SetString(tstate, PyExc_ImportError, "__import__ not found");
|
_PyErr_SetString(tstate, PyExc_ImportError, "__import__ not found");
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *locals = frame->f_locals;
|
PyObject *locals = frame->f_locals;
|
||||||
|
if (locals == NULL) {
|
||||||
|
locals = Py_None;
|
||||||
|
}
|
||||||
|
|
||||||
/* Fast path for not overloaded __import__. */
|
/* Fast path for not overloaded __import__. */
|
||||||
if (_PyImport_IsDefaultImportFunc(tstate->interp, import_func)) {
|
if (_PyImport_IsDefaultImportFunc(tstate->interp, import_func)) {
|
||||||
int ilevel = _PyLong_AsInt(level);
|
int ilevel = _PyLong_AsInt(level);
|
||||||
if (ilevel == -1 && _PyErr_Occurred(tstate)) {
|
if (ilevel == -1 && _PyErr_Occurred(tstate)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
res = PyImport_ImportModuleLevelObject(
|
return PyImport_ImportModuleLevelObject(
|
||||||
name,
|
name,
|
||||||
frame->f_globals,
|
frame->f_globals,
|
||||||
locals == NULL ? Py_None :locals,
|
locals,
|
||||||
fromlist,
|
fromlist,
|
||||||
ilevel);
|
ilevel);
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject* args[5] = {name, frame->f_globals, locals, fromlist, level};
|
||||||
Py_INCREF(import_func);
|
Py_INCREF(import_func);
|
||||||
|
PyObject *res = PyObject_Vectorcall(import_func, args, 5, NULL);
|
||||||
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);
|
|
||||||
Py_DECREF(import_func);
|
Py_DECREF(import_func);
|
||||||
return res;
|
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);
|
_PyErr_WriteUnraisableMsg("in audit hook", NULL);
|
||||||
}
|
}
|
||||||
if (hook) {
|
if (hook) {
|
||||||
PyObject* stack[3];
|
PyObject* args[3] = {typ, exc, tb};
|
||||||
stack[0] = typ;
|
PyObject *result = PyObject_Vectorcall(hook, args, 3, NULL);
|
||||||
stack[1] = exc;
|
|
||||||
stack[2] = tb;
|
|
||||||
PyObject *result = _PyObject_FastCall(hook, stack, 3);
|
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
handle_system_exit();
|
handle_system_exit();
|
||||||
|
|
||||||
|
|
|
@ -268,7 +268,7 @@ sys_audit_tstate(PyThreadState *ts, const char *event,
|
||||||
PyThreadState_LeaveTracing(ts);
|
PyThreadState_LeaveTracing(ts);
|
||||||
}
|
}
|
||||||
PyObject* args[2] = {eventName, eventArgs};
|
PyObject* args[2] = {eventName, eventArgs};
|
||||||
o = _PyObject_FastCallTstate(ts, hook, args, 2);
|
o = _PyObject_VectorcallTstate(ts, hook, args, 2, NULL);
|
||||||
if (canTrace) {
|
if (canTrace) {
|
||||||
PyThreadState_EnterTracing(ts);
|
PyThreadState_EnterTracing(ts);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue