@@ -883,7 +883,8 @@ dummy_func(void) {
883883 op (_LOAD_ATTR , (owner -- attr , self_or_null [oparg & 1 ])) {
884884 PyObject * value = sym_get_probable_value (owner );
885885 PyTypeObject * type = NULL ;
886- if (value != NULL && PyType_Check (value )) {
886+ bool is_class = PyType_Check (value );
887+ if (value != NULL && is_class ) {
887888 type = (PyTypeObject * )value ;
888889 }
889890 else {
@@ -905,26 +906,42 @@ dummy_func(void) {
905906 callable = _PyStaticMethod_GetFunc (descr );
906907 }
907908 assert (callable );
909+ if (is_class && class_method ) {
910+ PyObject * meth = PyMethod_New (callable , value );
911+ if (meth == NULL || sym_promote_to_constant_pool (ctx , meth ) != 0 ) {
912+ ctx -> done = true;
913+ ctx -> out_of_space = true;
914+ break ;
915+ }
916+ callable = meth ;
917+ }
908918 bool immortal = _Py_IsImmortal (callable ) || (type -> tp_flags & Py_TPFLAGS_IMMUTABLETYPE );
909- if (PyType_Check ( value ) ) {
919+ if (is_class && class_method ) {
910920 ADD_OP (_CHECK_ATTR_CLASS , 0 , type -> tp_version_tag );
921+ ADD_OP (_POP_TOP , 0 , 0 );
922+ ADD_OP (immortal ? _LOAD_CONST_INLINE_BORROW : _LOAD_CONST_INLINE , 0 , (uintptr_t )callable );
923+ ADD_OP (_PUSH_NULL , 0 , 0 );
924+ self_or_null [0 ] = sym_new_null (ctx );
925+ attr = sym_new_const (ctx , callable );
926+ PyType_Watch (TYPE_WATCHER_ID , (PyObject * )type );
927+ _Py_BloomFilter_Add (dependencies , (PyTypeObject * )type );
911928 }
912929 else {
913930 ADD_OP (_GUARD_TYPE_VERSION , 0 , type -> tp_version_tag );
931+ ADD_OP (_POP_TOP , 0 , 0 );
932+ ADD_OP (immortal ? _LOAD_CONST_INLINE_BORROW : _LOAD_CONST_INLINE , 0 , (uintptr_t )callable );
933+ if (class_method ) {
934+ ADD_OP (_LOAD_CONST_INLINE_BORROW , 0 , (uintptr_t )type );
935+ self_or_null [0 ] = sym_new_const (ctx , (PyObject * )type );
936+ }
937+ else {
938+ ADD_OP (_PUSH_NULL , 0 , 0 );
939+ self_or_null [0 ] = sym_new_null (ctx );
940+ }
941+ attr = sym_new_const (ctx , callable );
942+ PyType_Watch (TYPE_WATCHER_ID , (PyObject * )type );
943+ _Py_BloomFilter_Add (dependencies , (PyTypeObject * )type );
914944 }
915- ADD_OP (_POP_TOP , 0 , 0 );
916- ADD_OP (immortal ? _LOAD_CONST_INLINE_BORROW : _LOAD_CONST_INLINE , 0 , (uintptr_t )callable );
917- if (class_method ) {
918- ADD_OP (_LOAD_CONST_INLINE_BORROW , 0 , (uintptr_t )type );
919- self_or_null [0 ] = sym_new_const (ctx , (PyObject * )type );
920- }
921- else {
922- ADD_OP (_PUSH_NULL , 0 , 0 );
923- self_or_null [0 ] = sym_new_null (ctx );
924- }
925- attr = sym_new_const (ctx , callable );
926- PyType_Watch (TYPE_WATCHER_ID , (PyObject * )type );
927- _Py_BloomFilter_Add (dependencies , (PyTypeObject * )type );
928945 }
929946 else {
930947 attr = sym_new_not_null (ctx );
@@ -1040,8 +1057,15 @@ dummy_func(void) {
10401057 }
10411058
10421059 op (_INIT_CALL_BOUND_METHOD_EXACT_ARGS , (callable , self_or_null , unused [oparg ] -- callable , self_or_null , unused [oparg ])) {
1043- callable = sym_new_not_null (ctx );
1044- self_or_null = sym_new_not_null (ctx );
1060+ PyObject * meth = sym_get_const (ctx , callable );
1061+ if (meth != NULL ) {
1062+ callable = sym_new_const (ctx , ((PyMethodObject * )meth )-> im_func );
1063+ self_or_null = sym_new_const (ctx , ((PyMethodObject * )meth )-> im_self );
1064+ }
1065+ else {
1066+ callable = sym_new_not_null (ctx );
1067+ self_or_null = sym_new_not_null (ctx );
1068+ }
10451069 }
10461070
10471071 op (_CHECK_FUNCTION_VERSION , (func_version /2 , callable , self_or_null , unused [oparg ] -- callable , self_or_null , unused [oparg ])) {
0 commit comments