Skip to content

Commit fcc627b

Browse files
committed
return the passed obj in PyUnicode_FromObject only if getClass == PString
1 parent 16c18f6 commit fcc627b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2707,12 +2707,12 @@ protected boolean checkBase(int base) {
27072707
public abstract static class PySequenceTupleNode extends PythonUnaryBuiltinNode {
27082708
@Specialization(guards = "isTuple(obj, getClassNode)")
27092709
public PTuple values(PTuple obj,
2710-
@SuppressWarnings("unused") @Cached GetClassNode getClassNode) {
2710+
@SuppressWarnings("unused") @Cached GetClassNode getClassNode) {
27112711
return obj;
27122712
}
27132713

27142714
@Specialization(guards = "!isTuple(obj, getClassNode)")
2715-
public Object values(VirtualFrame frame, Object obj,
2715+
public Object values(VirtualFrame frame, Object obj,
27162716
@Cached TupleNode tupleNode,
27172717
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
27182718
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
@@ -2724,7 +2724,7 @@ public Object values(VirtualFrame frame, Object obj,
27242724
return getNativeNullNode.execute();
27252725
}
27262726
}
2727-
2727+
27282728
protected boolean isTuple(Object obj, GetClassNode getClassNode) {
27292729
return getClassNode.execute(obj) == PythonBuiltinClassType.PTuple;
27302730
}
@@ -3010,12 +3010,13 @@ public String fromObject(String s) {
30103010
return s;
30113011
}
30123012

3013-
@Specialization
3014-
public PString fromObject(PString s) {
3013+
@Specialization(guards = "isPStringType(s, getClassNode)")
3014+
public PString fromObject(PString s,
3015+
@SuppressWarnings("unused") @Cached GetClassNode getClassNode) {
30153016
return s;
30163017
}
30173018

3018-
@Specialization(guards = {"!isString(obj)", "isStringSubtype(frame, obj, getClassNode, isSubtypeNode)"})
3019+
@Specialization(guards = {"!isPStringType(obj, getClassNode)", "isStringSubtype(frame, obj, getClassNode, isSubtypeNode)"})
30193020
public Object fromObject(VirtualFrame frame, Object obj,
30203021
@Cached StrNode strNode,
30213022
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
@@ -3030,7 +3031,7 @@ public Object fromObject(VirtualFrame frame, Object obj,
30303031
}
30313032
}
30323033

3033-
@Specialization(guards = {"!isString(obj)", "!isStringSubtype(frame, obj, getClassNode, isSubtypeNode)"})
3034+
@Specialization(guards = {"!isStringSubtype(frame, obj, getClassNode, isSubtypeNode)"})
30343035
public Object fromObject(VirtualFrame frame, Object obj,
30353036
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
30363037
@SuppressWarnings("unused") @Cached IsSubtypeNode isSubtypeNode,
@@ -3042,6 +3043,10 @@ public Object fromObject(VirtualFrame frame, Object obj,
30423043
protected boolean isStringSubtype(VirtualFrame frame, Object obj, GetClassNode getClassNode, IsSubtypeNode isSubtypeNode) {
30433044
return isSubtypeNode.execute(frame, getClassNode.execute(obj), PythonBuiltinClassType.PString);
30443045
}
3046+
3047+
protected boolean isPStringType(Object obj, GetClassNode getClassNode) {
3048+
return getClassNode.execute(obj) == PythonBuiltinClassType.PString;
3049+
}
30453050
}
30463051

30473052
@Builtin(name = "PyUnicode_GetLength", minNumOfPositionalArgs = 1)

0 commit comments

Comments
 (0)