Skip to content

Commit 824b292

Browse files
committed
in PySequence_Tuple return obj only if getClass == PythonBuiltinClassType.PTuple
1 parent 060947b commit 824b292

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,14 +2705,16 @@ protected boolean checkBase(int base) {
27052705
@Builtin(name = "PySequence_Tuple", minNumOfPositionalArgs = 1)
27062706
@GenerateNodeFactory
27072707
public abstract static class PySequenceTupleNode extends PythonUnaryBuiltinNode {
2708-
@Specialization
2709-
public PTuple values(PTuple obj) {
2708+
@Specialization(guards = "isTuple(obj, getClassNode)")
2709+
public PTuple values(PTuple obj,
2710+
@SuppressWarnings("unused") @Cached GetClassNode getClassNode) {
27102711
return obj;
27112712
}
27122713

2713-
@Specialization
2714-
public Object values(VirtualFrame frame, Object obj,
2714+
@Specialization(guards = "!isTuple(obj, getClassNode)")
2715+
public Object values(VirtualFrame frame, Object obj,
27152716
@Cached TupleNode tupleNode,
2717+
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
27162718
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
27172719
@Cached GetNativeNullNode getNativeNullNode) {
27182720
try {
@@ -2722,6 +2724,10 @@ public Object values(VirtualFrame frame, Object obj,
27222724
return getNativeNullNode.execute();
27232725
}
27242726
}
2727+
2728+
protected boolean isTuple(Object obj, GetClassNode getClassNode) {
2729+
return getClassNode.execute(obj) == PythonBuiltinClassType.PTuple;
2730+
}
27252731
}
27262732

27272733
@Builtin(name = "PySequence_List", minNumOfPositionalArgs = 1)

0 commit comments

Comments
 (0)