(original) (raw)

changeset: 102846:5587d0dfab4c user: Victor Stinner victor.stinner@gmail.com date: Mon Aug 22 23:33:13 2016 +0200 files: Objects/typeobject.c Python/bltinmodule.c description: Issue #27809: Use _PyObject_FastCallDict() Modify: * init_subclass() * builtin___build_class__() Fix also a bug in init_subclass(): check for super() failure. diff -r ef0110a52e24 -r 5587d0dfab4c Objects/typeobject.c --- a/Objects/typeobject.c Mon Aug 22 23:26:00 2016 +0200 +++ b/Objects/typeobject.c Mon Aug 22 23:33:13 2016 +0200 @@ -7007,30 +7007,28 @@ static int init_subclass(PyTypeObject *type, PyObject *kwds) { - PyObject *super, *func, *tmp, *tuple; - - super = PyObject_CallFunctionObjArgs((PyObject *) &PySuper_Type, - type, type, NULL); + PyObject *super, *func, *result; + PyObject *args[2] = {(PyObject *)type, (PyObject *)type}; + + super = _PyObject_FastCall((PyObject *)&PySuper_Type, args, 2); + if (super == NULL) { + return -1; + } + func = _PyObject_GetAttrId(super, &PyId___init_subclass__); Py_DECREF(super); - - if (func == NULL) + if (func == NULL) { return -1; - - tuple = PyTuple_New(0); - if (tuple == NULL) { - Py_DECREF(func); - return 0; - } - - tmp = PyObject_Call(func, tuple, kwds); - Py_DECREF(tuple); + } + + + result = _PyObject_FastCallDict(func, NULL, 0, kwds); Py_DECREF(func); - - if (tmp == NULL) + if (result == NULL) { return -1; - - Py_DECREF(tmp); + } + + Py_DECREF(result); return 0; } diff -r ef0110a52e24 -r 5587d0dfab4c Python/bltinmodule.c --- a/Python/bltinmodule.c Mon Aug 22 23:26:00 2016 +0200 +++ b/Python/bltinmodule.c Mon Aug 22 23:33:13 2016 +0200 @@ -155,16 +155,8 @@ } } else { - PyObject *pargs = PyTuple_Pack(2, name, bases); - if (pargs == NULL) { - Py_DECREF(prep); - Py_DECREF(meta); - Py_XDECREF(mkw); - Py_DECREF(bases); - return NULL; - } - ns = PyEval_CallObjectWithKeywords(prep, pargs, mkw); - Py_DECREF(pargs); + PyObject *pargs[2] = {name, bases}; + ns = _PyObject_FastCallDict(prep, pargs, 2, mkw); Py_DECREF(prep); } if (ns == NULL) { /victor.stinner@gmail.com