Skip to content

Commit e189c2a

Browse files
committed
Fix ClassCastException caused by specialization arg eval order
1 parent 1dd5d65 commit e189c2a

File tree

1 file changed

+5
-9
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str

1 file changed

+5
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/PString.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
4848
import com.oracle.truffle.api.CompilerDirectives;
4949
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
50-
import com.oracle.truffle.api.dsl.Bind;
5150
import com.oracle.truffle.api.dsl.Cached;
5251
import com.oracle.truffle.api.dsl.Cached.Exclusive;
5352
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -152,15 +151,16 @@ static int nativeString(PString self, @SuppressWarnings("unused") ThreadState st
152151
"isBuiltin(self, profile) || hasBuiltinLen(self, lookupSelf, lookupString)"
153152
}, replaces = "nativeString", limit = "1")
154153
static int nativeStringMat(PString self, @SuppressWarnings("unused") ThreadState state,
155-
@Bind("getNativeCharSequence(self)") NativeCharSequence nativeCharSequence,
156154
@SuppressWarnings("unused") @Shared("builtinProfile") @Cached IsBuiltinClassProfile profile,
157155
@SuppressWarnings("unused") @Shared("lookupSelf") @Cached LookupInheritedAttributeNode.Dynamic lookupSelf,
158156
@SuppressWarnings("unused") @Shared("lookupString") @Cached LookupAttributeInMRONode.Dynamic lookupString,
159-
@CachedLibrary("nativeCharSequence.getPtr()") InteropLibrary lib,
157+
@CachedLibrary(limit = "1") InteropLibrary lib,
160158
@Cached CastToJavaIntExactNode castToJavaIntNode,
161159
@Shared("stringMaterializeNode") @Cached StringMaterializeNode materializeNode) {
162-
if (lib.hasArrayElements(nativeCharSequence.getPtr())) {
163-
return nativeCharSequence.length(lib, castToJavaIntNode);
160+
// this cast is guaranteed by cast 'isNativeString(self.getCharSequence())'
161+
NativeCharSequence value = (NativeCharSequence) self.value;
162+
if (lib.hasArrayElements(value.getPtr())) {
163+
return value.length(lib, castToJavaIntNode);
164164
} else {
165165
return materializeNode.execute(self).length();
166166
}
@@ -180,10 +180,6 @@ static int subclassedString(PString self, ThreadState state,
180180
// call the generic implementation in the superclass
181181
return self.lengthWithState(state, plib, methodLib, hasLen, ltZero, raiseNode, lib, toLong, ignoreOverflow, overflow);
182182
}
183-
184-
static NativeCharSequence getNativeCharSequence(PString self) {
185-
return (NativeCharSequence) self.value;
186-
}
187183
}
188184

189185
@ExportMessage

0 commit comments

Comments
 (0)