]> granicus.if.org Git - python/commitdiff
Issue #27809: Use _PyObject_FastCallDict()
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 22 Aug 2016 21:33:13 +0000 (23:33 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 22 Aug 2016 21:33:13 +0000 (23:33 +0200)
Modify:

* init_subclass()
* builtin___build_class__()

Fix also a bug in init_subclass(): check for super() failure.

Objects/typeobject.c
Python/bltinmodule.c

index 544d0b5f4ede26f937ce38f1df34377a81c0f4f6..63bfd66747739bb4aaf426e1f5b6610bb2666459 100644 (file)
@@ -7007,30 +7007,28 @@ set_names(PyTypeObject *type)
 static int
 init_subclass(PyTypeObject *type, PyObject *kwds)
 {
-    PyObject *super, *func, *tmp, *tuple;
+    PyObject *super, *func, *result;
+    PyObject *args[2] = {(PyObject *)type, (PyObject *)type};
+
+    super = _PyObject_FastCall((PyObject *)&PySuper_Type, args, 2);
+    if (super == NULL) {
+        return -1;
+    }
 
-    super = PyObject_CallFunctionObjArgs((PyObject *) &PySuper_Type,
-                                         type, type, NULL);
     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);
-    Py_DECREF(func);
 
-    if (tmp == NULL)
+    result = _PyObject_FastCallDict(func, NULL, 0, kwds);
+    Py_DECREF(func);
+    if (result == NULL) {
         return -1;
+    }
 
-    Py_DECREF(tmp);
+    Py_DECREF(result);
     return 0;
 }
 
index 1cdc0e2563a6b2264dd4464f728ba35b42721d02..b22867eb073f420f1b9a1d84e3ff72556612dbd2 100644 (file)
@@ -155,16 +155,8 @@ builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
         }
     }
     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) {