|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * The Universal Permissive License (UPL), Version 1.0
|
|
46 | 46 | import com.oracle.graal.python.builtins.PythonBuiltinClassType;
|
47 | 47 | import com.oracle.graal.python.builtins.objects.PNone;
|
48 | 48 | import com.oracle.graal.python.builtins.objects.cext.PythonNativeClass;
|
49 |
| -import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.GetItemScalarNode; |
50 | 49 | import com.oracle.graal.python.builtins.objects.frame.PFrame;
|
51 | 50 | import com.oracle.graal.python.builtins.objects.object.PythonObject;
|
52 | 51 | import com.oracle.graal.python.builtins.objects.traceback.LazyTraceback;
|
53 | 52 | import com.oracle.graal.python.builtins.objects.traceback.PTraceback;
|
54 | 53 | import com.oracle.graal.python.builtins.objects.tuple.PTuple;
|
55 | 54 | import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
|
56 | 55 | import com.oracle.graal.python.builtins.objects.type.TypeNodes;
|
57 |
| -import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetNameNode; |
58 | 56 | import com.oracle.graal.python.lib.PyExceptionInstanceCheckNode;
|
59 | 57 | import com.oracle.graal.python.nodes.PRaiseNode;
|
60 | 58 | import com.oracle.graal.python.nodes.attributes.ReadAttributeFromPythonObjectNode;
|
61 | 59 | import com.oracle.graal.python.nodes.object.GetClassNode;
|
62 |
| -import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode; |
63 | 60 | import com.oracle.graal.python.nodes.util.CannotCastException;
|
64 | 61 | import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
|
65 | 62 | import com.oracle.graal.python.runtime.GilNode;
|
| 63 | +import com.oracle.graal.python.runtime.exception.ExceptionUtils; |
66 | 64 | import com.oracle.graal.python.runtime.exception.PException;
|
67 |
| -import com.oracle.graal.python.runtime.formatting.ErrorMessageFormatter; |
68 |
| -import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage; |
69 | 65 | import com.oracle.graal.python.util.PythonUtils;
|
70 | 66 | import com.oracle.truffle.api.CompilerAsserts;
|
71 |
| -import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; |
72 | 67 | import com.oracle.truffle.api.dsl.Bind;
|
73 | 68 | import com.oracle.truffle.api.dsl.Cached;
|
74 | 69 | import com.oracle.truffle.api.dsl.Cached.Exclusive;
|
@@ -235,36 +230,6 @@ public Object[] getMessageArgs() {
|
235 | 230 | return messageArgs != null ? messageArgs.clone() : PythonUtils.EMPTY_OBJECT_ARRAY;
|
236 | 231 | }
|
237 | 232 |
|
238 |
| - @TruffleBoundary |
239 |
| - public String getFormattedMessage() { |
240 |
| - final Object clazz = GetPythonObjectClassNode.executeUncached(this); |
241 |
| - String typeName = GetNameNode.doSlowPath(clazz).toJavaStringUncached(); |
242 |
| - if (args == null) { |
243 |
| - if (messageArgs != null && messageArgs.length > 0) { |
244 |
| - return typeName + ": " + ErrorMessageFormatter.format(messageFormat.toJavaStringUncached(), getMessageArgs()); |
245 |
| - } else if (hasMessageFormat) { |
246 |
| - return typeName + ": " + messageFormat.toJavaStringUncached(); |
247 |
| - } else { |
248 |
| - return typeName; |
249 |
| - } |
250 |
| - } else { |
251 |
| - SequenceStorage storage = args.getSequenceStorage(); |
252 |
| - if (storage.length() == 0) { |
253 |
| - return typeName; |
254 |
| - } else { |
255 |
| - StringBuilder builder = new StringBuilder(typeName); |
256 |
| - builder.append(": "); |
257 |
| - for (int i = 0; i < storage.length(); i++) { |
258 |
| - if (i > 0) { |
259 |
| - builder.append(", "); |
260 |
| - } |
261 |
| - builder.append(GetItemScalarNode.executeUncached(storage, i)); |
262 |
| - } |
263 |
| - return builder.toString(); |
264 |
| - } |
265 |
| - } |
266 |
| - } |
267 |
| - |
268 | 233 | @Override
|
269 | 234 | public String toString() {
|
270 | 235 | CompilerAsserts.neverPartOfCompilation();
|
@@ -384,7 +349,7 @@ boolean hasExceptionMessage() {
|
384 | 349 | String getExceptionMessage(@Shared("gil") @Cached GilNode gil) {
|
385 | 350 | boolean mustRelease = gil.acquire();
|
386 | 351 | try {
|
387 |
| - return getFormattedMessage(); |
| 352 | + return ExceptionUtils.getExceptionMessage(this); |
388 | 353 | } finally {
|
389 | 354 | gil.release(mustRelease);
|
390 | 355 | }
|
@@ -425,32 +390,21 @@ int getExceptionExitStatus(
|
425 | 390 | }
|
426 | 391 |
|
427 | 392 | @ExportMessage
|
428 |
| - boolean hasExceptionCause(@Shared("gil") @Cached GilNode gil) { |
429 |
| - boolean mustRelease = gil.acquire(); |
430 |
| - try { |
431 |
| - return cause != null || (!suppressContext && context != null); |
432 |
| - } finally { |
433 |
| - gil.release(mustRelease); |
434 |
| - } |
| 393 | + boolean hasExceptionCause() { |
| 394 | + return cause != null || !suppressContext && context != null; |
435 | 395 | }
|
436 | 396 |
|
437 | 397 | @ExportMessage
|
438 | 398 | Object getExceptionCause(
|
439 | 399 | @Bind("$node") Node inliningTarget,
|
440 |
| - @Exclusive @Cached InlinedBranchProfile unsupportedProfile, |
441 |
| - @Shared("gil") @Cached GilNode gil) throws UnsupportedMessageException { |
442 |
| - boolean mustRelease = gil.acquire(); |
443 |
| - try { |
444 |
| - if (cause != null) { |
445 |
| - return cause; |
446 |
| - } |
447 |
| - if (!suppressContext && context != null) { |
448 |
| - return context; |
449 |
| - } |
450 |
| - unsupportedProfile.enter(inliningTarget); |
451 |
| - throw UnsupportedMessageException.create(); |
452 |
| - } finally { |
453 |
| - gil.release(mustRelease); |
| 400 | + @Exclusive @Cached InlinedBranchProfile unsupportedProfile) throws UnsupportedMessageException { |
| 401 | + if (cause != null) { |
| 402 | + return cause; |
| 403 | + } |
| 404 | + if (!suppressContext && context != null) { |
| 405 | + return context; |
454 | 406 | }
|
| 407 | + unsupportedProfile.enter(inliningTarget); |
| 408 | + throw UnsupportedMessageException.create(); |
455 | 409 | }
|
456 | 410 | }
|
0 commit comments