Skip to content

Commit 6c8bd16

Browse files
fangerertimfel
authored andcommitted
Fix: transform exception in ctx_Float_AsDouble and ctxFloatAsDouble
1 parent efbca39 commit 6c8bd16

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContext.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,9 +1452,13 @@ public final double ctxFloatAsDouble(long handle) {
14521452
return GraalHPyBoxing.unboxInt(handle);
14531453
} else {
14541454
Object object = getObjectForHPyHandle(GraalHPyBoxing.unboxHandle(handle)).getDelegate();
1455-
return PyFloatAsDoubleNodeGen.getUncached().execute(null, object);
1455+
try {
1456+
return PyFloatAsDoubleNodeGen.getUncached().execute(null, object);
1457+
} catch (PException e) {
1458+
HPyTransformExceptionToNativeNodeGen.getUncached().execute(this, e);
1459+
return -1.0;
1460+
}
14561461
}
1457-
14581462
}
14591463

14601464
public final long ctxLongAsLong(long handle) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ Object execute(Object[] arguments,
872872
@Cached HPyAsHandleNode asHandleNode) throws ArityException {
873873
checkArity(arguments, 2);
874874
GraalHPyContext context = asContextNode.execute(arguments[0]);
875+
// note: node 'CastToJavaDoubleNode' cannot throw a PException
875876
double value = castToJavaDoubleNode.execute(arguments[1]);
876877
return asHandleNode.execute(context, value);
877878
}
@@ -884,10 +885,16 @@ public static final class GraalHPyFloatAsDouble extends GraalHPyContextFunction
884885
Object execute(Object[] arguments,
885886
@Cached HPyAsContextNode asContextNode,
886887
@Cached HPyAsPythonObjectNode asPythonObjectNode,
887-
@Cached PyFloatAsDoubleNode asDoubleNode) throws ArityException {
888+
@Cached PyFloatAsDoubleNode asDoubleNode,
889+
@Cached HPyTransformExceptionToNativeNode transformExceptionToNativeNode) throws ArityException {
888890
checkArity(arguments, 2);
889891
GraalHPyContext context = asContextNode.execute(arguments[0]);
890-
return asDoubleNode.execute(null, asPythonObjectNode.execute(context, arguments[1]));
892+
try {
893+
return asDoubleNode.execute(null, asPythonObjectNode.execute(context, arguments[1]));
894+
} catch (PException e) {
895+
transformExceptionToNativeNode.execute(context, e);
896+
return -1.0;
897+
}
891898
}
892899
}
893900

0 commit comments

Comments
 (0)