Skip to content

Commit 09a3546

Browse files
committed
[GR-27443] Use exact conversion in PInt.asJavaLong, fixed int shortcut in argument clinic
PullRequest: graalpython/1390
2 parents 06bf257 + af801e6 commit 09a3546

File tree

4 files changed

+8
-21
lines changed

4 files changed

+8
-21
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/PInt.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
4444
import com.oracle.graal.python.nodes.util.CastToJavaDoubleNode;
4545
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
46-
import com.oracle.graal.python.nodes.util.CastToJavaLongLossyNode;
46+
import com.oracle.graal.python.nodes.util.CastToJavaLongExactNode;
4747
import com.oracle.graal.python.runtime.PythonContext;
4848
import com.oracle.graal.python.runtime.exception.PException;
4949
import com.oracle.graal.python.util.OverflowException;
@@ -277,7 +277,7 @@ public boolean canBeJavaLong() {
277277

278278
@ExportMessage
279279
public long asJavaLongWithState(@SuppressWarnings("unused") ThreadState threadState,
280-
@Cached CastToJavaLongLossyNode castToLong) {
280+
@Cached CastToJavaLongExactNode castToLong) {
281281
return castToLong.execute(this);
282282
}
283283

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/DefaultPythonStringExports.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,6 @@ static Object getLazyPythonClass(@SuppressWarnings("unused") String value) {
8484
return PythonBuiltinClassType.PString;
8585
}
8686

87-
@ExportMessage
88-
static boolean isBuffer(@SuppressWarnings("unused") String str) {
89-
return false;
90-
}
91-
92-
@ExportMessage
93-
static int getBufferLength(@SuppressWarnings("unused") String str) {
94-
return getBufferBytes(str).length;
95-
}
96-
97-
@ExportMessage
98-
@TruffleBoundary
99-
static byte[] getBufferBytes(String str) {
100-
return str.getBytes();
101-
}
102-
10387
@ExportMessage
10488
@TruffleBoundary
10589
static long hashWithState(String self, @SuppressWarnings("unused") ThreadState state) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/PythonTernaryClinicBuiltinNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected Object castWithNode(ArgumentClinicProvider clinic, VirtualFrame frame,
7979
public Object callWithInt(VirtualFrame frame, Object arg, int arg2, Object arg3) {
8080
ArgumentClinicProvider clinic = getArgumentClinic();
8181
if (clinic.acceptsInt(1)) {
82-
return executeWithInt(frame, arg, arg2, arg3);
82+
return executeWithInt(frame, cast(clinic, frame, 0, arg), arg2, cast(clinic, frame, 2, arg3));
8383
} else {
8484
return call(frame, arg, arg2, arg3);
8585
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/JavaIntConversionNode.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@
4747
import com.oracle.graal.python.annotations.ClinicConverterFactory.DefaultValue;
4848
import com.oracle.graal.python.annotations.ClinicConverterFactory.UseDefaultForNone;
4949
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
50+
import com.oracle.graal.python.builtins.objects.function.PArguments;
5051
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
5152
import com.oracle.graal.python.nodes.ErrorMessages;
5253
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
54+
import com.oracle.graal.python.nodes.util.CastToJavaLongLossyNode;
5355
import com.oracle.truffle.api.dsl.Cached;
5456
import com.oracle.truffle.api.dsl.Specialization;
5557
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -65,12 +67,13 @@ protected JavaIntConversionNode(int defaultValue, boolean useDefaultForNone) {
6567
int doOthers(VirtualFrame frame, Object value,
6668
@Cached IsSubtypeNode isSubtypeNode,
6769
@Cached BranchProfile isFloatProfile,
68-
@CachedLibrary("value") PythonObjectLibrary lib) {
70+
@CachedLibrary("value") PythonObjectLibrary lib,
71+
@Cached CastToJavaLongLossyNode castToLongNode) {
6972
if (isSubtypeNode.execute(lib.getLazyPythonClass(value), PythonBuiltinClassType.PFloat)) {
7073
isFloatProfile.enter();
7174
throw raise(TypeError, ErrorMessages.INTEGER_EXPECTED_GOT_FLOAT);
7275
}
73-
long result = lib.asJavaLong(value, frame);
76+
long result = castToLongNode.execute(lib.asPIntWithState(value, PArguments.getThreadState(frame)));
7477
if (!fitsInInt(result)) {
7578
throw raise(TypeError, ErrorMessages.VALUE_TOO_LARGE_TO_FIT_INTO_INDEX);
7679
}

0 commit comments

Comments
 (0)