Skip to content

Commit fbfb00a

Browse files
committed
PyObject_GenericGet/SetAttr have to explicitly use the object.__setatrr/getattribute__ methods
1 parent 6103886 commit fbfb00a

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextObjectBuiltins.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,16 @@
7070
import com.oracle.graal.python.lib.PyObjectAsFileDescriptor;
7171
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
7272
import com.oracle.graal.python.lib.PyObjectDelItem;
73-
import com.oracle.graal.python.lib.PyObjectGetAttr;
7473
import com.oracle.graal.python.lib.PyObjectLookupAttr;
7574
import com.oracle.graal.python.lib.PyObjectReprAsObjectNode;
76-
import com.oracle.graal.python.lib.PyObjectSetAttr;
7775
import com.oracle.graal.python.lib.PyObjectSetItem;
7876
import com.oracle.graal.python.lib.PyObjectStrAsObjectNode;
77+
import com.oracle.graal.python.nodes.SpecialMethodNames;
78+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__SETATTR__;
7979
import com.oracle.graal.python.nodes.attributes.GetAttributeNode.GetAnyAttributeNode;
8080
import 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;
8183
import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
8284
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
8385
import 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

Comments
 (0)