Skip to content

Commit c3cd4d4

Browse files
committed
Do not deopt when raising FatalError
1 parent c51e690 commit c3cd4d4

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

graalpython/com.oracle.graal.python.cext/src/pylifecycle.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242

4343
UPCALL_ID(PyTruffle_FatalError);
4444
void _Py_NO_RETURN Py_FatalError(const char *msg) {
45-
UPCALL_CEXT_VOID(_jls_PyTruffle_FatalError, Py_NoValue, polyglot_from_string(msg, SRC_CS), -1);
46-
/* should never be reached; avoids compiler warning */
47-
exit(1);
45+
UPCALL_CEXT_VOID(_jls_PyTruffle_FatalError, polyglot_from_string(msg, SRC_CS), -1);
46+
/* If the above upcall returns, then we just fall through to the 'abort' call. */
47+
abort();
4848
}
4949

5050
PyOS_sighandler_t PyOS_setsig(int sig, PyOS_sighandler_t handler) {

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3013,17 +3013,20 @@ Object doIt(Object clazz, String name, PTuple mroTuple,
30133013
}
30143014
}
30153015

3016-
@Builtin(name = "PyTruffle_FatalError", minNumOfPositionalArgs = 3)
3016+
@Builtin(name = "PyTruffle_FatalError", parameterNames = {"prefix", "msg", "status"})
30173017
@GenerateNodeFactory
30183018
@TypeSystemReference(PythonTypes.class)
30193019
public abstract static class PyTruffle_FatalError extends PythonBuiltinNode {
30203020

30213021
@Specialization
3022+
@TruffleBoundary
30223023
Object doStrings(String prefix, String msg, int status) {
3023-
throw CExtCommonNodes.fatalError(this, getContext(), prefix, msg, status);
3024+
CExtCommonNodes.fatalError(this, PythonLanguage.getContext(), prefix, msg, status);
3025+
return PNone.NONE;
30243026
}
30253027

30263028
@Specialization
3029+
@TruffleBoundary
30273030
Object doGeneric(Object prefixObj, Object msgObj, int status) {
30283031
String prefix = prefixObj == PNone.NO_VALUE ? null : (String) prefixObj;
30293032
String msg = msgObj == PNone.NO_VALUE ? null : (String) msgObj;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtCommonNodes.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,10 @@
116116
import com.oracle.truffle.api.profiles.BranchProfile;
117117

118118
public abstract class CExtCommonNodes {
119-
120119
private static final int SIGABRT_EXIT_CODE = 134;
121120

122121
@TruffleBoundary
123-
public static PythonExitException fatalError(Node location, PythonContext context, String prefix, String msg, int status) {
122+
public static void fatalError(Node location, PythonContext context, String prefix, String msg, int status) {
124123
PrintWriter stderr = new PrintWriter(context.getStandardErr());
125124
stderr.print("Fatal Python error: ");
126125
if (prefix != null) {
@@ -137,7 +136,8 @@ public static PythonExitException fatalError(Node location, PythonContext contex
137136

138137
if (status < 0) {
139138
// In CPython, this will use 'abort()' which sets a special exit code.
140-
throw new PythonExitException(location, SIGABRT_EXIT_CODE);
139+
System.exit(SIGABRT_EXIT_CODE);
140+
throw CompilerDirectives.shouldNotReachHere();
141141
}
142142
throw new PythonExitException(location, status);
143143
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,8 @@ Object execute(Object[] arguments,
890890
// ignore
891891
}
892892
}
893-
throw CExtCommonNodes.fatalError(asContextNode, context.getContext(), null, errorMessage, -1);
893+
CExtCommonNodes.fatalError(asContextNode, context.getContext(), null, errorMessage, -1);
894+
throw CompilerDirectives.shouldNotReachHere();
894895
}
895896
}
896897

0 commit comments

Comments
 (0)