Skip to content

Commit 5d246c1

Browse files
committed
[GR-24114] Use CastToJavaStringNode instead of PString.getValue.
PullRequest: graalpython/1114
2 parents c29f564 + 33c175a commit 5d246c1

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@
5454
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
5555
import com.oracle.graal.python.nodes.ErrorMessages;
5656
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
57+
import com.oracle.graal.python.nodes.util.CannotCastException;
58+
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
5759
import com.oracle.graal.python.runtime.PythonCore;
60+
import com.oracle.truffle.api.CompilerDirectives;
5861
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5962
import com.oracle.truffle.api.dsl.Cached;
6063
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -193,8 +196,14 @@ public String normalize(@SuppressWarnings("unused") String form, String unistr,
193196
@Specialization(guards = {"form.equals(cachedForm)"}, limit = "4")
194197
public String normalize(String form, PString unistr,
195198
@Cached("form") String cachedForm,
199+
@Cached CastToJavaStringNode castToJavaStringNode,
196200
@Cached("getForm(cachedForm)") Normalizer.Form cachedNormForm) {
197-
return normalize(form, unistr.getValue(), cachedForm, cachedNormForm);
201+
try {
202+
return normalize(form, castToJavaStringNode.execute(unistr), cachedForm, cachedNormForm);
203+
} catch (CannotCastException e) {
204+
CompilerDirectives.transferToInterpreterAndInvalidate();
205+
throw new IllegalStateException("should not be reached");
206+
}
198207
}
199208

200209
}
@@ -226,8 +235,14 @@ public boolean isNormalized(@SuppressWarnings("unused") String form, String unis
226235
@Specialization(guards = {"form.equals(cachedForm)"}, limit = "4")
227236
public boolean normalize(String form, PString unistr,
228237
@Cached("form") String cachedForm,
238+
@Cached CastToJavaStringNode castToJavaStringNode,
229239
@Cached("getForm(cachedForm)") Normalizer.Form cachedNormForm) {
230-
return isNormalized(form, unistr.getValue(), cachedForm, cachedNormForm);
240+
try {
241+
return isNormalized(form, castToJavaStringNode.execute(unistr), cachedForm, cachedNormForm);
242+
} catch (CannotCastException e) {
243+
CompilerDirectives.transferToInterpreterAndInvalidate();
244+
throw new IllegalStateException("should not be reached");
245+
}
231246
}
232247
}
233248
}

0 commit comments

Comments
 (0)