Skip to content

Commit 03248ce

Browse files
committed
[GR-44275] Assorted minor fixes.
PullRequest: graalpython/2638
2 parents bef234d + 8d6e6e9 commit 03248ce

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception/TopLevelExceptionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ private void handleJavaException(Throwable e) {
214214
try {
215215
boolean exitException = InteropLibrary.getUncached().isException(e) && InteropLibrary.getUncached().getExceptionType(e) == ExceptionType.EXIT;
216216
if (!exitException) {
217-
ExceptionUtils.printPythonLikeStackTrace(e);
217+
ExceptionUtils.printPythonLikeStackTrace(getContext(), e);
218218
if (PythonOptions.isWithJavaStacktrace(getPythonLanguage())) {
219219
e.printStackTrace();
220220
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import static com.oracle.graal.python.nodes.BuiltinNames.T_SYS;
4444

4545
import java.io.IOException;
46+
import java.io.PrintWriter;
4647
import java.util.ArrayList;
4748
import java.util.List;
4849
import java.util.ListIterator;
@@ -97,7 +98,7 @@ public static void printPythonLikeStackTrace() {
9798
appendStackLine(stack, location, rootNode, true, lineno);
9899
return null;
99100
});
100-
printStack(stack);
101+
printStack(new PrintWriter(System.err), stack);
101102
}
102103

103104
private static int getLineno(Frame frame) {
@@ -114,10 +115,23 @@ private static int getLineno(Frame frame) {
114115
}
115116

116117
/**
117-
* this method is similar to 'PyErr_WriteUnraisable'
118+
* this method is similar to 'PyErr_WriteUnraisable' and may be used when the context is not
119+
* available.
118120
*/
119121
@TruffleBoundary
120122
public static void printPythonLikeStackTrace(Throwable e) {
123+
printPythonLikeStackTrace(new PrintWriter(System.err), e);
124+
}
125+
126+
/**
127+
* this method is similar to 'PyErr_WriteUnraisable'
128+
*/
129+
@TruffleBoundary
130+
public static void printPythonLikeStackTrace(PythonContext context, Throwable e) {
131+
printPythonLikeStackTrace(new PrintWriter(context.getEnv().err()), e);
132+
}
133+
134+
private static void printPythonLikeStackTrace(PrintWriter p, Throwable e) {
121135
List<TruffleStackTraceElement> stackTrace = TruffleStackTrace.getStackTrace(e);
122136
if (stackTrace != null) {
123137
ArrayList<String> stack = new ArrayList<>();
@@ -127,17 +141,17 @@ public static void printPythonLikeStackTrace(Throwable e) {
127141
int lineno = getLineno(frame.getFrame());
128142
appendStackLine(stack, location, rootNode, false, lineno);
129143
}
130-
printStack(stack);
144+
printStack(p, stack);
131145
}
132146
InteropLibrary lib = InteropLibrary.getUncached();
133147
if (lib.isException(e) && lib.hasExceptionMessage(lib)) {
134148
try {
135-
System.err.println(lib.getExceptionMessage(e));
149+
p.println(lib.getExceptionMessage(e));
136150
} catch (UnsupportedMessageException unsupportedMessageException) {
137151
throw CompilerDirectives.shouldNotReachHere();
138152
}
139153
} else {
140-
System.err.println(e.getMessage());
154+
p.println(e.getMessage());
141155
}
142156
}
143157

@@ -175,11 +189,11 @@ private static void appendStackLine(ArrayList<String> stack, Node location, Root
175189
}
176190
}
177191

178-
private static void printStack(final ArrayList<String> stack) {
179-
System.err.println("Traceback (most recent call last):");
192+
private static void printStack(PrintWriter p, final ArrayList<String> stack) {
193+
p.println("Traceback (most recent call last):");
180194
ListIterator<String> listIterator = stack.listIterator(stack.size());
181195
while (listIterator.hasPrevious()) {
182-
System.err.println(listIterator.previous());
196+
p.println(listIterator.previous());
183197
}
184198
}
185199

graalpython/lib-python/3/test/test_subprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ def is_env_var_to_ignore(n):
788788
n == 'LD_PRELOAD' or n.startswith('SANDBOX') or # Gentoo
789789
n == 'PWD' or n == 'SHLVL' or # Graalpython bash launcher
790790
n.startswith('JAVA_MAIN_CLASS') or # JVM on MacOS
791-
n == 'LD_LIBRARY_PATH' or # Added by graalpy launcher
791+
n == 'LD_LIBRARY_PATH' or n == 'DYLD_LIBRARY_PATH' or # Added by graalpy launcher
792792
n == 'LC_CTYPE') # Locale coercion triggered
793793

794794
with subprocess.Popen([sys.executable, "-c",

0 commit comments

Comments
 (0)