summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2024-06-18 11:17:46 (GMT)
committerGitHub <noreply@github.com>2024-06-18 11:17:46 (GMT)
commit9cefcc0ee781a1bef9e0685c2271237005fb488b (patch)
tree7c02067f4e021d90ec4fd850d9a06315b8fc39ab /Objects
parent73dc1c678eb720c2ced94d2f435a908bb6d18566 (diff)
downloadcpython-9cefcc0ee781a1bef9e0685c2271237005fb488b.zip
cpython-9cefcc0ee781a1bef9e0685c2271237005fb488b.tar.gz
cpython-9cefcc0ee781a1bef9e0685c2271237005fb488b.tar.bz2
GH-120507: Lower the `BEFORE_WITH` and `BEFORE_ASYNC_WITH` instructions. (#120640)
* Remove BEFORE_WITH and BEFORE_ASYNC_WITH instructions. * Add LOAD_SPECIAL instruction * Reimplement `with` and `async with` statements using LOAD_SPECIAL
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 958f424..a380e74 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2705,6 +2705,34 @@ _PyObject_LookupSpecial(PyObject *self, PyObject *attr)
return res;
}
+/* Steals a reference to self */
+PyObject *
+_PyObject_LookupSpecialMethod(PyObject *self, PyObject *attr, PyObject **self_or_null)
+{
+ PyObject *res;
+
+ res = _PyType_LookupRef(Py_TYPE(self), attr);
+ if (res == NULL) {
+ Py_DECREF(self);
+ *self_or_null = NULL;
+ return NULL;
+ }
+
+ if (_PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR)) {
+ /* Avoid temporary PyMethodObject */
+ *self_or_null = self;
+ }
+ else {
+ descrgetfunc f = Py_TYPE(res)->tp_descr_get;
+ if (f != NULL) {
+ Py_SETREF(res, f(res, self, (PyObject *)(Py_TYPE(self))));
+ }
+ *self_or_null = NULL;
+ Py_DECREF(self);
+ }
+ return res;
+}
+
PyObject *
_PyObject_LookupSpecialId(PyObject *self, _Py_Identifier *attrid)
{