Skip to content

Commit aa0cbaa

Browse files
msimacektimfel
authored andcommitted
Fix print method lookup
1 parent a0eeb6f commit aa0cbaa

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,27 +1553,32 @@ public abstract static class PrintNode extends PythonBuiltinNode {
15531553
@Specialization
15541554
@SuppressWarnings("unused")
15551555
PNone printNoKeywords(VirtualFrame frame, Object[] values, PNone sep, PNone end, PNone file, PNone flush,
1556-
@Shared("callWrite") @Cached PyObjectCallMethodObjArgs callWrite,
1556+
@Shared("lookupWrite") @Cached PyObjectLookupAttr lookupWrite,
1557+
@Shared("callWrite") @Cached CallNode callWrite,
15571558
@Shared("callFlush") @Cached PyObjectCallMethodObjArgs callFlush,
15581559
@Shared("strNode") @Cached PyObjectStrAsObjectNode strNode) {
15591560
Object stdout = getStdout();
1560-
return printAllGiven(frame, values, DEFAULT_SEPARATOR, DEFAULT_END, stdout, false, callWrite, callFlush, strNode);
1561+
return printAllGiven(frame, values, DEFAULT_SEPARATOR, DEFAULT_END, stdout, false, lookupWrite, callWrite, callFlush, strNode);
15611562
}
15621563

15631564
@Specialization(guards = {"!isNone(file)", "!isNoValue(file)"})
15641565
PNone printAllGiven(VirtualFrame frame, Object[] values, String sep, String end, Object file, boolean flush,
1565-
@Shared("callWrite") @Cached PyObjectCallMethodObjArgs callWrite,
1566+
@Shared("lookupWrite") @Cached PyObjectLookupAttr lookupWrite,
1567+
@Shared("callWrite") @Cached CallNode callWrite,
15661568
@Shared("callFlush") @Cached PyObjectCallMethodObjArgs callFlush,
15671569
@Shared("strNode") @Cached PyObjectStrAsObjectNode strNode) {
15681570
int lastValue = values.length - 1;
1571+
// Note: the separate lookup is necessary due to different __getattr__ treatment than
1572+
// method lookup
1573+
Object writeMethod = lookupWrite.executeStrict(frame, this, file, "write");
15691574
for (int i = 0; i < lastValue; i++) {
1570-
callWrite.execute(frame, file, "write", strNode.execute(frame, values[i]));
1571-
callWrite.execute(frame, file, "write", sep);
1575+
callWrite.execute(frame, writeMethod, strNode.execute(frame, values[i]));
1576+
callWrite.execute(frame, writeMethod, sep);
15721577
}
15731578
if (lastValue >= 0) {
1574-
callWrite.execute(frame, file, "write", strNode.execute(frame, values[lastValue]));
1579+
callWrite.execute(frame, writeMethod, strNode.execute(frame, values[lastValue]));
15751580
}
1576-
callWrite.execute(frame, file, "write", end);
1581+
callWrite.execute(frame, writeMethod, end);
15771582
if (flush) {
15781583
callFlush.execute(frame, file, "flush");
15791584
}
@@ -1586,7 +1591,8 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
15861591
@Cached CastToJavaStringNode castEnd,
15871592
@Cached("createIfTrueNode()") CoerceToBooleanNode castFlush,
15881593
@Cached PRaiseNode raiseNode,
1589-
@Shared("callWrite") @Cached PyObjectCallMethodObjArgs callWrite,
1594+
@Shared("lookupWrite") @Cached PyObjectLookupAttr lookupWrite,
1595+
@Shared("callWrite") @Cached CallNode callWrite,
15901596
@Shared("callFlush") @Cached PyObjectCallMethodObjArgs callFlush,
15911597
@Shared("strNode") @Cached PyObjectStrAsObjectNode strNode) {
15921598
String sep;
@@ -1615,7 +1621,7 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
16151621
} else {
16161622
flush = castFlush.executeBoolean(frame, flushIn);
16171623
}
1618-
return printAllGiven(frame, values, sep, end, file, flush, callWrite, callFlush, strNode);
1624+
return printAllGiven(frame, values, sep, end, file, flush, lookupWrite, callWrite, callFlush, strNode);
16191625
}
16201626

16211627
private Object getStdout() {

0 commit comments

Comments
 (0)