Skip to content

Commit a4baf51

Browse files
committed
Fix exception handling in PyLong_AsVoidPtr
1 parent 7507f10 commit a4baf51

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,7 +2181,12 @@ long doPointer(PInt n,
21812181
return n.longValueExact();
21822182
} catch (OverflowException e) {
21832183
overflowProfile.enter();
2184-
throw raise(OverflowError);
2184+
try {
2185+
throw raise(OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "C long");
2186+
} catch (PException pe) {
2187+
ensureTransformExcNode().execute(pe);
2188+
return 0;
2189+
}
21852190
}
21862191
}
21872192

@@ -2197,12 +2202,14 @@ long doGeneric(Object n) {
21972202
asPrimitiveNode = insert(ConvertPIntToPrimitiveNodeGen.create());
21982203
}
21992204
try {
2200-
return asPrimitiveNode.executeLong(n, 0, Long.BYTES);
2201-
} catch (UnexpectedResultException e) {
2202-
throw CompilerDirectives.shouldNotReachHere();
2205+
try {
2206+
return asPrimitiveNode.executeLong(n, 0, Long.BYTES);
2207+
} catch (UnexpectedResultException e) {
2208+
throw raise(OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "C long");
2209+
}
22032210
} catch (PException e) {
22042211
ensureTransformExcNode().execute(e);
2205-
return -1;
2212+
return 0;
22062213
}
22072214
}
22082215

0 commit comments

Comments
 (0)