7070import com .oracle .graal .python .lib .PyObjectAsFileDescriptor ;
7171import com .oracle .graal .python .lib .PyObjectCallMethodObjArgs ;
7272import com .oracle .graal .python .lib .PyObjectDelItem ;
73- import com .oracle .graal .python .lib .PyObjectGetAttr ;
7473import com .oracle .graal .python .lib .PyObjectLookupAttr ;
7574import com .oracle .graal .python .lib .PyObjectReprAsObjectNode ;
76- import com .oracle .graal .python .lib .PyObjectSetAttr ;
7775import com .oracle .graal .python .lib .PyObjectSetItem ;
7876import com .oracle .graal .python .lib .PyObjectStrAsObjectNode ;
77+ import com .oracle .graal .python .nodes .SpecialMethodNames ;
78+ import static com .oracle .graal .python .nodes .SpecialMethodNames .__SETATTR__ ;
7979import com .oracle .graal .python .nodes .attributes .GetAttributeNode .GetAnyAttributeNode ;
8080import com .oracle .graal .python .nodes .call .CallNode ;
81+ import com .oracle .graal .python .nodes .call .special .CallBinaryMethodNode ;
82+ import com .oracle .graal .python .nodes .call .special .CallTernaryMethodNode ;
8183import com .oracle .graal .python .nodes .call .special .CallUnaryMethodNode ;
8284import com .oracle .graal .python .nodes .classes .IsSubtypeNode ;
8385import com .oracle .graal .python .nodes .expression .BinaryComparisonNode ;
@@ -481,8 +483,16 @@ Object asFileDescriptor(VirtualFrame frame, Object obj,
481483 abstract static class PyObjectGenericGetAttrNode extends PythonBinaryBuiltinNode {
482484 @ Specialization
483485 Object getAttr (VirtualFrame frame , Object obj , Object attr ,
484- @ Cached PyObjectGetAttr getAttrNode ) {
485- return getAttrNode .execute (frame , obj , attr );
486+ @ Cached PyObjectLookupAttr lookupSetAttrNode ,
487+ @ Cached CallBinaryMethodNode callNode ,
488+ @ Cached TransformExceptionToNativeNode transformExceptionToNativeNode ) {
489+ try {
490+ Object setAttrCallable = lookupSetAttrNode .execute (frame , getCore ().lookupType (PythonBuiltinClassType .PythonObject ), SpecialMethodNames .__GETATTRIBUTE__ );
491+ return callNode .executeObject (frame , setAttrCallable , obj , attr );
492+ } catch (PException e ) {
493+ transformExceptionToNativeNode .execute (frame , e );
494+ return getContext ().getNativeNull ();
495+ }
486496 }
487497 }
488498
@@ -491,10 +501,12 @@ Object getAttr(VirtualFrame frame, Object obj, Object attr,
491501 abstract static class PyObjectGenericSetAttrNode extends PythonTernaryBuiltinNode {
492502 @ Specialization
493503 int setAttr (VirtualFrame frame , Object obj , Object attr , Object value ,
494- @ Cached PyObjectSetAttr setAttrNode ,
504+ @ Cached PyObjectLookupAttr lookupSetAttrNode ,
505+ @ Cached CallTernaryMethodNode callNode ,
495506 @ Cached TransformExceptionToNativeNode transformExceptionToNativeNode ) {
496507 try {
497- setAttrNode .execute (frame , obj , attr , value );
508+ Object setAttrCallable = lookupSetAttrNode .execute (frame , getCore ().lookupType (PythonBuiltinClassType .PythonObject ), __SETATTR__ );
509+ callNode .execute (frame , setAttrCallable , obj , attr , value );
498510 return 0 ;
499511 } catch (PException e ) {
500512 transformExceptionToNativeNode .execute (frame , e );
0 commit comments