diff --git a/third_party/python/Objects/dictobject.c b/third_party/python/Objects/dictobject.c index 6b25758d8..965e5173e 100644 --- a/third_party/python/Objects/dictobject.c +++ b/third_party/python/Objects/dictobject.c @@ -2911,7 +2911,7 @@ dict___contains__(PyDictObject *self, PyObject *key) } static PyObject * -dict_get(PyDictObject *mp, PyObject *args) +dict_get(PyDictObject *mp, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *key; PyObject *failobj = Py_None; @@ -2920,7 +2920,10 @@ dict_get(PyDictObject *mp, PyObject *args) Py_ssize_t ix; PyObject **value_addr; - if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &failobj)) + if (!_PyArg_UnpackStack(args, nargs, "get", 1, 2, &key, &failobj)) + return NULL; + + if (!_PyArg_NoStackKeywords("get", kwnames)) return NULL; if (!PyUnicode_CheckExact(key) || @@ -3029,14 +3032,17 @@ PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *defaultobj) } static PyObject * -dict_setdefault(PyDictObject *mp, PyObject *args) +dict_setdefault(PyDictObject *mp, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *key, *val; PyObject *defaultobj = Py_None; - if (!PyArg_UnpackTuple(args, "setdefault", 1, 2, &key, &defaultobj)) + if (!_PyArg_UnpackStack(args, nargs, "setdefault", 1, 2, &key, &defaultobj)) return NULL; + if(!_PyArg_NoStackKeywords("pop", kwnames)) + return NULL; + val = PyDict_SetDefault((PyObject *)mp, key, defaultobj); Py_XINCREF(val); return val; @@ -3050,11 +3056,14 @@ dict_clear(PyDictObject *mp) } static PyObject * -dict_pop(PyDictObject *mp, PyObject *args) +dict_pop(PyDictObject *mp, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *key, *deflt = NULL; - if(!PyArg_UnpackTuple(args, "pop", 1, 2, &key, &deflt)) + if(!_PyArg_UnpackStack(args, nargs, "pop", 1, 2, &key, &deflt)) + return NULL; + + if(!_PyArg_NoStackKeywords("pop", kwnames)) return NULL; return _PyDict_Pop((PyObject*)mp, key, deflt); @@ -3243,11 +3252,11 @@ static PyMethodDef mapp_methods[] = { getitem__doc__}, {"__sizeof__", (PyCFunction)dict_sizeof, METH_NOARGS, sizeof__doc__}, - {"get", (PyCFunction)dict_get, METH_VARARGS, + {"get", (PyCFunction)dict_get, METH_FASTCALL, get__doc__}, - {"setdefault", (PyCFunction)dict_setdefault, METH_VARARGS, + {"setdefault", (PyCFunction)dict_setdefault, METH_FASTCALL, setdefault_doc__}, - {"pop", (PyCFunction)dict_pop, METH_VARARGS, + {"pop", (PyCFunction)dict_pop, METH_FASTCALL, pop__doc__}, {"popitem", (PyCFunction)dict_popitem, METH_NOARGS, popitem__doc__}, diff --git a/third_party/python/Objects/fileobject.c b/third_party/python/Objects/fileobject.c index f0d65bb80..516033fbf 100644 --- a/third_party/python/Objects/fileobject.c +++ b/third_party/python/Objects/fileobject.c @@ -364,7 +364,7 @@ PyFile_NewStdPrinter(int fd) } static PyObject * -stdprinter_write(PyStdPrinter_Object *self, PyObject *args) +stdprinter_write(PyStdPrinter_Object *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *unicode; PyObject *bytes = NULL; @@ -380,7 +380,10 @@ stdprinter_write(PyStdPrinter_Object *self, PyObject *args) Py_RETURN_NONE; } - if (!PyArg_ParseTuple(args, "U", &unicode)) + if (!_PyArg_UnpackStack(args, nargs, "write", 1, 1, &unicode)) + return NULL; + + if(!_PyArg_NoStackKeywords("write", kwnames)) return NULL; /* encode Unicode to UTF-8 */ @@ -452,7 +455,7 @@ static PyMethodDef stdprinter_methods[] = { {"flush", (PyCFunction)stdprinter_noop, METH_NOARGS, ""}, {"fileno", (PyCFunction)stdprinter_fileno, METH_NOARGS, ""}, {"isatty", (PyCFunction)stdprinter_isatty, METH_NOARGS, ""}, - {"write", (PyCFunction)stdprinter_write, METH_VARARGS, ""}, + {"write", (PyCFunction)stdprinter_write, METH_FASTCALL, ""}, {NULL, NULL} /*sentinel */ }; diff --git a/third_party/python/Objects/floatobject.c b/third_party/python/Objects/floatobject.c index 7520a2661..6be701013 100644 --- a/third_party/python/Objects/floatobject.c +++ b/third_party/python/Objects/floatobject.c @@ -1038,15 +1038,19 @@ double_round(double x, int ndigits) { /* round a Python float v to the closest multiple of 10**-ndigits */ static PyObject * -float_round(PyObject *v, PyObject *args) +float_round(PyObject *v, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { double x, rounded; PyObject *o_ndigits = NULL; Py_ssize_t ndigits; x = PyFloat_AsDouble(v); - if (!PyArg_ParseTuple(args, "|O", &o_ndigits)) + if (!_PyArg_UnpackStack(args, nargs, "__round__", 0, 1, &o_ndigits)) return NULL; + + if(!_PyArg_NoStackKeywords("__round__", kwnames)) + return NULL; + if (o_ndigits == NULL || o_ndigits == Py_None) { /* single-argument round or with None ndigits: * round to nearest integer */ @@ -1762,13 +1766,16 @@ float_getzero(PyObject *v, void *closure) } static PyObject * -float__format__(PyObject *self, PyObject *args) +float__format__(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *format_spec; _PyUnicodeWriter writer; int ret; - if (!PyArg_ParseTuple(args, "U:__format__", &format_spec)) + if (!_PyArg_ParseStack(args, nargs, "U:__format__", &format_spec)) + return NULL; + + if(!_PyArg_NoStackKeywords("__format__", kwnames)) return NULL; _PyUnicodeWriter_Init(&writer); @@ -1794,7 +1801,7 @@ static PyMethodDef float_methods[] = { "Return self, the complex conjugate of any float."}, {"__trunc__", (PyCFunction)float_trunc, METH_NOARGS, "Return the Integral closest to x between 0 and x."}, - {"__round__", (PyCFunction)float_round, METH_VARARGS, + {"__round__", (PyCFunction)float_round, METH_FASTCALL, "Return the Integral closest to x, rounding half toward even.\n" "When an argument is passed, work like built-in round(x, ndigits)."}, {"as_integer_ratio", (PyCFunction)float_as_integer_ratio, METH_NOARGS, @@ -1819,7 +1826,7 @@ static PyMethodDef float_methods[] = { {"__setformat__", (PyCFunction)float_setformat, METH_VARARGS|METH_CLASS, float_setformat_doc}, {"__format__", (PyCFunction)float__format__, - METH_VARARGS, float__format__doc}, + METH_FASTCALL, float__format__doc}, {NULL, NULL} /* sentinel */ }; diff --git a/third_party/python/Objects/listobject.c b/third_party/python/Objects/listobject.c index 0c83c7247..357e76e77 100644 --- a/third_party/python/Objects/listobject.c +++ b/third_party/python/Objects/listobject.c @@ -755,11 +755,12 @@ list_ass_item(PyListObject *a, Py_ssize_t i, PyObject *v) } static PyObject * -listinsert(PyListObject *self, PyObject *args) +listinsert(PyListObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { Py_ssize_t i; PyObject *v; - if (!PyArg_ParseTuple(args, "nO:insert", &i, &v)) + if (!_PyArg_ParseStack(args, nargs, "nO:insert", &i, &v) + || !_PyArg_NoStackKeywords("insert", kwnames)) return NULL; if (ins1(self, i, v) == 0) Py_RETURN_NONE; @@ -920,13 +921,14 @@ list_inplace_concat(PyListObject *self, PyObject *other) } static PyObject * -listpop(PyListObject *self, PyObject *args) +listpop(PyListObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { Py_ssize_t i = -1; PyObject *v; int status; - if (!PyArg_ParseTuple(args, "|n:pop", &i)) + if (!_PyArg_ParseStack(args, nargs, "|n:pop", &i) + || !_PyArg_NoStackKeywords("pop", kwnames)) return NULL; if (Py_SIZE(self) == 0) { @@ -2384,9 +2386,9 @@ static PyMethodDef list_methods[] = { {"clear", (PyCFunction)listclear, METH_NOARGS, clear_doc}, {"copy", (PyCFunction)listcopy, METH_NOARGS, copy_doc}, {"append", (PyCFunction)listappend, METH_O, append_doc}, - {"insert", (PyCFunction)listinsert, METH_VARARGS, insert_doc}, + {"insert", (PyCFunction)listinsert, METH_FASTCALL, insert_doc}, {"extend", (PyCFunction)listextend, METH_O, extend_doc}, - {"pop", (PyCFunction)listpop, METH_VARARGS, pop_doc}, + {"pop", (PyCFunction)listpop, METH_FASTCALL, pop_doc}, {"remove", (PyCFunction)listremove, METH_O, remove_doc}, {"index", (PyCFunction)listindex, METH_VARARGS, index_doc}, {"count", (PyCFunction)listcount, METH_O, count_doc}, diff --git a/third_party/python/Objects/longobject.c b/third_party/python/Objects/longobject.c index 5d4257e76..141ac4000 100644 --- a/third_party/python/Objects/longobject.c +++ b/third_party/python/Objects/longobject.c @@ -4907,13 +4907,13 @@ long_get1(PyLongObject *v, void *context) { } static PyObject * -long__format__(PyObject *self, PyObject *args) +long__format__(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *format_spec; _PyUnicodeWriter writer; int ret; - if (!PyArg_ParseTuple(args, "U:__format__", &format_spec)) + if (!_PyArg_ParseStack(args, nargs, "U:__format__", &format_spec)) return NULL; _PyUnicodeWriter_Init(&writer); @@ -5026,7 +5026,7 @@ _PyLong_DivmodNear(PyObject *a, PyObject *b) } static PyObject * -long_round(PyObject *self, PyObject *args) +long_round(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *o_ndigits=NULL, *temp, *result, *ndigits; @@ -5044,7 +5044,7 @@ long_round(PyObject *self, PyObject *args) * * m - divmod_near(m, 10**n)[1]. */ - if (!PyArg_ParseTuple(args, "|O", &o_ndigits)) + if (!_PyArg_ParseStack(args, nargs, "|O", &o_ndigits)) return NULL; if (o_ndigits == NULL) return long_long(self); @@ -5368,11 +5368,11 @@ static PyMethodDef long_methods[] = { "Flooring an Integral returns itself."}, {"__ceil__", (PyCFunction)long_long, METH_NOARGS, "Ceiling of an Integral returns itself."}, - {"__round__", (PyCFunction)long_round, METH_VARARGS, + {"__round__", (PyCFunction)long_round, METH_FASTCALL, "Rounding an Integral returns itself.\n" "Rounding with an ndigits argument also returns an integer."}, {"__getnewargs__", (PyCFunction)long_getnewargs, METH_NOARGS}, - {"__format__", (PyCFunction)long__format__, METH_VARARGS}, + {"__format__", (PyCFunction)long__format__, METH_FASTCALL}, {"__sizeof__", (PyCFunction)long_sizeof, METH_NOARGS, "Returns size in memory, in bytes"}, {NULL, NULL} /* sentinel */ diff --git a/third_party/python/Python/bltinmodule.c b/third_party/python/Python/bltinmodule.c index d1241d6a7..a59c05ea5 100644 --- a/third_party/python/Python/bltinmodule.c +++ b/third_party/python/Python/bltinmodule.c @@ -406,15 +406,16 @@ PyDoc_STRVAR(build_class_doc, Internal helper function used by the class statement."); static PyObject * -builtin___import__(PyObject *self, PyObject *args, PyObject *kwds) +builtin___import__(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwds) { - static char *kwlist[] = {"name", "globals", "locals", "fromlist", + static const char * const kwlist[] = {"name", "globals", "locals", "fromlist", "level", 0}; PyObject *name, *globals = NULL, *locals = NULL, *fromlist = NULL; int level = 0; + static _PyArg_Parser _parser = {"U|OOOi:__import__", kwlist, 0}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "U|OOOi:__import__", - kwlist, &name, &globals, &locals, &fromlist, &level)) + if (!_PyArg_ParseStackAndKeywords(args, nargs, kwds, &_parser, + &name, &globals, &locals, &fromlist, &level)) return NULL; return PyImport_ImportModuleLevelObject(name, globals, locals, fromlist, level); @@ -973,11 +974,13 @@ finally: /* AC: cannot convert yet, as needs PEP 457 group support in inspect */ static PyObject * -builtin_dir(PyObject *self, PyObject *args) +builtin_dir(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *arg = NULL; - if (!PyArg_UnpackTuple(args, "dir", 0, 1, &arg)) + if (!_PyArg_UnpackStack(args, nargs, "dir", 0, 1, &arg)) + return NULL; + if (!_PyArg_NoStackKeywords("dir", kwnames)) return NULL; return PyObject_Dir(arg); } @@ -1640,11 +1643,13 @@ builtin_hex(PyObject *module, PyObject *number) /* AC: cannot convert yet, as needs PEP 457 group support in inspect */ static PyObject * -builtin_iter(PyObject *self, PyObject *args) +builtin_iter(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *v, *w = NULL; - if (!PyArg_UnpackTuple(args, "iter", 1, 2, &v, &w)) + if (!_PyArg_UnpackStack(args, nargs, "iter", 1, 2, &v, &w)) + return NULL; + if(!_PyArg_NoStackKeywords("iter", kwnames)) return NULL; if (w == NULL) return PyObject_GetIter(v); @@ -2367,12 +2372,14 @@ builtin_sorted(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwna /* AC: cannot convert yet, as needs PEP 457 group support in inspect */ static PyObject * -builtin_vars(PyObject *self, PyObject *args) +builtin_vars(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *v = NULL; PyObject *d; - if (!PyArg_UnpackTuple(args, "vars", 0, 1, &v)) + if (!_PyArg_UnpackStack(args, nargs, "vars", 0, 1, &v)) + return NULL; + if(!_PyArg_NoStackKeywords("vars", kwnames)) return NULL; if (v == NULL) { d = PyEval_GetLocals(); @@ -2828,7 +2835,7 @@ PyTypeObject PyZip_Type = { static PyMethodDef builtin_methods[] = { {"__build_class__", (PyCFunction)builtin___build_class__, METH_FASTCALL, build_class_doc}, - {"__import__", (PyCFunction)builtin___import__, METH_VARARGS | METH_KEYWORDS, import_doc}, + {"__import__", (PyCFunction)builtin___import__, METH_FASTCALL, import_doc}, BUILTIN_ABS_METHODDEF BUILTIN_ALL_METHODDEF BUILTIN_ANY_METHODDEF @@ -2838,7 +2845,7 @@ static PyMethodDef builtin_methods[] = { BUILTIN_CHR_METHODDEF BUILTIN_COMPILE_METHODDEF BUILTIN_DELATTR_METHODDEF - {"dir", builtin_dir, METH_VARARGS, dir_doc}, + {"dir", (PyCFunction)builtin_dir, METH_FASTCALL, dir_doc}, BUILTIN_DIVMOD_METHODDEF BUILTIN_EVAL_METHODDEF BUILTIN_EXEC_METHODDEF @@ -2852,7 +2859,7 @@ static PyMethodDef builtin_methods[] = { BUILTIN_INPUT_METHODDEF BUILTIN_ISINSTANCE_METHODDEF BUILTIN_ISSUBCLASS_METHODDEF - {"iter", builtin_iter, METH_VARARGS, iter_doc}, + {"iter", (PyCFunction)builtin_iter, METH_FASTCALL, iter_doc}, BUILTIN_LEN_METHODDEF BUILTIN_LOCALS_METHODDEF {"max", (PyCFunction)builtin_max, METH_VARARGS | METH_KEYWORDS, max_doc}, @@ -2867,7 +2874,7 @@ static PyMethodDef builtin_methods[] = { BUILTIN_SETATTR_METHODDEF BUILTIN_SORTED_METHODDEF BUILTIN_SUM_METHODDEF - {"vars", builtin_vars, METH_VARARGS, vars_doc}, + {"vars", (PyCFunction)builtin_vars, METH_FASTCALL, vars_doc}, {NULL, NULL}, }; diff --git a/third_party/python/Python/marshal.c b/third_party/python/Python/marshal.c index 238bd4770..454c01718 100644 --- a/third_party/python/Python/marshal.c +++ b/third_party/python/Python/marshal.c @@ -1688,7 +1688,7 @@ PyMarshal_WriteObjectToString(PyObject *x, int version) /* And an interface for Python programs... */ static PyObject * -marshal_dump(PyObject *self, PyObject *args) +marshal_dump(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { /* XXX Quick hack -- need to do this differently */ PyObject *x; @@ -1698,8 +1698,11 @@ marshal_dump(PyObject *self, PyObject *args) PyObject *res; _Py_IDENTIFIER(write); - if (!PyArg_ParseTuple(args, "OO|i:dump", &x, &f, &version)) + if (!_PyArg_ParseStack(args, nargs, "OO|i:dump", &x, &f, &version)) return NULL; + if (!_PyArg_NoStackKeywords("dump", kwnames)) + return NULL; + s = PyMarshal_WriteObjectToString(x, version); if (s == NULL) return NULL; @@ -1775,11 +1778,13 @@ dump(), load() will substitute None for the unmarshallable type."); static PyObject * -marshal_dumps(PyObject *self, PyObject *args) +marshal_dumps(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *x; int version = Py_MARSHAL_VERSION; - if (!PyArg_ParseTuple(args, "O|i:dumps", &x, &version)) + if (!_PyArg_ParseStack(args, nargs, "O|i:dumps", &x, &version)) + return NULL; + if(!_PyArg_NoStackKeywords("dumps", kwnames)) return NULL; return PyMarshal_WriteObjectToString(x, version); } @@ -1795,14 +1800,16 @@ The version argument indicates the data format that dumps should use."); static PyObject * -marshal_loads(PyObject *self, PyObject *args) +marshal_loads(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { RFILE rf; Py_buffer p; char *s; Py_ssize_t n; PyObject* result; - if (!PyArg_ParseTuple(args, "y*:loads", &p)) + if (!_PyArg_ParseStack(args, nargs, "y*:loads", &p)) + return NULL; + if(!_PyArg_NoStackKeywords("loads", kwnames)) return NULL; s = p.buf; n = p.len; @@ -1828,10 +1835,10 @@ raise EOFError, ValueError or TypeError. Extra bytes in the input are\n\ ignored."); static PyMethodDef marshal_methods[] = { - {"dump", marshal_dump, METH_VARARGS, dump_doc}, + {"dump", (PyCFunction)marshal_dump, METH_FASTCALL, dump_doc}, {"load", marshal_load, METH_O, load_doc}, - {"dumps", marshal_dumps, METH_VARARGS, dumps_doc}, - {"loads", marshal_loads, METH_VARARGS, loads_doc}, + {"dumps", (PyCFunction)marshal_dumps, METH_FASTCALL, dumps_doc}, + {"loads", (PyCFunction)marshal_loads, METH_FASTCALL, loads_doc}, {NULL, NULL} /* sentinel */ };