mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 13:52:28 +00:00
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:
parent
6f658f058b
commit
7fe9e70117
71 changed files with 4154 additions and 2450 deletions
142
third_party/python/Python/clinic/bltinmodule.inc
vendored
142
third_party/python/Python/clinic/bltinmodule.inc
vendored
|
@ -1,11 +1,4 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Python 3 │
|
||||
│ https://docs.python.org/3/license.html │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
/* clang-format off */
|
||||
|
||||
/*[clinic input]
|
||||
preserve
|
||||
[clinic start generated code]*/
|
||||
|
@ -90,22 +83,26 @@ PyDoc_STRVAR(builtin_format__doc__,
|
|||
"details.");
|
||||
|
||||
#define BUILTIN_FORMAT_METHODDEF \
|
||||
{"format", (PyCFunction)builtin_format, METH_VARARGS, builtin_format__doc__},
|
||||
{"format", (PyCFunction)builtin_format, METH_FASTCALL, builtin_format__doc__},
|
||||
|
||||
static PyObject *
|
||||
builtin_format_impl(PyObject *module, PyObject *value, PyObject *format_spec);
|
||||
|
||||
static PyObject *
|
||||
builtin_format(PyObject *module, PyObject *args)
|
||||
builtin_format(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *value;
|
||||
PyObject *format_spec = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O|U:format",
|
||||
if (!_PyArg_ParseStack(args, nargs, "O|U:format",
|
||||
&value, &format_spec)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("format", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = builtin_format_impl(module, value, format_spec);
|
||||
|
||||
exit:
|
||||
|
@ -127,9 +124,16 @@ builtin_chr_impl(PyObject *module, int i);
|
|||
static PyObject *
|
||||
builtin_chr(PyObject *module, PyObject *arg)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
int i;
|
||||
if (!PyArg_Parse(arg, "i:chr", &i)) return 0;
|
||||
return builtin_chr_impl(module, i);
|
||||
|
||||
if (!PyArg_Parse(arg, "i:chr", &i)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = builtin_chr_impl(module, i);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(builtin_compile__doc__,
|
||||
|
@ -171,7 +175,7 @@ builtin_compile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *k
|
|||
int dont_inherit = 0;
|
||||
int optimize = -1;
|
||||
|
||||
if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
|
||||
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
||||
&source, PyUnicode_FSDecoder, &filename, &mode, &flags, &dont_inherit, &optimize)) {
|
||||
goto exit;
|
||||
}
|
||||
|
@ -188,23 +192,27 @@ PyDoc_STRVAR(builtin_divmod__doc__,
|
|||
"Return the tuple (x//y, x%y). Invariant: div*y + mod == x.");
|
||||
|
||||
#define BUILTIN_DIVMOD_METHODDEF \
|
||||
{"divmod", (PyCFunction)builtin_divmod, METH_VARARGS, builtin_divmod__doc__},
|
||||
{"divmod", (PyCFunction)builtin_divmod, METH_FASTCALL, builtin_divmod__doc__},
|
||||
|
||||
static PyObject *
|
||||
builtin_divmod_impl(PyObject *module, PyObject *x, PyObject *y);
|
||||
|
||||
static PyObject *
|
||||
builtin_divmod(PyObject *module, PyObject *args)
|
||||
builtin_divmod(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *x;
|
||||
PyObject *y;
|
||||
|
||||
if (!PyArg_UnpackTuple(args, "divmod",
|
||||
if (!_PyArg_UnpackStack(args, nargs, "divmod",
|
||||
2, 2,
|
||||
&x, &y)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("divmod", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = builtin_divmod_impl(module, x, y);
|
||||
|
||||
exit:
|
||||
|
@ -224,25 +232,29 @@ PyDoc_STRVAR(builtin_eval__doc__,
|
|||
"If only globals is given, locals defaults to it.");
|
||||
|
||||
#define BUILTIN_EVAL_METHODDEF \
|
||||
{"eval", (PyCFunction)builtin_eval, METH_VARARGS, builtin_eval__doc__},
|
||||
{"eval", (PyCFunction)builtin_eval, METH_FASTCALL, builtin_eval__doc__},
|
||||
|
||||
static PyObject *
|
||||
builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
|
||||
PyObject *locals);
|
||||
|
||||
static PyObject *
|
||||
builtin_eval(PyObject *module, PyObject *args)
|
||||
builtin_eval(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *source;
|
||||
PyObject *globals = Py_None;
|
||||
PyObject *locals = Py_None;
|
||||
|
||||
if (!PyArg_UnpackTuple(args, "eval",
|
||||
if (!_PyArg_UnpackStack(args, nargs, "eval",
|
||||
1, 3,
|
||||
&source, &globals, &locals)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("eval", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = builtin_eval_impl(module, source, globals, locals);
|
||||
|
||||
exit:
|
||||
|
@ -262,25 +274,29 @@ PyDoc_STRVAR(builtin_exec__doc__,
|
|||
"If only globals is given, locals defaults to it.");
|
||||
|
||||
#define BUILTIN_EXEC_METHODDEF \
|
||||
{"exec", (PyCFunction)builtin_exec, METH_VARARGS, builtin_exec__doc__},
|
||||
{"exec", (PyCFunction)builtin_exec, METH_FASTCALL, builtin_exec__doc__},
|
||||
|
||||
static PyObject *
|
||||
builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
|
||||
PyObject *locals);
|
||||
|
||||
static PyObject *
|
||||
builtin_exec(PyObject *module, PyObject *args)
|
||||
builtin_exec(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *source;
|
||||
PyObject *globals = Py_None;
|
||||
PyObject *locals = Py_None;
|
||||
|
||||
if (!PyArg_UnpackTuple(args, "exec",
|
||||
if (!_PyArg_UnpackStack(args, nargs, "exec",
|
||||
1, 3,
|
||||
&source, &globals, &locals)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("exec", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = builtin_exec_impl(module, source, globals, locals);
|
||||
|
||||
exit:
|
||||
|
@ -317,23 +333,27 @@ PyDoc_STRVAR(builtin_hasattr__doc__,
|
|||
"This is done by calling getattr(obj, name) and catching AttributeError.");
|
||||
|
||||
#define BUILTIN_HASATTR_METHODDEF \
|
||||
{"hasattr", (PyCFunction)builtin_hasattr, METH_VARARGS, builtin_hasattr__doc__},
|
||||
{"hasattr", (PyCFunction)builtin_hasattr, METH_FASTCALL, builtin_hasattr__doc__},
|
||||
|
||||
static PyObject *
|
||||
builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name);
|
||||
|
||||
static PyObject *
|
||||
builtin_hasattr(PyObject *module, PyObject *args)
|
||||
builtin_hasattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *obj;
|
||||
PyObject *name;
|
||||
|
||||
if (!PyArg_UnpackTuple(args, "hasattr",
|
||||
if (!_PyArg_UnpackStack(args, nargs, "hasattr",
|
||||
2, 2,
|
||||
&obj, &name)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("hasattr", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = builtin_hasattr_impl(module, obj, name);
|
||||
|
||||
exit:
|
||||
|
@ -361,25 +381,29 @@ PyDoc_STRVAR(builtin_setattr__doc__,
|
|||
"setattr(x, \'y\', v) is equivalent to ``x.y = v\'\'");
|
||||
|
||||
#define BUILTIN_SETATTR_METHODDEF \
|
||||
{"setattr", (PyCFunction)builtin_setattr, METH_VARARGS, builtin_setattr__doc__},
|
||||
{"setattr", (PyCFunction)builtin_setattr, METH_FASTCALL, builtin_setattr__doc__},
|
||||
|
||||
static PyObject *
|
||||
builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name,
|
||||
PyObject *value);
|
||||
|
||||
static PyObject *
|
||||
builtin_setattr(PyObject *module, PyObject *args)
|
||||
builtin_setattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *obj;
|
||||
PyObject *name;
|
||||
PyObject *value;
|
||||
|
||||
if (!PyArg_UnpackTuple(args, "setattr",
|
||||
if (!_PyArg_UnpackStack(args, nargs, "setattr",
|
||||
3, 3,
|
||||
&obj, &name, &value)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("setattr", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = builtin_setattr_impl(module, obj, name, value);
|
||||
|
||||
exit:
|
||||
|
@ -395,23 +419,27 @@ PyDoc_STRVAR(builtin_delattr__doc__,
|
|||
"delattr(x, \'y\') is equivalent to ``del x.y\'\'");
|
||||
|
||||
#define BUILTIN_DELATTR_METHODDEF \
|
||||
{"delattr", (PyCFunction)builtin_delattr, METH_VARARGS, builtin_delattr__doc__},
|
||||
{"delattr", (PyCFunction)builtin_delattr, METH_FASTCALL, builtin_delattr__doc__},
|
||||
|
||||
static PyObject *
|
||||
builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name);
|
||||
|
||||
static PyObject *
|
||||
builtin_delattr(PyObject *module, PyObject *args)
|
||||
builtin_delattr(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *obj;
|
||||
PyObject *name;
|
||||
|
||||
if (!PyArg_UnpackTuple(args, "delattr",
|
||||
if (!_PyArg_UnpackStack(args, nargs, "delattr",
|
||||
2, 2,
|
||||
&obj, &name)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("delattr", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = builtin_delattr_impl(module, obj, name);
|
||||
|
||||
exit:
|
||||
|
@ -504,24 +532,28 @@ PyDoc_STRVAR(builtin_pow__doc__,
|
|||
"invoked using the three argument form.");
|
||||
|
||||
#define BUILTIN_POW_METHODDEF \
|
||||
{"pow", (PyCFunction)builtin_pow, METH_VARARGS, builtin_pow__doc__},
|
||||
{"pow", (PyCFunction)builtin_pow, METH_FASTCALL, builtin_pow__doc__},
|
||||
|
||||
static PyObject *
|
||||
builtin_pow_impl(PyObject *module, PyObject *x, PyObject *y, PyObject *z);
|
||||
|
||||
static PyObject *
|
||||
builtin_pow(PyObject *module, PyObject *args)
|
||||
builtin_pow(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *x;
|
||||
PyObject *y;
|
||||
PyObject *z = Py_None;
|
||||
|
||||
if (!PyArg_UnpackTuple(args, "pow",
|
||||
if (!_PyArg_UnpackStack(args, nargs, "pow",
|
||||
2, 3,
|
||||
&x, &y, &z)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("pow", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = builtin_pow_impl(module, x, y, z);
|
||||
|
||||
exit:
|
||||
|
@ -541,22 +573,26 @@ PyDoc_STRVAR(builtin_input__doc__,
|
|||
"On *nix systems, readline is used if available.");
|
||||
|
||||
#define BUILTIN_INPUT_METHODDEF \
|
||||
{"input", (PyCFunction)builtin_input, METH_VARARGS, builtin_input__doc__},
|
||||
{"input", (PyCFunction)builtin_input, METH_FASTCALL, builtin_input__doc__},
|
||||
|
||||
static PyObject *
|
||||
builtin_input_impl(PyObject *module, PyObject *prompt);
|
||||
|
||||
static PyObject *
|
||||
builtin_input(PyObject *module, PyObject *args)
|
||||
builtin_input(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *prompt = NULL;
|
||||
|
||||
if (!PyArg_UnpackTuple(args, "input",
|
||||
if (!_PyArg_UnpackStack(args, nargs, "input",
|
||||
0, 1,
|
||||
&prompt)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("input", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = builtin_input_impl(module, prompt);
|
||||
|
||||
exit:
|
||||
|
@ -585,23 +621,27 @@ PyDoc_STRVAR(builtin_sum__doc__,
|
|||
"reject non-numeric types.");
|
||||
|
||||
#define BUILTIN_SUM_METHODDEF \
|
||||
{"sum", (PyCFunction)builtin_sum, METH_VARARGS, builtin_sum__doc__},
|
||||
{"sum", (PyCFunction)builtin_sum, METH_FASTCALL, builtin_sum__doc__},
|
||||
|
||||
static PyObject *
|
||||
builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start);
|
||||
|
||||
static PyObject *
|
||||
builtin_sum(PyObject *module, PyObject *args)
|
||||
builtin_sum(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *iterable;
|
||||
PyObject *start = NULL;
|
||||
|
||||
if (!PyArg_UnpackTuple(args, "sum",
|
||||
if (!_PyArg_UnpackStack(args, nargs, "sum",
|
||||
1, 2,
|
||||
&iterable, &start)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("sum", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = builtin_sum_impl(module, iterable, start);
|
||||
|
||||
exit:
|
||||
|
@ -619,24 +659,28 @@ PyDoc_STRVAR(builtin_isinstance__doc__,
|
|||
"or ...`` etc.");
|
||||
|
||||
#define BUILTIN_ISINSTANCE_METHODDEF \
|
||||
{"isinstance", (PyCFunction)builtin_isinstance, METH_VARARGS, builtin_isinstance__doc__},
|
||||
{"isinstance", (PyCFunction)builtin_isinstance, METH_FASTCALL, builtin_isinstance__doc__},
|
||||
|
||||
static PyObject *
|
||||
builtin_isinstance_impl(PyObject *module, PyObject *obj,
|
||||
PyObject *class_or_tuple);
|
||||
|
||||
static PyObject *
|
||||
builtin_isinstance(PyObject *module, PyObject *args)
|
||||
builtin_isinstance(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *obj;
|
||||
PyObject *class_or_tuple;
|
||||
|
||||
if (!PyArg_UnpackTuple(args, "isinstance",
|
||||
if (!_PyArg_UnpackStack(args, nargs, "isinstance",
|
||||
2, 2,
|
||||
&obj, &class_or_tuple)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("isinstance", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = builtin_isinstance_impl(module, obj, class_or_tuple);
|
||||
|
||||
exit:
|
||||
|
@ -654,27 +698,31 @@ PyDoc_STRVAR(builtin_issubclass__doc__,
|
|||
"or ...`` etc.");
|
||||
|
||||
#define BUILTIN_ISSUBCLASS_METHODDEF \
|
||||
{"issubclass", (PyCFunction)builtin_issubclass, METH_VARARGS, builtin_issubclass__doc__},
|
||||
{"issubclass", (PyCFunction)builtin_issubclass, METH_FASTCALL, builtin_issubclass__doc__},
|
||||
|
||||
static PyObject *
|
||||
builtin_issubclass_impl(PyObject *module, PyObject *cls,
|
||||
PyObject *class_or_tuple);
|
||||
|
||||
static PyObject *
|
||||
builtin_issubclass(PyObject *module, PyObject *args)
|
||||
builtin_issubclass(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *cls;
|
||||
PyObject *class_or_tuple;
|
||||
|
||||
if (!PyArg_UnpackTuple(args, "issubclass",
|
||||
if (!_PyArg_UnpackStack(args, nargs, "issubclass",
|
||||
2, 2,
|
||||
&cls, &class_or_tuple)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("issubclass", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = builtin_issubclass_impl(module, cls, class_or_tuple);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=2ef82846acdfa0f5 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=17fedd2dec148677 input=a9049054013a1b77]*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue