summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>2022-08-17 11:37:07 (GMT)
committerGitHub <noreply@github.com>2022-08-17 11:37:07 (GMT)
commit7276ca25f5f1440aa4d025350d3de15141854dde (patch)
tree253f8e34893018705c9f04810d68e2d798c1bd24 /Include
parent36517101dd80cae93da379e95e98a688c52935b7 (diff)
downloadcpython-7276ca25f5f1440aa4d025350d3de15141854dde.zip
cpython-7276ca25f5f1440aa4d025350d3de15141854dde.tar.gz
cpython-7276ca25f5f1440aa4d025350d3de15141854dde.tar.bz2
GH-93911: Specialize `LOAD_ATTR` for custom `__getattribute__` (GH-93988)
Diffstat (limited to 'Include')
-rw-r--r--Include/internal/pycore_code.h1
-rw-r--r--Include/internal/pycore_opcode.h24
-rw-r--r--Include/internal/pycore_typeobject.h3
-rw-r--r--Include/opcode.h59
4 files changed, 46 insertions, 41 deletions
diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h
index 61e40eb..7d5fe94 100644
--- a/Include/internal/pycore_code.h
+++ b/Include/internal/pycore_code.h
@@ -118,6 +118,7 @@ struct callable_cache {
PyObject *isinstance;
PyObject *len;
PyObject *list_append;
+ PyObject *object__getattribute__;
};
/* "Locals plus" for a code object is the set of locals + cell vars +
diff --git a/Include/internal/pycore_opcode.h b/Include/internal/pycore_opcode.h
index 90bf5bb..6906cd5 100644
--- a/Include/internal/pycore_opcode.h
+++ b/Include/internal/pycore_opcode.h
@@ -152,6 +152,7 @@ const uint8_t _PyOpcode_Deopt[256] = {
[LOAD_ATTR] = LOAD_ATTR,
[LOAD_ATTR_ADAPTIVE] = LOAD_ATTR,
[LOAD_ATTR_CLASS] = LOAD_ATTR,
+ [LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN] = LOAD_ATTR,
[LOAD_ATTR_INSTANCE_VALUE] = LOAD_ATTR,
[LOAD_ATTR_METHOD_LAZY_DICT] = LOAD_ATTR,
[LOAD_ATTR_METHOD_NO_DICT] = LOAD_ATTR,
@@ -315,20 +316,20 @@ static const char *const _PyOpcode_OpName[267] = {
[PRINT_EXPR] = "PRINT_EXPR",
[LOAD_BUILD_CLASS] = "LOAD_BUILD_CLASS",
[LOAD_ATTR_CLASS] = "LOAD_ATTR_CLASS",
- [LOAD_ATTR_INSTANCE_VALUE] = "LOAD_ATTR_INSTANCE_VALUE",
+ [LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN] = "LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN",
[LOAD_ASSERTION_ERROR] = "LOAD_ASSERTION_ERROR",
[RETURN_GENERATOR] = "RETURN_GENERATOR",
+ [LOAD_ATTR_INSTANCE_VALUE] = "LOAD_ATTR_INSTANCE_VALUE",
[LOAD_ATTR_MODULE] = "LOAD_ATTR_MODULE",
[LOAD_ATTR_PROPERTY] = "LOAD_ATTR_PROPERTY",
[LOAD_ATTR_SLOT] = "LOAD_ATTR_SLOT",
[LOAD_ATTR_WITH_HINT] = "LOAD_ATTR_WITH_HINT",
[LOAD_ATTR_METHOD_LAZY_DICT] = "LOAD_ATTR_METHOD_LAZY_DICT",
- [LOAD_ATTR_METHOD_NO_DICT] = "LOAD_ATTR_METHOD_NO_DICT",
[LIST_TO_TUPLE] = "LIST_TO_TUPLE",
[RETURN_VALUE] = "RETURN_VALUE",
[IMPORT_STAR] = "IMPORT_STAR",
[SETUP_ANNOTATIONS] = "SETUP_ANNOTATIONS",
- [LOAD_ATTR_METHOD_WITH_DICT] = "LOAD_ATTR_METHOD_WITH_DICT",
+ [LOAD_ATTR_METHOD_NO_DICT] = "LOAD_ATTR_METHOD_NO_DICT",
[ASYNC_GEN_WRAP] = "ASYNC_GEN_WRAP",
[PREP_RERAISE_STAR] = "PREP_RERAISE_STAR",
[POP_EXCEPT] = "POP_EXCEPT",
@@ -355,7 +356,7 @@ static const char *const _PyOpcode_OpName[267] = {
[JUMP_FORWARD] = "JUMP_FORWARD",
[JUMP_IF_FALSE_OR_POP] = "JUMP_IF_FALSE_OR_POP",
[JUMP_IF_TRUE_OR_POP] = "JUMP_IF_TRUE_OR_POP",
- [LOAD_ATTR_METHOD_WITH_VALUES] = "LOAD_ATTR_METHOD_WITH_VALUES",
+ [LOAD_ATTR_METHOD_WITH_DICT] = "LOAD_ATTR_METHOD_WITH_DICT",
[POP_JUMP_FORWARD_IF_FALSE] = "POP_JUMP_FORWARD_IF_FALSE",
[POP_JUMP_FORWARD_IF_TRUE] = "POP_JUMP_FORWARD_IF_TRUE",
[LOAD_GLOBAL] = "LOAD_GLOBAL",
@@ -363,7 +364,7 @@ static const char *const _PyOpcode_OpName[267] = {
[CONTAINS_OP] = "CONTAINS_OP",
[RERAISE] = "RERAISE",
[COPY] = "COPY",
- [LOAD_CONST__LOAD_FAST] = "LOAD_CONST__LOAD_FAST",
+ [LOAD_ATTR_METHOD_WITH_VALUES] = "LOAD_ATTR_METHOD_WITH_VALUES",
[BINARY_OP] = "BINARY_OP",
[SEND] = "SEND",
[LOAD_FAST] = "LOAD_FAST",
@@ -383,9 +384,9 @@ static const char *const _PyOpcode_OpName[267] = {
[STORE_DEREF] = "STORE_DEREF",
[DELETE_DEREF] = "DELETE_DEREF",
[JUMP_BACKWARD] = "JUMP_BACKWARD",
- [LOAD_FAST__LOAD_CONST] = "LOAD_FAST__LOAD_CONST",
+ [LOAD_CONST__LOAD_FAST] = "LOAD_CONST__LOAD_FAST",
[CALL_FUNCTION_EX] = "CALL_FUNCTION_EX",
- [LOAD_FAST__LOAD_FAST] = "LOAD_FAST__LOAD_FAST",
+ [LOAD_FAST__LOAD_CONST] = "LOAD_FAST__LOAD_CONST",
[EXTENDED_ARG] = "EXTENDED_ARG",
[LIST_APPEND] = "LIST_APPEND",
[SET_ADD] = "SET_ADD",
@@ -395,37 +396,37 @@ static const char *const _PyOpcode_OpName[267] = {
[YIELD_VALUE] = "YIELD_VALUE",
[RESUME] = "RESUME",
[MATCH_CLASS] = "MATCH_CLASS",
+ [LOAD_FAST__LOAD_FAST] = "LOAD_FAST__LOAD_FAST",
[LOAD_GLOBAL_ADAPTIVE] = "LOAD_GLOBAL_ADAPTIVE",
- [LOAD_GLOBAL_BUILTIN] = "LOAD_GLOBAL_BUILTIN",
[FORMAT_VALUE] = "FORMAT_VALUE",
[BUILD_CONST_KEY_MAP] = "BUILD_CONST_KEY_MAP",
[BUILD_STRING] = "BUILD_STRING",
+ [LOAD_GLOBAL_BUILTIN] = "LOAD_GLOBAL_BUILTIN",
[LOAD_GLOBAL_MODULE] = "LOAD_GLOBAL_MODULE",
[RESUME_QUICK] = "RESUME_QUICK",
[STORE_ATTR_ADAPTIVE] = "STORE_ATTR_ADAPTIVE",
- [STORE_ATTR_INSTANCE_VALUE] = "STORE_ATTR_INSTANCE_VALUE",
[LIST_EXTEND] = "LIST_EXTEND",
[SET_UPDATE] = "SET_UPDATE",
[DICT_MERGE] = "DICT_MERGE",
[DICT_UPDATE] = "DICT_UPDATE",
+ [STORE_ATTR_INSTANCE_VALUE] = "STORE_ATTR_INSTANCE_VALUE",
[STORE_ATTR_SLOT] = "STORE_ATTR_SLOT",
[STORE_ATTR_WITH_HINT] = "STORE_ATTR_WITH_HINT",
[STORE_FAST__LOAD_FAST] = "STORE_FAST__LOAD_FAST",
[STORE_FAST__STORE_FAST] = "STORE_FAST__STORE_FAST",
- [STORE_SUBSCR_ADAPTIVE] = "STORE_SUBSCR_ADAPTIVE",
[CALL] = "CALL",
[KW_NAMES] = "KW_NAMES",
[POP_JUMP_BACKWARD_IF_NOT_NONE] = "POP_JUMP_BACKWARD_IF_NOT_NONE",
[POP_JUMP_BACKWARD_IF_NONE] = "POP_JUMP_BACKWARD_IF_NONE",
[POP_JUMP_BACKWARD_IF_FALSE] = "POP_JUMP_BACKWARD_IF_FALSE",
[POP_JUMP_BACKWARD_IF_TRUE] = "POP_JUMP_BACKWARD_IF_TRUE",
+ [STORE_SUBSCR_ADAPTIVE] = "STORE_SUBSCR_ADAPTIVE",
[STORE_SUBSCR_DICT] = "STORE_SUBSCR_DICT",
[STORE_SUBSCR_LIST_INT] = "STORE_SUBSCR_LIST_INT",
[UNPACK_SEQUENCE_ADAPTIVE] = "UNPACK_SEQUENCE_ADAPTIVE",
[UNPACK_SEQUENCE_LIST] = "UNPACK_SEQUENCE_LIST",
[UNPACK_SEQUENCE_TUPLE] = "UNPACK_SEQUENCE_TUPLE",
[UNPACK_SEQUENCE_TWO_TUPLE] = "UNPACK_SEQUENCE_TWO_TUPLE",
- [183] = "<183>",
[184] = "<184>",
[185] = "<185>",
[186] = "<186>",
@@ -513,7 +514,6 @@ static const char *const _PyOpcode_OpName[267] = {
#endif
#define EXTRA_CASES \
- case 183: \
case 184: \
case 185: \
case 186: \
diff --git a/Include/internal/pycore_typeobject.h b/Include/internal/pycore_typeobject.h
index 4eb0efc..2efe388 100644
--- a/Include/internal/pycore_typeobject.h
+++ b/Include/internal/pycore_typeobject.h
@@ -75,6 +75,9 @@ extern void _PyStaticType_ClearWeakRefs(PyTypeObject *type);
extern void _PyStaticType_Dealloc(PyTypeObject *type);
+PyObject *_Py_slot_tp_getattro(PyObject *self, PyObject *name);
+PyObject *_Py_slot_tp_getattr_hook(PyObject *self, PyObject *name);
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/opcode.h b/Include/opcode.h
index f90ebb1..210e3fe 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -176,35 +176,36 @@ extern "C" {
#define JUMP_BACKWARD_QUICK 66
#define LOAD_ATTR_ADAPTIVE 67
#define LOAD_ATTR_CLASS 72
-#define LOAD_ATTR_INSTANCE_VALUE 73
-#define LOAD_ATTR_MODULE 76
-#define LOAD_ATTR_PROPERTY 77
-#define LOAD_ATTR_SLOT 78
-#define LOAD_ATTR_WITH_HINT 79
-#define LOAD_ATTR_METHOD_LAZY_DICT 80
-#define LOAD_ATTR_METHOD_NO_DICT 81
-#define LOAD_ATTR_METHOD_WITH_DICT 86
-#define LOAD_ATTR_METHOD_WITH_VALUES 113
-#define LOAD_CONST__LOAD_FAST 121
-#define LOAD_FAST__LOAD_CONST 141
-#define LOAD_FAST__LOAD_FAST 143
-#define LOAD_GLOBAL_ADAPTIVE 153
-#define LOAD_GLOBAL_BUILTIN 154
-#define LOAD_GLOBAL_MODULE 158
-#define RESUME_QUICK 159
-#define STORE_ATTR_ADAPTIVE 160
-#define STORE_ATTR_INSTANCE_VALUE 161
-#define STORE_ATTR_SLOT 166
-#define STORE_ATTR_WITH_HINT 167
-#define STORE_FAST__LOAD_FAST 168
-#define STORE_FAST__STORE_FAST 169
-#define STORE_SUBSCR_ADAPTIVE 170
-#define STORE_SUBSCR_DICT 177
-#define STORE_SUBSCR_LIST_INT 178
-#define UNPACK_SEQUENCE_ADAPTIVE 179
-#define UNPACK_SEQUENCE_LIST 180
-#define UNPACK_SEQUENCE_TUPLE 181
-#define UNPACK_SEQUENCE_TWO_TUPLE 182
+#define LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN 73
+#define LOAD_ATTR_INSTANCE_VALUE 76
+#define LOAD_ATTR_MODULE 77
+#define LOAD_ATTR_PROPERTY 78
+#define LOAD_ATTR_SLOT 79
+#define LOAD_ATTR_WITH_HINT 80
+#define LOAD_ATTR_METHOD_LAZY_DICT 81
+#define LOAD_ATTR_METHOD_NO_DICT 86
+#define LOAD_ATTR_METHOD_WITH_DICT 113
+#define LOAD_ATTR_METHOD_WITH_VALUES 121
+#define LOAD_CONST__LOAD_FAST 141
+#define LOAD_FAST__LOAD_CONST 143
+#define LOAD_FAST__LOAD_FAST 153
+#define LOAD_GLOBAL_ADAPTIVE 154
+#define LOAD_GLOBAL_BUILTIN 158
+#define LOAD_GLOBAL_MODULE 159
+#define RESUME_QUICK 160
+#define STORE_ATTR_ADAPTIVE 161
+#define STORE_ATTR_INSTANCE_VALUE 166
+#define STORE_ATTR_SLOT 167
+#define STORE_ATTR_WITH_HINT 168
+#define STORE_FAST__LOAD_FAST 169
+#define STORE_FAST__STORE_FAST 170
+#define STORE_SUBSCR_ADAPTIVE 177
+#define STORE_SUBSCR_DICT 178
+#define STORE_SUBSCR_LIST_INT 179
+#define UNPACK_SEQUENCE_ADAPTIVE 180
+#define UNPACK_SEQUENCE_LIST 181
+#define UNPACK_SEQUENCE_TUPLE 182
+#define UNPACK_SEQUENCE_TWO_TUPLE 183
#define DO_TRACING 255
#define HAS_ARG(op) ((((op) >= HAVE_ARGUMENT) && (!IS_PSEUDO_OPCODE(op)))\