pyodide/cpython/patches/0008-Add-call-to-JsProxy_Ge...

61 lines
1.9 KiB
Diff

From ff4534318481437542f2e49348033a00354a069d Mon Sep 17 00:00:00 2001
From: Hood Chatham <roberthoodchatham@gmail.com>
Date: Thu, 25 Jul 2024 14:41:37 +0200
Subject: [PATCH 8/8] Add call to `JsProxy_GetMethod` to help remove temporary
`_PyObject_GetMethod` is a special attribute lookup function that won't call the
`__get__` descriptor on a method to avoid creating a temporary PyMethodObject.
We also want to optimize away a temporary JsProxy in a special way. In order to
do this, we patch the behavior of `_PyObject_GetMethod` to use
`JsProxy_GetMethod`.
In order to avoid linker errors when used with just Python and not with
libpyodide.a, we declare a dummy JsProxy_GetMethod with weak linkage that does
nothing. When linked to libpyodide.a it will get overridden by the real
function. Otherwise, this patch does nothing.
See the definition of `JsProxy_GetMethod` in `jsproxy.c` and particularly
`JsMethodCallSingleton` for how this is used.
---
Objects/object.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/Objects/object.c b/Objects/object.c
index 6b2e0aeaab9..9240b33b08a 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1280,6 +1280,18 @@ _PyObject_NextNotImplemented(PyObject *self)
}
+
+PyObject* __attribute__((weak))
+JsProxy_GetAttr(PyObject* self, PyObject* attr) {
+ return NULL;
+}
+
+PyObject* __attribute__((weak))
+JsProxy_GetMethod(PyObject* obj, PyObject* name) {
+ return NULL;
+}
+
+
/* Specialized version of _PyObject_GenericGetAttrWithDict
specifically for the LOAD_METHOD opcode.
@@ -1304,6 +1316,11 @@ _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method)
}
}
+ if (tp->tp_getattro == JsProxy_GetAttr) {
+ *method = JsProxy_GetMethod(obj, name);
+ return 0;
+ }
+
if (tp->tp_getattro != PyObject_GenericGetAttr || !PyUnicode_CheckExact(name)) {
*method = PyObject_GetAttr(obj, name);
return 0;
--
2.34.1