[Python-checkins] bpo-44661: Update property_descr_set to use vectorcall if possible. (GH-27206)

corona10 webhook-mailer at python.org
Mon Jul 19 06:13:32 EDT 2021


https://github.com/python/cpython/commit/635bfe8162981332b36cc556bac78e869af579c2
commit: 635bfe8162981332b36cc556bac78e869af579c2
branch: main
author: Dong-hee Na <donghee.na at python.org>
committer: corona10 <donghee.na92 at gmail.com>
date: 2021-07-19T19:13:27+09:00
summary:

bpo-44661: Update property_descr_set to use vectorcall if possible. (GH-27206)

files:
A Misc/NEWS.d/next/Core and Builtins/2021-07-17-14-20-59.bpo-44661.BQbXiH.rst
M Objects/descrobject.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-07-17-14-20-59.bpo-44661.BQbXiH.rst b/Misc/NEWS.d/next/Core and Builtins/2021-07-17-14-20-59.bpo-44661.BQbXiH.rst
new file mode 100644
index 0000000000000..bafa98e5826cd
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2021-07-17-14-20-59.bpo-44661.BQbXiH.rst	
@@ -0,0 +1,2 @@
+Update ``property_descr_set`` to use vectorcall if possible. Patch by Dong-hee
+Na.
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index 57a9607d10c31..0565992bdb79f 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -1614,10 +1614,13 @@ property_descr_set(PyObject *self, PyObject *obj, PyObject *value)
     propertyobject *gs = (propertyobject *)self;
     PyObject *func, *res;
 
-    if (value == NULL)
+    if (value == NULL) {
         func = gs->prop_del;
-    else
+    }
+    else {
         func = gs->prop_set;
+    }
+
     if (func == NULL) {
         if (gs->prop_name != NULL) {
             PyErr_Format(PyExc_AttributeError,
@@ -1625,7 +1628,8 @@ property_descr_set(PyObject *self, PyObject *obj, PyObject *value)
                         "can't delete attribute %R" :
                         "can't set attribute %R",
                         gs->prop_name);
-        } else {
+        }
+        else {
             PyErr_SetString(PyExc_AttributeError,
                             value == NULL ?
                             "can't delete attribute" :
@@ -1633,12 +1637,19 @@ property_descr_set(PyObject *self, PyObject *obj, PyObject *value)
         }
         return -1;
     }
-    if (value == NULL)
+
+    if (value == NULL) {
         res = PyObject_CallOneArg(func, obj);
-    else
-        res = PyObject_CallFunctionObjArgs(func, obj, value, NULL);
-    if (res == NULL)
+    }
+    else {
+        PyObject *args[] = { obj, value };
+        res = PyObject_Vectorcall(func, args, 2, NULL);
+    }
+
+    if (res == NULL) {
         return -1;
+    }
+
     Py_DECREF(res);
     return 0;
 }



More information about the Python-checkins mailing list