mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +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
|
@ -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]*/
|
||||
|
@ -74,7 +67,7 @@ bytearray_translate(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs,
|
|||
PyObject *table;
|
||||
PyObject *deletechars = NULL;
|
||||
|
||||
if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
|
||||
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
||||
&table, &deletechars)) {
|
||||
goto exit;
|
||||
}
|
||||
|
@ -96,22 +89,26 @@ PyDoc_STRVAR(bytearray_maketrans__doc__,
|
|||
"The bytes objects frm and to must be of the same length.");
|
||||
|
||||
#define BYTEARRAY_MAKETRANS_METHODDEF \
|
||||
{"maketrans", (PyCFunction)bytearray_maketrans, METH_VARARGS|METH_STATIC, bytearray_maketrans__doc__},
|
||||
{"maketrans", (PyCFunction)bytearray_maketrans, METH_FASTCALL|METH_STATIC, bytearray_maketrans__doc__},
|
||||
|
||||
static PyObject *
|
||||
bytearray_maketrans_impl(Py_buffer *frm, Py_buffer *to);
|
||||
|
||||
static PyObject *
|
||||
bytearray_maketrans(void *null, PyObject *args)
|
||||
bytearray_maketrans(void *null, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
Py_buffer frm = {NULL, NULL};
|
||||
Py_buffer to = {NULL, NULL};
|
||||
|
||||
if (!PyArg_ParseTuple(args, "y*y*:maketrans",
|
||||
if (!_PyArg_ParseStack(args, nargs, "y*y*:maketrans",
|
||||
&frm, &to)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("maketrans", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = bytearray_maketrans_impl(&frm, &to);
|
||||
|
||||
exit:
|
||||
|
@ -141,24 +138,28 @@ PyDoc_STRVAR(bytearray_replace__doc__,
|
|||
"replaced.");
|
||||
|
||||
#define BYTEARRAY_REPLACE_METHODDEF \
|
||||
{"replace", (PyCFunction)bytearray_replace, METH_VARARGS, bytearray_replace__doc__},
|
||||
{"replace", (PyCFunction)bytearray_replace, METH_FASTCALL, bytearray_replace__doc__},
|
||||
|
||||
static PyObject *
|
||||
bytearray_replace_impl(PyByteArrayObject *self, Py_buffer *old,
|
||||
Py_buffer *new, Py_ssize_t count);
|
||||
|
||||
static PyObject *
|
||||
bytearray_replace(PyByteArrayObject *self, PyObject *args)
|
||||
bytearray_replace(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
Py_buffer old = {NULL, NULL};
|
||||
Py_buffer new = {NULL, NULL};
|
||||
Py_ssize_t count = -1;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "y*y*|n:replace",
|
||||
if (!_PyArg_ParseStack(args, nargs, "y*y*|n:replace",
|
||||
&old, &new, &count)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("replace", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = bytearray_replace_impl(self, &old, &new, count);
|
||||
|
||||
exit:
|
||||
|
@ -204,7 +205,7 @@ bytearray_split(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyOb
|
|||
PyObject *sep = Py_None;
|
||||
Py_ssize_t maxsplit = -1;
|
||||
|
||||
if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
|
||||
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
||||
&sep, &maxsplit)) {
|
||||
goto exit;
|
||||
}
|
||||
|
@ -279,7 +280,7 @@ bytearray_rsplit(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyO
|
|||
PyObject *sep = Py_None;
|
||||
Py_ssize_t maxsplit = -1;
|
||||
|
||||
if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
|
||||
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
||||
&sep, &maxsplit)) {
|
||||
goto exit;
|
||||
}
|
||||
|
@ -319,22 +320,26 @@ PyDoc_STRVAR(bytearray_insert__doc__,
|
|||
" The item to be inserted.");
|
||||
|
||||
#define BYTEARRAY_INSERT_METHODDEF \
|
||||
{"insert", (PyCFunction)bytearray_insert, METH_VARARGS, bytearray_insert__doc__},
|
||||
{"insert", (PyCFunction)bytearray_insert, METH_FASTCALL, bytearray_insert__doc__},
|
||||
|
||||
static PyObject *
|
||||
bytearray_insert_impl(PyByteArrayObject *self, Py_ssize_t index, int item);
|
||||
|
||||
static PyObject *
|
||||
bytearray_insert(PyByteArrayObject *self, PyObject *args)
|
||||
bytearray_insert(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
Py_ssize_t index;
|
||||
int item;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "nO&:insert",
|
||||
if (!_PyArg_ParseStack(args, nargs, "nO&:insert",
|
||||
&index, _getbytevalue, &item)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("insert", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = bytearray_insert_impl(self, index, item);
|
||||
|
||||
exit:
|
||||
|
@ -396,21 +401,25 @@ PyDoc_STRVAR(bytearray_pop__doc__,
|
|||
"If no index argument is given, will pop the last item.");
|
||||
|
||||
#define BYTEARRAY_POP_METHODDEF \
|
||||
{"pop", (PyCFunction)bytearray_pop, METH_VARARGS, bytearray_pop__doc__},
|
||||
{"pop", (PyCFunction)bytearray_pop, METH_FASTCALL, bytearray_pop__doc__},
|
||||
|
||||
static PyObject *
|
||||
bytearray_pop_impl(PyByteArrayObject *self, Py_ssize_t index);
|
||||
|
||||
static PyObject *
|
||||
bytearray_pop(PyByteArrayObject *self, PyObject *args)
|
||||
bytearray_pop(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
Py_ssize_t index = -1;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "|n:pop",
|
||||
if (!_PyArg_ParseStack(args, nargs, "|n:pop",
|
||||
&index)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("pop", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = bytearray_pop_impl(self, index);
|
||||
|
||||
exit:
|
||||
|
@ -456,22 +465,26 @@ PyDoc_STRVAR(bytearray_strip__doc__,
|
|||
"If the argument is omitted or None, strip leading and trailing ASCII whitespace.");
|
||||
|
||||
#define BYTEARRAY_STRIP_METHODDEF \
|
||||
{"strip", (PyCFunction)bytearray_strip, METH_VARARGS, bytearray_strip__doc__},
|
||||
{"strip", (PyCFunction)bytearray_strip, METH_FASTCALL, bytearray_strip__doc__},
|
||||
|
||||
static PyObject *
|
||||
bytearray_strip_impl(PyByteArrayObject *self, PyObject *bytes);
|
||||
|
||||
static PyObject *
|
||||
bytearray_strip(PyByteArrayObject *self, PyObject *args)
|
||||
bytearray_strip(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *bytes = Py_None;
|
||||
|
||||
if (!PyArg_UnpackTuple(args, "strip",
|
||||
if (!_PyArg_UnpackStack(args, nargs, "strip",
|
||||
0, 1,
|
||||
&bytes)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("strip", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = bytearray_strip_impl(self, bytes);
|
||||
|
||||
exit:
|
||||
|
@ -487,22 +500,26 @@ PyDoc_STRVAR(bytearray_lstrip__doc__,
|
|||
"If the argument is omitted or None, strip leading ASCII whitespace.");
|
||||
|
||||
#define BYTEARRAY_LSTRIP_METHODDEF \
|
||||
{"lstrip", (PyCFunction)bytearray_lstrip, METH_VARARGS, bytearray_lstrip__doc__},
|
||||
{"lstrip", (PyCFunction)bytearray_lstrip, METH_FASTCALL, bytearray_lstrip__doc__},
|
||||
|
||||
static PyObject *
|
||||
bytearray_lstrip_impl(PyByteArrayObject *self, PyObject *bytes);
|
||||
|
||||
static PyObject *
|
||||
bytearray_lstrip(PyByteArrayObject *self, PyObject *args)
|
||||
bytearray_lstrip(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *bytes = Py_None;
|
||||
|
||||
if (!PyArg_UnpackTuple(args, "lstrip",
|
||||
if (!_PyArg_UnpackStack(args, nargs, "lstrip",
|
||||
0, 1,
|
||||
&bytes)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("lstrip", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = bytearray_lstrip_impl(self, bytes);
|
||||
|
||||
exit:
|
||||
|
@ -518,22 +535,26 @@ PyDoc_STRVAR(bytearray_rstrip__doc__,
|
|||
"If the argument is omitted or None, strip trailing ASCII whitespace.");
|
||||
|
||||
#define BYTEARRAY_RSTRIP_METHODDEF \
|
||||
{"rstrip", (PyCFunction)bytearray_rstrip, METH_VARARGS, bytearray_rstrip__doc__},
|
||||
{"rstrip", (PyCFunction)bytearray_rstrip, METH_FASTCALL, bytearray_rstrip__doc__},
|
||||
|
||||
static PyObject *
|
||||
bytearray_rstrip_impl(PyByteArrayObject *self, PyObject *bytes);
|
||||
|
||||
static PyObject *
|
||||
bytearray_rstrip(PyByteArrayObject *self, PyObject *args)
|
||||
bytearray_rstrip(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *bytes = Py_None;
|
||||
|
||||
if (!PyArg_UnpackTuple(args, "rstrip",
|
||||
if (!_PyArg_UnpackStack(args, nargs, "rstrip",
|
||||
0, 1,
|
||||
&bytes)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("rstrip", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = bytearray_rstrip_impl(self, bytes);
|
||||
|
||||
exit:
|
||||
|
@ -571,7 +592,7 @@ bytearray_decode(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyO
|
|||
const char *encoding = NULL;
|
||||
const char *errors = NULL;
|
||||
|
||||
if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
|
||||
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
||||
&encoding, &errors)) {
|
||||
goto exit;
|
||||
}
|
||||
|
@ -617,7 +638,7 @@ bytearray_splitlines(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs,
|
|||
static _PyArg_Parser _parser = {"|i:splitlines", _keywords, 0};
|
||||
int keepends = 0;
|
||||
|
||||
if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
|
||||
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
||||
&keepends)) {
|
||||
goto exit;
|
||||
}
|
||||
|
@ -682,21 +703,25 @@ PyDoc_STRVAR(bytearray_reduce_ex__doc__,
|
|||
"Return state information for pickling.");
|
||||
|
||||
#define BYTEARRAY_REDUCE_EX_METHODDEF \
|
||||
{"__reduce_ex__", (PyCFunction)bytearray_reduce_ex, METH_VARARGS, bytearray_reduce_ex__doc__},
|
||||
{"__reduce_ex__", (PyCFunction)bytearray_reduce_ex, METH_FASTCALL, bytearray_reduce_ex__doc__},
|
||||
|
||||
static PyObject *
|
||||
bytearray_reduce_ex_impl(PyByteArrayObject *self, int proto);
|
||||
|
||||
static PyObject *
|
||||
bytearray_reduce_ex(PyByteArrayObject *self, PyObject *args)
|
||||
bytearray_reduce_ex(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
int proto = 0;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "|i:__reduce_ex__",
|
||||
if (!_PyArg_ParseStack(args, nargs, "|i:__reduce_ex__",
|
||||
&proto)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!_PyArg_NoStackKeywords("__reduce_ex__", kwnames)) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = bytearray_reduce_ex_impl(self, proto);
|
||||
|
||||
exit:
|
||||
|
@ -720,4 +745,4 @@ bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
|
|||
{
|
||||
return bytearray_sizeof_impl(self);
|
||||
}
|
||||
/*[clinic end generated code: output=8f022100f059226c input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=c1b1b83b0e19df74 input=a9049054013a1b77]*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue