Skip to content

Commit fad98f0

Browse files
committed
[GR-12508] Make FDs and PIDs context-local
PullRequest: graalpython/274
2 parents 011af1c + 1c14069 commit fad98f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+898
-361
lines changed

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,10 @@ protected void launch(Builder contextBuilder) {
227227
if (!noSite) {
228228
evalInternal(context, "import site\n");
229229
}
230-
System.err.println("Please note: This Python implementation is in the very early stages, " +
231-
"and can run little more than basic benchmarks at this point.");
230+
if (!quietFlag) {
231+
System.err.println("Please note: This Python implementation is in the very early stages, " +
232+
"and can run little more than basic benchmarks at this point.");
233+
}
232234
consoleHandler.setContext(context);
233235

234236
if (commandString != null || inputFile != null) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,7 @@ public Object createInt(PythonClass cls, String arg, Object keywordArg) {
11221122
return factory().createInt(cls, (int) value);
11231123
}
11241124
} else {
1125+
CompilerDirectives.transferToInterpreter();
11251126
throw new RuntimeException("Not implemented integer with base: " + keywordArg);
11261127
}
11271128
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ public abstract static class BinNode extends PythonUnaryBuiltinNode {
242242

243243
public abstract String executeObject(Object x);
244244

245+
@TruffleBoundary
245246
private static String buildString(boolean isNegative, String number) {
246247
StringBuilder sb = new StringBuilder();
247248
if (isNegative) {
@@ -254,7 +255,12 @@ private static String buildString(boolean isNegative, String number) {
254255

255256
@Specialization
256257
public String doL(long x) {
257-
return buildString(x < 0, Long.toBinaryString(Math.abs(x)));
258+
return buildString(x < 0, longToBinaryString(x));
259+
}
260+
261+
@TruffleBoundary
262+
private static String longToBinaryString(long x) {
263+
return Long.toBinaryString(Math.abs(x));
258264
}
259265

260266
@Specialization
@@ -1287,7 +1293,7 @@ public Object print(PTuple values, String sep, String end, Object file, boolean
12871293
append(sb, " ");
12881294
}
12891295
append(sb, callStr.executeObject(getItemNode.execute(store, store.length() - 1)));
1290-
sb.append(end);
1296+
append(sb, end);
12911297
write(context, sb.toString());
12921298
}
12931299
} catch (IOException e) {
@@ -1604,7 +1610,7 @@ String input(@SuppressWarnings("unused") PNone prompt) {
16041610
buf.rewind();
16051611
return buf.toString();
16061612
} catch (IOException e) {
1607-
throw raise(PythonBuiltinClassType.EOFError, e.getMessage());
1613+
throw raise(PythonBuiltinClassType.EOFError, e);
16081614
}
16091615
}
16101616

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ private PBytes encodeString(String self, String encoding, String errors) {
315315
} catch (IllegalArgumentException e) {
316316
throw raise(LookupError, "unknown encoding: %s", encoding);
317317
} catch (CharacterCodingException e) {
318-
throw raise(UnicodeEncodeError, "%s", e.getMessage());
318+
throw raise(UnicodeEncodeError, e);
319319
}
320320
}
321321

@@ -375,7 +375,7 @@ private Object[] encodeString(String self, String errors) {
375375
// TODO(fa): bytes object creation should not be behind a TruffleBoundary
376376
return new Object[]{factory().createBytes(data), codePoints};
377377
} catch (CharacterCodingException e) {
378-
throw raise(UnicodeEncodeError, "%s", e.getMessage());
378+
throw raise(UnicodeEncodeError, e);
379379
}
380380
}
381381

@@ -443,7 +443,7 @@ String decodeBytes(ByteBuffer bytes, String encoding, String errors) {
443443
} catch (IllegalArgumentException e) {
444444
throw raise(LookupError, "unknown encoding: %s", encoding);
445445
} catch (CharacterCodingException e) {
446-
throw raise(UnicodeDecodeError, "%s", e.getMessage());
446+
throw raise(UnicodeDecodeError, e);
447447
}
448448
}
449449
}
@@ -504,7 +504,7 @@ String decodeBytes(ByteBuffer bytes, String errors) {
504504
CharBuffer decoded = charset.newDecoder().onMalformedInput(errorAction).onUnmappableCharacter(errorAction).decode(buf);
505505
return String.valueOf(decoded);
506506
} catch (CharacterCodingException e) {
507-
throw raise(UnicodeDecodeError, "%s", e.getMessage());
507+
throw raise(UnicodeDecodeError, e);
508508
}
509509
}
510510
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ private CheckFunctionResultNode getCheckResultNode() {
267267
return checkResultNode;
268268
}
269269

270+
@TruffleBoundary
270271
private PException reportImportError(RuntimeException e, String path) {
271272
StringBuilder sb = new StringBuilder();
272273
sb.append(e.getMessage());

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ Object read(TruffleObject receiver, Object key,
229229
try {
230230
return ForeignAccess.sendRead(readNode, receiver, key);
231231
} catch (UnknownIdentifierException | UnsupportedMessageException e) {
232-
throw raise(PythonErrorType.AttributeError, e.getMessage());
232+
throw raise(PythonErrorType.AttributeError, e);
233233
}
234234
}
235235
}
@@ -244,7 +244,7 @@ Object write(TruffleObject receiver, Object key, Object value,
244244
try {
245245
return ForeignAccess.sendWrite(writeNode, receiver, key, value);
246246
} catch (UnknownIdentifierException | UnsupportedMessageException | UnsupportedTypeException e) {
247-
throw raise(PythonErrorType.AttributeError, e.getMessage());
247+
throw raise(PythonErrorType.AttributeError, e);
248248
}
249249
}
250250
}
@@ -259,7 +259,7 @@ Object remove(TruffleObject receiver, Object key,
259259
try {
260260
return ForeignAccess.sendRemove(removeNode, receiver, key);
261261
} catch (UnknownIdentifierException | UnsupportedMessageException e) {
262-
throw raise(PythonErrorType.AttributeError, e.getMessage());
262+
throw raise(PythonErrorType.AttributeError, e);
263263
}
264264
}
265265
}
@@ -274,7 +274,7 @@ Object remove(TruffleObject receiver, Object[] arguments,
274274
try {
275275
return ForeignAccess.sendExecute(executeNode, receiver, arguments);
276276
} catch (UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
277-
throw raise(PythonErrorType.AttributeError, e.getMessage());
277+
throw raise(PythonErrorType.AttributeError, e);
278278
}
279279
}
280280
}
@@ -289,7 +289,7 @@ Object remove(TruffleObject receiver, Object[] arguments,
289289
try {
290290
return ForeignAccess.sendNew(executeNode, receiver, arguments);
291291
} catch (UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
292-
throw raise(PythonErrorType.AttributeError, e.getMessage());
292+
throw raise(PythonErrorType.AttributeError, e);
293293
}
294294
}
295295
}
@@ -304,7 +304,7 @@ Object remove(TruffleObject receiver, String key, Object[] arguments,
304304
try {
305305
return ForeignAccess.sendInvoke(executeNode, receiver, key, arguments);
306306
} catch (UnsupportedMessageException | UnsupportedTypeException | ArityException | UnknownIdentifierException e) {
307-
throw raise(PythonErrorType.AttributeError, e.getMessage());
307+
throw raise(PythonErrorType.AttributeError, e);
308308
}
309309
}
310310
}
@@ -346,7 +346,7 @@ Object remove(TruffleObject receiver,
346346
try {
347347
return ForeignAccess.sendGetSize(executeNode, receiver);
348348
} catch (UnsupportedMessageException e) {
349-
throw raise(PythonErrorType.TypeError, e.getMessage());
349+
throw raise(PythonErrorType.TypeError, e);
350350
}
351351
}
352352
}
@@ -399,7 +399,7 @@ TruffleObject remove(TruffleObject receiver,
399399
try {
400400
return ForeignAccess.sendKeys(executeNode, receiver);
401401
} catch (UnsupportedMessageException e) {
402-
throw raise(PythonErrorType.TypeError, e.getMessage());
402+
throw raise(PythonErrorType.TypeError, e);
403403
}
404404
}
405405
}

0 commit comments

Comments
 (0)