Skip to content

Commit 773dc6d

Browse files
committed
__build_class__() builtin uses METH_FASTCALL
1 parent 69de71b commit 773dc6d

1 file changed

Lines changed: 9 additions & 15 deletions

File tree

Python/bltinmodule.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,51 +52,45 @@ _Py_IDENTIFIER(stderr);
5252

5353
/* AC: cannot convert yet, waiting for *args support */
5454
static PyObject *
55-
builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
55+
builtin___build_class__(PyObject *self, PyObject **args, Py_ssize_t nargs,
56+
PyObject *kwnames)
5657
{
5758
PyObject *func, *name, *bases, *mkw, *meta, *winner, *prep, *ns;
5859
PyObject *cls = NULL, *cell = NULL;
59-
Py_ssize_t nargs;
6060
int isclass = 0; /* initialize to prevent gcc warning */
6161

62-
assert(args != NULL);
63-
if (!PyTuple_Check(args)) {
64-
PyErr_SetString(PyExc_TypeError,
65-
"__build_class__: args is not a tuple");
66-
return NULL;
67-
}
68-
nargs = PyTuple_GET_SIZE(args);
6962
if (nargs < 2) {
7063
PyErr_SetString(PyExc_TypeError,
7164
"__build_class__: not enough arguments");
7265
return NULL;
7366
}
74-
func = PyTuple_GET_ITEM(args, 0); /* Better be callable */
67+
func = args[0]; /* Better be callable */
7568
if (!PyFunction_Check(func)) {
7669
PyErr_SetString(PyExc_TypeError,
7770
"__build_class__: func must be a function");
7871
return NULL;
7972
}
80-
name = PyTuple_GET_ITEM(args, 1);
73+
name = args[1];
8174
if (!PyUnicode_Check(name)) {
8275
PyErr_SetString(PyExc_TypeError,
8376
"__build_class__: name is not a string");
8477
return NULL;
8578
}
86-
bases = PyTuple_GetSlice(args, 2, nargs);
79+
bases = _PyStack_AsTupleSlice(args, nargs, 2, nargs);
8780
if (bases == NULL)
8881
return NULL;
8982

90-
if (kwds == NULL) {
83+
if (kwnames == NULL) {
9184
meta = NULL;
9285
mkw = NULL;
9386
}
9487
else {
95-
mkw = PyDict_Copy(kwds); /* Don't modify kwds passed in! */
88+
mkw = _PyStack_AsDict(args + nargs, kwnames);
9689
if (mkw == NULL) {
9790
Py_DECREF(bases);
9891
return NULL;
9992
}
93+
10094
meta = _PyDict_GetItemId(mkw, &PyId_metaclass);
10195
if (meta != NULL) {
10296
Py_INCREF(meta);
@@ -2612,7 +2606,7 @@ PyTypeObject PyZip_Type = {
26122606

26132607
static PyMethodDef builtin_methods[] = {
26142608
{"__build_class__", (PyCFunction)builtin___build_class__,
2615-
METH_VARARGS | METH_KEYWORDS, build_class_doc},
2609+
METH_FASTCALL, build_class_doc},
26162610
{"__import__", (PyCFunction)builtin___import__, METH_VARARGS | METH_KEYWORDS, import_doc},
26172611
BUILTIN_ABS_METHODDEF
26182612
BUILTIN_ALL_METHODDEF

0 commit comments

Comments
 (0)