Backporting METH_FASTCALL from Python 3.7 (#317)

* dict copy speedup

refer to bpo-31179 or python/cpython@boa7a037b8fde

* __build_class__() uses METH_FASTCALL

refer python/cpython@69de71b255
refer python/cpython@773dc6dd06

a single test related to __prepare__ fails.

* type_prepare uses METH_FASTCALL

refer python/cpython@d526cfe546
refer python/cpython@80ab22fa2c

the prepare-related test still fails.  It's just related to the error
message format though.

* separate into ParseStack and ParseStackAndKeywords

refer python/cpython@6518a93cb1
refer python/cpython@3e1fad6913
refer python/cpython@c0083fc47d

* Add _PyArg_NoStackKeywords

refer python/cpython@29d39cc8f5

* _PyStack_UnpackDict now returns int

refer python/cpython@998c20962c

* METH_FASTCALL changes to .inc files

done via python's Argument Clinic tool,
refer python/cpython@259f0e4437

* Added _PyArg_UnpackStack

refer python/cpython@fe54dda08

* Argument Clinic FASTCALL again

refer python/cpython@0c4a828ca

* Argument Clinic for ordered dictionary object

refer python/cpython@b05cbac052

* speed up getargs

refer python/cpython@1741441649

* FASTCALL for sorted, next, and getattr

refer python/cpython@5a60ecaa7a
refer python/cpython@fda6d0acf0
refer python/cpython@84b388bb80

* Optimize methoddescr_call

refer python/cpython@2a1b676d1f
refer python/cpython@c52572319c
refer python/cpython@35ecebe165
refer python/cpython@8128d5a491

* cleanup _PyMethodDef_RawFastCallDict

refer python/cpython@0a2e46835d
refer python/cpython@98ccba8344
refer python/cpython@c89ef828cf
refer python/cpython@250e4b0063

* print now uses METH_FASTCALL

refer python/cpython@c3858bd7c6
refer python/cpython@bd584f169f
refer python/cpython@06d34393c2

* _struct module now uses Argument Clinic

refer python/cpython@3f2d10132d

* make deque methods faster

refer python/cpython@dd407d5006

* recursive calls in PyObject_Call

refer python/cpython@7399a05965

only partially ported, because RawFastCallKeywords hasn't been ported

* add macros

refer python/cpython@68a001dd59

* all tests pass in MODE=dbg

* convert some internal functions to FASTCALL

__import__ might need to be changed later, if it is possible to backport
the METH_FASTCALL | METH_KEYWORDS flag distinction later.

* speed up unpickling

refer python/cpython@bee09aecc2

* added _PyMethodDef_RawFastCallKeywords

refer python/cpython@7399a05965

* PyCFunction_Call performance

refer python/cpython@12c5838dae

* avoid PyMethodObject in slots

main change in python/cpython@516b98161a
test_exceptions changed in python/cpython@331bbe6aaa
type_settattro changed in python/cpython@193f7e094f
_PyObject_CallFunctionVa changed in python/cpython@fe4ff83049

* fix refcount error found in MODE=dbg

all tests now pass in MODE=dbg
This commit is contained in:
Gautham 2021-11-13 04:56:57 +05:30 committed by GitHub
parent 6f658f058b
commit 7fe9e70117
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
71 changed files with 4154 additions and 2450 deletions

View file

@ -75,22 +75,26 @@ PyDoc_STRVAR(signal_signal__doc__,
"the first is the signal number, the second is the interrupted stack frame.");
#define SIGNAL_SIGNAL_METHODDEF \
{"signal", (PyCFunction)signal_signal, METH_VARARGS, signal_signal__doc__},
{"signal", (PyCFunction)signal_signal, METH_FASTCALL, signal_signal__doc__},
static PyObject *
signal_signal_impl(PyObject *module, int signalnum, PyObject *handler);
static PyObject *
signal_signal(PyObject *module, PyObject *args)
signal_signal(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
int signalnum;
PyObject *handler;
if (!PyArg_ParseTuple(args, "iO:signal",
if (!_PyArg_ParseStack(args, nargs, "iO:signal",
&signalnum, &handler)) {
goto exit;
}
if (!_PyArg_NoStackKeywords("signal", kwnames)) {
goto exit;
}
return_value = signal_signal_impl(module, signalnum, handler);
exit:
@ -142,22 +146,26 @@ PyDoc_STRVAR(signal_siginterrupt__doc__,
"signal sig, else system calls will be interrupted.");
#define SIGNAL_SIGINTERRUPT_METHODDEF \
{"siginterrupt", (PyCFunction)signal_siginterrupt, METH_VARARGS, signal_siginterrupt__doc__},
{"siginterrupt", (PyCFunction)signal_siginterrupt, METH_FASTCALL, signal_siginterrupt__doc__},
static PyObject *
signal_siginterrupt_impl(PyObject *module, int signalnum, int flag);
static PyObject *
signal_siginterrupt(PyObject *module, PyObject *args)
signal_siginterrupt(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
int signalnum;
int flag;
if (!PyArg_ParseTuple(args, "ii:siginterrupt",
if (!_PyArg_ParseStack(args, nargs, "ii:siginterrupt",
&signalnum, &flag)) {
goto exit;
}
if (!_PyArg_NoStackKeywords("siginterrupt", kwnames)) {
goto exit;
}
return_value = signal_siginterrupt_impl(module, signalnum, flag);
exit:
@ -180,24 +188,28 @@ PyDoc_STRVAR(signal_setitimer__doc__,
"Returns old values as a tuple: (delay, interval).");
#define SIGNAL_SETITIMER_METHODDEF \
{"setitimer", (PyCFunction)signal_setitimer, METH_VARARGS, signal_setitimer__doc__},
{"setitimer", (PyCFunction)signal_setitimer, METH_FASTCALL, signal_setitimer__doc__},
static PyObject *
signal_setitimer_impl(PyObject *module, int which, double seconds,
double interval);
static PyObject *
signal_setitimer(PyObject *module, PyObject *args)
signal_setitimer(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
int which;
double seconds;
double interval = 0.0;
if (!PyArg_ParseTuple(args, "id|d:setitimer",
if (!_PyArg_ParseStack(args, nargs, "id|d:setitimer",
&which, &seconds, &interval)) {
goto exit;
}
if (!_PyArg_NoStackKeywords("setitimer", kwnames)) {
goto exit;
}
return_value = signal_setitimer_impl(module, which, seconds, interval);
exit:
@ -246,22 +258,26 @@ PyDoc_STRVAR(signal_pthread_sigmask__doc__,
"Fetch and/or change the signal mask of the calling thread.");
#define SIGNAL_PTHREAD_SIGMASK_METHODDEF \
{"pthread_sigmask", (PyCFunction)signal_pthread_sigmask, METH_VARARGS, signal_pthread_sigmask__doc__},
{"pthread_sigmask", (PyCFunction)signal_pthread_sigmask, METH_FASTCALL, signal_pthread_sigmask__doc__},
static PyObject *
signal_pthread_sigmask_impl(PyObject *module, int how, PyObject *mask);
static PyObject *
signal_pthread_sigmask(PyObject *module, PyObject *args)
signal_pthread_sigmask(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
int how;
PyObject *mask;
if (!PyArg_ParseTuple(args, "iO:pthread_sigmask",
if (!_PyArg_ParseStack(args, nargs, "iO:pthread_sigmask",
&how, &mask)) {
goto exit;
}
if (!_PyArg_NoStackKeywords("pthread_sigmask", kwnames)) {
goto exit;
}
return_value = signal_pthread_sigmask_impl(module, how, mask);
exit:
@ -338,24 +354,28 @@ PyDoc_STRVAR(signal_sigtimedwait__doc__,
"The timeout is specified in seconds, with floating point numbers allowed.");
#define SIGNAL_SIGTIMEDWAIT_METHODDEF \
{"sigtimedwait", (PyCFunction)signal_sigtimedwait, METH_VARARGS, signal_sigtimedwait__doc__},
{"sigtimedwait", (PyCFunction)signal_sigtimedwait, METH_FASTCALL, signal_sigtimedwait__doc__},
static PyObject *
signal_sigtimedwait_impl(PyObject *module, PyObject *sigset,
PyObject *timeout_obj);
static PyObject *
signal_sigtimedwait(PyObject *module, PyObject *args)
signal_sigtimedwait(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
PyObject *sigset;
PyObject *timeout_obj;
if (!PyArg_UnpackTuple(args, "sigtimedwait",
if (!_PyArg_UnpackStack(args, nargs, "sigtimedwait",
2, 2,
&sigset, &timeout_obj)) {
goto exit;
}
if (!_PyArg_NoStackKeywords("sigtimedwait", kwnames)) {
goto exit;
}
return_value = signal_sigtimedwait_impl(module, sigset, timeout_obj);
exit:
@ -373,22 +393,26 @@ PyDoc_STRVAR(signal_pthread_kill__doc__,
"Send a signal to a thread.");
#define SIGNAL_PTHREAD_KILL_METHODDEF \
{"pthread_kill", (PyCFunction)signal_pthread_kill, METH_VARARGS, signal_pthread_kill__doc__},
{"pthread_kill", (PyCFunction)signal_pthread_kill, METH_FASTCALL, signal_pthread_kill__doc__},
static PyObject *
signal_pthread_kill_impl(PyObject *module, long thread_id, int signalnum);
static PyObject *
signal_pthread_kill(PyObject *module, PyObject *args)
signal_pthread_kill(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
long thread_id;
int signalnum;
if (!PyArg_ParseTuple(args, "li:pthread_kill",
if (!_PyArg_ParseStack(args, nargs, "li:pthread_kill",
&thread_id, &signalnum)) {
goto exit;
}
if (!_PyArg_NoStackKeywords("pthread_kill", kwnames)) {
goto exit;
}
return_value = signal_pthread_kill_impl(module, thread_id, signalnum);
exit:
@ -440,4 +464,4 @@ exit:
#ifndef SIGNAL_PTHREAD_KILL_METHODDEF
#define SIGNAL_PTHREAD_KILL_METHODDEF
#endif /* !defined(SIGNAL_PTHREAD_KILL_METHODDEF) */
/*[clinic end generated code: output=c6990ef0d0ba72b6 input=a9049054013a1b77]*/
/*[clinic end generated code: output=fab3dba32c058588 input=a9049054013a1b77]*/